Code Monkey home page Code Monkey logo

hansemannn.ti.paypal's Introduction

Ti.PayPal

Build Status License Contact

Summary

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

  • Simple Payments
  • Future Payments
  • Merchant Configuration

Note: This is the iOS version of Ti.PayPal. You might want to check appwert/ti.paypal for the Android equivalent ๐Ÿš€.

Requirements

  • Titanium Mobile SDK 5.2.0.GA or later
  • iOS 7.1 or later
  • Xcode 7.0 or later

Download + Setup

Download

Setup

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

<modules>
    <module platform="iphone">ti.paypal</module>
</modules>

Integrate the following snippet in your tiapp.xml. It is used to enable 1Password support that is used by the PayPal-SDK:

<ios>
    <plist>
        <dict>
            <key>LSApplicationQueriesSchemes</key>
            <array>
                <string>com.paypal.ppclient.touch.v1</string>
                <string>com.paypal.ppclient.touch.v2</string>
                <string>org-appextension-feature-password-management</string>
            </array>
        </dict>
    </plist>
</ios>

Initialize the module by setting the PayPal credentials which you can get from here.

var PayPal = require("ti.paypal");
PayPal.initialize({
    clientIdSandbox: "<YOUR_CLIENT_ID_SANDBOX>",
    clientIdProduction: "<YOUR_CLIENT_ID_PRODUCTION>",
    environment: PayPal.ENVIRONMENT_SANDBOX // or: ENVIRONMENT_PRODUCTION, or: ENVIRONMENT_NO_NETWORK
});

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 item1 = PayPal.createPaymentItem({
    name: "My item",
    price: 23.99,
    sku: "my-item",
    quantity: 1,
    currency: "USD" // Any ISO-4217
});

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",
    payeeEmail: "[email protected]", // Optional thirdparty receiver
    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: [item1]
});

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

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

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

payment.show();	

Future Payment

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

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

var payment = PayPal.createFuturePayment({
    configuration: configuration
});

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

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

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

payment.show();	

Profile Sharing

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");
    Ti.API.warn(e.authorization);
});

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

profile.show();

Example

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

Author

Hans Knoechel (@hansemannnn / Web)

License

Apache 2.0

Contributing

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

hansemannn.ti.paypal's People

Contributors

hansemannn avatar

Watchers

James Cloos avatar Brenton House avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.