Myket KB for Developers

View Categories

Cordova and PhoneGap In-App Purchases

Introduction

In this document, you will learn how to implement a Myket in-App Purchase service for application under Cordova and PhoneGap. All steps described in this document are implemented in a test application. You can download this app here.

Download and install the plugin

To implement In-App Billing in Cordova / PhoneGap apps, just download the “myket-iab-cordova-plugin” plugin here. Now, just plug the plugin into the plugins of your application. If you have not installed the Android platform, simply install the platform and Myket plugin with the below command:

2

cordova platform add android

2

But if you have already installed this platform and you do not want to remove it, simply run the below command to install the Myket In App Billing plugin on your application:

plugman install --platform android --project [TARGET-PATH] --plugin [PLUGIN-PATH]/platforms/android
where
[TARGET-PATH] = path to folder containing your cordova/phonegap project
[PLUGIN-PATH] = path to folder containing this plugin

After installing this plugin, you can use the platform / android / src / ir / myket / example / iab / InAppBillingPlugin.java to register BASE64_ENCODED_PUBLIC_KEY that download from the Myket developer’s panel.

How to use

First, add this line to the index.html file:

<script type="text/javascript" src="inappbilling.js"></script>

Like the sample application, you can implement the following functions:

– Installing Myket In-App Purchase, you must call this function before any other function in order to find out about the status of the installation of Myket and its support for this service:

  • – Installing Myket In-App Purchase, you must call this function before any other function in order to find out about the status of the installation of Myket and its support for this service:
inappbilling.init(successHandler, errorHandler, {showLog:true});
  • – Buy a key item like “gas”:
inappbilling.buy(successHandler, errorHandler,"gas");
  • – List all purchases:
inappbilling.getPurchases(successHandler, errorHandler);
  • – Announcement of the consumed product purchased:
inappbilling.consumePurchase(successHandler, errorHandler, "gas");
  • – Purchase Subscriptions:
inappbilling.subscribe(successHandler, errorHandler,"infinite_gas");
  • – Getting the details of the products:
inappbilling.getProductDetails(successHandler, errorHandler, ["gas","infinite_gas"]);
  • – Get all the available products:
inappbilling.getAvailableProducts(successHandler, errorHandler);

*After properly implementing inappbilling functions or copying these functions from the myket-iab-cordova-sample application, Myket in-App purchase will work entirely on your application.