Skip to main content

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 bool startUsingService ()
 Start up the service, should be called from onStart. 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...
 

Static Public Attributes

const string BFGSETTING_FULLGAMEPURCHASE_KEY = "BFGSETTING_FULLGAMEPURCHASE_KEY"
 
const string NOTIFICATION_PURCHASE_ASKUSER = bfgCommon.NOTIFICATION_PURCHASE_ASKUSER
 Notification for asking the user to confirm the purchase.
 
const string NOTIFICATION_PURCHASE_NOTALLOWED = "NOTIFICATION_PURCHASE_NOTALLOWED"
 Notification that this user is not allowed to make purchases on this phone.
 
const string NOTIFICATION_PURCHASE_STARTED = "NOTIFICATION_PURCHASE_STARTED"
 Notification that a purchase has started.
 
const string NOTIFICATION_PURCHASE_REVOKED = bfgCommon.NOTIFICATION_PURCHASE_REVOKED
 SKU Revoked.
 
const string NOTIFICATION_RESTORE_COMPLETED = bfgCommon.NOTIFICATION_RESTORE_COMPLETED
 Restore completed.
 
const string NOTIFICATION_PURCHASE_CANCELLED = bfgCommon.NOTIFICATION_PURCHASE_CANCELLED
 Purchase cancelled.
 
const string NOTIFICATION_PURCHASE_GETUSERID_SUCCEEDED = "NOTIFICATION_PURCHASE_GETUSERID_SUCCEEDED"
 User id successfully retrieved.
 
const string NOTIFICATION_BILLING_INITIALIZE_SUCCEEDED = bfgCommon.NOTIFICATION_BILLING_INITIALIZE_SUCCEEDED
 Indicates that purchase services were initialized successfully.
 
const string NOTIFICATION_BILLING_INITIALIZE_FAILED = bfgCommon.NOTIFICATION_BILLING_INITIALIZE_FAILED
 Indicates that purchase services were unable to be initialized.
 
const string NOTIFICATION_PURCHASE_PRODUCTINFORMATION_FAILED = "NOTIFICATION_PURCHASE_PRODUCTINFORMATION_FAILED"
 Indicates that product information failed to be retrieved.
 
const string NOTIFICATION_PURCHASE_CONSUMPTION_SUCCEEDED = "NOTIFICATION_PURCHASE_CONSUMPTION_SUCCEEDED"
 Indicates that the purchase was consumed successfully.
 
const string NOTIFICATION_PURCHASE_CONSUMPTION_FAILED = "NOTIFICATION_PURCHASE_CONSUMPTION_FAILED"
 Indicates that the purchase failed to be consumed.
 
const string NOTIFICATION_PURCHASE_SUCCEEDED_WITH_RECEIPT = "NOTIFICATION_PURCHASE_SUCCEEDED_WITH_RECEIPT"
 Indicates that the purchase succeeded with receipt.
 
const string NOTIFICATION_POST_CURRENT_INVENTORY_SUCCEEDED = bfgCommon.NOTIFICATION_POST_CURRENT_INVENTORY_SUCCEEDED
 Indicates that a GoogleInventory object was successfully retrieved from Google Play services.
 
const string NOTIFICATION_POST_CURRENT_INVENTORY_FAILED = "NOTIFICATION_POST_CURRENT_INVENTORY_FAILED"
 Indicates that a GoogleInventory object failed to be retrieved from Google Play services.
 
const string kPurchaseKeyPrefix = "PURCHASEKEY-"
 
const string kPurchaseMapName = "PurchaseMap"
 
const string kSkuMapName = "SkuMap"
 

Detailed Description

This is the bfgPurchaseAndroid wrapper class for the native Android purchase functionality.

Member Function Documentation

◆ beginPurchase() [1/2]

static bool BFGSDK.bfgPurchaseAndroid.beginPurchase ()
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]

static bool BFGSDK.bfgPurchaseAndroid.beginPurchase (string productid)
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
productIdThe product id to purchase.
Returns
Boolean true if able to begin purchase, false if not.

◆ completePurchase() [1/2]

static void BFGSDK.bfgPurchaseAndroid.completePurchase (string productid)
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
productIdof product to be purchased.

◆ completePurchase() [2/2]

static bool BFGSDK.bfgPurchaseAndroid.completePurchase (string productid,
string additionalPayload 
)
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
productIdof product to be purchased.
additionalPayloadString with a max length of 128 characters.

◆ consumePurchase()

static void BFGSDK.bfgPurchaseAndroid.consumePurchase (string productid)
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
productidProduct Id to be consumed.

◆ defineConsumableSKUs()

static void BFGSDK.bfgPurchaseAndroid.defineConsumableSKUs (List< string > skus)
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
skusList of SKUs for products whose purchases should be consumed automatically by the SDK.

◆ finishPurchase()

static void BFGSDK.bfgPurchaseAndroid.finishPurchase (string sku)
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()

static string BFGSDK.bfgPurchaseAndroid.getAppstoreName ()
inlinestatic
Gets the name of the app store.
Returns
String "google" or "amazon".

◆ getCurrentUser()

static string BFGSDK.bfgPurchaseAndroid.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()

static Dictionary< string, object > BFGSDK.bfgPurchaseAndroid.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()

static bool BFGSDK.bfgPurchaseAndroid.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]

static Dictionary< string, string > BFGSDK.bfgPurchaseAndroid.productInformation ()
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]

static Dictionary< string, string > BFGSDK.bfgPurchaseAndroid.productInformation (string productid)
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]

static void BFGSDK.bfgPurchaseAndroid.restorePurchase ()
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]

static void BFGSDK.bfgPurchaseAndroid.restorePurchase (List< string > productids)
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
productidsList of product Ids to restore.

◆ restorePurchase() [3/3]

static void BFGSDK.bfgPurchaseAndroid.restorePurchase (string productid)
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
productIdId of product to be restored.

◆ setCurrentUser()

static void BFGSDK.bfgPurchaseAndroid.setCurrentUser (string userId)
inlinestatic
Mutator for current user identifier. This is typically only used by Amazon In-App Purchase.
Parameters
userIdString representing the current user id.

◆ setupService()

static void BFGSDK.bfgPurchaseAndroid.setupService ()
inlinestatic
Does preliminary setup in preparation of starting the purchasing service The following are requirements and extra details for using this method:
  1. This method must be called before any purchasing start calls are made.
  2. This method should be called after setting up all of the billing notifications
  3. This method should be called from the UI thread
  4. This method establishes the relationship between the Activity and the SDK
  5. Calling this method will result in sending billing initialization notifications

◆ startUsingService()

static bool BFGSDK.bfgPurchaseAndroid.startUsingService ()
inlinestatic
Start up the service, should be called from onStart.
Returns
Boolean true if service could be started, false if not.