Purchase plugin for Cordova: iOS + Android

As you may know, we ran a small crowd funding campaign a month a ago to fund the development of a cross-platform In-App Purchase plugin for PhoneGap / Cordova. Fovea sponsored half of the cost, the guys behind the Ionic Framework a large part of the remaining half.

As the campaign went successfully, we started the development and now have something pretty stable and useable to show. It fully supports consumable and non-consumable purchases, so if you don’t need subscriptions it’s soon will be time to take a look.

In the next few days, I’ll write guides that covers the setup of a project for both platforms, describe the API and get you started. In the meantime, you can check the #unified branch on GitHub and the demo project: you’ll eventually make some sense of it.

Stay tuned.

Iā€™m a consultant and developer for Mobile, Web, Games and Apps projects. I co-founded Fovea 8 years ago.

Tagged with: , , , ,
Posted in Blog
14 comments on “Purchase plugin for Cordova: iOS + Android
  1. E. e dev says:

    I was visiting the github page of the plugin because I had too look at the loadReceipts function. I’ve used the plugin itselfe many times, but I haven’t used the receipts before and the small quoted code in the documentation I saved locally wasn’t really explaining to me how to get/use receipts.
    So when I visited the page today I was really surprised to find a completely different version of the plugin.

    It seems more sophisticated but way more complicated, I don’t really understand the new version. Why did you change the way it worked?

  2. Hi,

    The plugin now supports both Android and iOS, so it had to be adjusted to use a higher level API.

    The documentation probably needs some work, because I don’t think it’s more complicated. I plan on posting a short tutorial soon.

    Anyway, you can still access the latest pre-refactoring stable release here :


    And it can still be installed using cordova and phonegap, if you do not use the plugin registery and used to do:

    cordova plugin add https://github.com/j3k0/cordova-plugin-purchase.git

    now append: #v3.4.1 to force the old version.

    cordova plugin add https://github.com/j3k0/cordova-plugin-purchase.git#v3.4.1

    Note that it’s not really necessary, as the plugin is backward compatible with the old API.


  3. Mike Dailor says:

    Hey Jean-Christophe, thanks for all the hard work on this plugin. I’ve got it mostly working for me on iOS but have a question about reloading the user’s products. I have a product whose alias is “RegisterApp”, and I am handling the “updated” event for it:

    store.when(“RegisterApp”).updated(function (product) {
    myRegistrationData.AppIsRegistered = product.owned;
    logger.logInfo(“product.owned = ” + product.owned);

    The user has previously purchased this product, so when I call store.order() the following happens:

    1. User is prompted to log in to their iTunes account.
    2. User gets “Do you want to buy this?” dialog.
    3. User clicks “Buy”.
    4. User gets “Already bought, will be restored for free” dialog.

    At this point the store.when(“RegisterApp”).updated function is called, and I would expect that product.owned would be true, but instead it is false. Is there a different way I should be handling this situation? I see there’s quite a bit of “restore” stuff in the underlying storekit, but nothing in the docs about if/how to use it.

    Thanks in advance, and again, nice work!


  4. Hi Mike,

    Maybe you’ve spotted a bug. Can you copy-paste the logs? Make sure to set store.verbosity to store.DEBUG


    • Mike Dailor says:

      Sure, but you will have to deal with my iOS n00bness. šŸ™‚ I am running this on an iPad, how would I go about getting the logs off of the device?

      • If you’re using Cordova. After a “cordova build ios” you should have a MY_APP.xcodeproject file created in “platforms/ios”. This will open with XCode. You can then hit “run” and you’ll see the logs. An other way is to use remote debugging with Safari (simple) or weinre (a bit less simple).

    • Mike Dailor says:

      Also, while I’ve got you on the line… šŸ™‚

      I am now trying to get things working on the Android side of the house & I’ve hit a show-stopper. I am building in the cloud (Intel XDK) so I don’t have all of the Cordova stuff installed on my developer box. No plugins, no plugman, no platform directories, just a www source folder with my HTML5/JavaScript/CSS files and a config.xml file. So long story short, I don’t have a “platform/android/res/values” dir to put the billing_key.xml file per the instructions at https://github.com/j3k0/cordova-plugin-purchase/wiki/HOWTO#add-android-billing-key. (And BTW, shouldn’t that first dir be “platforms”, not “platform”?) I did try creating platform/android/res/values/billing_key.xml within the www directory of my project, but it had no effect. I also tried adding a ” tag to the config.xml file per your instructions at https://github.com/j3k0/cordova-plugin-purchase/blob/master/doc/android.md, but that had no effect either. The specific error I’m getting is “Store error: 6777001: Init failed – String resource ID #0x0”, and yeah… can’t find the file, no doubt.

      Any thoughts on how I might proceed? Thanks!


      • Hi, sorry I’ve no idea how how/if Intel XDK has a way of putting custom files in your Android project. I never used the tool. Maybe if they allow custom cordova’s hooks? I suppose the best would be to ask in XDK’s forum directly.

  5. shlee says:

    Hi. Thank you for building this nice plugin. I am using IAP plugin for my iOS project and have few questions. I know you would super busy at the moment but it would be very appreciate if you share time to rescue me who digging someplace without any clues.

    When I tested IAP, the plugin seems works well for purchasing items. However, only transection id and product id are returned when all purchase process done. The code I still stuck is this line.

    IAP.onpurchase = function(transactionId, productId, receipt){
    console.log(“check”, transactionId, productId, receipt);

    I need a receipt to verify everything is secure.
    but don’t know how to get it with this plugin. The apple document stated that base64 encoded receipt
    will be returned when some native object-c code to
    x-code project. But I am not sure where to put
    those code to InAppPurchase.m file. can you tell me
    how can I get a receipt when all purchase process
    is done? once I get a receipt I could send it to
    my own server and everything would be secure.
    But still stuck to dig how get the receipt.

  6. Allen Sessoms says:

    I first want to thank you for developing the in-app-purchase plugin for cordova ios. I have installed the plugin and setup in-app-purcahse in itunes-connect. Everything looks like its working fine. my app has been excepted in to the app store and when I run the test to purchase the app the app is in the app store.
    The only thing that I am not sure about is why when I try to purchase the app through the in-app-purchase plugin I get this message [Environment: sandbox] and the purchase completes successfully but when I go to itunes-connect the purchase doesn’t register. Can you explain to me what might I be doing wrong. Is it that the device I am using is a test device and it is running in test mode in the sandbox.
    Your advice is appreciated.
    Thanks in advance for your help

  7. Fred says:

    Hi Jean-Christophe,

    First of all many thanks for building an in-app purchase plugin which works both on Android and IOS. This is extremely useful.

    I am a bit green when it comes to Cordova and in-app purchase. I have created an app which records archery scores (Archery Score Master Pro on google play) and I am attempting to get the android version of your plugin to work.

    I checked https://github.com/Fovea/cordova-plugin-purchase-demo for an example, I got as far as the store ready part and store.refresh(). No info is displayed on the screen about my registered in-app product. I guess this function is never called:
    store.when(“product”).updated(function (p) {

    Could you please give us a sample code to enable purchase and also sample code to allow users to restore a purchase?

    Very much appreciated thanks

  8. George says:

    Is there a specific set of requirements for working with iOS? I have created 2 in-app purchases which currently have the status “Ready to submit” however whenever registering the products in the app, the plugin (and app store) come back with the response that the products are invalid. Any suggestions?

  9. Lou says:

    I’m testing your plugin with IOS trying to implement a non-renewing subscription. When the code attempts to rebuy the subscription (as in when it is expired), the storekit comes back with something like “already purchased, you purchase will be restored”. Is there something that need to be done so that the repurchase can take place after exiry? Thanks

  10. Subu says:


    Thanks so much for this awesome plugin!

    Is there a way to check if the product is in free trial mode? I have setup my product as a subscription and it has a week long trial period. When the user installs the product, I get a list of available products and was hoping some product attribute would tell me if it is in trial period (like product.owned says if the user has bought the product). I dont see any such attribute.