-
Notifications
You must be signed in to change notification settings - Fork 115
/
Copy pathCardPresentModalSuccessEmailSent.swift
66 lines (47 loc) · 2.29 KB
/
CardPresentModalSuccessEmailSent.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import UIKit
/// Modal presented when the payment has been collected successfully
/// Customer attached to order therefore an email receipt is sent automatically
final class CardPresentModalSuccessEmailSent: CardPresentPaymentsModalViewModel {
/// Closure to execute when primary button is tapped
private let printReceiptAction: () -> Void
/// Closure to execute when secondary button is tapped.
private let noReceiptAction: () -> Void
let textMode: PaymentsModalTextMode = .fullInfo
let actionsMode: PaymentsModalActionsMode = .twoAction
let topTitle: String = CardPresentModalSuccess.Localization.paymentSuccessful
var topSubtitle: String? = nil
let image: UIImage = .celebrationImage
let primaryButtonTitle: String? = CardPresentModalSuccess.Localization.printReceipt
let secondaryButtonTitle: String? = CardPresentModalSuccess.Localization.saveReceiptAndContinue
let auxiliaryButtonTitle: String? = nil
let bottomTitle: String? = nil
let bottomAttributedTitle: NSAttributedString?
let bottomSubtitle: String? = nil
var accessibilityLabel: String? {
return topTitle
}
init(printReceipt: @escaping () -> Void,
noReceiptAction: @escaping () -> Void,
email: String) {
self.printReceiptAction = printReceipt
self.noReceiptAction = noReceiptAction
let formattedMessage = String(format: CardPresentModalSuccess.Localization.receiptMessage, email)
let attributedString = NSMutableAttributedString(string: formattedMessage)
if let emailRange = formattedMessage.range(of: email) {
let nsRange = NSRange(emailRange, in: formattedMessage)
attributedString.addAttributes([.font: UIFont.preferredFont(forTextStyle: .body).bold], range: nsRange)
}
self.bottomAttributedTitle = attributedString
}
func didTapPrimaryButton(in viewController: UIViewController?) {
viewController?.dismiss(animated: true, completion: { [weak self] in
self?.printReceiptAction()
})
}
func didTapSecondaryButton(in viewController: UIViewController?) {
viewController?.dismiss(animated: true) { [weak self] in
self?.noReceiptAction()
}
}
func didTapAuxiliaryButton(in viewController: UIViewController?) {}
}