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
- Firebase Functions - https://firebase.google.com/docs/functions
- Firebase Firestore - https://firebase.google.com/docs/firestore
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.
Nothing Special Need to be Done For iOS.
Refer https://github.com/voltrue2/in-app-purchase for other platform setup
-
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");
provide following credentails that you have acquired in setup process
- googleAccToken
- googleRefToken
- googleClientID
- googleClientSecret
Nothing Special Need to be Done For iOS.
provide following credentails that you have acquired in setup process
- applePassword (this comes from iTunes Connect)
Refer https://github.com/voltrue2/in-app-purchase for other platform 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
<firebase_function_baseurl>/verifyInAppPurchase
POST
Content-Type: application/json
type=[string] (apple/google)
transactionId=[string]
receipt=[string|json] (refer https://github.com/voltrue2/in-app-purchase for detail)
Code: 200
Content: Verified
Code: 400
Content: Invalid Request | Duplicate Transaction | Invalid TransactionId | Item is Canelled
curl --location --request POST 'https://<firebase_function_baseurl>/verifyInAppPurchase' \
--header 'Content-Type: application/json' \
--data-raw '{"receipt":"<recipt>", "transactionId":"<transcation_id>", "type":"apple"}'
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"}'