Skip to content

Commit 06ee43b

Browse files
authored
Merge pull request #6195 from woocommerce/issue/5980-wp3-manual
[Mobile Payments] Use configuration loader to decide which reader manual to show
2 parents 2305e88 + ddc992e commit 06ee43b

File tree

3 files changed

+54
-10
lines changed

3 files changed

+54
-10
lines changed

WooCommerce/Classes/ViewRelated/Dashboard/Settings/In-Person Payments/InPersonPaymentsMenuViewController.swift

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import UIKit
22
import SwiftUI
3+
import Yosemite
34

45
final class InPersonPaymentsMenuViewController: UITableViewController {
56
private var rows = [Row]()
7+
private let configurationLoader: CardPresentConfigurationLoader
68

79
init() {
10+
configurationLoader = CardPresentConfigurationLoader()
811
super.init(style: .grouped)
912
}
1013

@@ -28,10 +31,23 @@ private extension InPersonPaymentsMenuViewController {
2831
func configureRows() {
2932
rows = [
3033
.orderCardReader,
31-
.manageCardReader,
32-
.bbposChipper2XBTManual,
33-
.stripeM2Manual
34-
]
34+
.manageCardReader
35+
] + readerManualRows()
36+
}
37+
38+
func readerManualRows() -> [Row] {
39+
configurationLoader.configuration.supportedReaders.map { readerType in
40+
switch readerType {
41+
case .chipper:
42+
return .bbposChipper2XBTManual
43+
case .stripeM2:
44+
return .stripeM2Manual
45+
case .wisepad3:
46+
return .wisepad3Manual
47+
case .other:
48+
preconditionFailure("Unknown card reader type was present in the supported readers list. This should not be possible")
49+
}
50+
}
3551
}
3652

3753
func configureTableView() {
@@ -59,6 +75,8 @@ private extension InPersonPaymentsMenuViewController {
5975
configureChipper2XManual(cell: cell)
6076
case let cell as LeftImageTableViewCell where row == .stripeM2Manual:
6177
configureStripeM2Manual(cell: cell)
78+
case let cell as LeftImageTableViewCell where row == .wisepad3Manual:
79+
configureWisepad3Manual(cell: cell)
6280
default:
6381
fatalError()
6482
}
@@ -91,6 +109,13 @@ private extension InPersonPaymentsMenuViewController {
91109
cell.selectionStyle = .default
92110
cell.configure(image: .cardReaderManualIcon, text: Localization.stripeM2CardReaderManual)
93111
}
112+
113+
func configureWisepad3Manual(cell: LeftImageTableViewCell) {
114+
cell.imageView?.tintColor = .text
115+
cell.accessoryType = .disclosureIndicator
116+
cell.selectionStyle = .default
117+
cell.configure(image: .cardReaderManualIcon, text: Localization.wisepad3CardReaderManual)
118+
}
94119
}
95120

96121
// MARK: - Convenience methods
@@ -126,6 +151,10 @@ extension InPersonPaymentsMenuViewController {
126151
func stripeM2ManualWasPressed() {
127152
WebviewHelper.launch(Constants.stripeM2ManualURL, with: self)
128153
}
154+
155+
func wisepad3ManualWasPressed() {
156+
WebviewHelper.launch(Constants.wisepad3ManualURL, with: self)
157+
}
129158
}
130159

131160
// MARK: - UITableViewDataSource
@@ -163,6 +192,8 @@ extension InPersonPaymentsMenuViewController {
163192
bbposChipper2XBTManualWasPressed()
164193
case .stripeM2Manual:
165194
stripeM2ManualWasPressed()
195+
case .wisepad3Manual:
196+
wisepad3ManualWasPressed()
166197
}
167198
}
168199
}
@@ -190,6 +221,11 @@ private extension InPersonPaymentsMenuViewController {
190221
"Stripe M2 card reader manual",
191222
comment: "Navigates to Stripe M2 Card Reader manual"
192223
)
224+
225+
static let wisepad3CardReaderManual = NSLocalizedString(
226+
"WisePad 3 card reader manual",
227+
comment: "Navigates to WisePad 3 Card Reader manual"
228+
)
193229
}
194230
}
195231

@@ -198,6 +234,7 @@ private enum Row: CaseIterable {
198234
case manageCardReader
199235
case bbposChipper2XBTManual
200236
case stripeM2Manual
237+
case wisepad3Manual
201238

202239
var type: UITableViewCell.Type {
203240
LeftImageTableViewCell.self
@@ -212,6 +249,7 @@ private enum Constants {
212249
static let woocommercePurchaseCardReaderURL = URL(string: "https://woocommerce.com/products/m2-card-reader/")!
213250
static let bbposChipper2XBTManualURL = URL(string: "https://developer.bbpos.com/quick_start_guide/Chipper%202X%20BT%20Quick%20Start%20Guide.pdf")!
214251
static let stripeM2ManualURL = URL(string: "https://stripe.com/files/docs/terminal/m2_product_sheet.pdf")!
252+
static let wisepad3ManualURL = URL(string: "https://stripe.com/files/docs/terminal/wp3_product_sheet.pdf")!
215253
}
216254

217255
// MARK: - SwiftUI compatibility

Yosemite/Yosemite/Model/Model.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ public typealias CardReaderEvent = Hardware.CardReaderEvent
133133
public typealias CardReaderSoftwareUpdateState = Hardware.CardReaderSoftwareUpdateState
134134
public typealias CardReaderServiceDiscoveryStatus = Hardware.CardReaderServiceDiscoveryStatus
135135
public typealias CardReaderServiceError = Hardware.CardReaderServiceError
136+
public typealias CardReaderType = Hardware.CardReaderType
136137
public typealias CardReaderConfigError = Hardware.CardReaderConfigError
137138
public typealias PaymentParameters = Hardware.PaymentIntentParameters
138139
public typealias PaymentIntent = Hardware.PaymentIntent

Yosemite/Yosemite/Model/Payments/CardPresentPaymentsConfiguration.swift

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ public struct CardPresentPaymentsConfiguration {
44
public let paymentMethods: [WCPayPaymentMethodType]
55
public let currencies: [String]
66
public let paymentGateways: [String]
7+
public let supportedReaders: [CardReaderType]
78

8-
init(paymentMethods: [WCPayPaymentMethodType], currencies: [String], paymentGateways: [String]) {
9+
init(paymentMethods: [WCPayPaymentMethodType], currencies: [String], paymentGateways: [String], supportedReaders: [CardReaderType]) {
910
self.paymentMethods = paymentMethods
1011
self.currencies = currencies
1112
self.paymentGateways = paymentGateways
13+
self.supportedReaders = supportedReaders
1214
}
1315

1416
public init(country: String, stripeEnabled: Bool, canadaEnabled: Bool) {
@@ -17,26 +19,29 @@ public struct CardPresentPaymentsConfiguration {
1719
self.init(
1820
paymentMethods: [.cardPresent],
1921
currencies: ["USD"],
20-
paymentGateways: [WCPayAccount.gatewayID, StripeAccount.gatewayID]
22+
paymentGateways: [WCPayAccount.gatewayID, StripeAccount.gatewayID],
23+
supportedReaders: [.chipper, .stripeM2]
2124
)
2225
case "US" where stripeEnabled == false:
2326
self.init(
2427
paymentMethods: [.cardPresent],
2528
currencies: ["USD"],
26-
paymentGateways: [WCPayAccount.gatewayID]
29+
paymentGateways: [WCPayAccount.gatewayID],
30+
supportedReaders: [.chipper, .stripeM2]
2731
)
2832
case "CA" where canadaEnabled == true:
2933
self.init(
3034
paymentMethods: [.cardPresent, .interacPresent],
3135
currencies: ["CAD"],
32-
paymentGateways: [WCPayAccount.gatewayID]
36+
paymentGateways: [WCPayAccount.gatewayID],
37+
supportedReaders: [.wisepad3]
3338
)
3439
default:
35-
self.init(paymentMethods: [], currencies: [], paymentGateways: [])
40+
self.init(paymentMethods: [], currencies: [], paymentGateways: [], supportedReaders: [])
3641
}
3742
}
3843

3944
public var isSupportedCountry: Bool {
40-
paymentMethods.isEmpty == false && currencies.isEmpty == false && paymentGateways.isEmpty == false
45+
paymentMethods.isEmpty == false && currencies.isEmpty == false && paymentGateways.isEmpty == false && supportedReaders.isEmpty == false
4146
}
4247
}

0 commit comments

Comments
 (0)