consumePurchase API

This document focuses on the consumePurchase API used for server-side purchase consumption.

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.

Important Information

  • This API must be called from your app backend server.

Base URL

 https://payments-api.now.gg/

Request Path

v2/order/consumePurchase

Request Method

 POST

Request Header

 'Authorization': '<payment_api_key_here>',
  'Content-Type': 'application/x-www-form-urlencoded'

Request Body

The following should be included within the request body with consumePurchase API:

"purchaseToken": "<purchase_token_here>",
 "productId": "<product_id_here>", // Required only for multi-store
 "developerPayload": developerPayload // Optional. // Required only for multi-store
 "currency": "<currency>", // Required only for multi-store
 "type": "<store>"  // xiaomi | onestore. If not present, fallback value will be nowgg.

Note: If type is not present, the fallback value will be nowgg.

Important Information

  • Amazon and Huawei Stores do not support server-side consumption. Please refer to client-side consumption:

Sample Consume Purchase Request

The following sample code illustrates the associated request using the consumePurchase API.

import requests

 url = "https://payments-api.now.gg/v2/order/consumePurchase"

 headers = {
     "Authorization": "<payment_api_key_here>",
     "Content-Type": "application/x-www-form-urlencoded"
 }

 data = {
     "purchaseToken": "<purchase_token_here>",
     "productId": "<product_id_here>", // Required only for multi-store
     "developerPayload": "developerPayload",  // Optional // Required only for multi-store 
     "currency": "<currency>", // Required only for multi-store
     "type": "<store>"  // xiaomi, onestore. If not present, the fallback will be nowgg 
 }

 response = requests.post(url, headers=headers, data=data)

 print("Response Status Code:", response.status_code)
 print("Response Body:", response.text)
curl --location --request POST 'https://payments-api.now.gg/v2/order/consumePurchase' \
 --header 'Authorization: <payment_api_key_here>' \
 --header 'Content-Type': 'application/x-www-form-urlencoded' \
 --data '{
     "purchaseToken": "<purchase_token_here>",
     "productId": "<product_id_here>", // Required only for multi-store
     "developerPayload" : developerPayload, //Optional, // Required only for multi-store
     "currency": "<currency>", // Required only for multi-store
     "type": "<store>"  // xiaomi | onestore // If not present, fallback value will be nowgg
 }'

Important 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.
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.
5014 MULTISTORE_UNKNOWN_ERROR Indicates a generic error from the Multistore API.
5015 MULTISTORE_AUTH_ERROR Indicates an error while generating auth/credentials for Multistore API.
×
Text copied to clipboard
Link copied to clipbord
Questions? Please reach out to us at dev-support@now.gg