From 14a5256c079b6e42d146f39f5363ca5028b2c945 Mon Sep 17 00:00:00 2001 From: Andrei Mihu Date: Fri, 11 Nov 2022 18:58:39 +0000 Subject: [PATCH] Accept Google IAP receipts with or without wrapper structures. (#946) --- CHANGELOG.md | 1 + iap/iap.go | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e56fbe972..c9f37063e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ The format is based on [keep a changelog](http://keepachangelog.com) and this pr - Stricter validation of limit in runtime storage list operations. - Allow subdomain variance in Facebook Limited Login token issuer field. - Renamed `groupsGetRandom` to `groups_get_random` in the Lua runtime for consistency. +- Accept Google IAP receipts with or without wrapper structures. ### Fixed - Fix response selection in purchase lookups by identifier. diff --git a/iap/iap.go b/iap/iap.go index 5f7821b77..43b69e390 100644 --- a/iap/iap.go +++ b/iap/iap.go @@ -266,12 +266,14 @@ func decodeReceiptGoogle(receipt string) (*ReceiptGoogle, error) { unwrapped, ok := wrapper["json"].(string) if !ok { - return nil, errors.New("'json' field not found, receipt is malformed") + // If there is no 'json' field, assume the receipt is not in a + // wrapper. Just attempt and decode from the top level instead. + unwrapped = receipt } var gr ReceiptGoogle if err := json.Unmarshal([]byte(unwrapped), &gr); err != nil { - return nil, err + return nil, errors.New("receipt is malformed") } return &gr, nil } -- GitLab