Skip to content

Commit 9fe5c19

Browse files
authored
feat(paypal): add PayPal support (#491)
1 parent 76aa8a6 commit 9fe5c19

File tree

2 files changed

+181
-0
lines changed

2 files changed

+181
-0
lines changed

src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ import { NFC } from './plugins/nfc';
7373
import { OneSignal } from './plugins/onesignal';
7474
import { PhotoViewer } from './plugins/photo-viewer';
7575
import { ScreenOrientation } from './plugins/screen-orientation';
76+
import { PayPal } from './plugins/pay-pal';
7677
import { PinDialog } from './plugins/pin-dialog';
7778
import { PowerManagement } from './plugins/power-management';
7879
import { Printer } from './plugins/printer';
@@ -127,6 +128,7 @@ export * from './plugins/localnotifications';
127128
export * from './plugins/nfc';
128129
export * from './plugins/media';
129130
export * from './plugins/media-capture';
131+
export * from './plugins/pay-pal';
130132
export * from './plugins/native-page-transitions';
131133
export * from './plugins/printer';
132134
export * from './plugins/push';
@@ -267,6 +269,7 @@ window['IonicNative'] = {
267269
NativePageTransitions: NativePageTransitions,
268270
NativeStorage: NativeStorage,
269271
Network: Network,
272+
PayPal: PayPal,
270273
NFC: NFC,
271274
Printer: Printer,
272275
Push: Push,

src/plugins/pay-pal.ts

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
import {Plugin, Cordova} from './plugin';
2+
/**
3+
* @name PayPal
4+
* @description
5+
* PayPal plugin for Cordova/Ionic Applications
6+
*
7+
* @usage
8+
* ```
9+
* import {PayPal} from 'ionic-native';
10+
*
11+
* PayPal.init({
12+
* "PayPalEnvironmentProduction": "YOUR_PRODUCTION_CLIENT_ID",
13+
"PayPalEnvironmentSandbox": "YOUR_SANDBOX_CLIENT_ID"
14+
})
15+
* .then(onSuccess)
16+
* .catch(onError);
17+
*
18+
* ```
19+
*/
20+
@Plugin({
21+
plugin: 'com.paypal.cordova.mobilesdk',
22+
pluginRef: 'PayPalMobile',
23+
repo: 'https://github.com/paypal/PayPal-Cordova-Plugin'
24+
})
25+
export class PayPal {
26+
/**
27+
* You must preconnect to PayPal to prepare the device for processing payments.
28+
* This improves the user experience, by making the presentation of the
29+
* UI faster. The preconnect is valid for a limited time, so
30+
* the recommended time to preconnect is on page load.
31+
*
32+
* @param {String} environment: available options are "PayPalEnvironmentNoNetwork", "PayPalEnvironmentProduction" and "PayPalEnvironmentSandbox"
33+
* @param {PayPalConfiguration} configuration: For Future Payments merchantName, merchantPrivacyPolicyURL and merchantUserAgreementURL must be set be set
34+
*/
35+
@Cordova()
36+
static init(environment: PayPalEnvironment, configuration?: PayPalConfiguration): Promise<any> {return; }
37+
38+
/**
39+
* Retreive the version of PayPal iOS SDK Library.
40+
*/
41+
@Cordova()
42+
static version(): Promise<string> {return; }
43+
44+
/**
45+
* Start PayPal UI to collect payment from the user.
46+
* See https://developer.paypal.com/webapps/developer/docs/integration/mobile/ios-integration-guide/
47+
* for more documentation of the params.
48+
*
49+
* @param {PayPalPayment} payment: PayPalPayment object
50+
*/
51+
@Cordova()
52+
static renderSinglePaymentUI(payment: PayPalPayment): Promise<any> {return; }
53+
54+
/**
55+
* Once a user has consented to future payments, when the user subsequently initiates a PayPal payment
56+
* from their device to be completed by your server, PayPal uses a Correlation ID to verify that the
57+
* payment is originating from a valid, user-consented device+application.
58+
* This helps reduce fraud and decrease declines.
59+
* This method MUST be called prior to initiating a pre-consented payment (a "future payment") from a mobile device.
60+
* Pass the result to your server, to include in the payment request sent to PayPal.
61+
* Do not otherwise cache or store this value.
62+
*/
63+
@Cordova()
64+
static clientMetadataID(): Promise<any> {return; }
65+
66+
/**
67+
* Please Read Docs on Future Payments at https://github.com/paypal/PayPal-iOS-SDK#future-payments
68+
*/
69+
@Cordova()
70+
static renderFuturePaymentUI(): Promise<any> {return; }
71+
72+
/**
73+
* Please Read Docs on Profile Sharing at https://github.com/paypal/PayPal-iOS-SDK#profile-sharing
74+
*
75+
* @param {Array<string>} scopes: scopes Set of requested scope-values. Accepted scopes are: openid, profile, address, email, phone, futurepayments and paypalattributes
76+
* See https://developer.paypal.com/docs/integration/direct/identity/attributes/ for more details
77+
**/
78+
@Cordova()
79+
static renderProfileSharingUI(scopes: string[]): Promise<any> {return; }
80+
81+
}
82+
83+
export interface PayPalEnvironment {
84+
PayPalEnvironmentProduction: string;
85+
PayPalEnvironmentSandbox: string;
86+
}
87+
88+
export declare class PayPalPayment {
89+
/**
90+
* Convenience constructor.
91+
* Returns a PayPalPayment with the specified amount, currency code, and short description.
92+
* @param {String} amount: The amount of the payment.
93+
* @param {String} currencyCode: The ISO 4217 currency for the payment.
94+
* @param {String} shortDescription: A short descripton of the payment.
95+
* @param {String} intent: "Sale" for an immediate payment.
96+
*/
97+
new(amount: string, currencyCode: string, shortDescription: string, intent: string);
98+
99+
/**
100+
* Optional invoice number, for your tracking purposes. (up to 256 characters)
101+
* @param {String} invoiceNumber: The invoice number for the payment.
102+
*/
103+
invoiceNumber(invoiceNumber: string): void;
104+
105+
/**
106+
* Optional text, for your tracking purposes. (up to 256 characters)
107+
* @param {String} custom: The custom text for the payment.
108+
*/
109+
custom(custom: string): void;
110+
111+
/**
112+
* Optional text which will appear on the customer's credit card statement. (up to 22 characters)
113+
* @param {String} softDescriptor: credit card text for payment
114+
*/
115+
softDescriptor(softDescriptor: string): void;
116+
117+
/**
118+
* Optional Build Notation code ("BN code"), obtained from partnerprogram@paypal.com,
119+
* for your tracking purposes.
120+
* @param {String} bnCode: bnCode for payment
121+
*/
122+
bnCode(bnCode: string): void;
123+
124+
/**
125+
* Optional array of PayPalItem objects. @see PayPalItem
126+
* @note If you provide one or more items, be sure that the various prices correctly
127+
* sum to the payment `amount` or to `paymentDetails.subtotal`.
128+
* @param items {Array<PayPalItem>} Optional
129+
*/
130+
items(items?: any): void;
131+
132+
/**
133+
* Optional customer shipping address, if your app wishes to provide this to the SDK.
134+
* @note make sure to set `payPalShippingAddressOption` in PayPalConfiguration to 1 or 3.
135+
* @param {PayPalShippingAddress} shippingAddress: PayPalShippingAddress object
136+
*/
137+
shippingAddress(shippingAddress: PayPalShippingAddress): void;
138+
}
139+
140+
export interface PayPalConfigurationOptions {
141+
defaultUserEmail?: string;
142+
defaultUserPhoneCountryCode?: string;
143+
defaultUserPhoneNumber?: string;
144+
merchantName?: string;
145+
merchantPrivacyPolicyUrl?: string;
146+
merchantUserAgreementUrl?: string;
147+
acceptCreditCards?: boolean;
148+
payPalShippingAddressOption?: number;
149+
rememberUser?: boolean;
150+
languageOrLocale?: string;
151+
disableBlurWhenBackgrounding?: boolean;
152+
presentingInPopover?: boolean;
153+
forceDefaultsInSandbox?: boolean;
154+
sandboxUserPAssword?: string;
155+
sandboxUserPin?: string;
156+
}
157+
158+
export declare class PayPalConfiguration {
159+
/**
160+
* You use a PayPalConfiguration object to configure many aspects of how the SDK behaves.
161+
* see defaults for options available
162+
*/
163+
new(options: PayPalConfigurationOptions);
164+
}
165+
166+
export declare class PayPalShippingAddress {
167+
/**
168+
* See the documentation of the individual properties for more detail.
169+
* @param {String} recipientName: Name of the recipient at this address. 50 characters max.
170+
* @param {String} line1: Line 1 of the address (e.g., Number, street, etc). 100 characters max.
171+
* @param {String} Line 2 of the address (e.g., Suite, apt #, etc). 100 characters max. Optional.
172+
* @param {String} city: City name. 50 characters max.
173+
* @param {String} state: 2-letter code for US states, and the equivalent for other countries. 100 characters max. Required in certain countries.
174+
* @param {String} postalCode: ZIP code or equivalent is usually required for countries that have them. 20 characters max. Required in certain countries.
175+
* @param {String} countryCode: 2-letter country code. 2 characters max.
176+
*/
177+
new(recipientName: string, line1: string, line2: string, city: string, state: string, postalCode: string, countryCode: string);
178+
}

0 commit comments

Comments
 (0)