diff --git a/src/plugins/pay-pal.ts b/src/plugins/pay-pal.ts index 32c70fe8b..0fdc2a862 100644 --- a/src/plugins/pay-pal.ts +++ b/src/plugins/pay-pal.ts @@ -16,6 +16,13 @@ import { Plugin, Cordova } from './plugin'; * .catch(onError); * * ``` + * @interfaces + * PayPalEnvironment + * PayPalPayment + * PayPAlItem + * PayPalPaymentDetails + * PayPalConfigurationOptions + * PayPalShippingAddress */ @Plugin({ plugin: 'com.paypal.cordova.mobilesdk', @@ -84,101 +91,304 @@ export interface PayPalEnvironment { PayPalEnvironmentProduction: string; PayPalEnvironmentSandbox: string; } -/** - * @private - */ -export declare class PayPalPayment { +export declare var PayPalPayment: { /** * Convenience constructor. * Returns a PayPalPayment with the specified amount, currency code, and short description. * @param {String} amount: The amount of the payment. * @param {String} currencyCode: The ISO 4217 currency for the payment. - * @param {String} shortDescription: A short descripton of the payment. + * @param {String} shortDescription: A short description of the payment. * @param {String} intent: "Sale" for an immediate payment. */ - new(amount: string, currencyCode: string, shortDescription: string, intent: string); - + new(amount: string, currencyCode: string, shortDescription: string, intent: string): PayPalPayment; +}; +/** + * @private + */ +export interface PayPalPayment { /** - * Optional invoice number, for your tracking purposes. (up to 256 characters) - * @param {String} invoiceNumber: The invoice number for the payment. + * The amount of the payment. */ - invoiceNumber(invoiceNumber: string): void; - + amount: string; /** - * Optional text, for your tracking purposes. (up to 256 characters) - * @param {String} custom: The custom text for the payment. + * The ISO 4217 currency for the payment. */ - custom(custom: string): void; - + currencyCode: string; /** - * Optional text which will appear on the customer's credit card statement. (up to 22 characters) - * @param {String} softDescriptor: credit card text for payment + * A short description of the payment. */ - softDescriptor(softDescriptor: string): void; - + shortDescription: string; + /** + * "Sale" for an immediate payment. + */ + intent: string; /** * Optional Build Notation code ("BN code"), obtained from partnerprogram@paypal.com, * for your tracking purposes. - * @param {String} bnCode: bnCode for payment */ - bnCode(bnCode: string): void; + bnCode: string; + /** + * Optional invoice number, for your tracking purposes. (up to 256 characters) + */ + invoiceNumber: string; /** - * Optional array of PayPalItem objects. @see PayPalItem - * @note If you provide one or more items, be sure that the various prices correctly - * sum to the payment `amount` or to `paymentDetails.subtotal`. - * @param items {Array} Optional + * Optional text, for your tracking purposes. (up to 256 characters) */ - items(items?: any): void; + custom: string; + + /** + * Optional text which will appear on the customer's credit card statement. (up to 22 characters) + */ + softDescriptor: string; + + /** + * Optional array of PayPalItem objects. + */ + items: string; /** * Optional customer shipping address, if your app wishes to provide this to the SDK. - * @note make sure to set `payPalShippingAddressOption` in PayPalConfiguration to 1 or 3. - * @param {PayPalShippingAddress} shippingAddress: PayPalShippingAddress object */ - shippingAddress(shippingAddress: PayPalShippingAddress): void; + shippingAddress: string; } +export interface PayPalItem { + /** + * Name of the item. 127 characters max + */ + name: string; + /** + * Number of units. 10 characters max. + */ + quantity: number; + /** + * Unit price for this item 10 characters max. + */ + price: string; + /** + * ISO standard currency code. + */ + currency: string; + /** + * The stock keeping unit for this item. 50 characters max (optional) + */ + sku: string; +} + +export declare var PayPalItem: { + /** + * The PayPalItem class defines an optional itemization for a payment. + * @see https://developer.paypal.com/docs/api/#item-object for more details. + * @param {String} name: Name of the item. 127 characters max + * @param {Number} quantity: Number of units. 10 characters max. + * @param {String} price: Unit price for this item 10 characters max. + * May be negative for "coupon" etc + * @param {String} currency: ISO standard currency code. + * @param {String} sku: The stock keeping unit for this item. 50 characters max (optional) + */ + new(name: string, quantity: number, price: string, currency: string, sku: string): PayPalItem; +}; + +export interface PayPalPaymentDetails { + /** + * Sub-total (amount) of items being paid for. 10 characters max with support for 2 decimal places. + */ + subtotal: string; + /** + * Amount charged for shipping. 10 characters max with support for 2 decimal places. + */ + shipping: string; + /** + * Amount charged for tax. 10 characters max with support for 2 decimal places. + */ + tax: string; +} + +export declare var PayPalPaymentDetails: { + /** + * The PayPalPaymentDetails class defines optional amount details. + * @param {String} subtotal: Sub-total (amount) of items being paid for. 10 characters max with support for 2 decimal places. + * @param {String} shipping: Amount charged for shipping. 10 characters max with support for 2 decimal places. + * @param {String} tax: Amount charged for tax. 10 characters max with support for 2 decimal places. + */ + new(subtotal: string, shipping: string, tax: string): PayPalPaymentDetails; +}; + +/** + * @private + */ export interface PayPalConfigurationOptions { + /** + * Will be overridden by email used in most recent PayPal login. + */ defaultUserEmail?: string; + /** + * Will be overridden by phone country code used in most recent PayPal login + */ defaultUserPhoneCountryCode?: string; + /** + * Will be overridden by phone number used in most recent PayPal login. + */ defaultUserPhoneNumber?: string; + /** + * Your company name, as it should be displayed to the user when requesting consent via a PayPalFuturePaymentViewController. + */ merchantName?: string; + /** + * URL of your company's privacy policy, which will be offered to the user when requesting consent via a PayPalFuturePaymentViewController. + */ merchantPrivacyPolicyUrl?: string; + /** + * URL of your company's user agreement, which will be offered to the user when requesting consent via a PayPalFuturePaymentViewController. + */ merchantUserAgreementUrl?: string; + /** + * If set to NO, the SDK will only support paying with PayPal, not with credit cards. + * This applies only to single payments (via PayPalPaymentViewController). + * Future payments (via PayPalFuturePaymentViewController) always use PayPal. + * Defaults to true + */ acceptCreditCards?: boolean; + /** + * For single payments, options for the shipping address. + * - 0 - PayPalShippingAddressOptionNone: no shipping address applies. + * - 1 - PayPalShippingAddressOptionProvided: shipping address will be provided by your app, + * in the shippingAddress property of PayPalPayment. + * - 2 - PayPalShippingAddressOptionPayPal: user will choose from shipping addresses on file + * for their PayPal account. + * - 3 - PayPalShippingAddressOptionBoth: user will choose from the shipping address provided by your app, + * in the shippingAddress property of PayPalPayment, plus the shipping addresses on file for the user's PayPal account. + * Defaults to 0 (PayPalShippingAddressOptionNone). + */ payPalShippingAddressOption?: number; + /** + * If set to YES, then if the user pays via their PayPal account, + * the SDK will remember the user's PayPal username or phone number; + * if the user pays via their credit card, then the SDK will remember + * the PayPal Vault token representing the user's credit card. + * + * If set to NO, then any previously-remembered username, phone number, or + * credit card token will be erased, and subsequent payment information will + * not be remembered. + * + * Defaults to YES. + */ rememberUser?: boolean; + /** + * If not set, or if set to nil, defaults to the device's current language setting. + * + * Can be specified as a language code ("en", "fr", "zh-Hans", etc.) or as a locale ("en_AU", "fr_FR", "zh-Hant_HK", etc.). + * If the library does not contain localized strings for a specified locale, then will fall back to the language. E.g., "es_CO" -> "es". + * If the library does not contain localized strings for a specified language, then will fall back to American English. + * + * If you specify only a language code, and that code matches the device's currently preferred language, + * then the library will attempt to use the device's current region as well. + * E.g., specifying "en" on a device set to "English" and "United Kingdom" will result in "en_GB". + */ languageOrLocale?: string; + /** + * Normally, the SDK blurs the screen when the app is backgrounded, + * to obscure credit card or PayPal account details in the iOS-saved screenshot. + * If your app already does its own blurring upon backgrounding, you might choose to disable this. + * Defaults to NO. + */ disableBlurWhenBackgrounding?: boolean; + /** + * If you will present the SDK's view controller within a popover, then set this property to YES. + * Defaults to NO. (iOS only) + */ presentingInPopover?: boolean; + /** + * Sandbox credentials can be difficult to type on a mobile device. Setting this flag to YES will + * cause the sandboxUserPassword and sandboxUserPin to always be pre-populated into login fields. + */ forceDefaultsInSandbox?: boolean; - sandboxUserPAssword?: string; + /** + * Password to use for sandbox if 'forceDefaultsInSandbox' is set. + */ + sandboxUserPassword?: string; + /** + * PIN to use for sandbox if 'forceDefaultsInSandbox' is set. + */ sandboxUserPin?: string; } /** * @private */ -export declare class PayPalConfiguration { +export declare var PayPalConfiguration: { /** * You use a PayPalConfiguration object to configure many aspects of how the SDK behaves. * see defaults for options available */ - new(options: PayPalConfigurationOptions); + new(options: PayPalConfigurationOptions): PayPalConfiguration; +}; +/** + * @private + */ +export interface PayPalConfiguration { + defaultUserEmail: string; + defaultUserPhoneCountryCode: string; + defaultUserPhoneNumber: string; + merchantName: string; + merchantPrivacyPolicyUrl: string; + merchantUserAgreementUrl: string; + acceptCreditCards: boolean; + payPalShippingAddressOption: number; + rememberUser: boolean; + languageOrLocale: string; + disableBlurWhenBackgrounding: boolean; + presentingInPopover: boolean; + forceDefaultsInSandbox: boolean; + sandboxUserPassword: string; + sandboxUserPin: string; } /** * @private */ -export declare class PayPalShippingAddress { +export declare var PayPalShippingAddress: { /** * See the documentation of the individual properties for more detail. * @param {String} recipientName: Name of the recipient at this address. 50 characters max. * @param {String} line1: Line 1 of the address (e.g., Number, street, etc). 100 characters max. - * @param {String} Line 2 of the address (e.g., Suite, apt #, etc). 100 characters max. Optional. + * @param {String} line2: Line 2 of the address (e.g., Suite, apt #, etc). 100 characters max. Optional. * @param {String} city: City name. 50 characters max. * @param {String} state: 2-letter code for US states, and the equivalent for other countries. 100 characters max. Required in certain countries. * @param {String} postalCode: ZIP code or equivalent is usually required for countries that have them. 20 characters max. Required in certain countries. * @param {String} countryCode: 2-letter country code. 2 characters max. */ - new(recipientName: string, line1: string, line2: string, city: string, state: string, postalCode: string, countryCode: string); + new(recipientName: string, line1: string, line2: string, city: string, state: string, postalCode: string, countryCode: string): PayPalShippingAddress; +}; +/** + * @private + */ +export interface PayPalShippingAddress { + /** + * Name of the recipient at this address. 50 characters max. + */ + recipientName: string; + /** + * Line 1 of the address (e.g., Number, street, etc). 100 characters max. + */ + line1: string; + /** + * Line 2 of the address (e.g., Suite, apt #, etc). 100 characters max. Optional. + */ + line2: string; + /** + * City name. 50 characters max. + */ + city: string; + /** + * 2-letter code for US states, and the equivalent for other countries. 100 characters max. Required in certain countries. + */ + state: string; + /** + * ZIP code or equivalent is usually required for countries that have them. 20 characters max. Required in certain countries. + */ + postalCode: string; + /** + * 2-letter country code. 2 characters max. + */ + countryCode: string; }