Server Side Configuration - No Code Payment

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:

  • Select ‘No Code Payment’ within nowStudio – Follow this guide.
  • Implement Server side configurations for ‘No Code Payment’ using the steps below.

Workflow

Here is the workflow associated with now.gg No Code Payment:

  • The user selects an In-app product to purchase
  • now.gg Payment will be invoked.
  • After the payment is successfully processed, the game will get a purchase token.
  • The game will send the purchase token to its game server for verification.
  • The game server will verify the purchase token with now.gg server.
  • The game will assign the purchased in-app product to the user on successful verification.

Implementing Server side Configurations

This section illustrates the steps to implement Server side configurations for ‘No Code Payment’.
Contents

1. Verify Purchase

Using this step, you can verify the in-app purchases using now.gg No Code Payment.

Important Information

  • If you are already verifying your purchases with other providers, you will receive the purchase token in the same URL handler that you are already using.
  • now.gg purchase token starts with -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

Sample nowgg verification 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)

Important Information

  • PurchaseToken – Use the purchaseToken you received from the URL handler.
  • API Key – The Payment API Key can be found within the credentials section of nowStudio. More information.

Expected Response

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"
    }
  }

Response Params

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.


2. Consume Purchase

After you have verified the purchase, you should mark it as consumed.

Purchase consumption involves:

  • Assigning the purchased product to the user.
  • Notifying now.gg that the product has been consumed.

Sample Consume Purchase Code

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)

Important Information

  • PurchaseToken – Use the purchaseToken you received from the URL handler.
  • API Key – The Payment API Key can be found within the credentials section of nowStudio. More information.

Expected Response

The following is a sample response from the consumePurchase API.

 }  
   "success": true,
   "code": 0,
   "codeMsg": "success",
   "data": {}
 }

Response Params

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 Mapping

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.

Sequence Diagram

The following sequence diagram illustrates the entire flow associated with ‘No Code Payment’.

×
Text copied to clipboard
Link copied to clipbord
Questions? Please reach out to us at dev-support@now.gg