-
Download the PayPal iOS SDK
-
Read the iOS Integration Guide for conceptual information that will be useful during integration.
-
Follow the "Initial setup" instructions in the iOS Integration Guide to add the required files, linker flags, frameworks, and acknowledgments to your app.
-
Add
PayPalMobilePGPlugin.[h|m]
to your project, in the Plugins group -
Copy
PayPalMobilePGPlugin.js
to your project'swww
folder -
Add the following to
config.xml
, for PhoneGap version 3.0+:<feature name="PayPalMobile"> <param name="ios-package" value="PayPalMobilePGPlugin" /> </feature>
for older versions under the
plugins
tag:<plugin name="PayPalMobile" value="PayPalMobilePGPlugin" />
// 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 envrionment 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, completionCallback, cancelCallback);
}