Skip to content

Commit 35b72f7

Browse files
committed
Resets payment context on viewWillAppear
1 parent ac82695 commit 35b72f7

File tree

2 files changed

+13
-18
lines changed

2 files changed

+13
-18
lines changed

Photobook/Controllers/CheckoutViewController.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,9 @@ class CheckoutViewController: UIViewController {
306306
showEmptyScreen()
307307
return
308308
}
309+
310+
// Reset payment context in case we come back from payment methods
311+
hasSetUpStripe = false
309312
refresh(showProgress: emptyScreenViewController.view.superview == nil)
310313
}
311314

Photobook/Model/Order/PaymentAuthorizationManager.swift

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)