# Class Receipt

java.lang.Object
com.codename1.payment.Receipt

All Implemented Interfaces:
  `Externalizable`

public class Receipt extends Object implements Externalizable
Encapsulates a receipt for an in-app purchase.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final String`
  `STORE_CODE_ITUNES`
  `static final String`
  `STORE_CODE_PLAY`
  `static final String`
  `STORE_CODE_SIMULATOR`
  `static final String`
  `STORE_CODE_WINDOWS`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `Receipt()`
  `Receipt(String sku, Date expiryDate, Date cancellationDate, Date purchaseDate, int quantity, String transactionId, String orderData, String storeCode, String internalId)`
  Convenience constructor

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `externalize(java.io.DataOutputStream out)`
  Allows us to store an object state, this method must be implemented in order to save the state of an object
  `Date`
  `getCancellationDate()`
  Cancellation date of the receipt, if it has been cancelled.
  `Date`
  `getExpiryDate()`
  The expiry date of the receipt, in case this is a subscription receipt.
  `String`
  `getInternalId()`
  An internal ID that may be optionally used to link the receipt to an internal order ID.
  `String`
  `getObjectId()`
  The object id must be unique, it is used to identify the object when loaded even when it is obfuscated.
  `String`
  `getOrderData()`
  The order data that may be used to verify the receipt with the appropriate REST service.
  `Date`
  `getPurchaseDate()`
  Date of purchase.
  `int`
  `getQuantity()`
  Quantity.
  `String`
  `getSku()`

  ###### Returns

  `String`
  `getStoreCode()`
  The store code from which this receipt originated.
  `String`
  `getTransactionId()`
  The store-specific transaction ID.
  `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
  `void`
  `internalize(int version, java.io.DataInputStream in)`
  Loads the object from the input stream and allows deserialization
  `void`
  `setCancellationDate(Date cancellationDate)`

  ###### Parameters

  `void`
  `setExpiryDate(Date expiryDate)`

  ###### Parameters

  `void`
  `setInternalId(String internalId)`

  ###### Parameters

  `void`
  `setOrderData(String orderData)`

  ###### Parameters

  `void`
  `setPurchaseDate(Date originalPurchaseDate)`

  ###### Parameters

  `void`
  `setQuantity(int quantity)`

  ###### Parameters

  `void`
  `setSku(String sku)`

  ###### Parameters

  `void`
  `setStoreCode(String storeCode)`

  ###### Parameters

  `void`
  `setTransactionId(String transactionId)`

  ###### Parameters

  `String`
  `toString()`
  Returns a string representation of the object.

  ### Methods inherited from class Object

  `clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- ## Field Details

  - ### STORE_CODE_ITUNES

    public static final String STORE_CODE_ITUNES
    See Also:
      - Constant Field Values

  - ### STORE_CODE_PLAY

    public static final String STORE_CODE_PLAY
    See Also:
      - Constant Field Values

  - ### STORE_CODE_WINDOWS

    public static final String STORE_CODE_WINDOWS
    See Also:
      - Constant Field Values

  - ### STORE_CODE_SIMULATOR

    public static final String STORE_CODE_SIMULATOR
    See Also:
      - Constant Field Values

- ## 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`: the sku to set

    ###### See also

    - #getSku()

  - ### 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`: the expiryDate to set

    ###### See also

    - #getExpiryDate()

  - ### 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

    Specified by:
      `getVersion` in interface `Externalizable`

  - ### externalize

    public void externalize(java.io.DataOutputStream out) throws java.io.IOException

    Allows us to store an object state, this method must be implemented in order to save the state of an object

    ###### Parameters

    - `out`: the stream into which the object must be serialized

    ###### Throws

    - `java.io.IOException`: the method may throw an exception
    Specified by:
      `externalize` in interface `Externalizable`
    Throws:
      `java.io.IOException`

  - ### internalize

    public void internalize(int version, java.io.DataInputStream in) throws java.io.IOException

    Loads the object from the input stream and allows deserialization

    ###### Parameters

    - `version`: the version the class returned during the externalization processs

    - `in`: the input stream used to load the class

    ###### Throws

    - `java.io.IOException`: the method may throw an exception
    Specified by:
      `internalize` in interface `Externalizable`
    Throws:
      `java.io.IOException`

  - ### 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

    Specified by:
      `getObjectId` in interface `Externalizable`

  - ### 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`: the cancellationDate to set

    ###### See also

    - #getCancellationDate()

  - ### getPurchaseDate

    public Date getPurchaseDate()

    Date of purchase.

    ###### Returns

    the purchaseDate

  - ### setPurchaseDate

    public void setPurchaseDate(Date originalPurchaseDate)

    ###### Parameters

    - `originalPurchaseDate`: the purchaseDate to set

    ###### See also

    - #getPurchaseDate()

  - ### 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`: the quantity to set

    ###### See also

    - #getQuantity()

  - ### 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`: the transactionId to set

    ###### See also

    - #getTransactionId()

  - ### 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`: the orderData to set

    ###### See also

    - #getOrderData()

  - ### 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`: the storeCode to set

    ###### See also

    - #getStoreCode()

  - ### 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`: the internalId to set

    ###### See also

    - #getInternalId()

  - ### toString

    public String toString()
    Description copied from class: `Object`
    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())
    Overrides:
      `toString` in class `Object`