diff --git a/src/main/java/com/apple/itunes/storekit/model/JWSTransactionDecodedPayload.java b/src/main/java/com/apple/itunes/storekit/model/JWSTransactionDecodedPayload.java index 305677ea..a5c4d0e6 100644 --- a/src/main/java/com/apple/itunes/storekit/model/JWSTransactionDecodedPayload.java +++ b/src/main/java/com/apple/itunes/storekit/model/JWSTransactionDecodedPayload.java @@ -37,6 +37,9 @@ public class JWSTransactionDecodedPayload implements DecodedSignedData { private static final String SERIALIZED_NAME_STOREFRONT = "storefront"; private static final String SERIALIZED_NAME_STOREFRONT_ID = "storefrontId"; private static final String SERIALIZED_NAME_TRANSACTION_REASON = "transactionReason"; + private static final String SERIALIZED_NAME_PRICE = "price"; + private static final String SERIALIZED_NAME_CURRENCY = "currency"; + private static final String SERIALIZED_NAME_OFFER_DISCOUNT_TYPE = "offerDiscountType"; @SerializedName(SERIALIZED_NAME_ORIGINAL_TRANSACTION_ID) private String originalTransactionId; @SerializedName(SERIALIZED_NAME_TRANSACTION_ID) @@ -88,6 +91,12 @@ public class JWSTransactionDecodedPayload implements DecodedSignedData { private String storefrontId; @SerializedName(SERIALIZED_NAME_TRANSACTION_REASON) private String transactionReason; + @SerializedName(SERIALIZED_NAME_PRICE) + private Integer price; + @SerializedName(SERIALIZED_NAME_CURRENCY) + private String currency; + @SerializedName(SERIALIZED_NAME_OFFER_DISCOUNT_TYPE) + private String offerDiscountType; public JWSTransactionDecodedPayload() { @@ -596,6 +605,75 @@ public void setRawTransactionReason(String rawTransactionReason) { this.transactionReason = rawTransactionReason; } + public JWSTransactionDecodedPayload price(Integer price) { + this.price = price; + return this; + } + + /** + * The price of the in-app purchase or subscription offer that you configured in App Store Connect, as an integer. + * + * @return price + * @see price + **/ + public Integer getPrice() { + return price; + } + + public void setPrice(Integer price) { + this.price = price; + } + + public JWSTransactionDecodedPayload currency(String currency) { + this.currency = currency; + return this; + } + + /** + * The three-letter ISO 4217 currency code for the price of the product. + * + * @return currency + * @see currency + **/ + public String getCurrency() { + return this.currency; + } + + public void setCurrency(String currency) { + this.currency = currency; + } + + public JWSTransactionDecodedPayload offerDiscountType(OfferDiscountType offerDiscountType) { + this.offerDiscountType = offerDiscountType != null ? offerDiscountType.getValue() : null; + return this; + } + + /** + * The payment mode you configure for an introductory offer, promotional offer, or offer code on an auto-renewable subscription. + * + * @return offerDiscountType + * @see offerDiscountType + **/ + public OfferDiscountType getOfferDiscountType() { + return offerDiscountType != null ? OfferDiscountType.fromValue(offerDiscountType) : null; + } + + /** + * @see #getOfferDiscountType() + */ + public String getRawOfferDiscountType() { + return offerDiscountType; + } + + public void setOfferDiscountType(OfferDiscountType offerDiscountType) { + this.offerDiscountType = offerDiscountType != null ? offerDiscountType.getValue() : null; + } + + public void setRawOfferDiscountType(String rawOfferDiscountType) { + this.offerDiscountType = rawOfferDiscountType; + } + + @Override public boolean equals(Object o) { if (this == o) { @@ -627,12 +705,15 @@ public boolean equals(Object o) { Objects.equals(this.environment, jwSTransactionDecodedPayload.environment) && Objects.equals(this.storefront, jwSTransactionDecodedPayload.storefront) && Objects.equals(this.storefrontId, jwSTransactionDecodedPayload.storefrontId) && - Objects.equals(this.transactionReason, jwSTransactionDecodedPayload.transactionReason); + Objects.equals(this.transactionReason, jwSTransactionDecodedPayload.transactionReason) && + Objects.equals(this.price, jwSTransactionDecodedPayload.price) && + Objects.equals(this.currency, jwSTransactionDecodedPayload.currency) && + Objects.equals(this.offerDiscountType, jwSTransactionDecodedPayload.offerDiscountType); } @Override public int hashCode() { - return Objects.hash(originalTransactionId, transactionId, webOrderLineItemId, bundleId, productId, subscriptionGroupIdentifier, purchaseDate, originalPurchaseDate, expiresDate, quantity, type, appAccountToken, inAppOwnershipType, signedDate, revocationReason, revocationDate, isUpgraded, offerType, offerIdentifier, environment, storefront, storefrontId, transactionReason); + return Objects.hash(originalTransactionId, transactionId, webOrderLineItemId, bundleId, productId, subscriptionGroupIdentifier, purchaseDate, originalPurchaseDate, expiresDate, quantity, type, appAccountToken, inAppOwnershipType, signedDate, revocationReason, revocationDate, isUpgraded, offerType, offerIdentifier, environment, storefront, storefrontId, transactionReason, price, currency, offerDiscountType); } @Override @@ -661,6 +742,9 @@ public String toString() { ", storefront='" + storefront + '\'' + ", storefrontId='" + storefrontId + '\'' + ", transactionReason=" + transactionReason + + ", price=" + price + + ", currency'=" + currency + '\'' + + ", offerDiscountType=" + offerDiscountType + '}'; } } diff --git a/src/main/java/com/apple/itunes/storekit/model/OfferDiscountType.java b/src/main/java/com/apple/itunes/storekit/model/OfferDiscountType.java new file mode 100644 index 00000000..d0c3b28e --- /dev/null +++ b/src/main/java/com/apple/itunes/storekit/model/OfferDiscountType.java @@ -0,0 +1,60 @@ +// Copyright (c) 2023 Apple Inc. Licensed under MIT License. + +package com.apple.itunes.storekit.model; + +import com.google.gson.TypeAdapter; +import com.google.gson.annotations.JsonAdapter; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; + +import java.io.IOException; + +/** + * The payment mode you configure for an introductory offer, promotional offer, or offer code on an auto-renewable subscription. + * + * @see offerDiscountType + */ +@JsonAdapter(OfferDiscountType.Adapter.class) +public enum OfferDiscountType { + + FREE_TRIAL("FREE_TRIAL"), + PAY_AS_YOU_GO("PAY_AS_YOU_GO"), + PAY_UP_FRONT("PAY_UP_FRONT"); + + private final String value; + + OfferDiscountType(String value) { + this.value = value; + } + + public static OfferDiscountType fromValue(String value) { + for (OfferDiscountType b : OfferDiscountType.values()) { + if (b.value.equals(value)) { + return b; + } + } + throw new IllegalArgumentException("Unexpected value '" + value + "'"); + } + + public String getValue() { + return value; + } + + @Override + public String toString() { + return String.valueOf(value); + } + + public static class Adapter extends TypeAdapter { + @Override + public void write(final JsonWriter jsonWriter, final OfferDiscountType enumeration) throws IOException { + jsonWriter.value(enumeration.getValue()); + } + + @Override + public OfferDiscountType read(final JsonReader jsonReader) throws IOException { + String value = jsonReader.nextString(); + return OfferDiscountType.fromValue(value); + } + } +} \ No newline at end of file diff --git a/src/test/java/com/apple/itunes/storekit/model/JWSTransactionDecodedPayloadTest.java b/src/test/java/com/apple/itunes/storekit/model/JWSTransactionDecodedPayloadTest.java index 2c091f1d..73c412ea 100644 --- a/src/test/java/com/apple/itunes/storekit/model/JWSTransactionDecodedPayloadTest.java +++ b/src/test/java/com/apple/itunes/storekit/model/JWSTransactionDecodedPayloadTest.java @@ -50,5 +50,9 @@ public void testTransactionDecoding() throws IOException, NoSuchAlgorithmExcepti Assertions.assertEquals("PURCHASE", transaction.getRawTransactionReason()); Assertions.assertEquals(Environment.LOCAL_TESTING, transaction.getEnvironment()); Assertions.assertEquals("LocalTesting", transaction.getRawEnvironment()); + Assertions.assertEquals(10990, transaction.getPrice()); + Assertions.assertEquals("USD", transaction.getCurrency()); + Assertions.assertEquals(OfferDiscountType.PAY_AS_YOU_GO, transaction.getOfferDiscountType()); + Assertions.assertEquals("PAY_AS_YOU_GO", transaction.getRawOfferDiscountType()); } } diff --git a/src/test/resources/models/signedTransaction.json b/src/test/resources/models/signedTransaction.json index 3c44a569..0211857b 100644 --- a/src/test/resources/models/signedTransaction.json +++ b/src/test/resources/models/signedTransaction.json @@ -21,5 +21,8 @@ "environment":"LocalTesting", "transactionReason":"PURCHASE", "storefront":"USA", - "storefrontId":"143441" + "storefrontId":"143441", + "price": 10990, + "currency": "USD", + "offerDiscountType": "PAY_AS_YOU_GO" } \ No newline at end of file