@@ -10,7 +10,7 @@ import Combine
10
10
import Foundation
11
11
@_spi ( STP) import StripeCore
12
12
@_spi ( STP) @_spi ( v25) import StripeFinancialConnections
13
- import StripePaymentSheet
13
+ @ _spi ( STP ) import StripePaymentSheet
14
14
import SwiftUI
15
15
import UIKit
16
16
@@ -292,6 +292,8 @@ final class PlaygroundViewModel: ObservableObject {
292
292
setupStandalone ( )
293
293
case . paymentElement:
294
294
setupPaymentElement ( )
295
+ case . fcLite:
296
+ setupFcLite ( )
295
297
}
296
298
}
297
299
@@ -460,6 +462,116 @@ final class PlaygroundViewModel: ObservableObject {
460
462
}
461
463
}
462
464
465
+ private func setupFcLite( ) {
466
+ isLoading = true
467
+ SetupPlayground (
468
+ configurationDictionary: playgroundConfiguration. configurationDictionary
469
+ ) { [ weak self] setupPlaygroundResponse in
470
+ guard let self else { return }
471
+ if let setupPlaygroundResponse {
472
+ if let error = setupPlaygroundResponse [ " error " ] {
473
+ print ( " **** Error in playground setup response: \( error) " )
474
+ return
475
+ }
476
+
477
+ guard let clientSecret = setupPlaygroundResponse [ " client_secret " ] else {
478
+ print ( " **** No client_secret in response " )
479
+ return
480
+ }
481
+ guard let publishableKey = setupPlaygroundResponse [ " publishable_key " ] else {
482
+ print ( " **** No publishable_key in response " )
483
+ return
484
+ }
485
+
486
+ STPAPIClient . shared. publishableKey = publishableKey
487
+ DispatchQueue . main. async {
488
+ let topMostViewController = UIViewController . topMostViewController ( ) !
489
+ let fc = FinancialConnectionsLite (
490
+ clientSecret: clientSecret,
491
+ returnUrl: URL ( string: " financial-connections-example://redirect " ) !
492
+ )
493
+ fc. present ( from: topMostViewController) { [ weak self] result in
494
+ switch result {
495
+ case . completed( let completed) :
496
+ switch completed {
497
+ case . financialConnections( let linkedBank) :
498
+ let sessionId = linkedBank. sessionId
499
+ let accountId = linkedBank. accountId
500
+ let bankAccount : String
501
+ if let bankName = linkedBank. bankName, let last4 = linkedBank. last4 {
502
+ bankAccount = " \( bankName) .... \( last4) "
503
+ } else {
504
+ bankAccount = " Bank details unavailable "
505
+ }
506
+
507
+ let sessionInfo =
508
+ """
509
+ session_id= \( sessionId)
510
+ account_id= \( accountId)
511
+ """
512
+
513
+ let message = " \( bankAccount) \n \n \( sessionInfo) "
514
+ self ? . sessionOutput [ . message] = message
515
+ self ? . sessionOutput [ . sessionId] = sessionId
516
+ self ? . sessionOutput [ . accountIds] = accountId
517
+
518
+ UIAlertController . showAlert (
519
+ title: " Success " ,
520
+ message: message
521
+ )
522
+ case . instantDebits( let linkedBank) :
523
+ let sessionId = linkedBank. linkAccountSessionId ?? " N/a "
524
+ let paymentMethodId = linkedBank. paymentMethod. id
525
+ let bankAccount : String
526
+ if let bankName = linkedBank. bankName, let last4 = linkedBank. last4 {
527
+ bankAccount = " \( bankName) .... \( last4) "
528
+ } else {
529
+ bankAccount = " Bank details unavailable "
530
+ }
531
+
532
+ let sessionInfo =
533
+ """
534
+ session_id= \( sessionId)
535
+ payment_method_id= \( paymentMethodId)
536
+ """
537
+
538
+ let message = " \( bankAccount) \n \n \( sessionInfo) "
539
+ self ? . sessionOutput [ . message] = message
540
+ self ? . sessionOutput [ . sessionId] = sessionId
541
+
542
+ UIAlertController . showAlert (
543
+ title: " Success " ,
544
+ message: message
545
+ )
546
+ @unknown default :
547
+ UIAlertController . showAlert (
548
+ message: " Unknown payment method flow "
549
+ )
550
+ }
551
+ case . cancelled:
552
+ UIAlertController . showAlert (
553
+ title: " Cancelled "
554
+ )
555
+ case . failed( let error) :
556
+ UIAlertController . showAlert (
557
+ title: " Failed " ,
558
+ message: error. localizedDescription
559
+ )
560
+ }
561
+ }
562
+ }
563
+ } else {
564
+ UIAlertController . showAlert (
565
+ title: " Playground App Setup Failed " ,
566
+ message: " Try clearing 'Custom Keys' or delete & re-install the app. "
567
+ )
568
+ }
569
+ DispatchQueue . main. async {
570
+ self . isLoading = false
571
+ }
572
+ }
573
+ }
574
+
463
575
func didSelectClearCaches( ) {
464
576
URLSession . shared. reset ( completionHandler: { } )
465
577
}
0 commit comments