InApp Billing Verification Handler
InApp Purchase and Subscription for Apple, Google Play, Amazon Store, Roku, and Windows Verification Handler in Firebase Functions using popular node in-app-purchase module https://github.com/voltrue2/in-app-purchase
Resources Required
- Firebase Functions - https://firebase.google.com/docs/functions
- Firebase Firestore - https://firebase.google.com/docs/firestore
Setup Guide
Setup for Android
To set up purchase verification, follow these steps.
- Log in to the Google API console with your credentials
- Under Select a project find your app's project
- Select your organization, application, then OPEN
- Select API Credentials > Credentials > Create credentials
- From the drop-down menu, select Service account key
- Select an existing service account or create a new one
- Select JSON as your Key type
- Select Project > Viewer as your Role from the drop-down menu
- Select Create
Now, a JSON key will be downloaded to your computer. Next, follow these steps to complete the setup.
- Go to the Google Play Store and log in
- Select Settings
- Select Developer account > API access
- Find your application project and select LINK
- Under Service Accounts, on the relevant email address, select GRANT ACCESS
- In the Add a new user dialogue, select Finance from the Role drop-down menu
- If you want this user to have global access, select ADD USER
- If you want this user to have access only to one app, select Add an app, then ADD USER
- Navigate to Developer account > Users & permissions to view information on your users and access permissions
Great job! Purchase verification is now active for Android.
Setup for iOS
Nothing Special Need to be Done For iOS.
Setup Other Platforms
Refer https://github.com/voltrue2/in-app-purchase for other platform setup
Integration Guide
Integration Google IAP
-
Copy Base64 public key string from the Developer Console account for your application in file ./functions/google/iap-live and ./functions/google/iap-sandbox
-
replace ./functions/google/api-test.json with you private key (created in the setup process)
-
Open ./function/index.js and replace
let serviceAccount = require("./google/api-test.json");
with
let serviceAccount = require("./google/<your_private_key_name>.json");
Integration Google Subscription
provide following credentails that you have acquired in setup process
- googleAccToken
- googleRefToken
- googleClientID
- googleClientSecret
Integration iOS IAP
Nothing Special Need to be Done For iOS.
Integration iOS Subscription
provide following credentails that you have acquired in setup process
- applePassword (this comes from iTunes Connect)
Integration Other Platforms
Refer https://github.com/voltrue2/in-app-purchase for other platform setup
Project Setup
You have two option here
- Setup a new Firebase Project and replace functions folder content
- Project Firebase Application Id in .firebaserc json under 'default' key
That is it! Deploy on Firebase Function
Usage Instructions
Url
<firebase_function_baseurl>/verifyInAppPurchase
Method
POST
Header
Content-Type: application/json
Params
type=[string] (apple/google)
transactionId=[string]
receipt=[string|json] (refer https://github.com/voltrue2/in-app-purchase for detail)
Success Response
Code: 200
Content: Verified
Error Response
Code: 400
Content: Invalid Request | Duplicate Transaction | Invalid TransactionId | Item is Canelled
Sample Format iOS
curl --location --request POST 'https://<firebase_function_baseurl>/verifyInAppPurchase' \
--header 'Content-Type: application/json' \
--data-raw '{"receipt":"<recipt>", "transactionId":"<transcation_id>", "type":"apple"}'
Sample Format Android
curl --location --request POST 'https://<firebase_function_baseurl>/verifyInAppPurchase' \
--header 'Content-Type: application/json' \
--data-raw '{"receipt":{"packageName": <package_name>, "productId": <product_id>, "purchaseToken":<purchase_token>}, "transactionId":"<purchase_token>", "type":"google"}'