-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ios.js
804 lines (804 loc) · 30.6 KB
/
index.ios.js
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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
import { Frame, Utils, Application } from '@nativescript/core';
import { BankAccountHolderType, BankAccountStatus, CardBrand, CardFunding, CreditCardViewBase, GetBrand, isUSZipRequiredProperty, PaymentMethodType, showPostalCodeProperty } from './common';
import { PaymentMethodCard } from './paymentMethod';
import { Source } from './source';
export { init } from './utils';
export class Address {
constructor(card) {
this.ios = card;
}
static fromNative(card) {
return new Address(card);
}
set country(value) {
this.ios.country = value;
}
get country() {
return this.ios.country;
}
set postalCode(value) {
this.ios.postalCode = value;
}
get postalCode() {
return this.ios.postalCode;
}
set state(value) {
this.ios.state = value;
}
get state() {
return this.ios.state;
}
set line1(value) {
this.ios.line1 = value;
}
get line1() {
return this.ios.line1;
}
set line2(value) {
this.ios.line2 = value;
}
get line2() {
return this.ios.line2;
}
set city(value) {
this.ios.city = value;
}
get city() {
return this.ios.city;
}
get email() {
return this.ios.email;
}
set email(value) {
this.ios.email = value;
}
get name() {
return this.ios.name;
}
set name(value) {
this.ios.name = value;
}
get phone() {
return this.ios.phone;
}
set phone(value) {
this.ios.phone = value;
}
}
function toBankHolderType(account) {
switch (account) {
case 1 /* STPBankAccountHolderType.Company */:
return BankAccountHolderType.Company;
case 0 /* STPBankAccountHolderType.Individual */:
return BankAccountHolderType.Individual;
}
}
function toBankStatus(status) {
switch (status) {
case 4 /* STPBankAccountStatus.Errored */:
return BankAccountStatus.Errored;
case 0 /* STPBankAccountStatus.New */:
return BankAccountStatus.New;
case 1 /* STPBankAccountStatus.Validated */:
return BankAccountStatus.Validated;
case 3 /* STPBankAccountStatus.VerificationFailed */:
return BankAccountStatus.VerificationFailed;
case 2 /* STPBankAccountStatus.Verified */:
return BankAccountStatus.Verified;
}
}
export class BankAccount {
constructor(bankAccount) {
this.accountHolderName = bankAccount.accountHolderName;
this.accountHolderType = toBankHolderType(bankAccount.accountHolderType);
this.bankName = bankAccount.bankName;
this.country = bankAccount.country;
this.fingerprint = bankAccount.fingerprint;
this.last4 = bankAccount.last4;
this.routingNumber = bankAccount.routingNumber;
this.status = toBankStatus(bankAccount.status);
}
static fromNative(bankAccount) {
if (bankAccount) {
return new BankAccount(bankAccount);
}
return null;
}
}
export class Token {
constructor(token) {
this.id = token.tokenId;
this.bankAccount = BankAccount.fromNative(token.bankAccount);
this.card = Card.fromNative(token.card);
this.created = new Date(token.created);
this.liveMode = token.livemode;
this.ios = token;
}
static fromNative(token) {
return new Token(token);
}
}
export function handleOpenURL(url) {
return StripeAPI.handleStripeURLCallbackWithURL(url);
}
export function handleContinueUserActivity(userActivity) {
if (userActivity.activityType === NSUserActivityTypeBrowsingWeb) {
if (userActivity.webpageURL) {
return StripeAPI.handleStripeURLCallbackWithURL(userActivity.webpageURL);
}
}
return false;
}
export class StripeThreeDSUICustomization {
// eslint-disable-next-line @typescript-eslint/no-empty-function
static init() { }
}
export class Stripe {
constructor(apiKey) {
STPPaymentConfiguration.sharedConfiguration.publishableKey = apiKey;
}
setStripeAccount(accountId) {
STPAPIClient.sharedClient.stripeAccount = accountId;
STPPaymentConfiguration.sharedConfiguration.stripeAccount = accountId;
}
createCardToken(card, cb) {
if (!card) {
if (typeof cb === 'function') {
cb(new Error('Invalid card'), null);
}
return;
}
const apiClient = STPAPIClient.sharedClient;
apiClient.createTokenWithCardCompletion(card.native, callback(cb, (token) => Token.fromNative(token)));
}
createSource(card, cb) {
if (!card) {
if (typeof cb === 'function') {
cb(new Error('Invalid card'), null);
}
return;
}
const sourceParams = STPSourceParams.cardParamsWithCard(card.native);
const apiClient = STPAPIClient.sharedClient;
apiClient.createSourceWithParamsCompletion(sourceParams, callback(cb, (source) => Source.fromNative(source)));
}
createPaymentMethod(card, cb) {
if (!card) {
if (typeof cb === 'function') {
cb(new Error('Invalid card'), null);
}
return;
}
try {
const apiClient = STPAPIClient.sharedClient;
const cardParams = STPPaymentMethodCardParams.alloc().initWithCardSourceParams(card.native);
const billing = STPPaymentMethodBillingDetails.alloc().init();
billing.address = STPPaymentMethodAddress.alloc().initWithAddress(card.address.ios);
const params = STPPaymentMethodParams.paramsWithCardBillingDetailsMetadata(cardParams, billing, null);
apiClient.createPaymentMethodWithParamsCompletion(params, callback(cb, (pm) => PaymentMethod.fromNative(pm)));
}
catch (e) {
if (typeof cb === 'function') {
cb(new Error(e.localizedDescription), null);
}
}
}
retrievePaymentIntent(clientSecret, cb) {
const apiClient = STPAPIClient.sharedClient;
apiClient.retrievePaymentIntentWithClientSecretCompletion(clientSecret, callback(cb, (pi) => StripePaymentIntent.fromNative(pi)));
}
confirmSetupIntent(paymentMethodId, clientSecret, cb) {
STPPaymentHandler.sharedHandler.confirmSetupIntentWithAuthenticationContextCompletion(new StripeSetupIntentParams(paymentMethodId, clientSecret).native, this._getAuthentificationContext(), (status, si, error) => {
if (error) {
cb(new Error(error.localizedDescription), null);
}
else {
cb(null, StripeSetupIntent.fromNative(si));
}
});
}
authenticateSetupIntent(clientSecret, returnUrl, cb) {
STPPaymentHandler.sharedHandler.handleNextActionForSetupIntentWithAuthenticationContextReturnURLCompletion(clientSecret, this._getAuthentificationContext(), returnUrl, (status, pi, error) => {
if (error) {
cb(new Error(error.localizedDescription), null);
}
else {
cb(null, StripeSetupIntent.fromNative(pi));
}
});
}
confirmPaymentIntent(params, cb) {
STPPaymentHandler.sharedHandler.confirmPaymentWithAuthenticationContextCompletion(params.native, this._getAuthentificationContext(), (status, pi, error) => {
if (error) {
cb(new Error(error.localizedDescription), null);
}
else {
cb(null, StripePaymentIntent.fromNative(pi));
}
});
}
authenticatePaymentIntent(clientSecret, returnUrl, cb) {
STPPaymentHandler.sharedHandler.handleNextActionForPaymentWithAuthenticationContextReturnURLCompletion(clientSecret, this._getAuthentificationContext(), returnUrl, (status, pi, error) => {
if (error) {
cb(new Error(error.localizedDescription), null);
}
else {
cb(null, StripePaymentIntent.fromNative(pi));
}
});
}
get _rootViewController() {
const keyWindow = UIApplication.sharedApplication.keyWindow;
return keyWindow != null ? keyWindow.rootViewController : undefined;
}
findTopViewController(root) {
const presented = root.presentedViewController;
if (presented !== null) {
return this.findTopViewController(presented);
}
if (root instanceof UISplitViewController) {
const last = root.viewControllers.lastObject;
if (last == null) {
return root;
}
return this.findTopViewController(last);
}
else if (root instanceof UINavigationController) {
const top = root.topViewController;
if (top == null) {
return root;
}
return this.findTopViewController(top);
}
else if (root instanceof UITabBarController) {
const selected = root.selectedViewController;
if (selected == null) {
return root;
}
return this.findTopViewController(selected);
}
else {
if (presented === root.presentedViewController) {
return presented;
}
else {
return root;
}
}
}
_getAuthentificationContext() {
const rootVC = this.findTopViewController(Frame.topmost().currentPage.ios) || this._rootViewController;
if (!this._ctxImpl) {
this._ctxImpl = STPAuthenticationContextImp.initWithViewController(rootVC);
this._lastRoot = rootVC;
}
if (this._lastRoot !== rootVC) {
this._ctxImpl._vc = rootVC;
}
return this._ctxImpl;
}
}
var STPAuthenticationContextImp = /** @class */ (function (_super) {
__extends(STPAuthenticationContextImp, _super);
function STPAuthenticationContextImp() {
return _super !== null && _super.apply(this, arguments) || this;
}
STPAuthenticationContextImp_1 = STPAuthenticationContextImp;
STPAuthenticationContextImp.initWithViewController = function (vc) {
var delegate = STPAuthenticationContextImp_1.new();
delegate._vc = vc;
return delegate;
};
STPAuthenticationContextImp.prototype.authenticationPresentingViewController = function () {
return this._vc;
};
var STPAuthenticationContextImp_1;
STPAuthenticationContextImp = STPAuthenticationContextImp_1 = __decorate([
ObjCClass(STPAuthenticationContext)
], STPAuthenticationContextImp);
return STPAuthenticationContextImp;
}(NSObject));
function callback(cb, cvt) {
return (value, error) => {
if (!error) {
if (typeof cb === 'function') {
cb(null, cvt(value));
}
}
else {
if (typeof cb === 'function') {
cb(new Error(error.localizedDescription), null);
}
}
};
}
export class Card {
constructor(card) {
this.native = card;
this.brand = GetBrand(card.brand);
this.name = card.name;
this.address = Address.fromNative(card.address);
this.currency = card.currency;
this.last4 = card.last4;
this.dynamicLast4 = card.dynamicLast4;
this.funding = CardFunding.Unknown;
this.country = this.native.country;
}
static fromNative(card) {
return new Card(card);
}
/**
* Returns an image for a card given its brand.
* The returned value can be used as [src] in an Image tag.
*/
static cardImage(brand) {
let nativeBrand;
switch (brand) {
case CardBrand.AmericanExpress:
nativeBrand = 1 /* STPCardBrand.Amex */;
break;
case CardBrand.DinersClub:
nativeBrand = 5 /* STPCardBrand.DinersClub */;
break;
case CardBrand.Discover:
nativeBrand = 3 /* STPCardBrand.Discover */;
break;
case CardBrand.JCB:
nativeBrand = 4 /* STPCardBrand.JCB */;
break;
case CardBrand.MasterCard:
nativeBrand = 2 /* STPCardBrand.Mastercard */;
break;
case CardBrand.UnionPay:
nativeBrand = 1 /* STPCardBrand.Amex */;
break;
case CardBrand.Visa:
nativeBrand = 0 /* STPCardBrand.Visa */;
break;
default:
nativeBrand = 7 /* STPCardBrand.Unknown */;
break;
}
return STPImageLibrary.brandImageForCardBrand(nativeBrand);
}
}
export class CardParams {
constructor(...args) {
if (args[0] instanceof STPCardParams) {
this._cardParams = args[0];
}
else if (args.length === 4) {
this._cardParams = STPCardParams.alloc().init();
this._cardParams.number = args[0];
this._cardParams.expMonth = args[1];
this._cardParams.expYear = args[2];
this._cardParams.cvc = args[3];
}
else {
this._cardParams = STPCardParams.alloc().init();
}
}
static fromNative(card) {
return new CardParams(card);
}
get number() {
return this._cardParams.number;
}
set number(number) {
this._cardParams.number = number;
}
get expMonth() {
return this._cardParams.expMonth;
}
set expMonth(month) {
this._cardParams.expMonth = month;
}
get expYear() {
return this._cardParams.expYear;
}
set expYear(year) {
this._cardParams.expYear = year;
}
get cvc() {
return this._cardParams.cvc;
}
set cvc(cvc) {
this._cardParams.cvc = cvc;
}
get address() {
return Address.fromNative(this._cardParams.address);
}
set address(address) {
this._cardParams.address = address.ios;
}
get native() {
return this._cardParams;
}
get name() {
return this.native.name;
}
set name(value) {
this._cardParams.name = value;
}
get currency() {
return this.native.currency;
}
set currency(value) {
this._cardParams.currency = value;
}
get last4() {
return this._cardParams.last4();
}
}
var STPPaymentCardTextFieldDelegateImpl = /** @class */ (function (_super) {
__extends(STPPaymentCardTextFieldDelegateImpl, _super);
function STPPaymentCardTextFieldDelegateImpl() {
return _super !== null && _super.apply(this, arguments) || this;
}
STPPaymentCardTextFieldDelegateImpl.initWithOwner = function (owner) {
var delegate = STPPaymentCardTextFieldDelegateImpl.new();
delegate._owner = owner;
return delegate;
};
STPPaymentCardTextFieldDelegateImpl.prototype.paymentCardTextFieldDidChange = function (textField) {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2;
if (((_a = textField.cardParams) === null || _a === void 0 ? void 0 : _a.number) !== this.lastNumber) {
(_c = (_b = this === null || this === void 0 ? void 0 : this._owner) === null || _b === void 0 ? void 0 : _b.get()) === null || _c === void 0 ? void 0 : _c.notify({
eventName: CreditCardView.numberChangedEvent,
object: (_d = this === null || this === void 0 ? void 0 : this._owner) === null || _d === void 0 ? void 0 : _d.get(),
number: (_e = textField.cardParams) === null || _e === void 0 ? void 0 : _e.number,
});
this.lastNumber = (_f = textField.cardParams) === null || _f === void 0 ? void 0 : _f.number;
}
if (((_g = textField.cardParams) === null || _g === void 0 ? void 0 : _g.expMonth) !== this.lastExpMonth) {
(_j = (_h = this === null || this === void 0 ? void 0 : this._owner) === null || _h === void 0 ? void 0 : _h.get()) === null || _j === void 0 ? void 0 : _j.notify({
eventName: CreditCardView.expMonthChangedEvent,
object: (_k = this === null || this === void 0 ? void 0 : this._owner) === null || _k === void 0 ? void 0 : _k.get(),
expMonth: (_l = textField.cardParams) === null || _l === void 0 ? void 0 : _l.expMonth,
});
this.lastExpMonth = (_m = textField.cardParams) === null || _m === void 0 ? void 0 : _m.expMonth;
}
if (((_o = textField.cardParams) === null || _o === void 0 ? void 0 : _o.expYear) !== this.lastExpYear) {
(_q = (_p = this === null || this === void 0 ? void 0 : this._owner) === null || _p === void 0 ? void 0 : _p.get()) === null || _q === void 0 ? void 0 : _q.notify({
eventName: CreditCardView.expYearChangedEvent,
object: (_r = this === null || this === void 0 ? void 0 : this._owner) === null || _r === void 0 ? void 0 : _r.get(),
expYear: (_s = textField.cardParams) === null || _s === void 0 ? void 0 : _s.expYear,
});
this.lastExpYear = (_t = textField.cardParams) === null || _t === void 0 ? void 0 : _t.expYear;
}
if (((_u = textField.cardParams) === null || _u === void 0 ? void 0 : _u.cvc) !== this.lastCVC) {
(_w = (_v = this === null || this === void 0 ? void 0 : this._owner) === null || _v === void 0 ? void 0 : _v.get()) === null || _w === void 0 ? void 0 : _w.notify({
eventName: CreditCardView.cvcChangedEvent,
object: (_x = this === null || this === void 0 ? void 0 : this._owner) === null || _x === void 0 ? void 0 : _x.get(),
cvc: (_y = textField.cardParams) === null || _y === void 0 ? void 0 : _y.cvc,
});
this.lastCVC = (_z = textField.cardParams) === null || _z === void 0 ? void 0 : _z.cvc;
}
if (textField.postalCode !== this.lastPostal) {
(_1 = (_0 = this === null || this === void 0 ? void 0 : this._owner) === null || _0 === void 0 ? void 0 : _0.get()) === null || _1 === void 0 ? void 0 : _1.notify({
eventName: CreditCardView.postalCodeChangedEvent,
object: (_2 = this === null || this === void 0 ? void 0 : this._owner) === null || _2 === void 0 ? void 0 : _2.get(),
postalCode: textField.postalCode,
});
this.lastPostal = textField.postalCode;
}
};
STPPaymentCardTextFieldDelegateImpl.ObjCProtocols = [STPPaymentCardTextFieldDelegate];
return STPPaymentCardTextFieldDelegateImpl;
}(NSObject));
export class CreditCardView extends CreditCardViewBase {
createNativeView() {
this.delegate = STPPaymentCardTextFieldDelegateImpl.initWithOwner(new WeakRef(this));
return STPPaymentCardTextField.alloc().initWithFrame(CGRectMake(10, 10, 150, 44));
}
onMeasure(widthMeasureSpec, heightMeasureSpec) {
const nativeView = this.nativeView;
if (nativeView) {
const width = Utils.layout.getMeasureSpecSize(widthMeasureSpec);
const height = Utils.layout.getMeasureSpecSize(heightMeasureSpec);
this.setMeasuredDimension(width, height);
}
}
/**
* Initializes properties/listeners of the native view.
*/
initNativeView() {
// When nativeView is tapped we get the owning JS object through this field.
this.nativeView.owner = this;
super.initNativeView();
this.nativeView.delegate = this.delegate;
if (this.isUSZipRequired) {
this.nativeView.countryCode = 'US';
}
if (!this.showPostalCode) {
this.nativeView.postalCodeEntryEnabled = this.showPostalCode;
}
}
[showPostalCodeProperty.setNative](value) {
if (this.nativeView) {
this.nativeView.postalCodeEntryEnabled = value;
}
}
[isUSZipRequiredProperty.setNative](value) {
if (this.nativeView) {
if (value) {
this.nativeView.countryCode = 'US';
}
else {
this.nativeView.countryCode = null;
}
}
}
/**
* Clean up references to the native view and resets nativeView to its original state.
* If you have changed nativeView in some other way except through setNative callbacks
* you have a chance here to revert it back to its original state
* so that it could be reused later.
*/
disposeNativeView() {
this.nativeView.owner = null;
super.disposeNativeView();
}
get cardParams() {
const cardParams = STPCardParams.alloc().init();
cardParams.number = this.nativeView.cardParams.number;
cardParams.expMonth = this.nativeView.cardParams.expMonth;
cardParams.expYear = this.nativeView.cardParams.expYear;
cardParams.cvc = this.nativeView.cardParams.cvc;
return CardParams.fromNative(cardParams);
}
}
export class PaymentMethod {
static fromNative(native) {
const pm = new PaymentMethod();
pm.native = native;
return pm;
}
get id() {
return this.native.stripeId;
}
get created() {
return new Date(this.native.created);
}
get type() {
switch (this.native.type) {
case 1 /* STPPaymentMethodType.Alipay */:
return PaymentMethodType.Alipay;
case 7 /* STPPaymentMethodType.AUBECSDebit */:
return PaymentMethodType.AuBecsDebit;
case 8 /* STPPaymentMethodType.BacsDebit */:
return PaymentMethodType.BacsDebit;
case 12 /* STPPaymentMethodType.Bancontact */:
return PaymentMethodType.Bancontact;
case 0 /* STPPaymentMethodType.Card */:
return PaymentMethodType.Card;
case 5 /* STPPaymentMethodType.CardPresent */:
return PaymentMethodType.CardPresent;
case 11 /* STPPaymentMethodType.EPS */:
return PaymentMethodType.Eps;
case 4 /* STPPaymentMethodType.FPX */:
return PaymentMethodType.Fpx;
case 9 /* STPPaymentMethodType.Giropay */:
return PaymentMethodType.Giropay;
case 2 /* STPPaymentMethodType.GrabPay */:
return PaymentMethodType.GrabPay;
case 3 /* STPPaymentMethodType.iDEAL */:
return PaymentMethodType.Ideal;
/*case STPPaymentMethodType.Oxxo:
return PaymentMethodType.Oxxo;*/
case 10 /* STPPaymentMethodType.Przelewy24 */:
return PaymentMethodType.P24;
case 6 /* STPPaymentMethodType.SEPADebit */:
return PaymentMethodType.SepaDebit;
case 15 /* STPPaymentMethodType.Sofort */:
return PaymentMethodType.Sofort;
default:
return PaymentMethodType.Unknown;
}
}
get billingDetails() {
return this.native.billingDetails;
}
get card() {
return PaymentMethodCard.fromNative(this.native.card);
}
get customerId() {
return this.native.customerId;
}
}
class StripeIntent {
get native() {
return this._native;
}
set native(value) {
if (this.native instanceof STPSetupIntent) {
this._isSetupIntent = true;
}
this._native = value;
}
get created() {
return new Date(this.native.created);
}
get clientSecret() {
return this.native.clientSecret;
}
get status() {
if (this._isSetupIntent) {
switch (this.native.status) {
case 6 /* STPSetupIntentStatus.Canceled */:
return "canceled" /* StripePaymentIntentStatus.Canceled */;
case 4 /* STPSetupIntentStatus.Processing */:
return "processing" /* StripePaymentIntentStatus.Processing */;
case 3 /* STPSetupIntentStatus.RequiresAction */:
return "requires_action" /* StripePaymentIntentStatus.RequiresAction */;
case 2 /* STPSetupIntentStatus.RequiresConfirmation */:
return "requires_confirmation" /* StripePaymentIntentStatus.RequiresConfirmation */;
case 1 /* STPSetupIntentStatus.RequiresPaymentMethod */:
return "requires_payment_method" /* StripePaymentIntentStatus.RequiresPaymentMethod */;
case 5 /* STPSetupIntentStatus.Succeeded */:
return "succeeded" /* StripePaymentIntentStatus.Succeeded */;
default:
return null;
}
}
else {
switch (this.native.status) {
case 9 /* STPPaymentIntentStatus.Canceled */:
return "canceled" /* StripePaymentIntentStatus.Canceled */;
case 6 /* STPPaymentIntentStatus.Processing */:
return "processing" /* StripePaymentIntentStatus.Processing */;
case 4 /* STPPaymentIntentStatus.RequiresAction */:
return "requires_action" /* StripePaymentIntentStatus.RequiresAction */;
case 8 /* STPPaymentIntentStatus.RequiresCapture */:
return "requires_capture" /* StripePaymentIntentStatus.RequiresCapture */;
case 3 /* STPPaymentIntentStatus.RequiresConfirmation */:
return "requires_confirmation" /* StripePaymentIntentStatus.RequiresConfirmation */;
case 1 /* STPPaymentIntentStatus.RequiresPaymentMethod */:
return "requires_payment_method" /* StripePaymentIntentStatus.RequiresPaymentMethod */;
case 7 /* STPPaymentIntentStatus.Succeeded */:
return "succeeded" /* StripePaymentIntentStatus.Succeeded */;
default:
return null;
}
}
}
get requiresAction() {
return this.native.status === 4 /* STPPaymentIntentStatus.RequiresAction */;
}
get isSuccess() {
return this.status === "succeeded" /* StripePaymentIntentStatus.Succeeded */;
}
get requiresConfirmation() {
return this.status === "requires_confirmation" /* StripePaymentIntentStatus.RequiresConfirmation */;
}
get requiresCapture() {
if (this._isSetupIntent) {
return false;
}
return this.status === "requires_capture" /* StripePaymentIntentStatus.RequiresCapture */;
}
get description() {
return this.native.description;
}
}
export class StripePaymentIntent extends StripeIntent {
static fromNative(native) {
const pi = new StripePaymentIntent();
pi.native = native;
return pi;
}
static fromApi(json) {
const native = STPPaymentIntent.decodedObjectFromAPIResponse(json);
return StripePaymentIntent.fromNative(native);
}
get id() {
return this.native.stripeId;
}
get amount() {
return this.native.amount;
}
get currency() {
return this.native.currency;
}
get captureMethod() {
switch (this.native.captureMethod) {
case 1 /* STPPaymentIntentCaptureMethod.Automatic */:
return 'automatic';
case 2 /* STPPaymentIntentCaptureMethod.Manual */:
return 'manual';
}
return null;
}
}
export class StripePaymentIntentParams {
get native() {
const n = STPPaymentIntentParams.alloc().initWithClientSecret(this.clientSecret);
n.paymentMethodParams = this.paymentMethodParams;
n.paymentMethodId = this.paymentMethodId;
n.sourceParams = this.sourceParams;
n.sourceId = this.sourceId;
n.returnURL = this.returnURL;
return n;
}
}
export class StripeSetupIntent extends StripeIntent {
static fromNative(native) {
const si = new StripeSetupIntent();
si.native = native;
si._isSetupIntent = true;
return si;
}
get id() {
return this.native.stripeID;
}
get paymentMethodId() {
return this.native.paymentMethodID;
}
}
export class StripeSetupIntentParams {
constructor(paymentMethodId, clientSecret) {
this.native = STPSetupIntentConfirmParams.alloc().initWithClientSecret(clientSecret);
this.native.paymentMethodID = paymentMethodId;
}
}
export var StripeRedirectState;
(function (StripeRedirectState) {
StripeRedirectState[StripeRedirectState["NotStarted"] = 0] = "NotStarted";
StripeRedirectState[StripeRedirectState["InProgress"] = 1] = "InProgress";
StripeRedirectState[StripeRedirectState["Cancelled"] = 2] = "Cancelled";
StripeRedirectState[StripeRedirectState["Completed"] = 3] = "Completed";
})(StripeRedirectState || (StripeRedirectState = {}));
export class StripeRedirectSession {
constructor(paymentIntent, cb) {
this.native = STPRedirectContext.alloc().initWithPaymentIntentCompletion(paymentIntent.native, (clientSecret, error) => {
cb(new Error(error.localizedDescription), clientSecret);
//callback(cb, (clientSecret) => clientSecret)
});
}
startRedirectFlow(view = null) {
const vc = view?.viewController ?? (Frame.topmost().currentPage.ios || this._rootViewController);
this.native.startRedirectFlowFromViewController(vc);
}
cancel() {
this.native.cancel();
}
get _rootViewController() {
const keyWindow = UIApplication.sharedApplication.keyWindow;
return keyWindow != null ? keyWindow.rootViewController : undefined;
}
}
var CustomUIApplicationDelegate = /** @class */ (function (_super) {
__extends(CustomUIApplicationDelegate, _super);
function CustomUIApplicationDelegate() {
return _super !== null && _super.apply(this, arguments) || this;
}
CustomUIApplicationDelegate.ObjCProtocols = [UIApplicationDelegate];
return CustomUIApplicationDelegate;
}(UIResponder));
// setup app delegate
let delegate = Application.ios.delegate;
if (!delegate) {
delegate = Application.ios.delegate = CustomUIApplicationDelegate;
}
/**
* Add delegate method handler, but also preserve any existing one.
*/
function addDelegateHandler(classRef, methodName, handler) {
const crtHandler = classRef.prototype[methodName];
classRef.prototype[methodName] = function () {
// eslint-disable-next-line prefer-rest-params
const args = Array.from(arguments);
if (crtHandler) {
const result = crtHandler.apply(this, args);
args.push(result);
}
return handler.apply(this, args);
};
}
addDelegateHandler(delegate, 'applicationContinueUserActivityRestorationHandler', (_application, userActivity) => {
return handleContinueUserActivity(userActivity);
});
addDelegateHandler(delegate, 'applicationOpenURLOptions', (_app, url, _options) => {
return handleOpenURL(url);
});
//# sourceMappingURL=index.ios.js.map