public abstract class Purchase extends Object
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.
Constructor and Description |
---|
Purchase() |
Modifier and Type | Method and Description |
---|---|
Date |
getExpiryDate(String... skus)
Gets the expiry date for a set of skus.
|
Receipt |
getFirstReceiptExpiringAfter(Date dt,
String... skus)
Gets the first receipt that expires after the specified date for the provided
skus.
|
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
|
static Purchase |
getInAppPurchase(boolean d)
Deprecated.
use the version that takes no arguments
|
List<Receipt> |
getPendingPurchases()
Gets a list of purchases that haven't yet been sent to the server.
|
Product[] |
getProducts(String[] skus)
Returns the product list for the given SKU array
|
List<Receipt> |
getReceipts()
Gets all of the receipts for this app.
|
Receipt[] |
getReceipts(String... skus)
Gets all of the receipts for the specified skus.
|
protected ReceiptStore |
getReceiptStore() |
String |
getStoreCode()
Returns the store code associated with this in-app purchase object.
|
boolean |
isItemListingSupported()
Indicates whether the payment platform supports things such as "item listing" or
requires that items be coded into the system.
|
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.
|
boolean |
isManageSubscriptionsSupported()
Checks to see if this platform supports the
manageSubscriptions(java.lang.String) method. |
boolean |
isManualPaymentSupported()
Indicates whether the purchasing platform supports manual payments which
are just payments of a specific amount of money.
|
boolean |
isRefundable(String sku)
Indicates whether refunding is possible when the SKU is purchased
|
boolean |
isRestoreSupported()
Indicates whether a purchase restore button is supported by the OS
|
boolean |
isSubscribed(String... skus)
Checks to see if the user is currently subscribed to any of the given skus.
|
boolean |
isSubscriptionSupported()
Returns true if the subscription API is supported in this platform
|
boolean |
isUnsubscribeSupported()
Deprecated.
use
isManageSubscriptionsSupported() instead |
void |
manageSubscriptions(String sku)
Open the platform's UI for managing subscriptions.
|
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!
|
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!
|
static void |
postReceipt(String storeCode,
String sku,
String transactionId,
long datePurchased,
String orderData)
Deprecated.
For internal implementation use only.
|
void |
purchase(String sku)
Begins the purchase process for the given SKU
|
void |
purchase(String sku,
PromotionalOffer promotionalOffer)
Begins the purchase process for the given SKU using a provided promotional offer.
|
void |
refund(String sku)
Tries to refund the given SKU if applicable in the current market/product
|
void |
restore()
Restores purchases if applicable, this will only work if isRestoreSupported() returns true
|
void |
setReceiptStore(ReceiptStore store)
Installs a given receipt store to handle receipt management
|
void |
subscribe(String sku)
Begins subscribe process for the given subscription SKU
|
void |
subscribe(String sku,
PromotionalOffer promotionalOffer)
Begins subscribe process for the given subscription SKU using a provided promotional offer.
|
void |
synchronizeReceipts() |
void |
synchronizeReceipts(long ifOlderThanMs,
SuccessCallback<Boolean> callback)
Synchronize with receipt store.
|
boolean |
synchronizeReceiptsSync(long ifOlderThanMs)
Synchronize receipts and wait for the sync to complete before proceeding.
|
void |
unsubscribe(String sku)
Cancels the subscription to a given SKU
|
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 final void setReceiptStore(ReceiptStore store)
store
- protected final ReceiptStore getReceiptStore()
public final List<Receipt> getReceipts()
public final Receipt[] getReceipts(String... skus)
skus
- The skus for which to get receipts.public boolean isManualPaymentSupported()
public boolean isManagedPaymentSupported()
public String pay(double amount, String currency)
amount
- the amount to paycurrency
- the three letter currency typeRuntimeException
- This method is a part of the manual payments API and will fail if
isManualPaymentSupported() returns falsepublic String pay(double amount, String currency, String invoiceNumber)
amount
- the amount to paycurrency
- the three letter currency typeinvoiceNumber
- application specific invoice numberRuntimeException
- This method is a part of the manual payments API and will fail if
isManualPaymentSupported() returns falsepublic boolean isItemListingSupported()
public Product[] getProducts(String[] skus)
sku
- the ids for the specific productsRuntimeException
- This method is a part of the managed payments API and will fail if
isManagedPaymentSupported() returns falseRuntimeException
- This method works only if isItemListingSupported() returns truepublic boolean wasPurchased(String sku)
sku
- the id of the productRuntimeException
- This method is a part of the managed payments API and will fail if
isManagedPaymentSupported() returns falsepublic void purchase(String 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.
sku
- the SKU with which to perform the purchase processRuntimeException
- This method is a part of the managed payments API and will fail if
isManagedPaymentSupported() returns falsepublic void purchase(String sku, PromotionalOffer promotionalOffer)
Promotional offers are currently only supported on iOS. See Apple's documentation
sku
- the SKU with which to perform the purchase processpromotionalOffer
- The promotional offer.RuntimeException
- This method is a part of the managed payments API and will fail if
isManagedPaymentSupported() returns falseApplePromotionalOffer
public void subscribe(String 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.
sku
- the SKU with which to perform the purchase processRuntimeException
- This method is a part of the managed payments API and will fail if
isManagedPaymentSupported() returns falsepublic void subscribe(String sku, PromotionalOffer promotionalOffer)
Promotional offers are currently only supported on iOS. See Apple's documentation
sku
- the SKU with which to perform the purchase processpromotionalOffer
- The promotional offer.RuntimeException
- This method is a part of the managed payments API and will fail if
isManagedPaymentSupported() returns falseApplePromotionalOffer
public void unsubscribe(String sku)
sku
- the SKU with which to perform the purchase processRuntimeException
- This method is a part of the managed payments API and will fail if
isManagedPaymentSupported() returns falsepublic List<Receipt> getPendingPurchases()
public final void synchronizeReceipts()
public final void synchronizeReceipts(long ifOlderThanMs, SuccessCallback<Boolean> callback)
ifOlderThanMs
- Only fetch receipts if they haven't been fetched in ifOlderThanMs
milliseconds.callback
- 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.public static void postReceipt(String storeCode, String sku, String transactionId, long datePurchased, String orderData)
sku
- The sku of the producttransactionId
- The transaction IDdatePurchased
- The date of the purchase.public final boolean synchronizeReceiptsSync(long ifOlderThanMs)
ifOlderThanMs
- Only re-fetch if it hasn't been reloaded in this number of milliseconds.public final Date getExpiryDate(String... skus)
skus
- The skus to check. The latest expiry date of the set will be used.public final boolean isSubscribed(String... skus)
getExpiryDate(java.lang.String...)
returns a date
later than now.skus
- Set of skus to check.public Receipt getFirstReceiptExpiringAfter(Date dt, String... skus)
dt
- skus
- public boolean isRefundable(String sku)
sku
- the skupublic void refund(String sku)
sku
- the id for the productpublic static Purchase getInAppPurchase()
public static Purchase getInAppPurchase(boolean d)
public boolean isSubscriptionSupported()
public boolean isUnsubscribeSupported()
isManageSubscriptionsSupported()
insteadpublic boolean isRestoreSupported()
public void restore()
public boolean isManageSubscriptionsSupported()
manageSubscriptions(java.lang.String)
method.manageSubscriptions(java.lang.String)
method.public void manageSubscriptions(String sku)
isManageSubscriptionsSupported()
method to check
if the platform supports this feature.sku
- 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.public String getStoreCode()
Receipt.STORE_CODE_ITUNES
, Receipt.STORE_CODE_PLAY
, Receipt.STORE_CODE_SIMULATOR
, or
Receipt.STORE_CODE_WINDOWS
.