diff --git a/Passepartout-iOS/Scenes/Organizer/DonationViewController.swift b/Passepartout-iOS/Scenes/Organizer/DonationViewController.swift index fcc354ea..eadc62d3 100644 --- a/Passepartout-iOS/Scenes/Organizer/DonationViewController.swift +++ b/Passepartout-iOS/Scenes/Organizer/DonationViewController.swift @@ -56,6 +56,7 @@ class DonationViewController: UITableViewController, TableModelHost { model.add(.oneTime) // model.add(.recurring) model.setHeader(L10n.Donation.Sections.OneTime.header, for: .oneTime) + model.setFooter(L10n.Donation.Sections.OneTime.footer, for: .oneTime) // model.setHeader(L10n.Donation.Sections.Recurring.header, for: .recurring) model.set(list, in: .oneTime) } @@ -89,6 +90,10 @@ class DonationViewController: UITableViewController, TableModelHost { return model.header(for: section) } + override func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String? { + return model.footer(for: section) + } + override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return model.count(for: section) } @@ -103,6 +108,34 @@ class DonationViewController: UITableViewController, TableModelHost { cell.rightText = product.localizedPrice return cell } + + override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { + tableView.deselectRow(at: indexPath, animated: true) + + let productId = productIdentifier(at: indexPath) + guard let product = productsByIdentifier[productId] else { + fatalError("Row with no associated product") + } + InAppHelper.shared.purchase(product: product) { + self.handlePurchase(result: $0, error: $1) + } + } + + private func handlePurchase(result: InAppHelper.PurchaseResult, error: Error?) { + let alert: UIAlertController + switch result { + case .cancelled: + return + + case .success: + alert = Macros.alert(title, L10n.Donation.Alerts.Purchase.success) + + case .failure: + alert = Macros.alert(title, L10n.Donation.Alerts.Purchase.failure(error?.localizedDescription ?? "")) + } + alert.addCancelAction(L10n.Global.ok) + present(alert, animated: true, completion: nil) + } } extension DonationViewController { diff --git a/Passepartout/Resources/en.lproj/Localizable.strings b/Passepartout/Resources/en.lproj/Localizable.strings index 19ee48ef..71c0c062 100644 --- a/Passepartout/Resources/en.lproj/Localizable.strings +++ b/Passepartout/Resources/en.lproj/Localizable.strings @@ -249,7 +249,10 @@ "donation.title" = "Donate"; "donation.sections.one_time.header" = "One time"; -"donation.sections.recurring.header" = "Recurring"; +"donation.sections.one_time.footer" = "If you want to display gratitude for my free work, here are a couple amounts you can donate instantly.\n\nYou will only be charged once per donation, and you can donate multiple times."; +//"donation.sections.recurring.header" = "Recurring"; +"donation.alerts.purchase.success" = "THANK YOU!\n\nThis means a lot to me and I really hope you keep using and promoting this app."; +"donation.alerts.purchase.failure" = "Unable to perform the donation. %@"; "share.message" = "Passepartout is an user-friendly, open source OpenVPN client for iOS and macOS"; diff --git a/Passepartout/Sources/SwiftGen+Strings.swift b/Passepartout/Sources/SwiftGen+Strings.swift index 236c017b..a472f1a1 100644 --- a/Passepartout/Sources/SwiftGen+Strings.swift +++ b/Passepartout/Sources/SwiftGen+Strings.swift @@ -298,15 +298,23 @@ public enum L10n { public enum Donation { /// Donate public static let title = L10n.tr("Localizable", "donation.title") + public enum Alerts { + public enum Purchase { + /// Unable to perform the donation. %@ + public static func failure(_ p1: String) -> String { + return L10n.tr("Localizable", "donation.alerts.purchase.failure", p1) + } + /// THANK YOU!\n\nThis means a lot to me and I really hope you keep using and promoting this app. + public static let success = L10n.tr("Localizable", "donation.alerts.purchase.success") + } + } public enum Sections { public enum OneTime { + /// If you want to display gratitude for my free work, here are a couple amounts you can donate instantly.\n\nYou will only be charged once per donation, and you can donate multiple times. + public static let footer = L10n.tr("Localizable", "donation.sections.one_time.footer") /// One time public static let header = L10n.tr("Localizable", "donation.sections.one_time.header") } - public enum Recurring { - /// Recurring - public static let header = L10n.tr("Localizable", "donation.sections.recurring.header") - } } }