Skip to content

Commit ba0ae3a

Browse files
Merge pull request #61 from alexanderjordanbaker/ASSAv1.13
Add support for App Store Server API v1.13 and App Store Server Notif…
2 parents 2b18491 + 1cea28d commit ba0ae3a

File tree

4 files changed

+19
-3
lines changed

4 files changed

+19
-3
lines changed

Sources/AppStoreServerLibrary/Models/JWSRenewalInfoDecodedPayload.swift

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import Foundation
66
///[JWSRenewalInfoDecodedPayload](https://developer.apple.com/documentation/appstoreserverapi/jwsrenewalinfodecodedpayload)
77
public struct JWSRenewalInfoDecodedPayload: DecodedSignedData, Decodable, Encodable, Hashable {
88

9-
public init(expirationIntent: ExpirationIntent? = nil, originalTransactionId: String? = nil, autoRenewProductId: String? = nil, productId: String? = nil, autoRenewStatus: AutoRenewStatus? = nil, isInBillingRetryPeriod: Bool? = nil, priceIncreaseStatus: PriceIncreaseStatus? = nil, gracePeriodExpiresDate: Date? = nil, offerType: OfferType? = nil, offerIdentifier: String? = nil, signedDate: Date? = nil, environment: Environment? = nil, recentSubscriptionStartDate: Date? = nil, renewalDate: Date? = nil, currency: String? = nil, renewalPrice: Int64? = nil, offerDiscountType: OfferDiscountType? = nil) {
9+
public init(expirationIntent: ExpirationIntent? = nil, originalTransactionId: String? = nil, autoRenewProductId: String? = nil, productId: String? = nil, autoRenewStatus: AutoRenewStatus? = nil, isInBillingRetryPeriod: Bool? = nil, priceIncreaseStatus: PriceIncreaseStatus? = nil, gracePeriodExpiresDate: Date? = nil, offerType: OfferType? = nil, offerIdentifier: String? = nil, signedDate: Date? = nil, environment: Environment? = nil, recentSubscriptionStartDate: Date? = nil, renewalDate: Date? = nil, currency: String? = nil, renewalPrice: Int64? = nil, offerDiscountType: OfferDiscountType? = nil, eligibleWinBackOfferIds: [String]? = nil) {
1010
self.expirationIntent = expirationIntent
1111
self.originalTransactionId = originalTransactionId
1212
self.autoRenewProductId = autoRenewProductId
@@ -24,9 +24,10 @@ public struct JWSRenewalInfoDecodedPayload: DecodedSignedData, Decodable, Encoda
2424
self.currency = currency
2525
self.renewalPrice = renewalPrice
2626
self.offerDiscountType = offerDiscountType
27+
self.eligibleWinBackOfferIds = eligibleWinBackOfferIds
2728
}
2829

29-
public init(rawExpirationIntent: Int32? = nil, originalTransactionId: String? = nil, autoRenewProductId: String? = nil, productId: String? = nil, rawAutoRenewStatus: Int32? = nil, isInBillingRetryPeriod: Bool? = nil, rawPriceIncreaseStatus: Int32? = nil, gracePeriodExpiresDate: Date? = nil, rawOfferType: Int32? = nil, offerIdentifier: String? = nil, signedDate: Date? = nil, rawEnvironment: String? = nil, recentSubscriptionStartDate: Date? = nil, renewalDate: Date? = nil, currency: String? = nil, renewalPrice: Int64? = nil, offerDiscountType: OfferDiscountType? = nil) {
30+
public init(rawExpirationIntent: Int32? = nil, originalTransactionId: String? = nil, autoRenewProductId: String? = nil, productId: String? = nil, rawAutoRenewStatus: Int32? = nil, isInBillingRetryPeriod: Bool? = nil, rawPriceIncreaseStatus: Int32? = nil, gracePeriodExpiresDate: Date? = nil, rawOfferType: Int32? = nil, offerIdentifier: String? = nil, signedDate: Date? = nil, rawEnvironment: String? = nil, recentSubscriptionStartDate: Date? = nil, renewalDate: Date? = nil, currency: String? = nil, renewalPrice: Int64? = nil, offerDiscountType: OfferDiscountType? = nil, eligibleWinBackOfferIds: [String]? = nil) {
3031
self.rawExpirationIntent = rawExpirationIntent
3132
self.originalTransactionId = originalTransactionId
3233
self.autoRenewProductId = autoRenewProductId
@@ -44,6 +45,7 @@ public struct JWSRenewalInfoDecodedPayload: DecodedSignedData, Decodable, Encoda
4445
self.currency = currency
4546
self.renewalPrice = renewalPrice
4647
self.offerDiscountType = offerDiscountType
48+
self.eligibleWinBackOfferIds = eligibleWinBackOfferIds
4749
}
4850

4951
///The reason the subscription expired.
@@ -190,6 +192,11 @@ public struct JWSRenewalInfoDecodedPayload: DecodedSignedData, Decodable, Encoda
190192

191193
///See ``offerDiscountType``
192194
public var rawOfferDiscountType: String?
195+
196+
///An array of win-back offer identifiers that a customer is eligible to redeem, which sorts the identifiers to present the better offers first.
197+
///
198+
///[eligibleWinBackOfferIds](https://developer.apple.com/documentation/appstoreserverapi/eligiblewinbackofferids)
199+
public var eligibleWinBackOfferIds: [String]?
193200

194201
public enum CodingKeys: CodingKey {
195202
case expirationIntent
@@ -209,6 +216,7 @@ public struct JWSRenewalInfoDecodedPayload: DecodedSignedData, Decodable, Encoda
209216
case currency
210217
case renewalPrice
211218
case offerDiscountType
219+
case eligibleWinBackOfferIds
212220
}
213221

214222
public init(from decoder: any Decoder) throws {
@@ -230,6 +238,7 @@ public struct JWSRenewalInfoDecodedPayload: DecodedSignedData, Decodable, Encoda
230238
self.currency = try container.decodeIfPresent(String.self, forKey: .currency)
231239
self.renewalPrice = try container.decodeIfPresent(Int64.self, forKey: .renewalPrice)
232240
self.rawOfferDiscountType = try container.decodeIfPresent(String.self, forKey: .offerDiscountType)
241+
self.eligibleWinBackOfferIds = try container.decodeIfPresent([String].self, forKey: .eligibleWinBackOfferIds)
233242
}
234243

235244
public func encode(to encoder: any Encoder) throws {
@@ -251,5 +260,6 @@ public struct JWSRenewalInfoDecodedPayload: DecodedSignedData, Decodable, Encoda
251260
try container.encodeIfPresent(self.currency, forKey: .currency)
252261
try container.encodeIfPresent(self.renewalPrice, forKey: .renewalPrice)
253262
try container.encodeIfPresent(self.rawOfferDiscountType, forKey: .offerDiscountType)
263+
try container.encodeIfPresent(self.eligibleWinBackOfferIds, forKey: .eligibleWinBackOfferIds)
254264
}
255265
}

Sources/AppStoreServerLibrary/Models/OfferType.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ public enum OfferType: Int32, Decodable, Encodable, Hashable {
77
case introductoryOffer = 1
88
case promotionalOffer = 2
99
case subscriptionOfferCode = 3
10+
case winBackOffer = 4
1011
}

Tests/AppStoreServerLibraryTests/SignedModelTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ final class SignedModelTests: XCTestCase {
248248
XCTAssertEqual("USD", renewalInfo.currency)
249249
XCTAssertEqual(OfferDiscountType.payAsYouGo, renewalInfo.offerDiscountType)
250250
XCTAssertEqual("PAY_AS_YOU_GO", renewalInfo.rawOfferDiscountType)
251+
XCTAssertEqual(["eligible1", "eligible2"], renewalInfo.eligibleWinBackOfferIds)
251252
TestingUtility.confirmCodableInternallyConsistent(renewalInfo)
252253
}
253254

Tests/AppStoreServerLibraryTests/resources/models/signedRenewalInfo.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,9 @@
1515
"renewalDate": 1698148850000,
1616
"renewalPrice": 9990,
1717
"currency": "USD",
18-
"offerDiscountType": "PAY_AS_YOU_GO"
18+
"offerDiscountType": "PAY_AS_YOU_GO",
19+
"eligibleWinBackOfferIds": [
20+
"eligible1",
21+
"eligible2"
22+
]
1923
}

0 commit comments

Comments
 (0)