Skip to content

Commit bc89e2b

Browse files
committed
8085 Combine cancellation reasons in underlyingerror
1 parent 186f7a6 commit bc89e2b

File tree

6 files changed

+35
-22
lines changed

6 files changed

+35
-22
lines changed

Hardware/Hardware/CardReader/StripeCardReader/StripeCardReaderService.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -507,11 +507,15 @@ private extension StripeCardReaderService {
507507
/// the completion block for collectPaymentMethod will be called
508508
/// with error Canceled when collectPaymentMethod is canceled
509509
/// https://stripe.dev/stripe-terminal-ios/docs/Classes/SCPTerminal.html#/c:objc(cs)SCPTerminal(im)collectPaymentMethod:delegate:completion:
510-
if underlyingError == .commandCancelled {
510+
if case .commandCancelled(let cancellationSource) = underlyingError {
511511
DDLogWarn("💳 Warning: collect payment cancelled \(error)")
512512
/// If we've not used the cancellable in the app, the cancellation must have come from the reader
513-
if self?.paymentCancellable != nil {
514-
underlyingError = .commandCancelledOnReader
513+
if case .unknown = cancellationSource {
514+
if self?.paymentCancellable != nil {
515+
underlyingError = .commandCancelled(from: .reader)
516+
} else {
517+
underlyingError = .commandCancelled(from: .app)
518+
}
515519
}
516520
} else {
517521
DDLogError("💳 Error: collect payment method \(underlyingError)")

Hardware/Hardware/CardReader/StripeCardReader/UnderlyingError+Stripe.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ extension UnderlyingError {
2626
case ErrorCode.Code.featureNotAvailableWithConnectedReader.rawValue:
2727
self = .featureNotAvailableWithConnectedReader
2828
case ErrorCode.Code.canceled.rawValue:
29-
self = .commandCancelled
29+
self = .commandCancelled(from: .unknown)
3030
case ErrorCode.Code.locationServicesDisabled.rawValue:
3131
self = .locationServicesDisabled
3232
case ErrorCode.Code.bluetoothDisabled.rawValue:

Hardware/Hardware/CardReader/UnderlyingError.swift

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,15 @@ public enum UnderlyingError: Error, Equatable {
2727
case featureNotAvailableWithConnectedReader
2828

2929
/// A command was cancelled
30-
case commandCancelled
31-
32-
/// A command was cancelled on the reader.
33-
/// Note that this is not produced by Stripe, we have to infer it from commandCancelled.
34-
case commandCancelledOnReader
30+
case commandCancelled(from: CancellationSource)
31+
32+
/// A command can be cancelled on the reader, or in the app.
33+
/// Note that this is not produced by Stripe, we have to infer it from commandCancelled, so we start with `.unknown`.
34+
public enum CancellationSource {
35+
case unknown
36+
case app
37+
case reader
38+
}
3539

3640
/// Access to location services is currently disabled. This may be because:
3741
/// - The user disabled location services in the system settings.
@@ -286,12 +290,15 @@ extension UnderlyingError: LocalizedError {
286290
case .featureNotAvailableWithConnectedReader:
287291
return NSLocalizedString("Unable to perform request with the connected reader - unsupported feature - please try again with another reader",
288292
comment: "Error message when the card reader cannot be used to perform the requested task.")
289-
case .commandCancelled:
290-
return NSLocalizedString("The system canceled the command unexpectedly - please try again",
291-
comment: "Error message when the system cancels a command.")
292-
case .commandCancelledOnReader:
293-
return NSLocalizedString("The payment was canceled on the reader",
294-
comment: "Error message when the cancel button on the reader is used.")
293+
case .commandCancelled(let cancellationSource):
294+
switch cancellationSource {
295+
case .reader:
296+
return NSLocalizedString("The payment was canceled on the reader",
297+
comment: "Error message when the cancel button on the reader is used.")
298+
default:
299+
return NSLocalizedString("The system canceled the command unexpectedly - please try again",
300+
comment: "Error message when the system cancels a command.")
301+
}
295302
case .locationServicesDisabled:
296303
return NSLocalizedString("Unable to access Location Services - please enable Location Services and try again",
297304
comment: "Error message when location services is not enabled for this application.")

WooCommerce/Classes/ViewRelated/Dashboard/Settings/CardReadersV2/BluetoothCardReaderPaymentAlertsProvider.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ final class BluetoothCardReaderPaymentAlertsProvider: CardReaderTransactionAlert
9090

9191
func cancelledOnReader() -> CardPresentPaymentsModalViewModel? {
9292
CardPresentModalNonRetryableError(amount: amount,
93-
error: CardReaderServiceError.paymentMethodCollection(underlyingError: .commandCancelledOnReader),
93+
error: CardReaderServiceError.paymentMethodCollection(underlyingError: .commandCancelled(from: .reader)),
9494
onDismiss: { })
9595
}
9696
}

WooCommerce/Classes/ViewRelated/Orders/Collect Payments/CollectOrderPaymentUseCase.swift

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -274,10 +274,13 @@ private extension CollectOrderPaymentUseCase {
274274
switch result {
275275
case .success(let capturedPaymentData):
276276
self?.handleSuccessfulPayment(capturedPaymentData: capturedPaymentData, onCompletion: onCompletion)
277-
case .failure(CardReaderServiceError.paymentMethodCollection(.commandCancelledOnReader)):
278-
self?.handlePaymentCancellationFromReader(alertProvider: paymentAlerts)
279-
case .failure(CardReaderServiceError.paymentMethodCollection(.commandCancelled)):
280-
self?.handlePaymentCancellation()
277+
case .failure(CardReaderServiceError.paymentMethodCollection(.commandCancelled(let cancellationSource))):
278+
switch cancellationSource {
279+
case .reader:
280+
self?.handlePaymentCancellationFromReader(alertProvider: paymentAlerts)
281+
default:
282+
self?.handlePaymentCancellation()
283+
}
281284
case .failure(let error):
282285
self?.handlePaymentFailureAndRetryPayment(error, alertProvider: paymentAlerts, onCompletion: onCompletion)
283286
}

WooCommerce/Classes/ViewRelated/Orders/Collect Payments/LegacyCollectOrderPaymentUseCase.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,7 @@ private extension LegacyCollectOrderPaymentUseCase {
293293
switch result {
294294
case .success(let capturedPaymentData):
295295
self?.handleSuccessfulPayment(capturedPaymentData: capturedPaymentData, onCompletion: onCompletion)
296-
case .failure(CardReaderServiceError.paymentMethodCollection(.commandCancelledOnReader)),
297-
.failure(CardReaderServiceError.paymentMethodCollection(.commandCancelled)):
296+
case .failure(CardReaderServiceError.paymentMethodCollection(.commandCancelled(_))):
298297
self?.trackPaymentCancelation()
299298
onCompletion(.failure(CollectOrderPaymentUseCaseError.flowCanceledByUser))
300299
case .failure(let error):

0 commit comments

Comments
 (0)