palbaseDocs

Palbase IAP · API

POST/iap/google/purchases

Report Play Billing's purchases

The signed-in customer's app — a guest's too: a guest buys in the app — reports the purchases Play Billing gave it: one just made, or on a restore every one queryPurchasesAsync returns. Nothing of the device's word is taken: each is read from Play by its token, as the project's Play connection account, and applied to the ledger. Whose a purchase is: one nobody has becomes the customer's its obfuscated account id names, or the reporter's; one another customer has stays theirs — unless a new purchase on it (no renewal) names another customer in its obfuscated account id, which moves it to them, who paid; or restore, which moves it to the reporter (an account's is never taken by a guest's restore). One purchase moves 3 times in 30 days at most, restores and new purchases counted together; one that stays is answered once the rest is applied (403 restore_account_owned, 409 restore_limit). A purchase the catalog maps is acknowledged — a consumable's consumed — once the ledger has it (Play refunds one not acknowledged in three days); one it does not map gives nothing and is not acknowledged.

Called by a signed-in user of your app, with their token and the publishable key.

Request body

purchasesobject[] · requiredThe purchases: one just made (PurchasesUpdatedListener), or every one queryPurchasesAsync returns on a restore.
restoreboolean · optionalThe customer asked to restore their purchases: each moves to them from the customer that has it — never an account's by a guest's restore, and one purchase 3 times in 30 days at most, with the new purchases that moved it; one that stays is answered (403, 409) once the rest is applied. Without it, a purchase another customer has stays theirs — unless a new purchase on it names another customer in its obfuscated account id, which moves it to its buyer.
curl
curl -X POST "https://<your-ref>.palbase.studio/iap/google/purchases" \
  -H "apikey: $PALBASE_PUBLISHABLE_KEY" \
  -H "authorization: Bearer $USER_ACCESS_TOKEN" \
  -H "content-type: application/json" \
  -d '{"purchases":[{"product_id":"string","purchase_token":"string"}]}'

Responses

200What the customer has now

400`purchases` holds no purchase or more than 100, or one without its token and product (`invalid_purchases`), or the body is not the request

401No customer's session (`session_required`): a customer's own is reached with the publishable key and their access token; or the edge refused the key or token

403A restore left purchases another customer has where they were; the rest of the report is applied (read GET /iap/me), and the description says how many and why: an account has them and the reporter is a guest (`restore_account_owned`), or another customer's account has them — Play's obfuscated account id names that customer, not the reporter, and a restore moves a Play purchase from a guest alone (`restore_other_account`), or another environment of the project gave Play's obfuscated account id — that environment's customer made them (`restore_other_environment`)

404The user's id is longer than a customer's (128 characters; `customer_not_found`)

409The environment sells nothing on Google Play (`google_not_connected`), Play does not let the project's Play connection account read the app's purchases (`google_no_access`), or a restore, or the reporter's new purchase, left purchases where they were because each moved between customers 3 times in 30 days (`restore_limit`)

410The user was deleted (`customer_erased`): their id is no customer's again

413The body is over 256 KiB

422Play knows no such purchase of the app, it is not the product it was reported as, or (not a restore) it is a purchase of another environment's customer — its obfuscated account id is one another environment of the project gave (`invalid_purchase`: the description names which, `purchases[i]`)

429Over the project's share of calls to Google (`google_rate_limited`): Palbase's Cloud project holds every project's Play quota, and each project's calls are its own share; Retry-After says when to try again. Or over the project's request limit

502Play refused to read a purchase (`google_refused`, in its words)

503Google could not be reached, or did not answer (`google_unreachable`, Retry-After), or this Palbase has no Google Cloud project (`google_unavailable`); or the customer is busy elsewhere (`busy`, Retry-After)

defaultAn error: the envelope names it (`error`) and explains it (`error_description`).

Operation ReportGooglePurchases of iap's contract.