Skip to content

Commit 8c8d46b

Browse files
committed
8089 Specific error for built-in reader disconnect
When the built in reader disconnects during a payment flow, e.g. because of going in to the background, or recieving a call, we handle the error as non-retryable. This commit updates the error message to specifically tell the user about this interruption without using the word “disconnected”, which is strange in the context of the built in reader, and informs them about how to continue with the payment.
1 parent c5b5776 commit 8c8d46b

File tree

2 files changed

+35
-28
lines changed

2 files changed

+35
-28
lines changed

WooCommerce/Classes/ViewModels/CardPresentPayments/CardPresentModalNonRetryableError.swift

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ final class CardPresentModalNonRetryableError: CardPresentPaymentsModalViewModel
66
/// Amount charged
77
private let amount: String
88

9-
/// The error returned by the stack
10-
private let error: Error
11-
129
/// Called when the view is dismissed
1310
private let onDismiss: () -> Void
1411

@@ -29,9 +26,7 @@ final class CardPresentModalNonRetryableError: CardPresentPaymentsModalViewModel
2926

3027
let auxiliaryButtonTitle: String? = nil
3128

32-
var bottomTitle: String? {
33-
error.localizedDescription
34-
}
29+
let bottomTitle: String?
3530

3631
let bottomSubtitle: String? = nil
3732

@@ -43,12 +38,16 @@ final class CardPresentModalNonRetryableError: CardPresentPaymentsModalViewModel
4338
return topTitle + bottomTitle
4439
}
4540

46-
init(amount: String, error: Error, onDismiss: @escaping () -> Void) {
41+
init(amount: String, errorDescription: String?, onDismiss: @escaping () -> Void) {
4742
self.amount = amount
48-
self.error = error
43+
self.bottomTitle = errorDescription
4944
self.onDismiss = onDismiss
5045
}
5146

47+
convenience init(amount: String, error: Error, onDismiss: @escaping () -> Void) {
48+
self.init(amount: amount, errorDescription: error.localizedDescription, onDismiss: onDismiss)
49+
}
50+
5251
func didTapPrimaryButton(in viewController: UIViewController?) {
5352
viewController?.dismiss(animated: true) { [weak self] in
5453
self?.onDismiss()

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

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -48,32 +48,16 @@ final class BuiltInCardReaderPaymentAlertsProvider: CardReaderTransactionAlertsP
4848
}
4949

5050
func error(error: Error, tryAgain: @escaping () -> Void, dismissCompletion: @escaping () -> Void) -> CardPresentPaymentsModalViewModel {
51-
let errorDescription: String?
52-
if let error = error as? CardReaderServiceError {
53-
switch error {
54-
case .connection(let underlyingError),
55-
.discovery(let underlyingError),
56-
.disconnection(let underlyingError),
57-
.intentCreation(let underlyingError),
58-
.paymentMethodCollection(let underlyingError),
59-
.paymentCapture(let underlyingError),
60-
.paymentCancellation(let underlyingError),
61-
.softwareUpdate(let underlyingError, _):
62-
errorDescription = Localization.errorDescription(underlyingError: underlyingError)
63-
default:
64-
errorDescription = error.errorDescription
65-
}
66-
} else {
67-
errorDescription = error.localizedDescription
68-
}
69-
return CardPresentModalError(errorDescription: errorDescription,
51+
return CardPresentModalError(errorDescription: builtInReaderDescription(for: error),
7052
transactionType: .collectPayment,
7153
primaryAction: tryAgain,
7254
dismissCompletion: dismissCompletion)
7355
}
7456

7557
func nonRetryableError(error: Error, dismissCompletion: @escaping () -> Void) -> CardPresentPaymentsModalViewModel {
76-
CardPresentModalNonRetryableError(amount: amount, error: error, onDismiss: dismissCompletion)
58+
CardPresentModalNonRetryableError(amount: amount,
59+
errorDescription: builtInReaderDescription(for: error),
60+
onDismiss: dismissCompletion)
7761
}
7862

7963
func retryableError(tryAgain: @escaping () -> Void) -> CardPresentPaymentsModalViewModel {
@@ -86,6 +70,26 @@ final class BuiltInCardReaderPaymentAlertsProvider: CardReaderTransactionAlertsP
8670
}
8771

8872
private extension BuiltInCardReaderPaymentAlertsProvider {
73+
func builtInReaderDescription(for error: Error) -> String? {
74+
if let error = error as? CardReaderServiceError {
75+
switch error {
76+
case .connection(let underlyingError),
77+
.discovery(let underlyingError),
78+
.disconnection(let underlyingError),
79+
.intentCreation(let underlyingError),
80+
.paymentMethodCollection(let underlyingError),
81+
.paymentCapture(let underlyingError),
82+
.paymentCancellation(let underlyingError),
83+
.softwareUpdate(let underlyingError, _):
84+
return Localization.errorDescription(underlyingError: underlyingError)
85+
default:
86+
return error.errorDescription
87+
}
88+
} else {
89+
return error.localizedDescription
90+
}
91+
}
92+
8993
enum Localization {
9094
static func errorDescription(underlyingError: UnderlyingError) -> String? {
9195
switch underlyingError {
@@ -102,6 +106,10 @@ private extension BuiltInCardReaderPaymentAlertsProvider {
102106
"Sorry, this payment couldn’t be processed",
103107
comment: "Error message when the card reader service experiences an unexpected internal service error."
104108
)
109+
case .notConnectedToReader:
110+
return NSLocalizedString(
111+
"The payment was interrupted and cannot be continued. You can retry the payment from the order screen.",
112+
comment: "Error shown when the built-in card reader payment is interrupted by activity on the phone")
105113
default:
106114
return underlyingError.errorDescription
107115
}

0 commit comments

Comments
 (0)