-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.d.ts
275 lines (274 loc) · 10.4 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
import { IonicNativePlugin } from '@ionic-native/core';
import { Observable } from 'rxjs';
export declare type IMakePayments = 'This device can make payments and has a supported card' | 'This device cannot make payments.' | 'This device can make payments but has no supported cards';
export declare type IShippingType = 'shipping' | 'delivery' | 'store' | 'service';
export declare type IBillingRequirement = 'none' | 'all' | 'postcode' | 'name' | 'email' | 'phone';
export declare type ITransactionStatus = 'success' | 'failure' | 'invalid-billing-address' | 'invalid-shipping-address' | 'invalid-shipping-contact' | 'require-pin' | 'incorrect-pin' | 'locked-pin';
export declare type ICompleteTransaction = 'Payment status applied.';
export declare type IUpdateItemsAndShippingStatus = 'Updated List Info' | 'Did you make a payment request?';
export declare type IMerchantCapabilities = '3ds' | 'credit' | 'debit' | 'emv';
export declare type ISupportedNetworks = 'visa' | 'amex' | 'discover' | 'masterCard';
export interface IPaymentResponse {
billingNameFirst?: string;
billingNameMiddle?: string;
billingNameLast?: string;
billingEmailAddress?: string;
billingSupplementarySubLocality?: string;
billingAddressStreet?: string;
billingAddressCity?: string;
billingAddressState?: string;
billingPostalCode?: string;
billingCountry?: string;
billingISOCountryCode?: string;
shippingNameFirst?: string;
shippingNameMiddle?: string;
shippingNameLast?: string;
shippingEmailAddress?: string;
shippingPhoneNumber?: string;
shippingSupplementarySubLocality?: string;
shippingAddressStreet?: string;
shippingAddressCity?: string;
shippingAddressState?: string;
shippingPostalCode?: string;
shippingCountry?: string;
shippingISOCountryCode?: string;
paymentData: string;
transactionIdentifier: string;
paymentMethodDisplayName?: string;
paymentMethodNetwork?: string;
paymentMethodTypeCard?: string;
}
export interface IOrderItem {
label: string;
amount: number;
}
export interface IShippingMethod {
identifier: string;
label: string;
detail: string;
amount: number;
}
export interface IOrderItemsAndShippingMethods {
items: IOrderItem[];
shippingMethods?: IShippingMethod[];
}
export interface IOrder extends IOrderItemsAndShippingMethods {
merchantIdentifier: string;
currencyCode: string;
countryCode: string;
billingAddressRequirement?: IBillingRequirement | IBillingRequirement[];
shippingAddressRequirement?: IBillingRequirement | IBillingRequirement[];
shippingType?: IShippingType;
merchantCapabilities?: IMerchantCapabilities | IMerchantCapabilities[];
supportedNetworks?: ISupportedNetworks | ISupportedNetworks[];
}
export interface ISelectedShippingContact {
shippingAddressCity: string;
shippingAddressState: string;
shippingPostalCode: string;
shippingISOCountryCode: string;
}
/**
* @name Apple Pay
* @description
* A dependency free Cordova plugin to provide Apple Pay functionality.
*
* @usage
* ```typescript
* import { ApplePay } from '@ionic-native/apple-pay/ngx';
*
*
* constructor(private applePay: ApplePay) { }
*
* ...
* async applePay() {
* // This block is optional -- only if you need to update order items/shipping
* // methods in response to shipping method selections
* this.applePay.startListeningForShippingContactSelection()
* .subscribe(async selection => {
* try {
* await this.applePay.updateItemsAndShippingMethods({
* items: getFromSelection(selection),
* shippingMethods: getFromSelection(selection),
* });
* }
* catch {
* // handle update items error
* }
* });
*
* try {
* const applePayTransaction = await this.applePay.makePaymentRequest({
* items,
* shippingMethods,
* merchantIdentifier,
* currencyCode,
* countryCode,
* billingAddressRequirement: ['name', 'email', 'phone'],
* shippingAddressRequirement: 'none',
* shippingType: 'shipping'
* });
*
* const transactionStatus = await completeTransactionWithMerchant(applePayTransaction);
* await this.applePay.completeLastTransaction(transactionStatus);
* } catch {
* // handle payment request error
* // Can also handle stop complete transaction but these should normally not occur
* }
*
* // only if you started listening before
* await this.applePay.stopListeningForShippingContactSelection();
* }
* ```
*/
export declare class ApplePayOriginal extends IonicNativePlugin {
/**
* Detects if the current device supports Apple Pay and has any capable cards registered.
* @return {Promise<IMakePayments>} Returns a promise
*
* @usage
* try {
* const message = await this.applePay.canMakePayments();
* // Apple Pay is enabled and a supported card is setup. Expect:
* // 'This device can make payments and has a supported card'
* } catch (message) {
* // There is an issue, examine the message to see the details, will be:
* // 'This device cannot make payments.''
* // 'This device can make payments but has no supported cards'
* }
*/
canMakePayments(): Promise<IMakePayments>;
/**
* Starts listening for shipping contact selection changes
* Any time the user selects shipping contact, this callback will fire.
* You *must* call `updateItemsAndShippingMethods` in response or else the
* user will not be able to process payment.
* @return {Observable<ISelectedShippingContact>} emits with shipping contact information on
* shipping contact selection changes
*/
startListeningForShippingContactSelection(): Observable<ISelectedShippingContact>;
/**
* Stops listening for shipping contact selection changes
* @return {Promise} whether stop listening was successful. This should
* really only fail if this is called without starting listening
*/
stopListeningForShippingContactSelection(): Promise<boolean>;
/**
* Update the list of pay sheet items and shipping methods in response to
* a shipping contact selection event. This *must* be called in response to
* any shipping contact selection event or else the user will not be able
* to complete a transaction on the pay sheet. Do not call without
* subscribing to shipping contact selection events first
*
* @param {IOrderItemsAndShippingMethods} list `items` and `shippingMethods` properties.
* @returns {Promise<IUpdateItemsAndShippingStatus>}
*
* @usage
* this.applePay.startListeningForShippingContactSelection().pluck('shippingAddressState').subscribe(shippingAddressState => {
* let shippingMethods;
* if ('AK' === shippingAddressState) {
* shippingMethods = [{
* identifier: 'Alaska',
* label: 'Alaska',
* detail: 'For shipping to Alaska',
* amount: 9.99
* },];
* } else {
* shippingMethods = [{
* identifier: 'Continental',
* label: 'Continental',
* detail: 'For shipping Continentally',
* amount: 5.99
* }];
* }
* this.paySheetItems.shippingCost = {
* label: 'Shipping Cost',
* amount: shippingMethod[0].amount
* }
* this.applePay.updateItemsAndShippingMethods(this.paySheetItems, shippingMethods);
* });
*/
updateItemsAndShippingMethods(list: IOrderItemsAndShippingMethods): Promise<IUpdateItemsAndShippingStatus>;
/**
* Request a payment with Apple Pay
*
* @param {IOrder} order
* @return {Promise<IPaymentResponse>} Returns a promise that resolves when something happens
*
* @usage
* try {
* const paymentResponse = this.applePay.makePaymentRequest({
* items: [
* {
* label: '3 x Basket Items',
* amount: 49.99
* },
* {
* label: 'Next Day Delivery',
* amount: 3.99
* },
* {
* label: 'My Fashion Company',
* amount: 53.98
* }
* ],
* shippingMethods: [
* {
* identifier: 'NextDay',
* label: 'NextDay',
* detail: 'Arrives tomorrow by 5pm.',
* amount: 3.99
* },
* {
* identifier: 'Standard',
* label: 'Standard',
* detail: 'Arrive by Friday.',
* amount: 4.99
* },
* {
* identifier: 'SaturdayDelivery',
* label: 'Saturday',
* detail: 'Arrive by 5pm this Saturday.',
* amount: 6.99
* }
* ],
* merchantIdentifier: 'merchant.apple.test',
* currencyCode: 'GBP',
* countryCode: 'GB',
* billingAddressRequirement: 'none',
* shippingAddressRequirement: 'none',
* shippingType: 'shipping',
* });
*
* // The user has authorized the payment.
*
* // Handle the token, asynchronously, i.e. pass to your merchant bank to
* // action the payment, then once finished, depending on the outcome:
*
* // Here is an example implementation:
*
* const captureStatus = await MyPaymentProvider.authorizeApplePayToken(paymentResponse.paymentData);
* await this.applePay.completeLastTransaction('success');
* }
* catch (err) {
* if (isPaymentAuthError(err)) {
* this.completeLastTransaction('failure');
* }
* else {
* // Failed to open pay sheet or user canceled payment
* }
* }
*/
makePaymentRequest(order: IOrder): Promise<IPaymentResponse>;
/**
* Once the makePaymentRequest has been resolved successfully, the device will be waiting for a completion event.
* This means, that the application must proceed with the token authorization and return a success, failure,
* or other validation error. Once this has been passed back, the Apple Pay sheet will be dismissed via an animation.
*
* @param {ITransactionStatus} complete
* @return {Promise<ICompleteTransaction>} Returns a promise that resolves after confirmation of payment authorization completion
*
*/
completeLastTransaction(complete: ITransactionStatus): Promise<ICompleteTransaction>;
}
export declare const ApplePay: ApplePayOriginal;