Skip to content

Commit c4f0fb7

Browse files
authored
[Woo POS] Cancel payment after leaving POS (#15205)
2 parents 9fe6551 + 0acbbbc commit c4f0fb7

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

WooCommerce/Classes/POS/Card Present Payments/CardPresentPaymentService.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ final class CardPresentPaymentService: CardPresentPaymentFacade {
110110
DDLogError("Attempting to cancel the payment has failed \(error)")
111111
}
112112

113-
paymentTask?.cancel()
114113
connectionControllerManager.knownReaderProvider.forgetCardReader()
115114

116115
return await withCheckedContinuation { continuation in
@@ -166,11 +165,13 @@ final class CardPresentPaymentService: CardPresentPaymentFacade {
166165
}
167166

168167
func cancelPayment() {
169-
paymentTask?.cancel()
168+
cancelPaymentTask()
170169
}
171170

172171
@MainActor
173172
func cancelPayment() async throws {
173+
cancelPaymentTask()
174+
174175
try await withCheckedThrowingContinuation { continuation in
175176
var nillableContinuation: CheckedContinuation<Void, any Error>? = continuation
176177
let action = CardPresentPaymentAction.cancelPayment { result in
@@ -180,6 +181,11 @@ final class CardPresentPaymentService: CardPresentPaymentFacade {
180181
stores.dispatch(action)
181182
}
182183
}
184+
185+
private func cancelPaymentTask() {
186+
paymentTask?.cancel()
187+
paymentTask = nil
188+
}
183189
}
184190

185191
private extension CardPresentPaymentService {

WooCommerce/Classes/POS/Models/PointOfSaleAggregateModel.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,13 @@ extension PointOfSaleAggregateModel {
486486
@available(iOS 17.0, *)
487487
extension PointOfSaleAggregateModel {
488488
func pointOfSaleClosed() {
489+
// We cancel any payment to prevent the reader from remaining live and awaiting a card tap. Otherwise, it would
490+
// wait until the timeout, which is 30-45 minutes. In that time, it uses more battery, and may result
491+
// in a shopper paying for the wrong order.
492+
Task { [cardPresentPaymentService] in
493+
try await cardPresentPaymentService.cancelPayment()
494+
}
495+
489496
// Before exiting Point of Sale, we warn the merchant about losing their in-progress order.
490497
// We need to clear it down as any accidental retention can cause issues especially when reconnecting card readers.
491498
orderController.clearOrder()

0 commit comments

Comments
 (0)