Skip to main content
Version: 5.7.0

VerifyPurchase

Used to verify a purchase receipt for Apple AppStore, Google Play, Facebook or Windows. The contents passed into receiptData are store-specific. On success, the player will be awarded the associated currencies.

ReceiptData formats

Apple AppStore

Use "itunes" as the storeId.

iTunes receiptData format:

{
"receipt": "ENCODED-RECEIPT-DATA",
"excludeOldTransactions": false
}

Google Play Store

Use "googlePlay" as the storeId.

tip

Ensure that the parameter includeSubscriptionCheck setting is set to true for Product Type as Subscription.

Google Play receiptData format:

{
"productId" : "gems_pack_small",
"orderId" : "GPA.0000-1111-2222-33333",
"token" : "ENCODED_TOKEN_STRING",
"developerPayload" : "STRING_ENCODED_JSON",
"includeSubscriptionCheck" : false
}

Facebook

Use "facebook" as the storeId.

Facebook receiptData format:

{
"signedRequest": "string-of-signedRequest"
}

Amazon Store

Use "amazon" as the storeId.

Amazon receiptData format:

{
"receiptId": "a-receipt-id",
"userId": "a-user-id"
}

Response fields

The following fields are included in the json response:

FieldDescription
resultCodethe overall status of the operation
errorMessage(optional) message describing non-zero result codes
storethe store used for the purchase
transactionSummarythe store-specific response details. Contents vary by store-type.
rewardsthe total currencies being rewarded as a result of the purchases(s). Includes subsections by currency scope.
currencycurrency balances.
parentCurrencybalances of parent currencies (if any)
peerCurrencybalances of peer currencies (if any)
server_timeutc time on the server (in millis)

VerifyPurchase responses

The key values of the return to evaluate include:

  • processedCount - number of transactions successfully processed. To be processed, a transaction receipt must be valid, the product must be found, and the transaction must not have been processed before.
  • unprocessedCount - the number of transactions that were rejected. See the transactionStatus code associated with the transaction for details.
ServiceOperation
appStoreVERIFY_PURCHASE

Method Parameters

ParameterDescription
storeIdThe store type - "itunes", "googlePlay", "amazon", "facebook" or "windows"
receiptDataA JSON object with data in the format for the specified store

Usage

http://localhost:3000
string storeId = "hghghsgfh";
string receiptData = "{\"productId\":\"ugfhffhgj\"}";
SuccessCallback successCallback = (response, cbObject) =>
{
Debug.Log(string.Format("Success | {0}", response));
};
FailureCallback failureCallback = (status, code, error, cbObject) =>
{
Debug.Log(string.Format("Failed | {0} {1} {2}", status, code, error));
};

_bc.AppStoreService.VerifyPurchase(storeId, receiptData, successCallback, failureCallback);
JSON Response
{
"status": 200,
"data": {
"resultCode": 0,
"errorMessage": null,
"store": "itunes",
"transactionSummary": {
"processedCount": 1,
"unprocessedCount": 1,
"transactionDetails": [
{
"transactionId": "80000557199459",
"itemId": "barBundle1Imp",
"transactionResultCode": 0,
"processed": true,
"originalTransactionId": "80000557199459",
"quantity": 1,
"purchaseDateMs": 1550639146000,
"productId": "...coinBundle1Imp",
"purchaseDate": "2019-02-20 05:05:46 Etc/GMT",
"rewards": {
"extra": null,
"currency": {
"bar": 10,
"coinMultiplier": 1
}
}
},
{
"transactionId": "80000557201213",
"itemId": "coinBundle2Imp",
"transactionResultCode": 100,
"processed": false,
"originalTransactionId": "80000557201213",
"quantity": 1,
"purchaseDateMs": 1550639681000,
"productId": "...coinBundle2Imp",
"errorMessage": "Item already processed",
"purchaseDate": "2019-02-20 05:14:41 Etc/GMT"
}
],
"extra": {
"appleReceipt": "stringified json receipt data"
}
},
"rewards": {
"currency": {
"coins": 1000
},
"parentCurrency": {
"awesomeMaster": {
"rubies": 2000
}
},
"peerCurrency": {
"peerApp": {
"rogerCurrency": 30
}
}
},
"currency": {
"coins": {
"balance": 1000,
"purchased": 1000,
"awarded": 0,
"consumed": 0
}
},

"parentCurrency": {
"awesomeMaster": {
"rubies": {
"balance": 2000,
"purchased": 2000,
"awarded": 0,
"consumed": 0
}
}
},

"peerCurrency": {
"peerApp": {
"rogerCurrency": {
"balance": 30,
"purchased": 30,
"awarded": 0,
"consumed": 0
}
}
},

"server_time": 1473325588695
}
}
Common Error Code

Status Codes

CodeNameDescription
0RESULT_OKSuccessfully verified, new currencies awarded.
100RESULT_FAILED_ALREADY_PROCESSEDAlready verified and awarded currencies.
101RESULT_FAILED_APPSTORE_ERRORPurchase error with the used app store.
102RESULT_FAILED_PRODUCT_NOT_FOUNDCannot locate the product in brainCloud Product Inventory. *This is likely a configuration error in the brainCloud product - double-check the price settings for the product.**
103RESULT_FAILED_UNKNOWN_ERRORUnexpected error.
104RESULT_FAILED_CONFIGURATION_ERRORConfiguration error on the used app store.
105RESULT_FAILED_REQUEST_ERRORCredential missing for used app store. Ensure Facebook or Stream credential is correct.