From 5817acfb44b6cb54bb0ff4ea1f7995ac6f5ccd17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Bu=C3=9Fmann?= Date: Sat, 8 Oct 2016 23:18:29 +0200 Subject: [PATCH 1/2] Fixed bugs with selection of environment and added missing prepareToRender function --- src/plugins/pay-pal.ts | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/plugins/pay-pal.ts b/src/plugins/pay-pal.ts index 1627ee1f28..ecdc2bd7d6 100644 --- a/src/plugins/pay-pal.ts +++ b/src/plugins/pay-pal.ts @@ -31,23 +31,33 @@ import { Plugin, Cordova } from './plugin'; repo: 'https://github.com/paypal/PayPal-Cordova-Plugin' }) export class PayPal { + /** + * Retrieve the version of the PayPal iOS SDK library. Useful when contacting support. + */ + @Cordova() + static version(): Promise {return; } + /** * You must preconnect to PayPal to prepare the device for processing payments. * This improves the user experience, by making the presentation of the * UI faster. The preconnect is valid for a limited time, so * the recommended time to preconnect is on page load. * - * @param {String} environment available options are "PayPalEnvironmentNoNetwork", "PayPalEnvironmentProduction" and "PayPalEnvironmentSandbox" - * @param {PayPalConfiguration} configuration For Future Payments merchantName, merchantPrivacyPolicyURL and merchantUserAgreementURL must be set be set + * @param {PayPalEnvironment} clientIdsForEnvironments: set of client ids for environments */ @Cordova() - static init(environment: PayPalEnvironment, configuration?: PayPalConfiguration): Promise {return; } + static init(clientIdsForEnvironments: PayPalEnvironment): Promise {return; } /** - * Retreive the version of PayPal iOS SDK Library. - */ + * You must preconnect to PayPal to prepare the device for processing payments. + * This improves the user experience, by making the presentation of the UI faster. + * The preconnect is valid for a limited time, so the recommended time to preconnect is on page load. + * + * @param {String} environment: available options are "PayPalEnvironmentNoNetwork", "PayPalEnvironmentProduction" and "PayPalEnvironmentSandbox" + * @param {PayPalConfiguration} configuration: PayPalConfiguration object, for Future Payments merchantName, merchantPrivacyPolicyURL and merchantUserAgreementURL must be set be set + **/ @Cordova() - static version(): Promise {return; } + static prepareToRender(environment: string, configuration: PayPalConfiguration): Promise {return; } /** * Start PayPal UI to collect payment from the user. @@ -85,7 +95,6 @@ export class PayPal { **/ @Cordova() static renderProfileSharingUI(scopes: string[]): Promise {return; } - } export interface PayPalEnvironment { From fb0a612d38df00dbaf3bfe4b0572dead05a9e454 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Bu=C3=9Fmann?= Date: Sat, 8 Oct 2016 23:48:54 +0200 Subject: [PATCH 2/2] Updated PayPal usage example --- src/plugins/pay-pal.ts | 44 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/src/plugins/pay-pal.ts b/src/plugins/pay-pal.ts index ecdc2bd7d6..4b0b96975f 100644 --- a/src/plugins/pay-pal.ts +++ b/src/plugins/pay-pal.ts @@ -6,15 +6,47 @@ import { Plugin, Cordova } from './plugin'; * * @usage * ``` - * import {PayPal} from 'ionic-native'; + * import {PayPal, PayPalPayment, PayPalConfiguration} from "ionic-native"; * * PayPal.init({ - * "PayPalEnvironmentProduction": "YOUR_PRODUCTION_CLIENT_ID", - "PayPalEnvironmentSandbox": "YOUR_SANDBOX_CLIENT_ID" - }) - * .then(onSuccess) - * .catch(onError); + * "PayPalEnvironmentProduction": "YOUR_PRODUCTION_CLIENT_ID", + * "PayPalEnvironmentSandbox": "YOUR_SANDBOX_CLIENT_ID" + * }).then(() => { + * // Environments: PayPalEnvironmentNoNetwork, PayPalEnvironmentSandbox, PayPalEnvironmentProduction + * PayPal.prepareToRender('PayPalEnvironmentSandbox', new PayPalConfiguration({ + * // Only needed if you get an "Internal Service Error" after PayPal login! + * //payPalShippingAddressOption: 2 // PayPalShippingAddressOptionPayPal + * })).then(() => { + * let payment = new PayPalPayment('3.33', 'USD', 'Description', 'sale'); + * PayPal.renderSinglePaymentUI(payment).then(() => { + * // Successfully paid * + * // Example sandbox response + * // + * // { + * // "client": { + * // "environment": "sandbox", + * // "product_name": "PayPal iOS SDK", + * // "paypal_sdk_version": "2.16.0", + * // "platform": "iOS" + * // }, + * // "response_type": "payment", + * // "response": { + * // "id": "PAY-1AB23456CD789012EF34GHIJ", + * // "state": "approved", + * // "create_time": "2016-10-03T13:33:33Z", + * // "intent": "sale" + * // } + * // } + * }, () => { + * // Error or render dialog closed without being successful + * }); + * }, () => { + * // Error in configuration + * }); + * }, () => { + * // Error in initialization, maybe PayPal isn't supported or something else + * }); * ``` * @interfaces * PayPalEnvironment