Skip to content

Commit

Permalink
Add Stripe version of something went wrong alert
Browse files Browse the repository at this point in the history
  • Loading branch information
miasma13 committed Dec 22, 2023
1 parent ab18525 commit b6aa098
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
12 changes: 9 additions & 3 deletions DuckDuckGo/Tab/UserScripts/SubscriptionPagesUserScript.swift
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ final class SubscriptionPagesUseSubscriptionFeature: Subfeature {
case .success(let purchaseUpdate):
await pushPurchaseUpdate(originalMessage: message, purchaseUpdate: purchaseUpdate)
case .failure:
// TODO: handle error with alert?
await WindowControllersManager.shared.lastKeyMainWindowController?.showSomethingWentWrongAlert()
return nil
}
#else
Expand Down Expand Up @@ -366,10 +366,16 @@ final class SubscriptionPagesUseSubscriptionFeature: Subfeature {
extension MainWindowController {

@MainActor
func showSomethingWentWrongAlert() {
func showSomethingWentWrongAlert(environment: SubscriptionPurchaseEnvironment.Environment = SubscriptionPurchaseEnvironment.current) {
guard let window else { return }

window.show(.somethingWentWrongAlert())
switch environment {
case .appStore:
window.show(.somethingWentWrongAlert())
case .stripe:
window.show(.somethingWentWrongStripeAlert())
}

}

@MainActor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ public extension NSAlert {
return alert
}

static func somethingWentWrongStripeAlert() -> NSAlert {
let alert = NSAlert()
alert.messageText = UserText.somethingWentWrongAlertTitle
alert.informativeText = UserText.somethingWentWrongStripeAlertDescription
alert.addButton(withTitle: UserText.okButtonTitle)
return alert
}

static func subscriptionNotFoundAlert() -> NSAlert {
let alert = NSAlert()
alert.messageText = UserText.subscriptionNotFoundAlertTitle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ enum UserText {

static let somethingWentWrongAlertTitle = NSLocalizedString("subscription.alert.something.went.wrong.title", value: "Something Went Wrong", comment: "Alert title when unknown error has occurred")
static let somethingWentWrongAlertDescription = NSLocalizedString("subscription.alert.something.went.wrong.description", value: "The App Store was not able to process your purchase. Please try again later.", comment: "Alert message when unknown error has occurred")
static let somethingWentWrongStripeAlertDescription = NSLocalizedString("subscription.alert.something.went.wrong.stripe.description", value: "We were not able to start your purchase process. Please try again later.", comment: "Alert message when unknown error has occurred")

static let subscriptionNotFoundAlertTitle = NSLocalizedString("subscription.alert.subscription.not.found.title", value: "Subscription Not Found", comment: "Alert title when subscription was not found")
static let subscriptionNotFoundAlertDescription = NSLocalizedString("subscription.alert.subscription.not.found.description", value: "We couldn’t find a subscription associated with this Apple ID.", comment: "Alert message when subscription was not found")
Expand Down

0 comments on commit b6aa098

Please sign in to comment.