This document explains the steps to configure server-side IAP verification.
The now.gg No Code Payment implements server-side verification to ascertain the authenticity of a purchase. On successful verification, the game can allot the purchased product to the user and mark the purchase as consumed.
To implement No Code Payment with your app:
Here is the workflow associated with now.gg No Code Payment:
Using this step, you can verify the in-app purchases using now.gg No Code Payment.
purchase token
in the same URL handler that you are already using.-nowgg-
. You can use this to identify the in-app purchases from now.gg.The following sample illustrates the implementation to verify the in-app purchases:
def verify_purchase(package_name, product_id, purchase_token): # game-specific validation code if purchase_token.startswith("-nowgg-"): response = verify_purchase_with_nowgg( package_name, product_id, purchase_token) else: # continue verification with other providers # game-specific response handling code
The following sample code illustrates the associated request using the verifyPurchase
API.
import requests url = "https://cloud-api.bluestacks.cn/v2/seller/order/verifyPurchase" payload = 'purchaseToken=<nowgg_purchase_token>' headers = { 'Authorization': '<payment_api_key_here>', 'Content-Type': 'application/x-www-form-urlencoded' } response = requests.request("POST", url, headers=headers, data=payload) print(response.text)
purchaseToken
you received from the URL handler.Payment API Key
can be found within the credentials section of nowStudio. More information.The following is a sample response from the verifyPurchase
API.
{ "success": true, "code": 0, "codeMsg": "success", "data": { "purchaseTimeMillis": "1630529397125", "purchaseState": 0, "consumptionState": 0, "developerPayload": "<developer_payload>", "orderId": "<orderId_here>", "kind": "nowgg#productPurchase", "regionCode": "JP" } }
Params | Type | Description |
---|---|---|
success | boolean | Returns success as true or false. |
code | int | Returns 0 for success and non-zero for failure. |
codeMsg | string | Returns msg related to error code. (Provided here) |
purchaseTimeMillis | string (int 64) | The time the product was purchased, in milliseconds since the epoch. |
purchaseState | int | The purchase state of the order. Possible values are: 0: Unpaid, 1: Paid, 2: Failed |
consumptionState | int | The consumption state of the in-app product. Possible values are: 0: Yet to be consumed, 1: Consumed |
developerPayload | string | A developer-specified string containing supplemental information about an order. |
orderId | string | The order ID (Unique transaction identifier) associated with every in-app purchase product. |
kind | string | The kind of in-app product purchased with a hardcoded type nowgg#productPurchase . |
regionCode | string | ISO 3166-1 alpha-2 billing region code of the user at the time the product was granted. |
After you have verified the purchase, you should mark it as consumed.
Purchase consumption involves:
The following sample code illustrates the associated request using the consumePurchase
API.
import requests url = "https://cloud-api.bluestacks.cn/v2/order/consumePurchase" payload = 'purchaseToken=nowgg-_purchase_token' headers = { 'Authorization': 'payment_api_key_here', 'Content-Type': 'application/x-www-form-urlencoded' } response = requests.request("POST", url, headers=headers, data=payload) print(response.text)
purchaseToken
you received from the URL handler.Payment API Key
can be found within the credentials section of nowStudio. More information.The following is a sample response from the consumePurchase
API.
} "success": true, "code": 0, "codeMsg": "success", "data": {} }
Params | Type | Description |
---|---|---|
success | boolean | Returns success as true or false. |
code | int | Returns 0 for success and non-zero for failure. |
codeMsg | string | Returns msg related to error code. (Provided here) |
data | object | Data returned as a response. |
Error Code | Message | Description |
---|---|---|
3800 | ERROR_CONSUMING_PRODUCT | There was an error consuming the product. |
3900 | INVALID_AUTHORIZATION_KEY | The API Key provided for authorization is invalid. |
3901 | INVALID_PURCHASE_TOKEN | The provided purchase token is invalid. |
The following sequence diagram illustrates the entire flow associated with ‘No Code Payment’.
Payments Module
Payments Module
Document Rev. 1.0