Skip to content

Commit 10faa93

Browse files
Merge pull request #54 from alexanderjordanbaker/FixAppAccountTokenEmptyValue
Send empty string for appAccountToken when the value is omitted
2 parents 8b6b870 + 994a50d commit 10faa93

17 files changed

+535
-38
lines changed

Sources/AppStoreServerLibrary/Models/AppTransaction.swift

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,49 @@ public struct AppTransaction: DecodedSignedData, Decodable, Encodable, Hashable
108108
public var signedDate: Date? {
109109
receiptCreationDate
110110
}
111+
112+
113+
public enum CodingKeys: CodingKey {
114+
case receiptType
115+
case appAppleId
116+
case bundleId
117+
case applicationVersion
118+
case versionExternalIdentifier
119+
case receiptCreationDate
120+
case originalPurchaseDate
121+
case originalApplicationVersion
122+
case deviceVerification
123+
case deviceVerificationNonce
124+
case preorderDate
125+
}
126+
127+
public init(from decoder: any Decoder) throws {
128+
let container = try decoder.container(keyedBy: CodingKeys.self)
129+
self.rawReceiptType = try container.decodeIfPresent(String.self, forKey: .receiptType)
130+
self.appAppleId = try container.decodeIfPresent(Int64.self, forKey: .appAppleId)
131+
self.bundleId = try container.decodeIfPresent(String.self, forKey: .bundleId)
132+
self.applicationVersion = try container.decodeIfPresent(String.self, forKey: .applicationVersion)
133+
self.versionExternalIdentifier = try container.decodeIfPresent(Int64.self, forKey: .versionExternalIdentifier)
134+
self.receiptCreationDate = try container.decodeIfPresent(Date.self, forKey: .receiptCreationDate)
135+
self.originalPurchaseDate = try container.decodeIfPresent(Date.self, forKey: .originalPurchaseDate)
136+
self.originalApplicationVersion = try container.decodeIfPresent(String.self, forKey: .originalApplicationVersion)
137+
self.deviceVerification = try container.decodeIfPresent(String.self, forKey: .deviceVerification)
138+
self.deviceVerificationNonce = try container.decodeIfPresent(UUID.self, forKey: .deviceVerificationNonce)
139+
self.preorderDate = try container.decodeIfPresent(Date.self, forKey: .preorderDate)
140+
}
141+
142+
public func encode(to encoder: any Encoder) throws {
143+
var container = encoder.container(keyedBy: CodingKeys.self)
144+
try container.encodeIfPresent(self.rawReceiptType, forKey: .receiptType)
145+
try container.encodeIfPresent(self.appAppleId, forKey: .appAppleId)
146+
try container.encodeIfPresent(self.bundleId, forKey: .bundleId)
147+
try container.encodeIfPresent(self.applicationVersion, forKey: .applicationVersion)
148+
try container.encodeIfPresent(self.versionExternalIdentifier, forKey: .versionExternalIdentifier)
149+
try container.encodeIfPresent(self.receiptCreationDate, forKey: .receiptCreationDate)
150+
try container.encodeIfPresent(self.originalPurchaseDate, forKey: .originalPurchaseDate)
151+
try container.encodeIfPresent(self.originalApplicationVersion, forKey: .originalApplicationVersion)
152+
try container.encodeIfPresent(self.deviceVerification, forKey: .deviceVerification)
153+
try container.encodeIfPresent(self.deviceVerificationNonce, forKey: .deviceVerificationNonce)
154+
try container.encodeIfPresent(self.preorderDate, forKey: .preorderDate)
155+
}
111156
}

Sources/AppStoreServerLibrary/Models/ConsumptionRequest.swift

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,16 @@ public struct ConsumptionRequest: Decodable, Encodable, Hashable {
9595
///The UUID that an app optionally generates to map a customer’s in-app purchase with its resulting App Store transaction.
9696
///
9797
///[appAccountToken](https://developer.apple.com/documentation/appstoreserverapi/appaccounttoken)
98-
public var appAccountToken: UUID?
98+
public var appAccountToken: UUID? {
99+
get {
100+
return rawAppAccountToken != "" ? UUID(uuidString: rawAppAccountToken) : nil
101+
}
102+
set {
103+
self.rawAppAccountToken = newValue.map { $0.uuidString } ?? ""
104+
}
105+
}
106+
107+
private var rawAppAccountToken: String = ""
99108

100109
///The age of the customer’s account.
101110
///
@@ -187,4 +196,50 @@ public struct ConsumptionRequest: Decodable, Encodable, Hashable {
187196
///See ``refundPreference``
188197
public var rawRefundPreference: Int32?
189198

199+
public enum CodingKeys: CodingKey {
200+
case customerConsented
201+
case consumptionStatus
202+
case platform
203+
case sampleContentProvided
204+
case deliveryStatus
205+
case appAccountToken
206+
case accountTenure
207+
case playTime
208+
case lifetimeDollarsRefunded
209+
case lifetimeDollarsPurchased
210+
case userStatus
211+
case refundPreference
212+
}
213+
214+
public init(from decoder: any Decoder) throws {
215+
let container = try decoder.container(keyedBy: CodingKeys.self)
216+
self.customerConsented = try container.decodeIfPresent(Bool.self, forKey: .customerConsented)
217+
self.rawConsumptionStatus = try container.decodeIfPresent(Int32.self, forKey: .consumptionStatus)
218+
self.rawPlatform = try container.decodeIfPresent(Int32.self, forKey: .platform)
219+
self.sampleContentProvided = try container.decodeIfPresent(Bool.self, forKey: .sampleContentProvided)
220+
self.rawDeliveryStatus = try container.decodeIfPresent(Int32.self, forKey: .deliveryStatus)
221+
self.rawAppAccountToken = try container.decode(String.self, forKey: .appAccountToken)
222+
self.rawAccountTenure = try container.decodeIfPresent(Int32.self, forKey: .accountTenure)
223+
self.rawPlayTime = try container.decodeIfPresent(Int32.self, forKey: .playTime)
224+
self.rawLifetimeDollarsRefunded = try container.decodeIfPresent(Int32.self, forKey: .lifetimeDollarsRefunded)
225+
self.rawLifetimeDollarsPurchased = try container.decodeIfPresent(Int32.self, forKey: .lifetimeDollarsPurchased)
226+
self.rawUserStatus = try container.decodeIfPresent(Int32.self, forKey: .userStatus)
227+
self.rawRefundPreference = try container.decodeIfPresent(Int32.self, forKey: .refundPreference)
228+
}
229+
230+
public func encode(to encoder: any Encoder) throws {
231+
var container = encoder.container(keyedBy: CodingKeys.self)
232+
try container.encodeIfPresent(self.customerConsented, forKey: .customerConsented)
233+
try container.encodeIfPresent(self.rawConsumptionStatus, forKey: .consumptionStatus)
234+
try container.encodeIfPresent(self.rawPlatform, forKey: .platform)
235+
try container.encodeIfPresent(self.sampleContentProvided, forKey: .sampleContentProvided)
236+
try container.encodeIfPresent(self.rawDeliveryStatus, forKey: .deliveryStatus)
237+
try container.encode(self.rawAppAccountToken, forKey: .appAccountToken)
238+
try container.encodeIfPresent(self.rawAccountTenure, forKey: .accountTenure)
239+
try container.encodeIfPresent(self.rawPlayTime, forKey: .playTime)
240+
try container.encodeIfPresent(self.rawLifetimeDollarsRefunded, forKey: .lifetimeDollarsRefunded)
241+
try container.encodeIfPresent(self.rawLifetimeDollarsPurchased, forKey: .lifetimeDollarsPurchased)
242+
try container.encodeIfPresent(self.rawUserStatus, forKey: .userStatus)
243+
try container.encodeIfPresent(self.rawRefundPreference, forKey: .refundPreference)
244+
}
190245
}

Sources/AppStoreServerLibrary/Models/Data.swift

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,39 @@ public struct Data: Decodable, Encodable, Hashable {
9696

9797
///See ``consumptionRequestReason``
9898
public var rawConsumptionRequestReason: String?
99+
100+
public enum CodingKeys: CodingKey {
101+
case environment
102+
case appAppleId
103+
case bundleId
104+
case bundleVersion
105+
case signedTransactionInfo
106+
case signedRenewalInfo
107+
case status
108+
case consumptionRequestReason
109+
}
110+
111+
public init(from decoder: any Decoder) throws {
112+
let container = try decoder.container(keyedBy: CodingKeys.self)
113+
self.rawEnvironment = try container.decodeIfPresent(String.self, forKey: .environment)
114+
self.appAppleId = try container.decodeIfPresent(Int64.self, forKey: .appAppleId)
115+
self.bundleId = try container.decodeIfPresent(String.self, forKey: .bundleId)
116+
self.bundleVersion = try container.decodeIfPresent(String.self, forKey: .bundleVersion)
117+
self.signedTransactionInfo = try container.decodeIfPresent(String.self, forKey: .signedTransactionInfo)
118+
self.signedRenewalInfo = try container.decodeIfPresent(String.self, forKey: .signedRenewalInfo)
119+
self.rawStatus = try container.decodeIfPresent(Int32.self, forKey: .status)
120+
self.rawConsumptionRequestReason = try container.decodeIfPresent(String.self, forKey: .consumptionRequestReason)
121+
}
122+
123+
public func encode(to encoder: any Encoder) throws {
124+
var container = encoder.container(keyedBy: CodingKeys.self)
125+
try container.encodeIfPresent(self.rawEnvironment, forKey: .environment)
126+
try container.encodeIfPresent(self.appAppleId, forKey: .appAppleId)
127+
try container.encodeIfPresent(self.bundleId, forKey: .bundleId)
128+
try container.encodeIfPresent(self.bundleVersion, forKey: .bundleVersion)
129+
try container.encodeIfPresent(self.signedTransactionInfo, forKey: .signedTransactionInfo)
130+
try container.encodeIfPresent(self.signedRenewalInfo, forKey: .signedRenewalInfo)
131+
try container.encodeIfPresent(self.rawStatus, forKey: .status)
132+
try container.encodeIfPresent(self.rawConsumptionRequestReason, forKey: .consumptionRequestReason)
133+
}
99134
}

Sources/AppStoreServerLibrary/Models/HistoryResponse.swift

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,33 @@ public struct HistoryResponse: Decodable, Encodable, Hashable {
6262
///
6363
///[JWSTransaction](https://developer.apple.com/documentation/appstoreserverapi/jwstransaction)
6464
public var signedTransactions: [String]?
65+
66+
public enum CodingKeys: CodingKey {
67+
case revision
68+
case hasMore
69+
case bundleId
70+
case appAppleId
71+
case environment
72+
case signedTransactions
73+
}
74+
75+
public init(from decoder: any Decoder) throws {
76+
let container = try decoder.container(keyedBy: CodingKeys.self)
77+
self.revision = try container.decodeIfPresent(String.self, forKey: .revision)
78+
self.hasMore = try container.decodeIfPresent(Bool.self, forKey: .hasMore)
79+
self.bundleId = try container.decodeIfPresent(String.self, forKey: .bundleId)
80+
self.appAppleId = try container.decodeIfPresent(Int64.self, forKey: .appAppleId)
81+
self.rawEnvironment = try container.decodeIfPresent(String.self, forKey: .environment)
82+
self.signedTransactions = try container.decodeIfPresent([String].self, forKey: .signedTransactions)
83+
}
84+
85+
public func encode(to encoder: any Encoder) throws {
86+
var container = encoder.container(keyedBy: CodingKeys.self)
87+
try container.encodeIfPresent(self.revision, forKey: .revision)
88+
try container.encodeIfPresent(self.hasMore, forKey: .hasMore)
89+
try container.encodeIfPresent(self.bundleId, forKey: .bundleId)
90+
try container.encodeIfPresent(self.appAppleId, forKey: .appAppleId)
91+
try container.encodeIfPresent(self.rawEnvironment, forKey: .environment)
92+
try container.encodeIfPresent(self.signedTransactions, forKey: .signedTransactions)
93+
}
6594
}

Sources/AppStoreServerLibrary/Models/JWSRenewalInfoDecodedPayload.swift

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,4 +159,57 @@ public struct JWSRenewalInfoDecodedPayload: DecodedSignedData, Decodable, Encoda
159159
///
160160
///[renewalDate](https://developer.apple.com/documentation/appstoreserverapi/renewaldate)
161161
public var renewalDate: Date?
162+
163+
public enum CodingKeys: CodingKey {
164+
case expirationIntent
165+
case originalTransactionId
166+
case autoRenewProductId
167+
case productId
168+
case autoRenewStatus
169+
case isInBillingRetryPeriod
170+
case priceIncreaseStatus
171+
case gracePeriodExpiresDate
172+
case offerType
173+
case offerIdentifier
174+
case signedDate
175+
case environment
176+
case recentSubscriptionStartDate
177+
case renewalDate
178+
}
179+
180+
public init(from decoder: any Decoder) throws {
181+
let container = try decoder.container(keyedBy: CodingKeys.self)
182+
self.rawExpirationIntent = try container.decodeIfPresent(Int32.self, forKey: .expirationIntent)
183+
self.originalTransactionId = try container.decodeIfPresent(String.self, forKey: .originalTransactionId)
184+
self.autoRenewProductId = try container.decodeIfPresent(String.self, forKey: .autoRenewProductId)
185+
self.productId = try container.decodeIfPresent(String.self, forKey: .productId)
186+
self.rawAutoRenewStatus = try container.decodeIfPresent(Int32.self, forKey: .autoRenewStatus)
187+
self.isInBillingRetryPeriod = try container.decodeIfPresent(Bool.self, forKey: .isInBillingRetryPeriod)
188+
self.rawPriceIncreaseStatus = try container.decodeIfPresent(Int32.self, forKey: .priceIncreaseStatus)
189+
self.gracePeriodExpiresDate = try container.decodeIfPresent(Date.self, forKey: .gracePeriodExpiresDate)
190+
self.rawOfferType = try container.decodeIfPresent(Int32.self, forKey: .offerType)
191+
self.offerIdentifier = try container.decodeIfPresent(String.self, forKey: .offerIdentifier)
192+
self.signedDate = try container.decodeIfPresent(Date.self, forKey: .signedDate)
193+
self.rawEnvironment = try container.decodeIfPresent(String.self, forKey: .environment)
194+
self.recentSubscriptionStartDate = try container.decodeIfPresent(Date.self, forKey: .recentSubscriptionStartDate)
195+
self.renewalDate = try container.decodeIfPresent(Date.self, forKey: .renewalDate)
196+
}
197+
198+
public func encode(to encoder: any Encoder) throws {
199+
var container = encoder.container(keyedBy: CodingKeys.self)
200+
try container.encodeIfPresent(self.rawExpirationIntent, forKey: .expirationIntent)
201+
try container.encodeIfPresent(self.originalTransactionId, forKey: .originalTransactionId)
202+
try container.encodeIfPresent(self.autoRenewProductId, forKey: .autoRenewProductId)
203+
try container.encodeIfPresent(self.productId, forKey: .productId)
204+
try container.encodeIfPresent(self.rawAutoRenewStatus, forKey: .autoRenewStatus)
205+
try container.encodeIfPresent(self.isInBillingRetryPeriod, forKey: .isInBillingRetryPeriod)
206+
try container.encodeIfPresent(self.rawPriceIncreaseStatus, forKey: .priceIncreaseStatus)
207+
try container.encodeIfPresent(self.gracePeriodExpiresDate, forKey: .gracePeriodExpiresDate)
208+
try container.encodeIfPresent(self.rawOfferType, forKey: .offerType)
209+
try container.encodeIfPresent(self.offerIdentifier, forKey: .offerIdentifier)
210+
try container.encodeIfPresent(self.signedDate, forKey: .signedDate)
211+
try container.encodeIfPresent(self.rawEnvironment, forKey: .environment)
212+
try container.encodeIfPresent(self.recentSubscriptionStartDate, forKey: .recentSubscriptionStartDate)
213+
try container.encodeIfPresent(self.renewalDate, forKey: .renewalDate)
214+
}
162215
}

0 commit comments

Comments
 (0)