Skip to content

Commit 466ecbd

Browse files
committed
Move CollectOrderPaymentUseCaseError to Yosemite for reuse
1 parent 26be5a6 commit 466ecbd

File tree

4 files changed

+56
-52
lines changed

4 files changed

+56
-52
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import Foundation
2+
3+
public enum CollectOrderPaymentUseCaseError: LocalizedError {
4+
case flowCanceledByUser
5+
case paymentGatewayNotFound
6+
case orderTotalChanged
7+
case couldNotRefreshOrder(Error)
8+
case orderAlreadyPaid
9+
10+
public var errorDescription: String? {
11+
switch self {
12+
case .flowCanceledByUser:
13+
return Localization.paymentCancelledLocalizedDescription
14+
case .paymentGatewayNotFound:
15+
return Localization.paymentGatewayNotFoundLocalizedDescription
16+
case .orderTotalChanged:
17+
return Localization.orderTotalChangedLocalizedDescription
18+
case .couldNotRefreshOrder(let error as LocalizedError):
19+
return error.errorDescription
20+
case .couldNotRefreshOrder(let error):
21+
return String.localizedStringWithFormat(Localization.couldNotRefreshOrderLocalizedDescription, error.localizedDescription)
22+
case .orderAlreadyPaid:
23+
return Localization.orderAlreadyPaidLocalizedDescription
24+
}
25+
}
26+
27+
private enum Localization {
28+
static let couldNotRefreshOrderLocalizedDescription = NSLocalizedString(
29+
"Unable to process payment. We could not fetch the latest order details. Please check your network " +
30+
"connection and try again. Underlying error: %1$@",
31+
comment: "Error message when collecting an In-Person Payment and unable to update the order. %!$@ will " +
32+
"be replaced with further error details.")
33+
34+
static let orderTotalChangedLocalizedDescription = NSLocalizedString(
35+
"collectOrderPaymentUseCase.error.message.orderTotalChanged",
36+
value: "Order total has changed since the beginning of payment. Please go back and check the order is " +
37+
"correct, then try the payment again.",
38+
comment: "Error message when collecting an In-Person Payment and the order total has changed remotely.")
39+
40+
static let orderAlreadyPaidLocalizedDescription = NSLocalizedString(
41+
"Unable to process payment. This order is already paid, taking a further payment would result in the " +
42+
"customer being charged twice for their order.",
43+
comment: "Error message shown during In-Person Payments when the order is found to be paid after it's refreshed.")
44+
45+
static let paymentGatewayNotFoundLocalizedDescription = NSLocalizedString(
46+
"Unable to process payment. We could not connect to the payment system. Please contact support if this " +
47+
"error continues.",
48+
comment: "Error message shown during In-Person Payments when the payment gateway is not available.")
49+
50+
static let paymentCancelledLocalizedDescription = NSLocalizedString(
51+
"The payment was cancelled.", comment: "Message shown if a payment cancellation is shown as an error.")
52+
}
53+
}
54+

WooCommerce/Classes/POS/Adaptors/Card Present Payments/CardPresentPaymentsAlertPresenterAdaptor.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import Foundation
22
import Combine
33
import enum Yosemite.ServerSidePaymentCaptureError
44
import enum Yosemite.CardReaderServiceError
5+
import enum Yosemite.CollectOrderPaymentUseCaseError
56

67
final class CardPresentPaymentsAlertPresenterAdaptor: CardPresentPaymentAlertsPresenting {
78
typealias AlertDetails = CardPresentPaymentEventDetails

WooCommerce/Classes/POS/Presentation/Card Present Payments/PointOfSaleCardPresentPaymentEventPresentationStyle.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Foundation
2+
import enum Yosemite.CollectOrderPaymentUseCaseError
23

34
enum PointOfSaleCardPresentPaymentEventPresentationStyle {
45
case message(PointOfSaleCardPresentPaymentMessageType)

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

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -919,58 +919,6 @@ enum CollectOrderPaymentUseCaseNotValidAmountError: Error, LocalizedError, Equat
919919
}
920920
}
921921

922-
enum CollectOrderPaymentUseCaseError: LocalizedError {
923-
case flowCanceledByUser
924-
case paymentGatewayNotFound
925-
case orderTotalChanged
926-
case couldNotRefreshOrder(Error)
927-
case orderAlreadyPaid
928-
929-
var errorDescription: String? {
930-
switch self {
931-
case .flowCanceledByUser:
932-
return Localization.paymentCancelledLocalizedDescription
933-
case .paymentGatewayNotFound:
934-
return Localization.paymentGatewayNotFoundLocalizedDescription
935-
case .orderTotalChanged:
936-
return Localization.orderTotalChangedLocalizedDescription
937-
case .couldNotRefreshOrder(let error as LocalizedError):
938-
return error.errorDescription
939-
case .couldNotRefreshOrder(let error):
940-
return String.localizedStringWithFormat(Localization.couldNotRefreshOrderLocalizedDescription, error.localizedDescription)
941-
case .orderAlreadyPaid:
942-
return Localization.orderAlreadyPaidLocalizedDescription
943-
}
944-
}
945-
946-
private enum Localization {
947-
static let couldNotRefreshOrderLocalizedDescription = NSLocalizedString(
948-
"Unable to process payment. We could not fetch the latest order details. Please check your network " +
949-
"connection and try again. Underlying error: %1$@",
950-
comment: "Error message when collecting an In-Person Payment and unable to update the order. %!$@ will " +
951-
"be replaced with further error details.")
952-
953-
static let orderTotalChangedLocalizedDescription = NSLocalizedString(
954-
"collectOrderPaymentUseCase.error.message.orderTotalChanged",
955-
value: "Order total has changed since the beginning of payment. Please go back and check the order is " +
956-
"correct, then try the payment again.",
957-
comment: "Error message when collecting an In-Person Payment and the order total has changed remotely.")
958-
959-
static let orderAlreadyPaidLocalizedDescription = NSLocalizedString(
960-
"Unable to process payment. This order is already paid, taking a further payment would result in the " +
961-
"customer being charged twice for their order.",
962-
comment: "Error message shown during In-Person Payments when the order is found to be paid after it's refreshed.")
963-
964-
static let paymentGatewayNotFoundLocalizedDescription = NSLocalizedString(
965-
"Unable to process payment. We could not connect to the payment system. Please contact support if this " +
966-
"error continues.",
967-
comment: "Error message shown during In-Person Payments when the payment gateway is not available.")
968-
969-
static let paymentCancelledLocalizedDescription = NSLocalizedString(
970-
"The payment was cancelled.", comment: "Message shown if a payment cancellation is shown as an error.")
971-
}
972-
}
973-
974922
enum CardPaymentRetryApproach {
975923
case reuseIntent
976924
case restart

0 commit comments

Comments
 (0)