Skip to content

Commit b8c4cb5

Browse files
committed
Handle onCardInserted case to hide cash payment view at this point
1 parent b9549a0 commit b8c4cb5

File tree

9 files changed

+39
-5
lines changed

9 files changed

+39
-5
lines changed

WooCommerce/Classes/POS/Models/PointOfSalePaymentState.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ enum PointOfSalePaymentState: Equatable {
88
enum PointOfSaleCardPaymentState: Equatable {
99
case idle
1010
case acceptingCard
11+
case cardInserted
1112
case validatingOrder
1213
case validatingOrderError
1314
case preparingReader
@@ -33,6 +34,8 @@ extension PointOfSalePaymentState {
3334
self = .card(.preparingReader)
3435
case .show(.tapSwipeOrInsertCard):
3536
self = .card(.acceptingCard)
37+
case .show(.cardInserted):
38+
self = .card(.cardInserted)
3639
case .show(.processing),
3740
.show(.displayReaderMessage):
3841
self = .card(.processingPayment)
@@ -65,7 +68,8 @@ extension PointOfSalePaymentState {
6568
.card(.validatingOrder),
6669
.card(.validatingOrderError),
6770
.card(.preparingReader),
68-
.card(.acceptingCard):
71+
.card(.acceptingCard),
72+
.card(.cardInserted):
6973
return false
7074
case .cash:
7175
return true

WooCommerce/Classes/POS/Presentation/TotalsView.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@ private extension TotalsView {
340340
sidePadding: POSPadding.none)
341341
case .idle,
342342
.acceptingCard,
343+
.cardInserted,
343344
.validatingOrder,
344345
.preparingReader,
345346
.processingPayment:

WooCommerce/Classes/POS/ViewHelpers/CartViewHelper.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ private extension PointOfSalePaymentState {
3838
.paymentError,
3939
.cardPaymentSuccessful,
4040
.validatingOrder,
41-
.preparingReader:
41+
.preparingReader,
42+
.cardInserted:
4243
return false
4344
case .idle, .validatingOrderError, .acceptingCard:
4445
return true

WooCommerce/Classes/POS/ViewHelpers/TotalsViewHelper.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ struct TotalsViewHelper {
77
switch cardPaymentState {
88
case .idle,
99
.acceptingCard,
10+
.cardInserted,
1011
.validatingOrder,
1112
.validatingOrderError,
1213
.preparingReader:
@@ -34,6 +35,7 @@ struct TotalsViewHelper {
3435
case .validatingOrder,
3536
.validatingOrderError,
3637
.processingPayment,
38+
.cardInserted,
3739
.paymentError,
3840
.cardPaymentSuccessful:
3941
return false

WooCommerce/WooCommerceTests/Mocks/MockPaymentCaptureOrchestrator.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ final class MockPaymentCaptureOrchestrator: PaymentCaptureOrchestrating {
66
var mockCollectPaymentHandler: ((_ onPreparingReader: () -> Void,
77
_ onWaitingForInput: (Yosemite.CardReaderInput) -> Void,
88
_ onProcessingMessage: () -> Void,
9+
_ onCardInserted: () -> Void,
910
_ onDisplayMessage: (String) -> Void,
1011
_ onProcessingCompletion: (Yosemite.PaymentIntent) -> Void,
1112
_ onCompletion: (Result<CardPresentCapturedPaymentData, Error>) -> Void) -> Void)? = nil
@@ -24,6 +25,7 @@ final class MockPaymentCaptureOrchestrator: PaymentCaptureOrchestrating {
2425
channel: PaymentChannel,
2526
onPreparingReader: () -> Void,
2627
onWaitingForInput: @escaping (CardReaderInput) -> Void,
28+
onCardInserted: @escaping () -> Void,
2729
onProcessingMessage: @escaping () -> Void,
2830
onDisplayMessage: @escaping (String) -> Void,
2931
onProcessingCompletion: @escaping (PaymentIntent) -> Void,
@@ -38,6 +40,7 @@ final class MockPaymentCaptureOrchestrator: PaymentCaptureOrchestrating {
3840
mockCollectPaymentHandler?(onPreparingReader,
3941
onWaitingForInput,
4042
onProcessingMessage,
43+
onCardInserted,
4144
onDisplayMessage,
4245
onProcessingCompletion,
4346
onCompletion)

WooCommerce/WooCommerceTests/POS/ViewHelpers/CartViewHelperTests.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,19 @@ struct CartViewHelperTests {
6565
paymentState: .card(.validatingOrderError)) == false)
6666
}
6767

68+
@Test func shouldPreventCartEditing_when_card_paymentState_cardInserted() async throws {
69+
// Given
70+
let orderLoaded = PointOfSaleOrderState.loaded(PointOfSaleOrderTotals(
71+
cartTotal: "$10.00",
72+
orderTotal: "$12.00",
73+
taxTotal: "$2.00",
74+
orderTotalDecimal: 12.0))
75+
76+
// When, Then
77+
#expect(sut.shouldPreventCartEditing(orderState: orderLoaded,
78+
paymentState: .card(.cardInserted)) == true)
79+
}
80+
6881
@Test(arguments: zip([0, 1, 2, 3], [nil, "1 item", "2 items", "3 items"]))
6982
func itemsInCartLabel(_ count: Int, _ expected: String?) async throws {
7083
// Given

WooCommerce/WooCommerceTests/POS/ViewHelpers/TotalsViewHelperTests.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ struct TotalsViewHelperTests {
3737
(CardPresentPaymentReaderConnectionStatus.connected(.init(name: "", batteryLevel: nil)), PointOfSaleCardPaymentState.preparingReader),
3838
(CardPresentPaymentReaderConnectionStatus.connected(.init(name: "", batteryLevel: nil)), PointOfSaleCardPaymentState.processingPayment),
3939
(CardPresentPaymentReaderConnectionStatus.connected(.init(name: "", batteryLevel: nil)), PointOfSaleCardPaymentState.validatingOrder),
40-
(CardPresentPaymentReaderConnectionStatus.connected(.init(name: "", batteryLevel: nil)), PointOfSaleCardPaymentState.validatingOrderError)
40+
(CardPresentPaymentReaderConnectionStatus.connected(.init(name: "", batteryLevel: nil)), PointOfSaleCardPaymentState.validatingOrderError),
41+
(CardPresentPaymentReaderConnectionStatus.connected(.init(name: "", batteryLevel: nil)), PointOfSaleCardPaymentState.cardInserted)
4142
])
4243
func test_shouldShowDisconnectedMessage_returns_false_when_reader_connected(
4344
readerConnectionStatus: CardPresentPaymentReaderConnectionStatus,
@@ -48,7 +49,8 @@ struct TotalsViewHelperTests {
4849

4950
@Test(arguments: [
5051
(PointOfSalePaymentState.card(.validatingOrderError)),
51-
(PointOfSalePaymentState.card(.acceptingCard))
52+
(PointOfSalePaymentState.card(.acceptingCard)),
53+
(PointOfSalePaymentState.card(.cardInserted))
5254
])
5355
func test_shouldShowCollectCashPaymentButton_returns_true_for_supported_states(
5456
paymentState: PointOfSalePaymentState) {
@@ -92,7 +94,8 @@ struct TotalsViewHelperTests {
9294

9395
@Test(arguments: [
9496
(PointOfSalePaymentState.card(.validatingOrderError)),
95-
(PointOfSalePaymentState.card(.acceptingCard))
97+
(PointOfSalePaymentState.card(.acceptingCard)),
98+
(PointOfSalePaymentState.card(.cardInserted))
9699
])
97100
func test_shouldShowCollectCashPaymentButton_returns_false_when_order_syncing(
98101
paymentState: PointOfSalePaymentState) {

WooCommerce/WooCommerceTests/ViewModels/CardPresentPayments/CollectOrderPaymentUseCaseTests.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@ private extension CollectOrderPaymentUseCaseTests {
368368
mockPaymentOrchestrator.mockCollectPaymentHandler = { onPreparingReader,
369369
onWaitingForInput,
370370
onProcessingMessage,
371+
onCardInserted,
371372
onDisplayMessage,
372373
onProcessingCompletion,
373374
onCompletion in
@@ -380,6 +381,7 @@ private extension CollectOrderPaymentUseCaseTests {
380381
mockPaymentOrchestrator.mockCollectPaymentHandler = { onPreparingReader,
381382
onWaitingForInput,
382383
onProcessingMessage,
384+
onCardInserted,
383385
onDisplayMessage,
384386
onProcessingCompletion,
385387
onCompletion in

WooCommerce/WooCommerceTests/ViewModels/CardPresentPayments/PaymentCaptureOrchestratorTests.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ final class PaymentCaptureOrchestratorTests: XCTestCase {
4848
channel: .storeManagement,
4949
onPreparingReader: {},
5050
onWaitingForInput: { _ in },
51+
onCardInserted: {},
5152
onProcessingMessage: {},
5253
onDisplayMessage: { _ in },
5354
onProcessingCompletion: { _ in },
@@ -80,6 +81,7 @@ final class PaymentCaptureOrchestratorTests: XCTestCase {
8081
channel: .storeManagement,
8182
onPreparingReader: {},
8283
onWaitingForInput: { _ in },
84+
onCardInserted: {},
8385
onProcessingMessage: {},
8486
onDisplayMessage: { _ in },
8587
onProcessingCompletion: { _ in },
@@ -120,6 +122,7 @@ final class PaymentCaptureOrchestratorTests: XCTestCase {
120122
channel: .storeManagement,
121123
onPreparingReader: {},
122124
onWaitingForInput: { _ in },
125+
onCardInserted: {},
123126
onProcessingMessage: {},
124127
onDisplayMessage: { _ in },
125128
onProcessingCompletion: { _ in },
@@ -174,6 +177,7 @@ final class PaymentCaptureOrchestratorTests: XCTestCase {
174177
channel: .storeManagement,
175178
onPreparingReader: {},
176179
onWaitingForInput: { _ in },
180+
onCardInserted: {},
177181
onProcessingMessage: {},
178182
onDisplayMessage: { _ in },
179183
onProcessingCompletion: { _ in },
@@ -211,6 +215,7 @@ final class PaymentCaptureOrchestratorTests: XCTestCase {
211215
channel: .storeManagement,
212216
onPreparingReader: {},
213217
onWaitingForInput: { _ in },
218+
onCardInserted: {},
214219
onProcessingMessage: {},
215220
onDisplayMessage: { _ in },
216221
onProcessingCompletion: { _ in },

0 commit comments

Comments
 (0)