Purchase on donation selection
This commit is contained in:
parent
70863da4ab
commit
2bf070650d
|
@ -56,6 +56,7 @@ class DonationViewController: UITableViewController, TableModelHost {
|
||||||
model.add(.oneTime)
|
model.add(.oneTime)
|
||||||
// model.add(.recurring)
|
// model.add(.recurring)
|
||||||
model.setHeader(L10n.Donation.Sections.OneTime.header, for: .oneTime)
|
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.setHeader(L10n.Donation.Sections.Recurring.header, for: .recurring)
|
||||||
model.set(list, in: .oneTime)
|
model.set(list, in: .oneTime)
|
||||||
}
|
}
|
||||||
|
@ -89,6 +90,10 @@ class DonationViewController: UITableViewController, TableModelHost {
|
||||||
return model.header(for: section)
|
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 {
|
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
||||||
return model.count(for: section)
|
return model.count(for: section)
|
||||||
}
|
}
|
||||||
|
@ -103,6 +108,34 @@ class DonationViewController: UITableViewController, TableModelHost {
|
||||||
cell.rightText = product.localizedPrice
|
cell.rightText = product.localizedPrice
|
||||||
return cell
|
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 {
|
extension DonationViewController {
|
||||||
|
|
|
@ -249,7 +249,10 @@
|
||||||
|
|
||||||
"donation.title" = "Donate";
|
"donation.title" = "Donate";
|
||||||
"donation.sections.one_time.header" = "One time";
|
"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";
|
"share.message" = "Passepartout is an user-friendly, open source OpenVPN client for iOS and macOS";
|
||||||
|
|
||||||
|
|
|
@ -298,15 +298,23 @@ public enum L10n {
|
||||||
public enum Donation {
|
public enum Donation {
|
||||||
/// Donate
|
/// Donate
|
||||||
public static let title = L10n.tr("Localizable", "donation.title")
|
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 Sections {
|
||||||
public enum OneTime {
|
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
|
/// One time
|
||||||
public static let header = L10n.tr("Localizable", "donation.sections.one_time.header")
|
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")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue