@@ -155,7 +155,7 @@ export class BankAccount implements IBankAccount {
155
155
}
156
156
157
157
public static fromNative ( bankAccount : STPBankAccount ) {
158
- if ( bankAccount ) {
158
+ if ( bankAccount ) {
159
159
return new BankAccount ( bankAccount ) ;
160
160
}
161
161
return null ;
@@ -309,19 +309,33 @@ export class Stripe {
309
309
) ;
310
310
}
311
311
312
+
313
+ private get _rootViewController ( ) : UIViewController | undefined {
314
+ const keyWindow = UIApplication . sharedApplication . keyWindow ;
315
+ return keyWindow != null ? keyWindow . rootViewController : undefined ;
316
+ }
317
+
312
318
/*
313
319
*. Private
314
320
*/
315
321
316
- private _getAuthentificationContext ( ) : STPPaymentContext {
317
- const authContext = STPPaymentContext . alloc ( ) ;
318
- const rootVC = Frame . topmost ( ) . currentPage . ios ;
322
+ private _getAuthentificationContext ( ) : STPAuthenticationContext {
323
+ const rootVC = Frame . topmost ( ) . currentPage . ios || this . _rootViewController ;
324
+ return STPAuthenticationContextImp . initWithViewController ( Utils . ios . getVisibleViewController ( rootVC ) ) ;
325
+ }
326
+ }
319
327
320
- authContext . hostViewController = Utils . ios . getVisibleViewController ( rootVC ) ;
321
- authContext . authenticationPresentingViewController = ( ) => {
322
- return authContext . hostViewController ;
323
- } ;
324
- return authContext ;
328
+ @NativeClass
329
+ class STPAuthenticationContextImp extends NSObject implements STPAuthenticationContext {
330
+ static ObjCProtocols = [ STPAuthenticationContext ] ;
331
+ private _vc : UIViewController ;
332
+ public static initWithViewController ( vc : UIViewController ) {
333
+ const delegate = < STPAuthenticationContextImp > STPAuthenticationContextImp . new ( ) ;
334
+ delegate . _vc = vc ;
335
+ return delegate ;
336
+ }
337
+ authenticationPresentingViewController ( ) : UIViewController {
338
+ return this . _vc ;
325
339
}
326
340
}
327
341
@@ -412,16 +426,59 @@ export class Card implements ICard {
412
426
export class CardParams implements ICardParams {
413
427
private _cardParams : STPCardParams ;
414
428
415
- private constructor (
416
- params : STPCardParams
417
- ) {
418
- this . _cardParams = params ;
429
+ constructor ( )
430
+ constructor ( params : STPCardParams )
431
+ constructor ( number : string , expMonth : number , expYear : number , cvc : string )
432
+ constructor ( ...args ) {
433
+ if ( args [ 0 ] instanceof STPCardParams ) {
434
+ this . _cardParams = args [ 0 ] ;
435
+ } else if ( args . length === 4 ) {
436
+ this . _cardParams = STPCardParams . alloc ( ) . init ( ) ;
437
+ this . _cardParams . number = args [ 0 ] ;
438
+ this . _cardParams . expMonth = args [ 1 ] ;
439
+ this . _cardParams . expYear = args [ 2 ] ;
440
+ this . _cardParams . cvc = args [ 3 ] ;
441
+ } else {
442
+ this . _cardParams = STPCardParams . alloc ( ) . init ( ) ;
443
+ }
419
444
}
420
445
421
446
public static fromNative ( card : STPCardParams ) : CardParams {
422
447
return new CardParams ( card ) ;
423
448
}
424
449
450
+ get number ( ) {
451
+ return this . _cardParams . number ;
452
+ }
453
+
454
+ set number ( number : string ) {
455
+ this . _cardParams . number = number ;
456
+ }
457
+
458
+ get expMonth ( ) {
459
+ return this . _cardParams . expMonth ;
460
+ }
461
+
462
+ set expMonth ( month : number ) {
463
+ this . _cardParams . expMonth = month ;
464
+ }
465
+
466
+ get expYear ( ) {
467
+ return this . _cardParams . expYear ;
468
+ }
469
+
470
+ set expYear ( year : number ) {
471
+ this . _cardParams . expYear = year ;
472
+ }
473
+
474
+ get cvc ( ) {
475
+ return this . _cardParams . cvc
476
+ }
477
+
478
+ set cvc ( cvc : string ) {
479
+ this . _cardParams . cvc = cvc ;
480
+ }
481
+
425
482
get address ( ) : Address {
426
483
return Address . fromNative ( this . _cardParams . address ) ;
427
484
}
@@ -703,9 +760,8 @@ export class StripeSetupIntentParams {
703
760
native : STPSetupIntentConfirmParams ;
704
761
705
762
constructor ( paymentMethodId : string , clientSecret : string ) {
706
- this . native = STPSetupIntentConfirmParams . alloc ( ) ;
763
+ this . native = STPSetupIntentConfirmParams . alloc ( ) . initWithClientSecret ( clientSecret ) ;
707
764
this . native . paymentMethodID = paymentMethodId ;
708
- this . native . clientSecret = clientSecret ;
709
765
}
710
766
}
711
767
0 commit comments