public abstract class Purchase
- Object
- Purchase
Represents the status of in-app-purchase goods, this class provides information about products purchased by a user as well as the ability to purchase additional products. There are generally two types of payment systems: Manual and managed. In manual payments we pay a specific amount in a specific currency while with managed payment systems we work against a product catalog defined in the server.
In-app-purchase API’s rely on managed server based products, other payment systems use the manual approach. An application dealing with virtual goods must support both since not all devices feature in-app-purchase API’s. An application dealing with physical goods & services must use the latter according to the TOS of current in-app-purchase solutions.
Constructors
public Purchase() |
Methods
public static void postReceipt(String storeCode, String sku, String transactionId, long datePurchased, String orderData) | Deprecated Posts a receipt to be added to the receipt store. |
public static Purchase getInAppPurchase() | Returns the native OS purchase implementation if applicable, if unavailable this method will try to fallback to a custom purchase implementation and failing that will return null |
public static Purchase getInAppPurchase(boolean d) | Deprecated |
protected final ReceiptStore getReceiptStore() | |
public final void setReceiptStore(ReceiptStore store) | Installs a given receipt store to handle receipt management |
public final List<Receipt> getReceipts() | Gets all of the receipts for this app. |
public final Receipt[] getReceipts(String... skus) | Gets all of the receipts for the specified skus. |
public boolean isManualPaymentSupported() | Indicates whether the purchasing platform supports manual payments which are just payments of a specific amount of money. |
public boolean isManagedPaymentSupported() | Indicates whether the purchasing platform supports managed payments which work by picking products that are handled by the servers/OS of the platform vendor. |
public String pay(double amount, String currency) | Performs payment of a specific amount based on the manual payment API, notice that this doesn’t use the in-app-purchase functionality of the device! |
public String pay(double amount, String currency, String invoiceNumber) | Performs payment of a specific amount based on the manual payment API, notice that this doesn’t use the in-app-purchase functionality of the device! |
public boolean isItemListingSupported() | Indicates whether the payment platform supports things such as “item listing” or requires that items be coded into the system. |
public Product[] getProducts(String[] skus) | Returns the product list for the given SKU array |
public boolean wasPurchased(String sku) | Returns true if the given SKU was purchased in the past, notice this method might not work as expected for Unmanaged/consumable products which can be purchased multiple times. |
public void purchase(String sku) | Begins the purchase process for the given SKU |
protected void purchaseImpl(String sku) | Platform hook for purchase(String). |
public void purchase(String sku, PromotionalOffer promotionalOffer) | Begins the purchase process for the given SKU using a provided promotional offer. |
protected void purchaseImpl(String sku, PromotionalOffer promotionalOffer) | Platform hook for purchase(String, PromotionalOffer). |
public void subscribe(String sku) | Begins subscribe process for the given subscription SKU |
public void subscribe(String sku, PromotionalOffer promotionalOffer) | Begins subscribe process for the given subscription SKU using a provided promotional offer. |
public void unsubscribe(String sku) | Cancels the subscription to a given SKU |
public List<Receipt> getPendingPurchases() | Gets a list of purchases that haven’t yet been sent to the server. |
public final void synchronizeReceipts() | |
public final void synchronizeReceipts(long ifOlderThanMs, SuccessCallback<Boolean> callback) | Synchronize with receipt store. |
public final boolean synchronizeReceiptsSync(long ifOlderThanMs) | Synchronize receipts and wait for the sync to complete before proceeding. |
public final Date getExpiryDate(String... skus) | Gets the expiry date for a set of skus. |
public final boolean isSubscribed(String... skus) | Checks to see if the user is currently subscribed to any of the given skus. |
public Receipt getFirstReceiptExpiringAfter(Date dt, String... skus) | Gets the first receipt that expires after the specified date for the provided skus. |
public boolean isRefundable(String sku) | Indicates whether refunding is possible when the SKU is purchased |
public void refund(String sku) | Tries to refund the given SKU if applicable in the current market/product |
public boolean isSubscriptionSupported() | Returns true if the subscription API is supported in this platform |
public boolean isUnsubscribeSupported() | Deprecated Some platforms support subscribing but don’t support unsubscribe |
public boolean isRestoreSupported() | Indicates whether a purchase restore button is supported by the OS |
public void restore() | Restores purchases if applicable, this will only work if isRestoreSupported() returns true |
public boolean isManageSubscriptionsSupported() | Checks to see if this platform supports the #manageSubscriptions(java.lang.String) method. |
public void manageSubscriptions(String sku) | Open the platform’s UI for managing subscriptions. |
public String getStoreCode() | Returns the store code associated with this in-app purchase object. |
Inherited methods
Constructor details
Purchase
public Purchase()Method details
postReceipt
public static void postReceipt(String storeCode, String sku, String transactionId, long datePurchased, String orderData)Parameters
storeCodeString- Not documented.
skuString- The sku of the product
transactionIdString- The transaction ID
datePurchasedlong- The date of the purchase.
orderDataString- Not documented.
getInAppPurchase
public static Purchase getInAppPurchase()Returns
getInAppPurchase
public static Purchase getInAppPurchase(boolean d)getReceiptStore
protected final ReceiptStore getReceiptStore()setReceiptStore
public final void setReceiptStore(ReceiptStore store)getReceipts
public final List<Receipt> getReceipts()Returns
getReceipts
public final Receipt[] getReceipts(String... skus)Parameters
skusString...- The skus for which to get receipts.
Returns
isManualPaymentSupported
public boolean isManualPaymentSupported()Returns
isManagedPaymentSupported
public boolean isManagedPaymentSupported()Returns
pay
public String pay(double amount, String currency)Parameters
amountdouble- the amount to pay
currencyString- the three letter currency type
Returns
Throws
RuntimeException- This method is a part of the manual payments API and will fail if isManualPaymentSupported() returns false
pay
public String pay(double amount, String currency, String invoiceNumber)Parameters
amountdouble- the amount to pay
currencyString- the three letter currency type
invoiceNumberString- application specific invoice number
Returns
Throws
RuntimeException- This method is a part of the manual payments API and will fail if isManualPaymentSupported() returns false
isItemListingSupported
public boolean isItemListingSupported()Returns
getProducts
public Product[] getProducts(String[] skus)Parameters
skusString[]- the ids for the specific products
Returns
Throws
RuntimeException- This method is a part of the managed payments API and will fail if isManagedPaymentSupported() returns false
RuntimeException- This method works only if isItemListingSupported() returns true
wasPurchased
public boolean wasPurchased(String sku)Parameters
skuString- the id of the product
Returns
Throws
RuntimeException- This method is a part of the managed payments API and will fail if isManagedPaymentSupported() returns false
purchase
public void purchase(String sku)Begins the purchase process for the given SKU
On Android you must use #subscribe(java.lang.String) for play store subscription products instead of this method. You cannot use #purchase(java.lang.String). On iOS
there is no difference between #subscribe(java.lang.String) and #purchase(java.lang.String), so if you are simulating subscriptions
on iOS using auto-renewables, you are better to use #subscribe(java.lang.String) as this will work correctly on both Android
and iOS.
Parameters
skuString- the SKU with which to perform the purchase process
Throws
RuntimeException- This method is a part of the managed payments API and will fail if isManagedPaymentSupported() returns false
purchaseImpl
protected void purchaseImpl(String sku)purchase(String). Native implementations
override this to begin the store transaction; the public
purchase method wraps it so the purchase_initiated
analytics event fires uniformly across platforms.Parameters
skuString- the SKU with which to perform the purchase process
purchase
public void purchase(String sku, PromotionalOffer promotionalOffer)Begins the purchase process for the given SKU using a provided promotional offer.
Promotional offers are currently only supported on iOS. See Apple’s documentation
Parameters
skuString- the SKU with which to perform the purchase process
promotionalOfferPromotionalOffer- The promotional offer.
Throws
RuntimeException- This method is a part of the managed payments API and will fail if isManagedPaymentSupported() returns false
See also
purchaseImpl
protected void purchaseImpl(String sku, PromotionalOffer promotionalOffer)purchase(String, PromotionalOffer). See
purchaseImpl(String).Parameters
skuString- the SKU with which to perform the purchase process
promotionalOfferPromotionalOffer- the promotional offer
subscribe
public void subscribe(String sku)Begins subscribe process for the given subscription SKU
On Android you must use this method for play store subscription products. You cannot use #purchase(java.lang.String). On iOS
there is no difference between #subscribe(java.lang.String) and #purchase(java.lang.String), so if you are simulating subscriptions
on iOS using auto-renewables, you are better to use #subscribe(java.lang.String) as this will work correctly on both Android
and iOS.
Parameters
skuString- the SKU with which to perform the purchase process
Throws
RuntimeException- This method is a part of the managed payments API and will fail if isManagedPaymentSupported() returns false
subscribe
public void subscribe(String sku, PromotionalOffer promotionalOffer)Begins subscribe process for the given subscription SKU using a provided promotional offer.
Promotional offers are currently only supported on iOS. See Apple’s documentation
Parameters
skuString- the SKU with which to perform the purchase process
promotionalOfferPromotionalOffer- The promotional offer.
Throws
RuntimeException- This method is a part of the managed payments API and will fail if isManagedPaymentSupported() returns false
See also
unsubscribe
public void unsubscribe(String sku)Parameters
skuString- the SKU with which to perform the purchase process
Throws
RuntimeException- This method is a part of the managed payments API and will fail if isManagedPaymentSupported() returns false
getPendingPurchases
public List<Receipt> getPendingPurchases()Returns
synchronizeReceipts
public final void synchronizeReceipts()synchronizeReceipts
public final void synchronizeReceipts(long ifOlderThanMs, SuccessCallback<Boolean> callback)Parameters
ifOlderThanMslong- Only fetch receipts if they haven’t been fetched in
ifOlderThanMsmilliseconds. callbackSuccessCallback<Boolean>- Callback called when sync is done. Will be passed true if all pending purchases were successfully submitted to the receipt store AND receipts were successfully loaded.
synchronizeReceiptsSync
public final boolean synchronizeReceiptsSync(long ifOlderThanMs)Parameters
ifOlderThanMslong- Only re-fetch if it hasn’t been reloaded in this number of milliseconds.
Returns
getExpiryDate
public final Date getExpiryDate(String... skus)Parameters
skusString...- The skus to check. The latest expiry date of the set will be used.
Returns
isSubscribed
public final boolean isSubscribed(String... skus)#getExpiryDate(java.lang.String...) returns a date
later than now.Parameters
skusString...- Set of skus to check.
getFirstReceiptExpiringAfter
public Receipt getFirstReceiptExpiringAfter(Date dt, String... skus)isRefundable
public boolean isRefundable(String sku)Parameters
skuString- the sku
Returns
refund
public void refund(String sku)Parameters
skuString- the id for the product
isSubscriptionSupported
public boolean isSubscriptionSupported()Returns
isUnsubscribeSupported
public boolean isUnsubscribeSupported()#isManageSubscriptionsSupported() insteadReturns
isRestoreSupported
public boolean isRestoreSupported()Returns
restore
public void restore()isManageSubscriptionsSupported
public boolean isManageSubscriptionsSupported()#manageSubscriptions(java.lang.String) method.Returns
#manageSubscriptions(java.lang.String) method.manageSubscriptions
public void manageSubscriptions(String sku)#isManageSubscriptionsSupported() method to check
if the platform supports this feature.Parameters
skuString- Optional sku of product whose subscription you wish to manage. If left null, then the general subscription management UI will be opened. iOS doesn’t support “deep-linking” directly to the management for a particular sku, so this parameter is ignored there. If included on Android, howerver, it will open the UI for managing the specified sku.
getStoreCode
public String getStoreCode()Returns
Receipt#STORE_CODE_ITUNES, Receipt#STORE_CODE_PLAY, Receipt#STORE_CODE_SIMULATOR, or
Receipt#STORE_CODE_WINDOWS.