Visit the free getting started tutorials on nativescript.org for JavaScript or Angular.
Kindly note that we filter out plugins that:
package.json
$ tns plugin add nativescript-paypal
NativeScript module for implementing simple PayPal checkouts using official SDK.
MIT license
Run
tns plugin add nativescript-paypal
inside your app project to install the module.
Keep sure to define the following permissions, activities and other data in your manifest file:
<?xml version="1.0" encoding="UTF-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.CAMERA" /> <uses-permission android:name="android.permission.VIBRATE" /> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> <uses-feature android:name="android.hardware.camera" android:required="false" /> <uses-feature android:name="android.hardware.camera.autofocus" android:required="false" /> <application> <activity android:name="com.paypal.android.sdk.payments.PaymentActivity" /> <activity android:name="com.paypal.android.sdk.payments.LoginActivity" /> <activity android:name="com.paypal.android.sdk.payments.PaymentMethodActivity" /> <activity android:name="com.paypal.android.sdk.payments.PaymentConfirmActivity" /> <activity android:name="com.paypal.android.sdk.payments.PayPalFuturePaymentActivity" /> <activity android:name="com.paypal.android.sdk.payments.FuturePaymentConsentActivity" /> <activity android:name="com.paypal.android.sdk.payments.FuturePaymentInfoActivity" /> <activity android:name="io.card.payment.DataEntryActivity" /> <service android:name="com.paypal.android.sdk.payments.PayPalService" android:exported="false" /> </application> </manifest>
Keep sure to have a reference to the PayPal SDK in your app/App_Resources/Android/app.gradle file of your project.
app/App_Resources/Android/app.gradle
dependencies { // PayPal compile 'com.paypal.sdk:paypal-android-sdk:2.14.2' }
For quick start have a look at the demo/app/main-view-model.js file of the demo app to learn how it works.
Otherwise ...
Include the module in your code-behind:
var PayPal = require("nativescript-paypal");
Initialize the environment:
function onPageLoaded(args) { PayPal.init({ clientId: '<YOUR-CLIENT-ID>' }); } exports.onPageLoaded = onPageLoaded;
The (optional) object that is submitted to the PayPal.init function has the following structure:
PayPal.init
(true)
0
ENVIRONMENT_SANDBOX
1
ENVIRONMENT_PRODUCTION
2
ENVIRONMENT_NO_NETWORK
230958624
The account object has the following structure:
account
The defaults object has the following structure:
defaults
function buyProduct(args) { // configure var payment = PayPal.newPayment() .setDescription('My product') .setAmount(59.79); // start checkout / payment payment.start(function(cbResult) { switch (cbResult.code) { case 0: // SUCCESS // pay key is stored in 'cbResult.key' break; case 1: // operation was CANCELLED break; case -1: // checkout FAILED break; case -2: // "unhandled exception" break; } }); } exports.buyProduct = buyProduct;
The payment object that is created by PayPal.newPayment function has the following structure.
payment
PayPal.newPayment
var a = payment.getAmount();
var bc = payment.getBnCode();
var c = payment.getCurrency();
var c = payment.getCustom();
var d = payment.getDescription();
var d = payment.getDetails();
var i = payment.getInvoiceNumber();
payment.setAmount(1.25);
payment.setBnCode('Your BN Code');
payment.setCurrency('EUR');
payment.setCustom('MY-PRODUCT-ID');
payment.setDetails(4.95, 199.99, 1.19);
payment.setDescription('This is really awesom!');
payment.setInvoiceNumber('MY_INVOICE-666');
The callback that is submitted to the payment.start method receives an object with the following properties:
payment.start
-3
-2
-1
3
code
If you want to get the logging output of the module, you can use PayPal.addLogger function to add a callback that receives a message from the module:
PayPal.addLogger
PayPal.addLogger(function(msg) { console.log('[nativescript-paypal]: ' + msg); });
Popularity metric based on:
Quality metric based on:
Maintenance metric based on: