Skip to content

Commit

Permalink
[Woo POS] Cancel payment after leaving POS (#15205)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshheald authored Feb 20, 2025
2 parents 9fe6551 + 0acbbbc commit c4f0fb7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ final class CardPresentPaymentService: CardPresentPaymentFacade {
DDLogError("Attempting to cancel the payment has failed \(error)")
}

paymentTask?.cancel()
connectionControllerManager.knownReaderProvider.forgetCardReader()

return await withCheckedContinuation { continuation in
Expand Down Expand Up @@ -166,11 +165,13 @@ final class CardPresentPaymentService: CardPresentPaymentFacade {
}

func cancelPayment() {
paymentTask?.cancel()
cancelPaymentTask()
}

@MainActor
func cancelPayment() async throws {
cancelPaymentTask()

try await withCheckedThrowingContinuation { continuation in
var nillableContinuation: CheckedContinuation<Void, any Error>? = continuation
let action = CardPresentPaymentAction.cancelPayment { result in
Expand All @@ -180,6 +181,11 @@ final class CardPresentPaymentService: CardPresentPaymentFacade {
stores.dispatch(action)
}
}

private func cancelPaymentTask() {
paymentTask?.cancel()
paymentTask = nil
}
}

private extension CardPresentPaymentService {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,13 @@ extension PointOfSaleAggregateModel {
@available(iOS 17.0, *)
extension PointOfSaleAggregateModel {
func pointOfSaleClosed() {
// We cancel any payment to prevent the reader from remaining live and awaiting a card tap. Otherwise, it would
// wait until the timeout, which is 30-45 minutes. In that time, it uses more battery, and may result
// in a shopper paying for the wrong order.
Task { [cardPresentPaymentService] in
try await cardPresentPaymentService.cancelPayment()
}

// Before exiting Point of Sale, we warn the merchant about losing their in-progress order.
// We need to clear it down as any accidental retention can cause issues especially when reconnecting card readers.
orderController.clearOrder()
Expand Down

0 comments on commit c4f0fb7

Please sign in to comment.