-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Send receipts after failed payments via the API (#14485)
- Loading branch information
Showing
18 changed files
with
483 additions
and
215 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
WooCommerce/Classes/ViewModels/CardPresentPayments/CardPresentModalErrorWithoutEmail.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import UIKit | ||
|
||
/// Modal presented on error | ||
final class CardPresentModalErrorWithoutEmail: CardPresentPaymentsModalViewModel { | ||
/// A closure to execute when the primary button is tapped | ||
private let tryAgainAction: () -> Void | ||
|
||
/// A closure to execute after the secondary button is tapped to dismiss the modal | ||
private let dismissCompletion: () -> Void | ||
|
||
let textMode: PaymentsModalTextMode = .reducedBottomInfo | ||
let actionsMode: PaymentsModalActionsMode = .twoAction | ||
|
||
let topTitle: String | ||
|
||
var topSubtitle: String? = nil | ||
|
||
let image: UIImage | ||
|
||
let primaryButtonTitle: String? | ||
|
||
let secondaryButtonTitle: String? | ||
|
||
let auxiliaryButtonTitle: String? = nil | ||
|
||
let bottomTitle: String? | ||
|
||
let bottomSubtitle: String? = nil | ||
|
||
var accessibilityLabel: String? { | ||
guard let bottomTitle = bottomTitle else { | ||
return topTitle | ||
} | ||
return topTitle + bottomTitle | ||
} | ||
|
||
init(errorDescription: String?, | ||
transactionType: CardPresentTransactionType, | ||
image: UIImage = .paymentErrorImage, | ||
tryAgainAction: @escaping () -> Void, | ||
dismissCompletion: @escaping () -> Void) { | ||
self.topTitle = CardPresentModalError.Localization.paymentFailed(transactionType: transactionType) | ||
self.bottomTitle = errorDescription | ||
self.image = image | ||
self.primaryButtonTitle = CardPresentModalError.Localization.tryAgain(transactionType: transactionType) | ||
self.secondaryButtonTitle = CardPresentModalError.Localization.noThanks(transactionType: transactionType) | ||
self.tryAgainAction = tryAgainAction | ||
self.dismissCompletion = dismissCompletion | ||
} | ||
|
||
func didTapPrimaryButton(in viewController: UIViewController?) { | ||
tryAgainAction() | ||
} | ||
|
||
func didTapSecondaryButton(in viewController: UIViewController?) { | ||
viewController?.dismiss(animated: true) { [weak self] in | ||
self?.dismissCompletion() | ||
} | ||
} | ||
|
||
func didTapAuxiliaryButton(in viewController: UIViewController?) { } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
...lasses/ViewModels/CardPresentPayments/CardPresentModalNonRetryableErrorWithoutEmail.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import UIKit | ||
|
||
/// Modal presented on error. Does not provide a retry action. | ||
final class CardPresentModalNonRetryableErrorWithoutEmail: CardPresentPaymentsModalViewModel { | ||
|
||
/// Amount charged | ||
private let amount: String | ||
|
||
/// Called when the view is dismissed | ||
private let onDismiss: () -> Void | ||
|
||
let textMode: PaymentsModalTextMode = .reducedBottomInfo | ||
let actionsMode: PaymentsModalActionsMode = .oneAction | ||
|
||
let topTitle: String = CardPresentModalNonRetryableError.Localization.paymentFailed | ||
|
||
var topSubtitle: String? { | ||
amount | ||
} | ||
|
||
let image: UIImage | ||
|
||
let primaryButtonTitle: String? = CardPresentModalNonRetryableError.Localization.dismiss | ||
|
||
let secondaryButtonTitle: String? = nil | ||
|
||
let auxiliaryButtonTitle: String? = nil | ||
|
||
let bottomTitle: String? | ||
|
||
let bottomSubtitle: String? = nil | ||
|
||
var accessibilityLabel: String? { | ||
guard let bottomTitle = bottomTitle else { | ||
return topTitle | ||
} | ||
|
||
return topTitle + bottomTitle | ||
} | ||
|
||
init(amount: String, | ||
errorDescription: String?, | ||
image: UIImage = .paymentErrorImage, | ||
onDismiss: @escaping () -> Void) { | ||
self.amount = amount | ||
self.bottomTitle = errorDescription | ||
self.image = image | ||
self.onDismiss = onDismiss | ||
} | ||
|
||
convenience init(amount: String, error: Error, onDismiss: @escaping () -> Void) { | ||
self.init(amount: amount, errorDescription: error.localizedDescription, onDismiss: onDismiss) | ||
} | ||
|
||
func didTapPrimaryButton(in viewController: UIViewController?) { | ||
guard let viewController else { | ||
return onDismiss() | ||
} | ||
viewController.dismiss(animated: true) { [weak self] in | ||
self?.onDismiss() | ||
} | ||
} | ||
|
||
func didTapSecondaryButton(in viewController: UIViewController?) { } | ||
|
||
func didTapAuxiliaryButton(in viewController: UIViewController?) { } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.