Product
The Product Service manages virtual currencies and handles receipt processing for the various app stores.
WARNING: As of brainCloud 3.9, the Product
service is being deprecated in favor of two replacement services: AppStore
for in-app purchases and product/promotions/pricing requests and VirtualCurrency
for currency operations. The APIs in the replacement services are similar, but improved; more generic method names and cleaner, more standardized response formats. The Product
service and APIs will continue to be available until the end of 2019. We strongly recommend that all new apps use the AppStore and VirtualCurrency services instead.
The Product service includes APIs for:
- Managing Virtual Currencies
- Handling In-app Purchases (IAP)
- Querying Promotions
Virtual Currencies
The following API calls are used to manage a user's currency balances:
[GetCurrency](/api/capi/product/getcurrency)
- get current currency balances[AwardCurrency](/api/capi/product/awardcurrency)
- call when currency is awarded. Note that[ConsumeCurrency](/api/capi/product/consumecurrency)
- call when currency is consumed[ResetCurrency](/api/capi/product/resetcurrency)
- resets the users currency to zero
Note that there are Parent and Peer versions of these APIs available as well.
For security reasons, the above calls are normally only available via cloud code. You can make them client callable by enabling the [x] Allow Currency Calls from Client compatibility flag on the Design | Core App Info | Advanced Settings page of the Design Portal.
In-app Purchases
The specifics of processing in-app purchases from platform to platform vary slightly, but the overall flow is as follows:
- Client app requests a list of products from brainCloud
- Client app requests the localized pricing details for the products from the AppStore
- Client app displays the products with prices to the user
- User chooses to purchase a product
- Client app invokes the purchase API from the AppStore. AppStore performs the purchase, and sends back a receipt to the client
- Client sends the receipt to brainCloud for validation. brainCloud performs a back-channel verification of the receipt with the AppStore – and if all is good, makes any required changes to virtual currency balances
The follow call requests the list of products for sale:
[GetSalesInventory](/api/capi/product/getsalesinventory)
[GetSalesInventoryByCategory](/api/capi/product/getsalesinventorybycategory)
These methods are used to confirm store receipts:
Facebook -
ConfirmFacebookPurchase
Google Play -
ConfirmGooglePlayPurchase
iOS -
VerifyItunesReceipt
Windows -
VerifyMicrosoftReceipt
These methods are for performing Steam purchases:
[StartSteamTransaction](/api/capi/product/startsteamtransaction)
[FinalizeSteamTransaction](/api/capi/product/finalizesteamtransaction)
Promotions
In addition to the above purchase flow, the app can also query to see if any promotions are currently active (for display in banners, etc.), using the GetEligiblePromotions
call – and can make manual adjustments to virtual currency balances.
The promotions APIs are:
[GetEligiblePromotions](/api/capi/product/geteligiblepromotions)
📄️ AwardCurrency
WARNING: This call, AwardCurrency(), is included in the client libraries for convenience and backwards compatibility, but for app security reasons we recommend it only be called server-side via Cloud Code. By default the servers will block any client-side invocations of currency altering methods. To enable client-side support (not recommended), you need to enable the [x] Allow Currency Calls from Client compatibility setting on the Design | Core App Info | Advanced Settings page of the portal.
📄️ AwardParentCurrency
Award parent user the passed-in amount of currency. Returns an object representing the new currency values.
📄️ AwardPeerCurrency
Used to award Peer currency.
📄️ ConfirmFacebookPurchase
Confirm Facebook Purchase. On success, the player will be awarded the associated currencies.
📄️ ConfirmGooglePlayPurchase
Confirm Google Play purchase.
📄️ ConsumeCurrency
WARNING:
📄️ ConsumeParentCurrency
Consumes currency in a parent app.
📄️ ConsumePeerCurrency
Consumes currency in a peer.
📄️ FinalizeSteamTransaction
Finalize Steam Transaction. On success, the player will be awarded the associated currencies.
📄️ GetCurrency
Gets the player's currency for the given currency type or all currency types if null passed in.
📄️ GetEligiblePromotions
Get eligible promotions.
📄️ GetParentCurrency
Gets the parent player's currency for the given currency type or all currency types if null passed in.
📄️ GetSalesInventory
Method gets the active sales inventory for the passed-in currency type and platform.
📄️ GetSalesInventoryByCategory
Method gets the active sales inventory for the passed-in currency type, platform, and category.
📄️ ResetCurrency
WARNING:
📄️ ResetParentCurrency
Resets the player's parent currency back to zero.
📄️ StartSteamTransaction
Initialize a Steam transaction.
📄️ VerifyItunesReceipt
Method verifies an iTunes receipt. On success, the player will be awarded the associated currencies.
📄️ VerifyMicrosoftReceipt
Verify Microsoft Receipt. On success, the player will be awarded the associated currencies.