morphinewan / firebase-function-iap-verification

Google and iOS IAP Verification Using Firebase Function and FireCloud

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

Setup Guide

Setup for Android

To set up purchase verification, follow these steps.

  1. Log in to the Google API console with your credentials
  2. Under Select a project find your app's project
  3. Select your organization, application, then OPEN
  4. Select API Credentials > Credentials > Create credentials
  5. From the drop-down menu, select Service account key
  6. Select an existing service account or create a new one
  7. Select JSON as your Key type
  8. Select Project > Viewer as your Role from the drop-down menu
  9. Select Create

Now, a JSON key will be downloaded to your computer. Next, follow these steps to complete the setup.

  1. Go to the Google Play Store and log in
  2. Select Settings
  3. Select Developer account > API access
  4. Find your application project and select LINK
  5. Under Service Accounts, on the relevant email address, select GRANT ACCESS
  6. 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
  7. 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

  1. Copy Base64 public key string from the Developer Console account for your application in file ./functions/google/iap-live and ./functions/google/iap-sandbox

  2. replace ./functions/google/api-test.json with you private key (created in the setup process)

  3. 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

Integration Other Platforms

Refer https://github.com/voltrue2/in-app-purchase for other platform setup

Project Setup

You have two option here

  1. Setup a new Firebase Project and replace functions folder content
  2. 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"}'

Happy Coding

About

Google and iOS IAP Verification Using Firebase Function and FireCloud


Languages

Language:JavaScript 100.0%