If you want to implement InAppPurchase in your Ionic App, here is the solution!

I take over 12 days to integrate InAppPurchase in my Ionic App, and only for Android!
I explain in broad outline how to integrate this tool at home, and avoid traps.

However, whereas my App is not available for iOS, I can give you only my experience for Android with Google Play Billing.

The InAppPurchase right version

According the native components of Ionic, there are In App Purchase and In App Purchase 2.

I began to integrate the first, but operation issues was found. After research, the developer suggest to use the second version, where development is active.

So use In App Purchase 2.

Test the process before deployement

Before to integrate feature in App and deploy it, you shall test it. InAppPurchase, using a tierce application, tests are complicated.

In the guide Test Google Play Billing, you can test in static process reserved products (android.test.purchased, android.test.canceled and android.test.item_unavailable)

However, when I try to test my integration with these products, an error like "Signature verification failed" is displayed systemaically.

I skipped this step and test my App with real products (functional tests).

Set-up of Google Play Billing

According to you needed integration, this work can be complicated. In my case, my products are managed by a remote server which allow the App to consume it.

I am in the following situation:

  1. my App, through the component In App Purchase 2, ask to Google Play Store to buy the product P by user request.
  2. a transaction is done between both entities and Google Play Store return back useful data to my App.
  3. my App ask to my server to unlock the product. My server treat the request and return back the authorization
  4. my App treat this authorization and if OK, unlock the product access.

This is the short version, but according to this Best Practice, you shall embed mecanisms as check from the server that the transaction is correctly performed by asking directly the Google server.

I give you below the process to configure the integration, to perform in order or you may have unpleasant surprises. XC

1. Enable the access to Google API

With you developper account, connect to Google Play console.

Go to Parameters > Developper account > API access.

Enable Google Play Android Developer.

In Service account, click on "Create a service account" with the following minimum right: "Display the financial data".

In API access, make sure that the service account have access to API. Click on Allow access otherwise.

Now, you can implement the purchase check using the service account on your server. If PHP is implemented, you can use the library Google APIs client.

2. Create a product

With you developper or administrator account, connect to Google Play console.

Select you App.

In Presence on the Play Store, go to Integrated products of App. (Translated from French, can be different)

Add your product.

3. Troubleshooting

When you implement the verification process in server side, the following errors can be raised:

Erreur 401

{
    "error": {
        "errors": [
            {
                "domain": "androidpublisher",
                "reason": "permissionDenied",
                "message": "The current user has insufficient permissions to perform the requested operation."
            }
        ],
        "code": 401,
        "message": "The current user has insufficient permissions to perform the requested operation."
    }
}

Erreur 403

{
  "error": {
    "errors": [
      {
        "domain": "androidpublisher", 
        "reason": "projectNotLinked"
        "message": "The project id used to call the Google Play Developer API has not been linked in the Google Play Developer Console.", 
      }
    ]
    "code": 403, 
    "message": "The project id used to call the Google Play Developer API has not been linked in the Google Play Developer Console.", 
  }
}

If you are sure that the configuration is right, problem may be due to Google issue with your product. In this case, add a new product with new Product Id.

I hope that this article was usefull for you... ;)

See you in the next article.xD

Previous Post Next Post


Add a comment