Created
February 25, 2022 11:05
-
-
Save koke/fdf4ee5c4249ef16a588c2e84d20770c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/Yosemite/Yosemite/Model/Payments/CardPresentPaymentsConfiguration.swift b/Yosemite/Yosemite/Model/Payments/CardPresentPaymentsConfiguration.swift | |
index 0aae4c9b9..8ef7cd097 100644 | |
--- a/Yosemite/Yosemite/Model/Payments/CardPresentPaymentsConfiguration.swift | |
+++ b/Yosemite/Yosemite/Model/Payments/CardPresentPaymentsConfiguration.swift | |
@@ -2,25 +2,25 @@ import Foundation | |
public struct CardPresentPaymentsConfiguration { | |
private let countryCode: String | |
- private let stripeTerminalforCanadaEnabled: Bool | |
public let paymentMethods: [WCPayPaymentMethodType] | |
public let currencies: [String] | |
public let paymentGateways: [String] | |
public let supportedReaders: [CardReaderType] | |
+ public let purchaseCardReaderUrl: (CardPresentPaymentsPlugins) -> URL | |
init(countryCode: String, | |
- stripeTerminalforCanadaEnabled: Bool, | |
paymentMethods: [WCPayPaymentMethodType], | |
currencies: [String], | |
paymentGateways: [String], | |
- supportedReaders: [CardReaderType]) { | |
+ supportedReaders: [CardReaderType], | |
+ purchaseCardReaderUrl: @escaping (CardPresentPaymentsPlugins) -> URL) { | |
self.countryCode = countryCode | |
- self.stripeTerminalforCanadaEnabled = stripeTerminalforCanadaEnabled | |
self.paymentMethods = paymentMethods | |
self.currencies = currencies | |
self.paymentGateways = paymentGateways | |
self.supportedReaders = supportedReaders | |
+ self.purchaseCardReaderUrl = purchaseCardReaderUrl | |
} | |
public init(country: String, canadaEnabled: Bool) { | |
@@ -28,29 +28,29 @@ public struct CardPresentPaymentsConfiguration { | |
case "US": | |
self.init( | |
countryCode: country, | |
- stripeTerminalforCanadaEnabled: canadaEnabled, | |
paymentMethods: [.cardPresent], | |
currencies: ["USD"], | |
paymentGateways: [WCPayAccount.gatewayID, StripeAccount.gatewayID], | |
- supportedReaders: [.chipper, .stripeM2] | |
+ supportedReaders: [.chipper, .stripeM2], | |
+ purchaseCardReaderUrl: Self.legacyPurchaseCardReaderUrl(plugin:) | |
) | |
case "CA" where canadaEnabled == true: | |
self.init( | |
countryCode: country, | |
- stripeTerminalforCanadaEnabled: true, | |
paymentMethods: [.cardPresent, .interacPresent], | |
currencies: ["CAD"], | |
paymentGateways: [WCPayAccount.gatewayID], | |
- supportedReaders: [.wisepad3] | |
+ supportedReaders: [.wisepad3], | |
+ purchaseCardReaderUrl: Self.countryBasedCardReaderUrl(country: country) | |
) | |
default: | |
self.init( | |
countryCode: country, | |
- stripeTerminalforCanadaEnabled: canadaEnabled, | |
paymentMethods: [], | |
currencies: [], | |
paymentGateways: [], | |
- supportedReaders: [] | |
+ supportedReaders: [], | |
+ purchaseCardReaderUrl: Self.legacyPurchaseCardReaderUrl(plugin:) | |
) | |
} | |
} | |
@@ -59,19 +59,22 @@ public struct CardPresentPaymentsConfiguration { | |
paymentMethods.isEmpty == false && currencies.isEmpty == false && paymentGateways.isEmpty == false && supportedReaders.isEmpty == false | |
} | |
- /// Given a two character country code and the active plugin, returns a URL | |
- /// where the merchant can purchase a card reader | |
- /// | |
- public func purchaseCardReaderUrl(for plugin: CardPresentPaymentsPlugins) -> URL { | |
- if case .stripe = plugin { | |
- return Constants.stripeReaderPurchaseUrl | |
+ static func countryBasedCardReaderUrl(country: String) -> (CardPresentPaymentsPlugins) -> URL { | |
+ return { plugin in | |
+ if case .stripe = plugin { | |
+ return Constants.stripeReaderPurchaseUrl | |
+ } | |
+ | |
+ return URL(string: Constants.purchaseReaderForCountryUrlBase + country) ?? Constants.fallbackInPersonPaymentsUrl | |
} | |
+ } | |
- if !stripeTerminalforCanadaEnabled { | |
- return Constants.purchaseM2ReaderUrl | |
+ static func legacyPurchaseCardReaderUrl(plugin: CardPresentPaymentsPlugins) -> URL { | |
+ if case .stripe = plugin { | |
+ return Constants.stripeReaderPurchaseUrl | |
} | |
- return URL(string: Constants.purchaseReaderForCountryUrlBase + self.countryCode) ?? Constants.fallbackInPersonPaymentsUrl | |
+ return Constants.purchaseM2ReaderUrl | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment