bfgPurchaseAndroid Class
This is the bfgPurchaseAndroid wrapper class for the native Android purchase functionality. More...
Public Types | |
enum | bfgStoreType { google , amazon } |
Enum to define the store type, i.e Google or Amazon. | |
Static Public Member Functions | |
static string | getAppstoreName () |
Gets the name of the app store. More... | |
static void | setupService () |
Does preliminary setup in preparation of starting the purchasing service The following are requirements and extra details for using this method: More... | |
static void | resumeUsingService () |
Resume the service, should be called from onResume. | |
static void | reportPurchaseCompletedSuccessfully (string receipt) |
Reports that a purchase was successfully completed. | |
static string | getCurrentUser () |
Gets the current user identifier. This is typically only used by Amazon In-App Purchase. More... | |
static void | setCurrentUser (string userId) |
Mutator for current user identifier. This is typically only used by Amazon In-App Purchase. More... | |
static void | stopUsingService () |
Stop using the service, should be called from onPause. | |
static void | cleanupService () |
Clean up the service. Should be called from onDestroy. | |
static bool | beginPurchase () |
Called when a user has selected the "buy" button. More... | |
static bool | beginPurchase (string productid) |
Begin a purchase of the product identified by the supplied product id. More... | |
static void | completePurchase (string productid) |
Called when the user has selected to "buy." Adds the payment to SKPaymentQueue. More... | |
static bool | completePurchase (string productid, string additionalPayload) |
Called when the user has selected to "buy". Adds the payment to SKPaymentQueue and allows for an additional payload to be sent as "game" field in developer payload. More... | |
static void | restorePurchase () |
Call if the user asks to restore previous purchase of default SKU. More... | |
static void | restorePurchase (string productid) |
Call if the user asks to restore previous purchase with a specific SKU. More... | |
static void | restorePurchase (List< string > productids) |
Call if the user asks to restore previous purchase with a list of SKUs. More... | |
static void | consumePurchase (string productid) |
Call to consume this purchase. More... | |
static Dictionary< string, object > | getVolatileInventory () |
Returns the PublicInventory, which is an instance of AmazonInventory or GoogleInventory. Use after receiving NOTIFICATION_BILLING_INITIALIZE_SUCCEEDED or NOTIFICATION_RESTORE_COMPLETED. More... | |
static Dictionary< string, string > | productInformation (string productid) |
Obtains product information for a specific SKU. More... | |
static Dictionary< string, string > | productInformation () |
Obtains product information for the default SKU. More... | |
static bool | postCurrentInventory () |
Used to initiate asynchronous retrieval of a GoogleInventory object from Google Play services. If the retrieval is successful, the inventory will be placed in the argument of a NOTIFICATION_POST_CURRENT_INVENTORY_SUCCEEDED notification. More... | |
static void | defineConsumableSKUs (List< string > skus) |
This method is used by the application to specify the product SKUs of purchases that should be consumed automatically. More... | |
static void | finishPurchase (string sku) |
The application uses this method to report that a purchase has been awarded. More... | |
Detailed Description
This is the bfgPurchaseAndroid wrapper class for the native Android purchase functionality.
Member Function Documentation
◆ beginPurchase() [1/2]
| inlinestatic |
Called when a user has selected the "buy" button. Checks that purchase is possible and sends NOTIFICATION_PURCHASE_ASKUSER. The client should respond to message by prompting user with the purchase dialog.
- Returns
- Boolean
true
if able to begin purchase,false
if not.
◆ beginPurchase() [2/2]
| inlinestatic |
Begin a purchase of the product identified by the supplied product id. Checks that purchase is possible and sends NOTIFICATION_PURCHASE_ASKUSER. The client should respond to message by prompting user with the purchase dialog.
- Parameters
productId The product id to purchase.
- Returns
- Boolean
true
if able to begin purchase,false
if not.
◆ completePurchase() [1/2]
| inlinestatic |
Called when the user has selected to "buy." Adds the payment to SKPaymentQueue. If sent an "askuser" notification, then the code should either call "complete" or "cancel" the purchase, depending upon the user's choice. This method will send a purchase failed notification if the product is already in the active purchases list or there is no Internet connectivity.
- Parameters
productId of product to be purchased.
◆ completePurchase() [2/2]
| inlinestatic |
Called when the user has selected to "buy". Adds the payment to SKPaymentQueue and allows for an additional payload to be sent as "game" field in developer payload. This additional Payload is max length 128 characters. The purchase will fail if a string larger than 128 characters is used. This will be useful only if you are doing your own server-side receipt verification.
- Warning
- Google only.
- Parameters
productId of product to be purchased. additionalPayload String with a max length of 128 characters.
◆ consumePurchase()
| inlinestatic |
Call to consume this purchase. NOTIFICATION_PURCHASE_CONSUMPTION_SUCCEEDED if the product was consumed successfully. NOTIFICATION_PURCHASE_CONSUMPTION_FAILED otherwise.The method will send NOTIFICATION_RESTORE_COMPLETED if the call completes successfully, regardless of whether the product has been purchased. If the method does not complete successfully, it will send NOTIFICATION_RESTORE_FAILED.
- Warning
- Google only.
- Parameters
productid Product Id to be consumed.
◆ defineConsumableSKUs()
| inlinestatic |
This method is used by the application to specify the product SKUs of purchases that should be consumed automatically. The method should be called on the UI thread.
- Warning
- Use on Google Purchases ONLY. This method will not do anything on Amazon purchases.
- Parameters
skus List of SKUs for products whose purchases should be consumed automatically by the SDK.
◆ finishPurchase()
| inlinestatic |
The application uses this method to report that a purchase has been awarded. It should be used only for SKUs that have been registered as consumable with a call to defineConsumableSKUs. The method should be called on the UI thread.
◆ getAppstoreName()
| inlinestatic |
Gets the name of the app store.
- Returns
- String "google" or "amazon".
◆ getCurrentUser()
| inlinestatic |
Gets the current user identifier. This is typically only used by Amazon In-App Purchase.
- Returns
- String userId, the current user id or null.
◆ getVolatileInventory()
| inlinestatic |
Returns the PublicInventory, which is an instance of AmazonInventory or GoogleInventory. Use after receiving NOTIFICATION_BILLING_INITIALIZE_SUCCEEDED or NOTIFICATION_RESTORE_COMPLETED.
- Warning
- Google only.
- Returns
- An empty "" string if not a google inventory, otherwise a dictionary with the Google inventory.
◆ postCurrentInventory()
| inlinestatic |
Used to initiate asynchronous retrieval of a GoogleInventory object from Google Play services. If the retrieval is successful, the inventory will be placed in the argument of a NOTIFICATION_POST_CURRENT_INVENTORY_SUCCEEDED notification.
- Returns
true
if retrieval could be initiated, false if a network connection was unavailable.
◆ productInformation() [1/2]
| inlinestatic |
Obtains product information for the default SKU.
- Returns
- Hashtable<String, Object> of SKUs mapped to their respective item information or null.
◆ productInformation() [2/2]
| inlinestatic |
Obtains product information for a specific SKU.
- Parameters
productId. The product id to get the information for.
- Returns
- Hashtable<String, Object> of SKUs mapped to their respective item information or null.
◆ restorePurchase() [1/3]
| inlinestatic |
Call if the user asks to restore previous purchase of default SKU. This sends a NOTIFICATION_RESTORE_SUCCEEDED with default SKU if the product identified by that SKU has been purchased. After receiving that notification, credit the user with the item. The method will send NOTIFICATION_RESTORE_COMPLETED if the call completes successfully, regardless of whether the product has been purchased. If the method does not complete successfully, it will send NOTIFICATION_RESTORE_FAILED.
◆ restorePurchase() [2/3]
| inlinestatic |
Call if the user asks to restore previous purchase with a list of SKUs. This sends a NOTIFICATION_RESTORE_SUCCEEDED with default SKU if the product identified by that SKU has been purchased. After receiving that notification, credit the user with the item. The method will send NOTIFICATION_RESTORE_COMPLETED if the call completes successfully, regardless of whether the product has been purchased. If the method does not complete successfully, it will send NOTIFICATION_RESTORE_FAILED. This is the preferred API to call if the application needs to restore purchases for multiple SKUs.
- Parameters
productids List of product Ids to restore.
◆ restorePurchase() [3/3]
| inlinestatic |
Call if the user asks to restore previous purchase with a specific SKU. This sends a NOTIFICATION_RESTORE_SUCCEEDED with default SKU if the product identified by that SKU has been purchased. After receiving that notification, credit the user with the item. The method will send NOTIFICATION_RESTORE_COMPLETED if the call completes successfully, regardless of whether the product has been purchased. If the method does not complete successfully, it will send NOTIFICATION_RESTORE_FAILED. This is the preferred API to call if the application needs to restore purchases for only one SKU. In that case, you will usually specify a product SKU that was defined by your producer.
- Parameters
productId Id of product to be restored.
◆ setCurrentUser()
| inlinestatic |
Mutator for current user identifier. This is typically only used by Amazon In-App Purchase.
- Parameters
userId String representing the current user id.
◆ setupService()
| inlinestatic |
Does preliminary setup in preparation of starting the purchasing service The following are requirements and extra details for using this method:
- This method must be called before any purchasing start calls are made.
- This method should be called after setting up all of the billing notifications
- This method should be called from the UI thread
- This method establishes the relationship between the Activity and the SDK
- Calling this method will result in sending billing initialization notifications