@@ -188,27 +188,15 @@ class PaymentAuthorizationManager: NSObject {
188188 }
189189 }
190190
191- // Stripe does not allow changing the host vc once set as this is usually the checkout vc.
192- // However, in our case it might be necessary to reset it to the payments vc or receipt vc.
193- private weak var _stripeHostViewControllerStorage1 : UIViewController ?
194- private weak var _stripeHostViewControllerStorage2 : UIViewController ?
191+ private var customerContext = STPCustomerContext ( keyProvider: KiteAPIClient . shared)
192+
195193 var stripeHostViewController : UIViewController ? {
196194 didSet {
197- guard stripePaymentContext != nil else { return }
198- if _stripeHostViewControllerStorage1 != nil {
199- guard _stripeHostViewControllerStorage1 != stripeHostViewController else { return }
200- _stripeHostViewControllerStorage1 = nil
201- _stripeHostViewControllerStorage2 = stripeHostViewController
202- stripePaymentContext? . hostViewController = _stripeHostViewControllerStorage2
203- } else {
204- guard _stripeHostViewControllerStorage2 != stripeHostViewController else { return }
205- _stripeHostViewControllerStorage2 = nil
206- _stripeHostViewControllerStorage1 = stripeHostViewController
207- stripePaymentContext? . hostViewController = _stripeHostViewControllerStorage1
208- }
195+ guard stripePaymentContext? . hostViewController == nil else { return }
196+ stripePaymentContext? . hostViewController = stripeHostViewController
209197 }
210198 }
211-
199+
212200 func setStripePaymentContext( ) {
213201 func configure( with stripeKey: String ) {
214202 let config = STPPaymentConfiguration . shared ( )
@@ -220,7 +208,6 @@ class PaymentAuthorizationManager: NSObject {
220208 config. canDeletePaymentOptions = true
221209 config. createCardSources = true
222210
223- let customerContext = STPCustomerContext ( keyProvider: KiteAPIClient . shared)
224211 let paymentContext = STPPaymentContext ( customerContext: customerContext,
225212 configuration: config,
226213 theme: . default( ) )
@@ -229,6 +216,11 @@ class PaymentAuthorizationManager: NSObject {
229216 stripePaymentContext = paymentContext
230217 }
231218
219+ if let stripePublicKey = PaymentAuthorizationManager . stripeKey {
220+ configure ( with: stripePublicKey)
221+ return
222+ }
223+
232224 PaymentAuthorizationManager . setPaymentKeys ( ) { error in
233225 guard let stripePublicKey = PaymentAuthorizationManager . stripeKey else { return }
234226 configure ( with: stripePublicKey)
0 commit comments