From 2ea10f1e094d9597806009aa873f598e5e0191f4 Mon Sep 17 00:00:00 2001 From: Chris Molozian Date: Wed, 27 Nov 2019 08:02:09 +0000 Subject: [PATCH] Update IAP validation example for Android Publisher v3 API. --- CHANGELOG.md | 1 + data/modules/iap_verifier.lua | 13 ++++++------- data/modules/iap_verifier_rpc.lua | 1 - 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b917fcef0..7fc6e900c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ The format is based on [keep a changelog](http://keepachangelog.com) and this pr ### Changed - Do not use absolute path for `tini` executable in default container entrypoint. - Faster validation of JSON object input payloads. +- Update IAP validation example for Android Publisher v3 API. ### Fixed - Correctly read pagination cursor in notification listings. diff --git a/data/modules/iap_verifier.lua b/data/modules/iap_verifier.lua index 4e38bacca..8bc256c25 100644 --- a/data/modules/iap_verifier.lua +++ b/data/modules/iap_verifier.lua @@ -85,7 +85,6 @@ function M.google_obtain_access_token(client_email, private_key) local iat = nk.time() / 1000 local exp = iat + 3600 -- current time + 1hr added in seconds - local algo_type = "RS256" local jwt_claimset = { @@ -132,10 +131,10 @@ Request object match the following format: } For Products, this function will return a Lua table that represents the data in this page: -https://developers.google.com/android-publisher/api-ref/purchases/products#resource +https://developers.google.com/android-publisher/api-ref/#Purchases.products For Subscritions, this function will return a Lua table that represents the data in this page: -https://developers.google.com/android-publisher/api-ref/purchases/subscriptions +https://developers.google.com/android-publisher/api-ref/#Purchases.subscriptions This function can also raise an error in case of bad network, bad authentication or invalid receipt data. --]] @@ -147,13 +146,13 @@ function M.verify_payment_google(request) error(access_token) end - local url_template = "https://www.googleapis.com/androidpublisher/v2/applications/%s/purchases/subscriptions/%s/tokens/%s?access_token=%s" + local url = "https://www.googleapis.com/androidpublisher/v3/applications/%s/purchases/subscriptions/%s/tokens/%s?access_token=%s" if (not request.is_subscription) then - url_template = "https://www.googleapis.com/androidpublisher/v2/applications/%s/purchases/products/%s/tokens/%s?access_token=%s" + url = "https://www.googleapis.com/androidpublisher/v3/applications/%s/purchases/products/%s/tokens/%s?access_token=%s" end - local url = url_template:format(request.package_name, request.product_id, request.purchase_token, access_token) - + url = url:format(request.package_name, request.product_id, request.purchase_token, access_token) + local http_headers = { ["Content-Type"] = "application/json", ["Accept"] = "application/json" diff --git a/data/modules/iap_verifier_rpc.lua b/data/modules/iap_verifier_rpc.lua index 577f05d16..217c04df9 100644 --- a/data/modules/iap_verifier_rpc.lua +++ b/data/modules/iap_verifier_rpc.lua @@ -72,7 +72,6 @@ local function apple_verify_payment(context, payload) ["result"] = result }) end - end nk.register_rpc(apple_verify_payment, "iap.apple_verify_payment") -- GitLab