This repository was archived by the owner on Oct 16, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathOpenIapAppTransaction.swift
More file actions
126 lines (110 loc) · 4.61 KB
/
OpenIapAppTransaction.swift
File metadata and controls
126 lines (110 loc) · 4.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import Foundation
import StoreKit
@available(iOS 16.0, macOS 13.0, *)
public struct OpenIapAppTransaction: Codable, Sendable {
public let bundleId: String
public let appVersion: String
public let originalAppVersion: String
public let originalPurchaseDate: Date
public let deviceVerification: String
public let deviceVerificationNonce: String
public let environment: String
public let signedDate: Date
public let appId: String
public let appVersionId: String
public let preorderDate: Date?
// iOS 18.4+ properties
public let appTransactionId: String?
public let originalPlatform: String?
}
@available(iOS 16.0, macOS 13.0, *)
extension OpenIapAppTransaction {
init(from appTransaction: AppTransaction) {
self.bundleId = appTransaction.bundleID
self.appVersion = appTransaction.appVersion
self.originalAppVersion = appTransaction.originalAppVersion
self.originalPurchaseDate = appTransaction.originalPurchaseDate
self.deviceVerification = appTransaction.deviceVerification.base64EncodedString()
self.deviceVerificationNonce = appTransaction.deviceVerificationNonce.uuidString
self.environment = appTransaction.environment.rawValue
self.signedDate = appTransaction.signedDate
self.appId = String(describing: appTransaction.appID)
self.appVersionId = String(describing: appTransaction.appVersionID)
self.preorderDate = appTransaction.preorderDate
#if swift(>=6.1)
if #available(iOS 18.4, *) {
self.appTransactionId = appTransaction.appTransactionID
self.originalPlatform = appTransaction.originalPlatform.rawValue
} else {
self.appTransactionId = nil
self.originalPlatform = nil
}
#else
self.appTransactionId = nil
self.originalPlatform = nil
#endif
}
}
public struct OpenIapSubscriptionStatus: Codable, Sendable {
public let state: Product.SubscriptionInfo.RenewalState
public let renewalInfo: OpenIapRenewalInfo?
enum CodingKeys: String, CodingKey {
case state
case renewalInfo
}
public init(state: Product.SubscriptionInfo.RenewalState, renewalInfo: OpenIapRenewalInfo?) {
self.state = state
self.renewalInfo = renewalInfo
}
// Encode enum as string for JSON compatibility
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(String(describing: state), forKey: .state)
try container.encodeIfPresent(renewalInfo, forKey: .renewalInfo)
}
// Decode state from string into known cases; fallback to .expired
public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
let raw = (try? container.decode(String.self, forKey: .state))?.lowercased()
switch raw {
case "subscribed": self.state = .subscribed
case "expired": self.state = .expired
case "inbillingretryperiod": self.state = .inBillingRetryPeriod
case "ingraceperiod": self.state = .inGracePeriod
case "revoked": self.state = .revoked
default: self.state = .expired
}
self.renewalInfo = try container.decodeIfPresent(OpenIapRenewalInfo.self, forKey: .renewalInfo)
}
}
public struct OpenIapRenewalInfo: Codable, Sendable {
public let autoRenewStatus: Bool
public let autoRenewPreference: String?
public let expirationReason: Int?
public let deviceVerification: String?
public let currentProductID: String?
public let gracePeriodExpirationDate: Date?
}
public struct OpenIapValidationResult: Codable, Sendable {
public let isValid: Bool
public let receiptData: String
public let jwsRepresentation: String
public let latestTransaction: OpenIapPurchase?
}
// MARK: - Product and Transaction serialization models
// OpenIapProductData is deprecated - use OpenIapProduct instead
// This type has been merged into OpenIapProduct for better API consistency
// IapTransactionData is deprecated - use OpenIapPurchase instead
// This type has been merged into OpenIapPurchase for better API consistency
public struct OpenIapPromotedProduct: Codable, Sendable {
public let productIdentifier: String
public let localizedTitle: String
public let localizedDescription: String
public let price: Double
public let priceLocale: OpenIapPriceLocale
}
public struct OpenIapPriceLocale: Codable, Sendable {
public let currencyCode: String
public let currencySymbol: String
public let countryCode: String
}