From 707ca73a3e567d617a4305b770711ec7af9818fa Mon Sep 17 00:00:00 2001 From: Alex Baker Date: Tue, 9 Jul 2024 09:38:25 -0600 Subject: [PATCH] Add support for App Store Server API v1.13 and App Store Server Notifications v2.13 https://developer.apple.com/documentation/appstoreserverapi/app_store_server_api_changelog https://developer.apple.com/documentation/appstoreservernotifications/app_store_server_notifications_changelog --- .../model/JWSRenewalInfoDecodedPayload.java | 37 ++++++++++++++++++- .../itunes/storekit/model/OfferType.java | 3 +- .../JWSRenewalInfoDecodedPayloadTest.java | 2 + .../resources/models/signedRenewalInfo.json | 8 +++- 4 files changed, 46 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/apple/itunes/storekit/model/JWSRenewalInfoDecodedPayload.java b/src/main/java/com/apple/itunes/storekit/model/JWSRenewalInfoDecodedPayload.java index dc0c15ab..af9b800b 100644 --- a/src/main/java/com/apple/itunes/storekit/model/JWSRenewalInfoDecodedPayload.java +++ b/src/main/java/com/apple/itunes/storekit/model/JWSRenewalInfoDecodedPayload.java @@ -6,6 +6,8 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import java.util.ArrayList; +import java.util.List; import java.util.Map; import java.util.Objects; @@ -32,6 +34,7 @@ public class JWSRenewalInfoDecodedPayload implements DecodedSignedData { private static final String SERIALIZED_NAME_RENEWAL_PRICE = "renewalPrice"; private static final String SERIALIZED_NAME_CURRENCY = "currency"; private static final String SERIALIZED_NAME_OFFER_DISCOUNT_TYPE = "offerDiscountType"; + private static final String SERIALIZED_NAME_ELIGIBLE_WIN_BACK_OFFER_IDS = "eligibleWinBackOfferIds"; @JsonProperty(SERIALIZED_NAME_EXPIRATION_INTENT) private Integer expirationIntent; @JsonProperty(SERIALIZED_NAME_ORIGINAL_TRANSACTION_ID) @@ -70,6 +73,8 @@ public class JWSRenewalInfoDecodedPayload implements DecodedSignedData { private String currency; @JsonProperty(SERIALIZED_NAME_OFFER_DISCOUNT_TYPE) private String offerDiscountType; + @JsonProperty(SERIALIZED_NAME_ELIGIBLE_WIN_BACK_OFFER_IDS) + private List eligibleWinBackOfferIds = null; @JsonAnySetter private Map unknownFields; @@ -466,6 +471,34 @@ public void setRawOfferDiscountType(String rawOfferDiscountType) { this.offerDiscountType = rawOfferDiscountType; } + public JWSRenewalInfoDecodedPayload eligibleWinBackOfferIds(List eligibleWinBackOfferIds) { + this.eligibleWinBackOfferIds = eligibleWinBackOfferIds; + return this; + } + + public JWSRenewalInfoDecodedPayload addEligibleWinBackOfferId(String eligibleWinBackOfferId) { + if (this.eligibleWinBackOfferIds == null) { + this.eligibleWinBackOfferIds = new ArrayList<>(); + } + this.eligibleWinBackOfferIds.add(eligibleWinBackOfferId); + return this; + } + + /** + * An array of win-back offer identifiers that a customer is eligible to redeem, which sorts the identifiers to present the better offers first. + * + * @return eligibleWinBackOfferIds + * @see eligibleWinBackOfferIds + **/ + public List getEligibleWinBackOfferIds() { + return eligibleWinBackOfferIds; + } + + public void setEligibleWinBackOfferIds(List eligibleWinBackOfferIds) { + this.eligibleWinBackOfferIds = eligibleWinBackOfferIds; + } + + public JWSRenewalInfoDecodedPayload unknownFields(Map unknownFields) { this.unknownFields = unknownFields; return this; @@ -510,12 +543,13 @@ public boolean equals(Object o) { Objects.equals(this.renewalPrice, jwSRenewalInfoDecodedPayload.renewalPrice) && Objects.equals(this.currency, jwSRenewalInfoDecodedPayload.currency) && Objects.equals(this.offerDiscountType, jwSRenewalInfoDecodedPayload.offerDiscountType) && + Objects.equals(this.eligibleWinBackOfferIds, jwSRenewalInfoDecodedPayload.eligibleWinBackOfferIds) && Objects.equals(this.unknownFields, jwSRenewalInfoDecodedPayload.unknownFields); } @Override public int hashCode() { - return Objects.hash(expirationIntent, originalTransactionId, autoRenewProductId, productId, autoRenewStatus, isInBillingRetryPeriod, priceIncreaseStatus, gracePeriodExpiresDate, offerType, offerIdentifier, signedDate, environment, recentSubscriptionStartDate, renewalDate, renewalPrice, currency, offerDiscountType, unknownFields); + return Objects.hash(expirationIntent, originalTransactionId, autoRenewProductId, productId, autoRenewStatus, isInBillingRetryPeriod, priceIncreaseStatus, gracePeriodExpiresDate, offerType, offerIdentifier, signedDate, environment, recentSubscriptionStartDate, renewalDate, renewalPrice, currency, offerDiscountType, eligibleWinBackOfferIds, unknownFields); } @Override @@ -538,6 +572,7 @@ public String toString() { ", renewalPrice=" + renewalPrice + ", currency='" + currency + '\'' + ", offerDiscountType='" + offerDiscountType + '\'' + + ", eligibleWinBackOfferIds=" + eligibleWinBackOfferIds + ", unknownFields=" + unknownFields + '}'; } diff --git a/src/main/java/com/apple/itunes/storekit/model/OfferType.java b/src/main/java/com/apple/itunes/storekit/model/OfferType.java index c3ee06d9..dba067c3 100644 --- a/src/main/java/com/apple/itunes/storekit/model/OfferType.java +++ b/src/main/java/com/apple/itunes/storekit/model/OfferType.java @@ -13,7 +13,8 @@ public enum OfferType { INTRODUCTORY_OFFER(1), PROMOTIONAL_OFFER(2), - SUBSCRIPTION_OFFER_CODE(3); + SUBSCRIPTION_OFFER_CODE(3), + WIN_BACK_OFFER(4); private final Integer value; diff --git a/src/test/java/com/apple/itunes/storekit/model/JWSRenewalInfoDecodedPayloadTest.java b/src/test/java/com/apple/itunes/storekit/model/JWSRenewalInfoDecodedPayloadTest.java index a0280c9f..b0d42590 100644 --- a/src/test/java/com/apple/itunes/storekit/model/JWSRenewalInfoDecodedPayloadTest.java +++ b/src/test/java/com/apple/itunes/storekit/model/JWSRenewalInfoDecodedPayloadTest.java @@ -10,6 +10,7 @@ import java.io.IOException; import java.security.NoSuchAlgorithmException; +import java.util.List; public class JWSRenewalInfoDecodedPayloadTest { @@ -42,5 +43,6 @@ public void testRenewalInfoDecoding() throws IOException, NoSuchAlgorithmExcepti Assertions.assertEquals("USD", renewalInfo.getCurrency()); Assertions.assertEquals(OfferDiscountType.PAY_AS_YOU_GO, renewalInfo.getOfferDiscountType()); Assertions.assertEquals("PAY_AS_YOU_GO", renewalInfo.getRawOfferDiscountType()); + Assertions.assertEquals(List.of("eligible1", "eligible2"), renewalInfo.getEligibleWinBackOfferIds()); } } diff --git a/src/test/resources/models/signedRenewalInfo.json b/src/test/resources/models/signedRenewalInfo.json index 3bc565b0..30b90d27 100644 --- a/src/test/resources/models/signedRenewalInfo.json +++ b/src/test/resources/models/signedRenewalInfo.json @@ -15,5 +15,9 @@ "renewalDate": 1698148850000, "renewalPrice": 9990, "currency": "USD", - "offerDiscountType": "PAY_AS_YOU_GO" -} \ No newline at end of file + "offerDiscountType": "PAY_AS_YOU_GO", + "eligibleWinBackOfferIds": [ + "eligible1", + "eligible2" + ] +}