Skip to content

Commit

Permalink
fix: Sets return URL for connections based on urlScheme (#1178)
Browse files Browse the repository at this point in the history
  • Loading branch information
vardges-stripe authored Oct 27, 2022
1 parent e681539 commit a424af7
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 63 deletions.
58 changes: 29 additions & 29 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -368,31 +368,31 @@ PODS:
- React-Core
- React-RCTImage
- SocketRocket (0.6.0)
- Stripe (22.8.1):
- Stripe/Stripe3DS2 (= 22.8.1)
- StripeApplePay (= 22.8.1)
- StripeCore (= 22.8.1)
- StripeUICore (= 22.8.1)
- stripe-react-native (0.18.1):
- Stripe (22.8.4):
- Stripe/Stripe3DS2 (= 22.8.4)
- StripeApplePay (= 22.8.4)
- StripeCore (= 22.8.4)
- StripeUICore (= 22.8.4)
- stripe-react-native (0.19.0):
- React-Core
- Stripe (~> 22.8.1)
- StripeFinancialConnections (~> 22.8.1)
- stripe-react-native/Tests (0.18.1):
- Stripe (~> 22.8.3)
- StripeFinancialConnections (~> 22.8.3)
- stripe-react-native/Tests (0.19.0):
- React-Core
- Stripe (~> 22.8.1)
- StripeFinancialConnections (~> 22.8.1)
- Stripe/Stripe3DS2 (22.8.1):
- StripeApplePay (= 22.8.1)
- StripeCore (= 22.8.1)
- StripeUICore (= 22.8.1)
- StripeApplePay (22.8.1):
- StripeCore (= 22.8.1)
- StripeCore (22.8.1)
- StripeFinancialConnections (22.8.1):
- StripeCore (= 22.8.1)
- StripeUICore (= 22.8.1)
- StripeUICore (22.8.1):
- StripeCore (= 22.8.1)
- Stripe (~> 22.8.3)
- StripeFinancialConnections (~> 22.8.3)
- Stripe/Stripe3DS2 (22.8.4):
- StripeApplePay (= 22.8.4)
- StripeCore (= 22.8.4)
- StripeUICore (= 22.8.4)
- StripeApplePay (22.8.4):
- StripeCore (= 22.8.4)
- StripeCore (22.8.4)
- StripeFinancialConnections (22.8.4):
- StripeCore (= 22.8.4)
- StripeUICore (= 22.8.4)
- StripeUICore (22.8.4):
- StripeCore (= 22.8.4)
- Yoga (1.14.0)
- YogaKit (1.18.1):
- Yoga (~> 1.14)
Expand Down Expand Up @@ -614,12 +614,12 @@ SPEC CHECKSUMS:
RNCPicker: abc646b53a3d28ccfa3232c927a0ca52e0cf024d
RNScreens: 4a1af06327774490d97342c00aee0c2bafb497b7
SocketRocket: fccef3f9c5cedea1353a9ef6ada904fde10d6608
Stripe: b4cf3aa317a8e984b930d3545bac10b490dd3106
stripe-react-native: 0a6687da9a81bf4a9f80374d3fddd103e0e8dd1a
StripeApplePay: 858c1dadc39b658d317661dea8cc2b7158533a17
StripeCore: 52e0aba2fad604455692db593bf5edc04758b760
StripeFinancialConnections: 40f6c8f86a4ddfcfe981d4da343828637abb3e69
StripeUICore: b3d64c5cbcb4cacfa88f9a0950cdf1b4df72792e
Stripe: 59f6659e8ea413def19c97c57e23f5ec6ea48cf8
stripe-react-native: 7135ed308ee04234d665da5e79e4d2737e549be3
StripeApplePay: 6e9aebd3d248464836e9fbdaef6e5fb1817d56a6
StripeCore: 193f27552fb98108ebfe0df11651fe5f38948305
StripeFinancialConnections: 955c345ada7d0dff1a9bd15c4ebc97eacce4ac75
StripeUICore: 6a5bbea0164d63bd91000f001903e7901859e1a4
Yoga: 236056dd74cda4d9d76c20306fd8c20bb087614d
YogaKit: f782866e155069a2cca2517aafea43200b01fd5a

Expand Down
40 changes: 21 additions & 19 deletions ios/FinancialConnections.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ import StripeFinancialConnections
import Stripe

class FinancialConnections {

internal static func present(
withClientSecret: String,
returnURL: String? = nil,
resolve: @escaping RCTPromiseResolveBlock
) -> Void {
DispatchQueue.main.async {
FinancialConnectionsSheet(financialConnectionsSessionClientSecret: withClientSecret).present(
FinancialConnectionsSheet(financialConnectionsSessionClientSecret: withClientSecret, returnURL: returnURL).present(
from: findViewControllerPresenter(from: UIApplication.shared.delegate?.window??.rootViewController ?? UIViewController()),
completion: { result in
switch result {
Expand All @@ -30,13 +31,14 @@ class FinancialConnections {
})
}
}

internal static func presentForToken(
withClientSecret: String,
returnURL: String? = nil,
resolve: @escaping RCTPromiseResolveBlock
) -> Void {
DispatchQueue.main.async {
FinancialConnectionsSheet(financialConnectionsSessionClientSecret: withClientSecret).presentForToken(
FinancialConnectionsSheet(financialConnectionsSessionClientSecret: withClientSecret, returnURL: returnURL).presentForToken(
from: findViewControllerPresenter(from: UIApplication.shared.delegate?.window??.rootViewController ?? UIViewController()),
completion: { result in
switch result {
Expand All @@ -55,7 +57,7 @@ class FinancialConnections {
})
}
}

internal static func mapFromSessionResult(
_ session: StripeAPI.FinancialConnectionsSession
) -> NSDictionary {
Expand All @@ -66,7 +68,7 @@ class FinancialConnections {
"accounts": mapFromAccountsList(accounts: session.accounts)
]
}

internal static func mapFromTokenResult(
_ token: StripeAPI.BankAccountToken?
) -> NSDictionary {
Expand All @@ -79,7 +81,7 @@ class FinancialConnections {
"created": NSNull(), // Doesn't exist on StripeAPI.BankAccountToken
]
}

internal static func mapFromBankAccount(
bankAccount: StripeAPI.BankAccountToken.BankAccount?
) -> NSDictionary? {
Expand All @@ -100,12 +102,12 @@ class FinancialConnections {
"status": bankAccount.status.prefix(1).uppercased() + bankAccount.status.lowercased().dropFirst(), // stripe-ios returns a string, not STPBankAccountStatus
]
}

internal static func mapFromAccountsList(
accounts: StripeAPI.FinancialConnectionsSession.AccountList
) -> [[String: Any]] {
var result = [[String: Any]]()

for account in accounts.data {
result.append([
"id": account.id,
Expand All @@ -123,7 +125,7 @@ class FinancialConnections {
"supportedPaymentMethodTypes": account.supportedPaymentMethodTypes.map { mapFromSupportedPaymentMethodTypes($0) },
])
}

return result
}

Expand All @@ -133,7 +135,7 @@ class FinancialConnections {
guard let balance = balance else {
return nil
}

return [
"asOf": balance.asOf * 1000,
"type": mapFromBalanceType(balance.type),
Expand All @@ -149,13 +151,13 @@ class FinancialConnections {
guard let balanceRefresh = balanceRefresh else {
return nil
}

return [
"status": mapFromBalanceRefreshStatus(balanceRefresh.status),
"lastAttemptedAt": balanceRefresh.lastAttemptedAt * 1000,
]
}

internal static func mapFromStatus( _ status: StripeAPI.FinancialConnectionsAccount.Status) -> String {
switch status {
case .active:
Expand All @@ -168,7 +170,7 @@ class FinancialConnections {
return "unparsable"
}
}

internal static func mapFromCategory( _ category: StripeAPI.FinancialConnectionsAccount.Category) -> String {
switch category {
case .cash:
Expand All @@ -183,7 +185,7 @@ class FinancialConnections {
return "unparsable"
}
}

internal static func mapFromSubcategory( _ subcategory: StripeAPI.FinancialConnectionsAccount.Subcategory) -> String {
switch subcategory {
case .savings:
Expand All @@ -202,7 +204,7 @@ class FinancialConnections {
return "unparsable"
}
}

internal static func mapFromPermission( _ permission: StripeAPI.FinancialConnectionsAccount.Permissions) -> String {
switch permission {
case .transactions:
Expand All @@ -219,7 +221,7 @@ class FinancialConnections {
return "unparsable"
}
}

internal static func mapFromSupportedPaymentMethodTypes( _ type: StripeAPI.FinancialConnectionsAccount.SupportedPaymentMethodTypes) -> String {
switch type {
case .usBankAccount:
Expand All @@ -230,7 +232,7 @@ class FinancialConnections {
return "unparsable"
}
}

internal static func mapFromBalanceType( _ type: StripeAPI.FinancialConnectionsAccount.Balance.ModelType) -> String {
switch type {
case .cash:
Expand All @@ -241,7 +243,7 @@ class FinancialConnections {
return "unparsable"
}
}

internal static func mapFromBalanceRefreshStatus( _ status: StripeAPI.FinancialConnectionsAccount.BalanceRefresh.Status) -> String {
switch status {
case .succeeded:
Expand Down
6 changes: 5 additions & 1 deletion ios/Mappers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class Mappers {
guard let bankAccount = bankAccount else {
return nil
}

let result: NSDictionary = [
"id": bankAccount.stripeID,
"bankName": bankAccount.bankName ?? NSNull(),
Expand Down Expand Up @@ -743,6 +743,10 @@ class Mappers {
return urlScheme + "://safepay"
}

class func mapToFinancialConnectionsReturnURL(urlScheme: String) -> String {
return urlScheme + "://financial_connections_redirect"
}

class func mapUICustomization(_ params: NSDictionary) -> STPThreeDSUICustomization {
let uiCustomization = STPThreeDSUICustomization()
if let labelSettings = params["label"] as? Dictionary<String, Any?> {
Expand Down
Loading

0 comments on commit a424af7

Please sign in to comment.