public class Receipt

  1. Object
  2. Receipt

ImplementsExternalizable

Encapsulates a receipt for an in-app purchase.

Fields

public static final String STORE_CODE_ITUNES = "itunes"
public static final String STORE_CODE_PLAY = "play"
public static final String STORE_CODE_WINDOWS = "windows"
public static final String STORE_CODE_SIMULATOR = "simulator"

Constructors

public Receipt()
public Receipt(String sku, Date expiryDate, Date cancellationDate, Date purchaseDate, int quantity, String transactionId, String orderData, String storeCode, String internalId)Convenience constructor

Methods

public String getSku()
public void setSku(String sku)
public Date getExpiryDate()The expiry date of the receipt, in case this is a subscription receipt.
public void setExpiryDate(Date expiryDate)
public int getVersion()Returns the version for the current persistance code, the version will be pased to internalized thus allowing the internalize method to recognize classes persisted in older revisions
public void externalize(DataOutputStream out) throws IOExceptionAllows us to store an object state, this method must be implemented in order to save the state of an object
public void internalize(int version, DataInputStream in) throws IOExceptionLoads the object from the input stream and allows deserialization
public String getObjectId()The object id must be unique, it is used to identify the object when loaded even when it is obfuscated.
public Date getCancellationDate()Cancellation date of the receipt, if it has been cancelled.
public void setCancellationDate(Date cancellationDate)
public Date getPurchaseDate()Date of purchase.
public void setPurchaseDate(Date originalPurchaseDate)
public int getQuantity()Quantity.
public void setQuantity(int quantity)
public String getTransactionId()The store-specific transaction ID.
public void setTransactionId(String transactionId)
public String getOrderData()The order data that may be used to verify the receipt with the appropriate REST service.
public void setOrderData(String orderData)
public String getStoreCode()The store code from which this receipt originated.
public void setStoreCode(String storeCode)
public String getInternalId()An internal ID that may be optionally used to link the receipt to an internal order ID.
public void setInternalId(String internalId)
public String toString()Returns a string representation of the object.

Inherited methods

Field details

STORE_CODE_ITUNES

public static final String STORE_CODE_ITUNES = "itunes"

STORE_CODE_PLAY

public static final String STORE_CODE_PLAY = "play"

STORE_CODE_WINDOWS

public static final String STORE_CODE_WINDOWS = "windows"

STORE_CODE_SIMULATOR

public static final String STORE_CODE_SIMULATOR = "simulator"

Constructor details

Receipt

public Receipt()

Receipt

public Receipt(String sku, Date expiryDate, Date cancellationDate, Date purchaseDate, int quantity, String transactionId, String orderData, String storeCode, String internalId)
Convenience constructor

Method details

getSku

public String getSku()

Returns

the sku

setSku

public void setSku(String sku)

Parameters

sku String
the sku to set

See also

getExpiryDate

public Date getExpiryDate()

The expiry date of the receipt, in case this is a subscription receipt.

NOTE: The expiry date will NOT be set automatically when the receipt is generated by the platform. It should be set by the ReceiptStore in the com.codename1.util.SuccessCallback) step, and usually on the server-side (in cases where a server is being used to track subscriptions), then the expiry date will be made available when the receipt is loaded using ReceiptStore#fetchReceipts(com.codename1.util.SuccessCallback).

Returns

the expiryDate Will be null for non-subscriptions.

setExpiryDate

public void setExpiryDate(Date expiryDate)

Parameters

expiryDate Date
the expiryDate to set

getVersion

public int getVersion()
Returns the version for the current persistance code, the version will be pased to internalized thus allowing the internalize method to recognize classes persisted in older revisions

Returns

version number for the persistant code

externalize

public void externalize(DataOutputStream out) throws IOException
Allows us to store an object state, this method must be implemented in order to save the state of an object

Parameters

out DataOutputStream
the stream into which the object must be serialized

Throws

java.io.IOException
the method may throw an exception

internalize

public void internalize(int version, DataInputStream in) throws IOException
Loads the object from the input stream and allows deserialization

Parameters

version int
the version the class returned during the externalization processs
in DataInputStream
the input stream used to load the class

Throws

java.io.IOException
the method may throw an exception

getObjectId

public String getObjectId()
The object id must be unique, it is used to identify the object when loaded even when it is obfuscated.

Returns

a unique id

getCancellationDate

public Date getCancellationDate()
Cancellation date of the receipt, if it has been cancelled. A cancelled receipt should be treated as if the purchase had never been made in the first place.

Returns

the cancellationDate

setCancellationDate

public void setCancellationDate(Date cancellationDate)

Parameters

cancellationDate Date
the cancellationDate to set

getPurchaseDate

public Date getPurchaseDate()
Date of purchase.

Returns

the purchaseDate

setPurchaseDate

public void setPurchaseDate(Date originalPurchaseDate)

Parameters

originalPurchaseDate Date
the purchaseDate to set

getQuantity

public int getQuantity()
Quantity. Currently this will always be 1, but potentially could be used internally to denote other quantities.

Returns

the quantity

setQuantity

public void setQuantity(int quantity)

Parameters

quantity int
the quantity to set

getTransactionId

public String getTransactionId()
The store-specific transaction ID. This will match exactly the transaction id of the store the issued the receipt. Use the storeCode to differentiate between transactions of different stores, which may potentially have the same transaction Ids.

Returns

the transactionId

setTransactionId

public void setTransactionId(String transactionId)

Parameters

transactionId String
the transactionId to set

getOrderData

public String getOrderData()

The order data that may be used to verify the receipt with the appropriate REST service. This data will be in different formats for different stores.

iTunes has a base64 encoded string, Play has a JSON structure, Windows has an XML string, etc…

This will be filled in at the time that the receipt is generated by the platform’s implementation, so developers should never have to explicitly set this.

Returns

the orderData

setOrderData

public void setOrderData(String orderData)

Parameters

orderData String
the orderData to set

getStoreCode

public String getStoreCode()
The store code from which this receipt originated. Will usually be one of #STORE_CODE_ITUNES, #STORE_CODE_PLAY, #STORE_CODE_WINDOWS, or #STORE_CODE_SIMULATOR, but developers could also use custom codes if they use a different store, or no store at all. This code can be used for validating the receipt.

Returns

the storeCode

setStoreCode

public void setStoreCode(String storeCode)

Parameters

storeCode String
the storeCode to set

getInternalId

public String getInternalId()
An internal ID that may be optionally used to link the receipt to an internal order ID.

Returns

the internalId

setInternalId

public void setInternalId(String internalId)

Parameters

internalId String
the internalId to set

toString

public String toString()
Returns a string representation of the object. In general, the toString method returns a string that “textually represents” this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method. The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@’, and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of: getClass().getName() + ‘@’ + Integer.toHexString(hashCode())