Skip to content

Commit 39f0030

Browse files
committed
Finish cancelPaymentIntent with an error if it has been already completed
Not finishing a task results in it running forever
1 parent 141dc69 commit 39f0030

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

Hardware/Hardware/CardReader/StripeCardReader/StripeCardReaderService.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,13 @@ extension StripeCardReaderService: CardReaderService {
430430
}
431431

432432
paymentCancellable.cancel({ [weak self] error in
433-
if error == nil {
433+
// If the action could not be canceled,
434+
// e.g. it has already completed, the completion block will be called with an
435+
// error. Otherwise, the completion block will be called with nil.
436+
if let error {
437+
let underlyingError = Self.logAndDecodeError(error)
438+
promise(.failure(CardReaderServiceError.paymentCancellation(underlyingError: underlyingError)))
439+
} else {
434440
self?.paymentCancellable = nil
435441
cancelPaymentIntent()
436442
}

0 commit comments

Comments
 (0)