本文档主要关注用于服务器端购买消费的 consumePurchase API。
您验证购买后,应将其标记为已消费。
购买的消费包含:
https://payments-api.now.gg/
v2/order/consumePurchase
POST
'Authorization': '<payment_api_key_here>', 'Content-Type': 'application/x-www-form-urlencoded'
以下参数须包含于 consumePurchase API的请求主体中。
"purchaseToken": "<purchase_token_here>", "productId": "<product_id_here>", // 已弃用 "developerPayload" : "developerPayload", // 可选 "type": "<store>" // 已弃用
以下示例代码演示了使用 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>",
"developerPayload": "developerPayload" // 可选
}
response = requests.post(url, headers=headers, data=data)
print("响应状态码:", response.status_code)
print("响应正文:", 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>",
"developerPayload" : "developerPayload" // 可选
}'
Payments API Key 可以在nowStudio的证书章节找到。更多信息。以下是 consumePurchase API 的示例响应。
{
"success": true,
"code": 0,
"codeMsg": "success",
"data": {}
}
| 参数 | 类型 | 描述 |
|---|---|---|
| success | boolean | 返回是否成功,true或false。 |
| code | int | 成功返回0,失败返回非0。 |
| codeMsg | string | 返回错误码关联的消息。 |
| data | object | 作为响应返回的数据。 |
| 错误码 | 消息 | 描述 |
|---|---|---|
| 3800 | ERROR_CONSUMING_PRODUCT | 消费产品发生错误。 |
| 3900 | INVALID_AUTHORIZATION_KEY | 提供的用于授权的API秘钥无效。 |
| 3901 | INVALID_PURCHASE_TOKEN | 提供的购买令牌无效。 |
| 5014 | MULTISTORE_UNKNOWN_ERROR | 表示来自Multistore API的通用错误。 |
| 5015 | MULTISTORE_AUTH_ERROR | 表示在生成Multistore API的认证/凭据时发生错误。 |