Skip to content

Commit

Permalink
feat: update PurchaseManager.swift
Browse files Browse the repository at this point in the history
  • Loading branch information
jurajhilje committed Apr 16, 2024
1 parent 6b8a786 commit 1d9df14
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 14 deletions.
6 changes: 2 additions & 4 deletions IVPNClient/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ extension AppDelegate: PurchaseManagerDelegate {
}
}

func purchaseSuccess(service: Any?, extended: Bool) {
func purchaseSuccess(activeUntil: String, extended: Bool) {
guard extended else {
return
}
Expand All @@ -422,9 +422,7 @@ extension AppDelegate: PurchaseManagerDelegate {
return
}

if let service = service as? ServiceStatus {
viewController.showSubscriptionActivatedAlert(serviceStatus: service)
}
viewController.showSubscriptionActivatedAlert(activeUntil: activeUntil)
}
}

Expand Down
4 changes: 2 additions & 2 deletions IVPNClient/Managers/PurchaseManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import StoreKit
@objc protocol PurchaseManagerDelegate: AnyObject {
func purchaseStart()
func purchasePending()
func purchaseSuccess(service: Any?, extended: Bool)
func purchaseSuccess(activeUntil: String, extended: Bool)
func purchaseError(error: Any?)
}

Expand Down Expand Up @@ -167,7 +167,7 @@ class PurchaseManager: NSObject {
Application.shared.serviceStatus = sessionStatus.serviceStatus
Task {
await transaction.finish()
self.delegate?.purchaseSuccess(service: sessionStatus.serviceStatus, extended: sessionStatus.extended ?? false)
self.delegate?.purchaseSuccess(activeUntil: sessionStatus.serviceStatus.activeUntilString(), extended: sessionStatus.extended ?? !sessionStatus.serviceStatus.isNewStyleAccount())
log(.info, message: "[Store] Purchase \(transaction.productID) completed successfully")
}
case .failure(let error):
Expand Down
8 changes: 2 additions & 6 deletions IVPNClient/Scenes/Signup/Payment/PaymentViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ extension PaymentViewController: PurchaseManagerDelegate {
}
}

func purchaseSuccess(service: Any?, extended: Bool) {
func purchaseSuccess(activeUntil: String, extended: Bool) {
guard extended else {
hud.dismiss()
return
Expand All @@ -295,11 +295,7 @@ extension PaymentViewController: PurchaseManagerDelegate {
DispatchQueue.main.async { [self] in
hud.dismiss()

guard let service = service as? ServiceStatus else {
return
}

showSubscriptionActivatedAlert(serviceStatus: service) {
showSubscriptionActivatedAlert(activeUntil: activeUntil) {
if KeyChain.sessionToken == nil {
KeyChain.username = KeyChain.tempUsername
KeyChain.tempUsername = nil
Expand Down
4 changes: 2 additions & 2 deletions IVPNClient/Utilities/Extensions/UIViewController+Ext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,10 @@ extension UIViewController {
}
}

func showSubscriptionActivatedAlert(serviceStatus: ServiceStatus, completion: (() -> Void)? = nil) {
func showSubscriptionActivatedAlert(activeUntil: String, completion: (() -> Void)? = nil) {
showAlert(
title: "Thank you!",
message: "The payment was successfully processed.\nService is active until: " + serviceStatus.activeUntilString(),
message: "The payment was successfully processed.\nService is active until: " + activeUntil,
handler: { _ in
if let completion = completion {
completion()
Expand Down

0 comments on commit 1d9df14

Please sign in to comment.