Skip to content

Commit 34998d9

Browse files
authored
Merge pull request #6654 from woocommerce/issue/6643-handle-retry-from-failed-interac-refund
[Mobile Payments] Allow retries of failed interac refunds
2 parents 35ce249 + 369a380 commit 34998d9

File tree

2 files changed

+7
-13
lines changed

2 files changed

+7
-13
lines changed

Hardware/Hardware/CardReader/StripeCardReader/StripeCardReaderService.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,10 +518,12 @@ extension StripeCardReaderService {
518518
return Future() { [weak self] promise in
519519
self?.refundCancellable = Terminal.shared.collectRefundPaymentMethod(parameters) { collectError in
520520
if let error = collectError {
521+
self?.refundCancellable = nil
521522
promise(.failure(CardReaderServiceError.refundPayment(underlyingError: UnderlyingError(with: error))))
522523
} else {
523524
// Process refund
524525
Terminal.shared.processRefund { processedRefund, processError in
526+
self?.refundCancellable = nil
525527
if let error = processError {
526528
promise(.failure(CardReaderServiceError.refundPayment(underlyingError: UnderlyingError(with: error))))
527529
} else if let refund = processedRefund {

WooCommerce/Classes/ViewRelated/Orders/Refund/RefundSubmissionUseCase.swift

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -290,20 +290,12 @@ private extension RefundSubmissionUseCase {
290290
// TODO: 5984 - tracks in-person refund error
291291
DDLogError("Failed to refund: \(error.localizedDescription)")
292292
// Informs about the error.
293+
//TODO: Check which refund errors can't be retried, and use that to call nonRetryableError(from: self.rootViewController, error: cancelError)
293294
alerts.error(error: error, tryAgain: { [weak self] in
294-
// Cancels current payment.
295-
self?.cardPresentRefundOrchestrator.cancelRefund { [weak self] result in
296-
guard let self = self else { return }
297-
298-
switch result {
299-
case .success:
300-
// Retries refund.
301-
self.attemptCardPresentRefund(refundAmount: refundAmount, charge: charge, onCompletion: onCompletion)
302-
case .failure(let cancelError):
303-
// Informs that payment can't be retried.
304-
self.alerts.nonRetryableError(from: self.rootViewController, error: cancelError)
305-
onCompletion(.failure(error))
306-
}
295+
// Cancels current refund, if possible.
296+
self?.cardPresentRefundOrchestrator.cancelRefund { [weak self] _ in
297+
// Regardless of whether the refund could be cancelled (e.g. it completed but failed), retry the refund.
298+
self?.attemptCardPresentRefund(refundAmount: refundAmount, charge: charge, onCompletion: onCompletion)
307299
}
308300
}, dismissCompletion: {
309301
onCompletion(.failure(error))

0 commit comments

Comments
 (0)