Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating new fields added in App Store Server API v1.10 #53

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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 <a href="https://developer.apple.com/documentation/appstoreserverapi/price">price</a>
**/
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 <a href="https://developer.apple.com/documentation/appstoreserverapi/currency">currency</a>
**/
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 <a href="https://developer.apple.com/documentation/appstoreserverapi/offerdiscounttype">offerDiscountType</a>
**/
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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -661,6 +742,9 @@ public String toString() {
", storefront='" + storefront + '\'' +
", storefrontId='" + storefrontId + '\'' +
", transactionReason=" + transactionReason +
", price=" + price +
", currency'=" + currency + '\'' +
", offerDiscountType=" + offerDiscountType +
'}';
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <a href="https://developer.apple.com/documentation/appstoreserverapi/offerdiscounttype">offerDiscountType</a>
*/
@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<OfferDiscountType> {
@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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
5 changes: 4 additions & 1 deletion src/test/resources/models/signedTransaction.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,8 @@
"environment":"LocalTesting",
"transactionReason":"PURCHASE",
"storefront":"USA",
"storefrontId":"143441"
"storefrontId":"143441",
"price": 10990,
"currency": "USD",
"offerDiscountType": "PAY_AS_YOU_GO"
}
Loading