Skip to content

πŸ’° Use the PayPal Android-SDK 2.x with Titanium Mobile. πŸš€

Notifications You must be signed in to change notification settings

AppWerft/Ti.Paypal

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Ti.PayPal

Summary

Ti.PayPal is an open-source project to support the PayPal Android-SDK 2.x in Appcelerator's Titanium Mobile. The module currently supports the following API's:

  • Simple Payments
  • Future Payments
  • Merchant Configuration

Attention: is still under work!

This interface und README is a copy of Hans's Ti.PayPal for iOS.

Requirements

  • Titanium Mobile SDK 5.2.2.GA or later
  • Android API 22 or later

Download + Setup

Setup

Unpack the module and place it inside the modules/android/ folder of your project. Edit the modules section of your tiapp.xml file to include this module:

<modules>
    <module platform="android">de.appwerft.paypal</module>
</modules>

Add this into your application section of Manifest:

<service android:name="com.paypal.android.sdk.payments.PayPalService" android:exported="false"/>
<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"/>

If you use tiapp.xml you can ignore this step.

Optionally you can modify the theming (suppressing/coloring actionbar and/or navigationbar)

var PayPal = require("de.appwerft.paypal");
PayPal.initialize({
    clientIdSandbox: "AYXg7yzeFQG08l*************zHkfoBOCtoB50KeooDq2",
    clientIdProduction: "AYXg7yzeFQG08l*************zHkfoBOCtoB50KeooDq2",
    environment: PayPal.ENVIRONMENT_SANDBOX // or: ENVIRONMENT_PRODUCTION
});

Features

Simple Payment

A simple payment is used for do instant payments with items you define. Watch the events for updates on your transaction.

var configuration = PayPal.createConfiguration( {
    merchantName: "John Doe",
    merchantPrivacyPolicyURL: "http://google.com",
    merchantUserAgreementURL: "http://google.com",
    locale: "en" // Any ISO 639-1
});

var payment = PayPal.createPayment({
    // Required
    configuration: configuration,
    currencyCode: "USD",
    amount: 23.99, // Has to match the amount of your items if you set them
    shortDescription: "Your shopping trip at FooBar",
    intent: PayPal.PAYMENT_INTENT_SALE, // or: PAYMENT_INTENT_AUTHORIZE, PAYMENT_INTENT_ORDER

    // Optional, you can also just specify the amount
    items: [{
        name: "My item",
        price: 23.99,
        sku: "my-item",
        quantity: 1,
        currency: "USD" // Any ISO-4217
    }],
    shipping : 10.0
    tax : 123,10
});

payment.addEventListener("paymentDidCancel", function(e) {
    Ti.API.warn("paymentDidCancel");
});

payment.addEventListener("paymentDidComplete", function(e) {
    Ti.API.warn("paymentDidComplete");
});

`paymentWillComplete` is not available for Android

payment.showPaymentOverLay();	

Or compact:

var payment = PayPal.createPayment({
    // Required
    configuration : {
        merchantName: "John Doe",
        merchantPrivacyPolicyURL: "http://google.com",
        merchantUserAgreementURL: "http://google.com",
        locale: "en" // Any ISO 639-1
    },
    currencyCode: "USD",
    amount: 23.99, // Has to match the amount of your items if you set them
    shortDescription: "Your shopping trip at FooBar",
    intent: PayPal.PAYMENT_INTENT_SALE, // or: PAYMENT_INTENT_AUTHORIZE, PAYMENT_INTENT_ORDER
    items: [{
        name: "Titanium workshop",
        price: 900.00,
        sku: "12345",
        quantity: 1,
        currency: "EUR"     
    }],
    shipping : 10.0
    tax : 123,10
});

payment.addEventListener("paymentDidCancel", function(e) {
    Ti.API.warn("paymentDidCancel");
});

payment.addEventListener("paymentDidComplete", function(e) {
    Ti.API.warn("paymentDidComplete");
});

payment.addEventListener("authorization", function(e) {
    Ti.API.warn("authorization");
});

payment.showPaymentOverlay();	

Future Payment

A future payment is used to ask the buyer for the permission to charge his account later.

var payment = PayPal.createPayment({
    configuration: {
        merchantName: "John Doe",
        merchantPrivacyPolicyURL: "http://google.com",
        merchantUserAgreementURL: "http://google.com",
        locale: "en"
    },
    futurePayment : true
});

payment.addEventListener("futurePaymentDidCancel", function(e) {
    Ti.API.warn("futurePaymentDidCancel");
});

payment.addEventListener("futurePaymentWillComplete", function(e) {
    Ti.API.warn("futurePaymentWillComplete");
});

payment.addEventListener("futurePaymentDidComplete", function(e) {
    Ti.API.warn("futurePaymentDidComplete");
});

payment.show();	

Profile Sharing

Note: This API is currently work in progress! Profile sharing is used to share a user profile by defining different scopes that can be authorized. Available Scopes:

  • SCOPE_FUTURE_PAYMENTS
  • SCOPE_PROFILE
  • SCOPE_OPEN_ID
  • SCOPE_PAYPAL_ATTRIBUTES
  • SCOPE_EMAIL
  • SCOPE_ADDRESS
  • SCOPE_PHONE
var configuration = PayPal.createConfiguration({
    merchantName: "John Doe",
    merchantPrivacyPolicyURL: "http://google.com",
    merchantUserAgreementURL: "http://google.com",
    locale: "en"
});

var profile = PayPal.createProfileSharing({
    configuration: configuration,
    scopes: [PayPal.SCOPE_PROFILE, PayPal.SCOPE_EMAIL]
});

profile.addEventListener("profileSharingDidCancel", function(e) {
    Ti.API.warn("profileSharingDidCancel");
});

profile.addEventListener("profileSharingWillLogIn", function(e) {
    Ti.API.warn("profileSharingWillLogIn");
});

profile.addEventListener("profileSharingDidLogIn", function(e) {
    Ti.API.warn("profileSharingDidLogIn");
});

profile.show();

Example

For a full example covering all API's, check the demo in android/example/app.js.

Author

Rainer Schleevoigt (@appwerft / Web)

License

Apache 2.0

Contributing

Code contributions are greatly appreciated, please submit a new pull request!

About

πŸ’° Use the PayPal Android-SDK 2.x with Titanium Mobile. πŸš€

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages