Skip to content

IAP v4 finalizing purchase

The purchase finalization API finalizes consumption for consumable product purchases.

Google Play

The Google Play consumable product finalization API finalizes consumption for consumable product purchases paid through Google Play, acting on behalf of the consume feature of the Google Play Developer API. If consumption is not completed within a certain period after an in-app purchase, for example within three days, Google Play automatically refunds the payment. Therefore, after the app server finishes granting the item to the user, it must immediately call this API to finalize consumption.

Google Market Account Setup Prerequisite

To use the Google Play consumable product finalization API, Google Market Account setup must be completed.

Duplicate Call Notice

This API must be called only once per receipt. If you call it again with a receipt whose consumption has already been finalized, 1000535 (Market API response was answered as failed.) is returned as the result response code.

Request URL

Item Description
Production URL https://hiveiap.qpyou.cn/external/api/finalize_purchase
Sandbox URL https://sandbox-hiveiap.qpyou.cn/external/api/finalize_purchase
HTTP Method POST
HTTP Header Content-Type: application/json
Authorization: Bearer {API_KEY}
(※ The Bearer token is the Hive authentication key value in App Center > Project Management > Game List > Select Game > Game Details > Basic Info.)
Data Format JSON

Request body

Field Type Required Description
purchase_bypass_info String Y Purchase user, device, and receipt information extracted from Hive SDK.

For IAP v4 in-app purchases, pass the bypassInfo of the IAPV4Receipt object, which is received through the callback of the Purchase() or Restore() method of the Hive SDK v4 IAPV4 class, in the order of 'Hive SDK v4 → app client → app server → IAP v4 Google consumable product finalization API server'. The bypassInfo value is a Base64-encoded JSON string.

※ This value must be used as-is and must not be parsed or modified directly by the app client or app server.

Response body

Field Type Required Description
result Integer Y Response code (0: success, others: failure. For details, see Result codes below.)
result_msg String Y Response message
finalize_result Array N List of finalization results. This is reference information and must not be used in the app server logic that determines whether item granting succeeded or failed.
market_transaction_id String N Market transaction (order) ID for which finalization was attempted
result_code Integer N Finalization result code returned by the Google Play Developer API
result_message String N Finalization result message returned by the Google Play Developer API

Result codes

Code Message Description
0 Success Consumption finalized successfully
1000006 The required parameter info is missing. A required parameter is missing
1000504 The Google public key hasn't been registered. Google service account key information is not registered
1000520 Failed to authenticate the API Key. Authentication failed for the Bearer token issued by App Center
1000535 Market API response was answered as failed. The Google Play Developer API response result is a failure
(※ Check the result_code and result_message under finalize_result for details.)

Request example

curl -L -v \
-d '{"purchase_bypass_info":"eyJ1aWQiOiIiLCJhbmFseXRpY3NfaWQiOiJqbXRsZkcwb1FZQzdlM3dVVDQ2cHJ3PT0i...(omitted)..."}' \
-H "Content-Type: application/json" \
-H "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJIaXZlIiwiaWF0IjoxNjAzNzc4OTU2LCJqdGkiOiIxODczMTExMzIwIn0.OxWo4R6UdI0BLP1ckt8RlMFrPAb5H7TNedmLFV1Cawc" \
[https://sandbox-hiveiap.qpyou.cn/external/api/finalize_purchase](https://sandbox-hiveiap.qpyou.cn/external/api/finalize_purchase)

Response example

{
  "result": 1000535,
  "result_msg": "Market API response was answered as failed.",
  "finalize_result": [
    {
      "market_transaction_id": "GPA.3373-7176-8955-08026",
      "result_code": 400,
      "result_message": "The product purchase is not owned by the user."
    }
  ]
}