From 642c6da1e5167eee3071038e1ba28be594621b14 Mon Sep 17 00:00:00 2001 From: Till Hellmund <tillh@stripe.com> Date: Fri, 17 Jan 2025 15:07:54 -0500 Subject: [PATCH] Take IBP incentive eligibility from return URL --- ...cialConnectionsWebFlowViewController.swift | 27 ++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/StripeFinancialConnections/StripeFinancialConnections/Source/Web/FinancialConnectionsWebFlowViewController.swift b/StripeFinancialConnections/StripeFinancialConnections/Source/Web/FinancialConnectionsWebFlowViewController.swift index e27490c5cc99..fae5d75e4b83 100644 --- a/StripeFinancialConnections/StripeFinancialConnections/Source/Web/FinancialConnectionsWebFlowViewController.swift +++ b/StripeFinancialConnections/StripeFinancialConnections/Source/Web/FinancialConnectionsWebFlowViewController.swift @@ -171,15 +171,9 @@ extension FinancialConnectionsWebFlowViewController { case .success(.success(let returnUrl)): if manifest.isProductInstantDebits { if let paymentMethod = returnUrl.extractLinkBankPaymentMethod() { - let instantDebitsLinkedBank = InstantDebitsLinkedBank( - paymentMethod: paymentMethod, - bankName: returnUrl.extractValue(forKey: "bank_name")? - // backend can return "+" instead of a more-common encoding of "%20" for spaces - .replacingOccurrences(of: "+", with: " "), - last4: returnUrl.extractValue(forKey: "last4"), - linkMode: elementsSessionContext?.linkMode, - // TODO: Parse this from the return URL - incentiveEligible: false + let instantDebitsLinkedBank = createInstantDebitsLinkedBank( + from: returnUrl, + with: paymentMethod ) self.notifyDelegateOfSuccess(result: .instantDebits(instantDebitsLinkedBank)) } else { @@ -212,6 +206,21 @@ extension FinancialConnectionsWebFlowViewController { self.authSessionManager = nil }) } + + private func createInstantDebitsLinkedBank( + from url: URL, + with paymentMethod: LinkBankPaymentMethod + ) -> InstantDebitsLinkedBank { + return InstantDebitsLinkedBank( + paymentMethod: paymentMethod, + bankName: url.extractValue(forKey: "bank_name")? + // backend can return "+" instead of a more-common encoding of "%20" for spaces + .replacingOccurrences(of: "+", with: " "), + last4: url.extractValue(forKey: "last4"), + linkMode: elementsSessionContext?.linkMode, + incentiveEligible: url.extractValue(forKey: "incentive_eligible").flatMap { Bool($0) } ?? false + ) + } private func redirect(to url: URL) { DispatchQueue.main.async {