Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migration from StoreKit 1 to StoreKit 2 #410

Merged
merged 47 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
3290f45
refactor(payments): create PurchaseManager.swift
jurajhilje Dec 4, 2023
d983758
refactor(payments): set DEPLOYMENT_TARGET to 15.0
jurajhilje Dec 4, 2023
d7d8660
feat(payments): update PurchaseManager.swift
jurajhilje Dec 4, 2023
cfb1eb7
refactor: update ProductIdentifier model
jurajhilje Dec 4, 2023
6094977
refactor(payments): update PurchaseManager.swift
jurajhilje Dec 4, 2023
e7adaaf
refactor(payments): update PurchaseManager.swift
jurajhilje Dec 4, 2023
6fe4972
Merge branch 'develop' into task/storekit2
jurajhilje Dec 5, 2023
424665f
refactor(payments): update PaymentViewController
jurajhilje Dec 6, 2023
a946b46
refactor(payments): update PaymentViewController
jurajhilje Dec 6, 2023
7ace0cc
refactor(payments): update UIViewController+Ext.swift
jurajhilje Dec 6, 2023
7dfa42b
refactor(payments): update PaymentViewController
jurajhilje Dec 7, 2023
c814d6e
refactor(payments): update PurchaseManager.swift
jurajhilje Dec 7, 2023
03b4e35
refactor: update LoginViewController
jurajhilje Dec 7, 2023
04665f0
refactor(payments): update SelectPlanViewController
jurajhilje Dec 8, 2023
e2578a6
feat(payments): update PurchaseManager
jurajhilje Dec 11, 2023
a72c9bf
refactor(payments): update LoginViewController
jurajhilje Dec 11, 2023
191d2f3
feat(payments): update PurchaseManager
jurajhilje Dec 12, 2023
11fc204
feat(payments): update error handling
jurajhilje Dec 12, 2023
e9fd707
chore: clean up PurchaseManager
jurajhilje Dec 12, 2023
74f5a12
feat(payments): update error handling
jurajhilje Dec 12, 2023
53eb718
feat(payments): update PurchaseManager
jurajhilje Dec 12, 2023
76700b1
refactor(payments): update PurchaseManager
jurajhilje Dec 13, 2023
c8c730a
refactor(payments): update AppDelegate
jurajhilje Dec 14, 2023
d5bbb9a
refactor(payments): update PurchaseManager
jurajhilje Dec 14, 2023
cccd23c
refactor(payments): update PaymentViewController
jurajhilje Dec 15, 2023
2945b8e
refactor(payments): create Store.storekit
jurajhilje Dec 15, 2023
796f1f6
Merge branch 'develop' into task/storekit2
jurajhilje Jan 3, 2024
8683cd2
refactor(payments): update PurchaseManager
jurajhilje Jan 12, 2024
e2a3df1
refactor(payments): update PurchaseManager
jurajhilje Jan 15, 2024
18e2b87
refactor(payments): update LoginViewController
jurajhilje Jan 15, 2024
47b51ae
refactor(payments): update AppDelegate
jurajhilje Jan 15, 2024
a64c7f0
refactor(payments): update Config.swift
jurajhilje Jan 24, 2024
2b1b3b1
refactor: update LoginViewController
jurajhilje Jan 24, 2024
fecfc78
refactor(payments): update PurchaseManager
jurajhilje Jan 25, 2024
65bac07
Merge branch 'develop' into task/storekit2
jurajhilje Jan 29, 2024
054547e
refactor(payments): update PurchaseManager
jurajhilje Jan 30, 2024
7108801
refactor(payments): update PurchaseManager
jurajhilje Jan 30, 2024
f74c085
refactor(payments): update PaymentViewController
jurajhilje Jan 30, 2024
3f04a18
refactor(payments): update PurchaseManager
jurajhilje Feb 20, 2024
7fd9f6b
refactor(payments): add PurchaseManagerDelegate
jurajhilje Feb 21, 2024
469a1fb
refactor(payments): update PurchaseManager
jurajhilje Feb 25, 2024
a7ca5e8
chore: clean up IAPManager.swift
jurajhilje Feb 25, 2024
7f7ee14
refactor(payments): update PurchaseManager
jurajhilje Mar 5, 2024
53985b1
Merge branch 'develop' into task/storekit2
jurajhilje Mar 21, 2024
3ef3f26
feat: update PurchaseManager.swift
jurajhilje Mar 21, 2024
6b8a786
feat: update PurchaseManagerDelegate
jurajhilje Mar 21, 2024
1d9df14
feat: update PurchaseManager.swift
jurajhilje Apr 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 33 additions & 29 deletions IVPNClient.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@
isEnabled = "YES">
</EnvironmentVariable>
</EnvironmentVariables>
<StoreKitConfigurationFileReference
identifier = "../../IVPNClient/Store.storekit">
</StoreKitConfigurationFileReference>
</LaunchAction>
<ProfileAction
buildConfiguration = "Debug"
Expand Down
67 changes: 52 additions & 15 deletions IVPNClient/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,6 @@ class AppDelegate: UIResponder {
FileSystemManager.createLogFiles()
}

private func finishIncompletePurchases() {
guard Application.shared.authentication.isLoggedIn || KeyChain.tempUsername != nil else {
return
}

IAPManager.shared.finishIncompletePurchases { serviceStatus, _ in
guard let viewController = UIApplication.topViewController() else { return }

if let serviceStatus = serviceStatus {
viewController.showSubscriptionActivatedAlert(serviceStatus: serviceStatus)
}
}
}

private func resetLastPingTimestamp() {
UserDefaults.shared.set(0, forKey: "LastPingTimestamp")
}
Expand Down Expand Up @@ -284,6 +270,11 @@ class AppDelegate: UIResponder {
}
}
}

private func startPurchaseObserver() {
PurchaseManager.shared.delegate = self
PurchaseManager.shared.startObserver()
}

}

Expand All @@ -294,10 +285,10 @@ extension AppDelegate: UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
evaluateUITests()
registerUserDefaults()
finishIncompletePurchases()
createLogFiles()
resetLastPingTimestamp()
clearURLCache()
startPurchaseObserver()
DNSManager.shared.loadProfile { _ in }

return true
Expand Down Expand Up @@ -402,3 +393,49 @@ extension AppDelegate: UIApplicationDelegate {
}

}

// MARK: - PurchaseManagerDelegate -

extension AppDelegate: PurchaseManagerDelegate {

func purchaseStart() {

}

func purchasePending() {
DispatchQueue.main.async {
guard let viewController = UIApplication.topViewController() else {
return
}

viewController.showAlert(title: "Pending payment", message: "Payment is pending for approval. We will complete the transaction as soon as payment is approved.")
}
}

func purchaseSuccess(activeUntil: String, extended: Bool) {
guard extended else {
return
}

DispatchQueue.main.async {
guard let viewController = UIApplication.topViewController() else {
return
}

viewController.showSubscriptionActivatedAlert(activeUntil: activeUntil)
}
}

func purchaseError(error: Any?) {
DispatchQueue.main.async {
guard let viewController = UIApplication.topViewController() else {
return
}

if let error = error as? ErrorResult {
viewController.showErrorAlert(title: "Error", message: error.message)
}
}
}

}
8 changes: 4 additions & 4 deletions IVPNClient/Config/Config.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ struct Config {
static let apiSessionDelete = "/v4/session/delete"
static let apiSessionWGKeySet = "/v4/session/wg/set"
static let apiAccountNew = "/v4/account/new"
static let apiPaymentInitial = "/v4/account/payment/ios/initial"
static let apiPaymentAdd = "/v4/account/payment/ios/add"
static let apiPaymentAddLegacy = "/v2/mobile/ios/subscription-purchased"
static let apiPaymentRestore = "/v4/account/payment/ios/restore"
static let apiPaymentInitial = "/v5/account/payment/ios/initial"
static let apiPaymentAdd = "/v5/account/payment/ios/add"
static let apiPaymentRestore = "/v5/account/payment/ios/restore"
static let apiPaymentAddLegacy = "/v2/mobile/ios/subscription-purchased-v2"

static let urlTypeLogin = "login"
static let urlTypeConnect = "connect"
Expand Down
1 change: 1 addition & 0 deletions IVPNClient/Enums/ApiResults/SessionStatus.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import Foundation
struct SessionStatus: Decodable {
let status: Int
let deviceName: String?
let extended: Bool?
let serviceStatus: ServiceStatus

var serviceActive: Bool {
Expand Down
Loading
Loading