Skip to content

timosaikkonen/PayPal-Android-SDK-PhoneGap

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

PayPal Android SDK PhoneGap Plug-in

Integration

  1. Download the PayPal Android SDK.

  2. Read the Android Integration Guide for conceptual information that will be useful during integration.

  3. Follow the "Initial setup" instructions in the Android Integration Guide to add the required files, acknowledgments and AndroidManifest.xml modifications to your app.

  4. Add PayPalMobilePGPlugin.java to your project, in src/com/paypal/android/sdk/phonegap.

  5. Copy PayPalMobilePGPlugin.js to your project's www/js folder.

  6. Add the following to res/xml/config.xml for PhoneGap version 3.0+:

     <feature name="PayPalMobile">
       <param name="android-package" value="com.paypal.android.sdk.phonegap.PayPalMobilePGPlugin" />
     </feature>

    for older versions under the plugins tag:

    <plugin name="PayPalMobile" value="com.paypal.android.sdk.phonegap.PayPalMobilePGPlugin" />

Sample code

// for simplicity we have defined a simple buyButton in our index.html
// `<button id="buyButton" disabled>Buy Now!</button>`
// and we defined a simple onclick function in our `deviceready` event
var buyButton = document.getElementById("buyButton");
buyButton.onclick = function(e) {

  // See PayPalMobilePGPlugin.js for full documentation
  // set environment you want to use
  window.plugins.PayPalMobile.setEnvironment("PayPalEnvironmentNoNetwork");

  // create a PayPalPayment object, usually you would pass parameters dynamically
  var payment = new PayPalPayment("1.99", "USD", "Awesome saws");
  
  // define a callback when payment has been completed
  var completionCallback = function(proofOfPayment) {
    // TODO: Send this result to the server for verification;
    // see https://developer.paypal.com/webapps/developer/docs/integration/mobile/verify-mobile-payment/ for details.
    console.log("Proof of payment: " + JSON.stringify(proofOfPayment));
  }

  // define a callback if payment has been canceled
  var cancelCallback = function(reason) {
    console.log("Payment cancelled: " + reason);
  }
  
  // launch UI, the PayPal UI will be present on screen until user cancels it or payment completed
  window.plugins.PayPalMobile.presentPaymentUI("YOUR_CLIENT_ID", "YOUR_PAYPAL_EMAIL_ADDRESS", "[email protected]", payment, false, completionCallback, cancelCallback);
}

About

PhoneGap plugin for the PayPal Android SDK

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 56.8%
  • JavaScript 43.2%