cordova-plugin-inapppurchases

3.0.3 • Public • Published

Cordova-Plugin-InAppPurchases

jump to: PLUGIN USAGE | Testing App | Demo App | Cordova | ADD IN APP PURCHASES | Testing Tips | Future Improvements | cozycode.ca | Open Source License


Cordova plugin to add in-app purchases (and subscriptions) into an app.
Use JavaScript to view, make, and complete purchases.

Updated 2023 for Cordova with current:
Android: Billing Library 6 (released June 2023) (verifies receipts internally)
iOS: StoreKit (not StoreKit 2, released 2021, which is only available for iOS 15 and up) (does not verify receipts currently - it returns them, and can be verified if needed)
Amazon Fire: compatible, but untested
Browser: not implemented
Windows: not implemented

Downloaded 50 - 500 times/week into apps.

If you notice any issues, submit here: github issues
Based on the original plugin working for many years made by Alex Disler (c) 2016 MIT, which is out of date for writing new apps: cordova-plugin-inapppurchase
Forked from another plugin, which is kept updated as well, if this plugin is broken, try this plugin: cordova-plugin-inapppurchase2
This new plugin distribution makes significant changes to the Google Play Billing Library and plugin integration code.

Have a good one! 😀

PLUGIN USAGE

Add these calls inside of your cordova JavaScript to make in-app purchases and subscriptions:

inAppPurchases.getAllProductInfo(productIds)
inAppPurchases.restorePurchases()
inAppPurchases.purchase(productId)
inAppPurchase.completePurchase(productId,consume)

The plugin creates an inAppPurchases object which can make calls to the store.

see how to add the plugin

see more on using the plugin

Testing App

After creating App Store and Google Play accounts and in-app products, this app can test purchases.
Download test app here: cordova-plugin-inapppurchases Test App

Demo App

This app shows how to use this plugin to load and make purchases in a Cordova app:
Download demo app here: cordova-plugin-inapppurchases Demo App

CREATE AN APP WITH CORDOVA

How to create a Cordova app:

npm install -g cordova
cordova create directory_name com.your_name_or_company.your_app_name

cordova app

Cordova is an open source project maintained by Apache that lets you make apps written in HTML, css, and JavaScript. You can create cross-platform apps to publish on the Google Play Store for Android, and the Appstore for iOS, MacOS, and Apple devices.

ADD IN APP PURCHASES

  1. Add the plugin
    The spelling of this plugin is cordova-plugin-inapppurchases with an s,
    (more plugins we've tested but were not fully working December 2022:
  • cordova-plugin-inapppurchase (first plugin worked for years)
  • cordova-plugin-inapppurchase-2 (active and almost fully working plugin by Wccrawford)
  • cordova-plugin-purchase (not updated to work in latest Android and iOS)
cordova plugin add cordova-plugin-inapppurchases
  1. In the Google Play Store and iOS app store, add your in app purchases and subscriptions (set product ids here, for example, com.name_or_company.app_name.purchase_product_name) (see testing tips below)

    • For the Google Play Store, retreive your Base64 Billing Key in monetization to use in the app
      Create a file within your cordova project at: www/manifest.json, containing:
    { "play_store_key": "<Base64-encoded public key from the Google Play Store>" }
  2. Add buy buttons (or any UI you make) to your Cordova html code

  3. Add calls to the plugin with the inAppPurchases object in your Cordova JavaScript code

  4. Test that your in-app purchases are working with test accounts

Testing Tips

see common error messages to handle other results

Android

  1. create a test track (closed works) and add an email address with a Google Play account
  2. after adding the plugin, build an aab file and add it to the Google Play test track, this enables the Google Play billing library for your app
  3. get your base64 billing key in the monetization section to add to the www/manifest.json
  4. make "products" with ids on the google play store in the in-app products and subscriptions sections
  5. log into your test account on your device and make purchases
    • use a real android device to test, simulators don't support billing (see the error message)
    • Google Store doesn't make a difference between consumable and non-consumable in-app purchases, don't call inAppPurchases(product_id,is_consumable); with is_comsumable=true for non-consumable purchases because it will consume them too

iOS

  1. create in app-purchases and subscriptions on App Store Connect, takes up to an hour to enable after creating the first one
  2. to enable testing, create a build and upload it to App Store Connect (once you do it for one app, you may not need to do this step again)
  3. create test accounts in the TestFlight section of App Store Connect
  4. now you can log in to test accounts in the test device's settings, or the prompt that comes up in a simulator and test out in-app purchases
    • you should be able to test without having to submit your app for review

Future Improvements

  • [ ] update to also include Storekit 2, in a couple years
  • [ ] will not add internal receipt checking for iOS, mostly helpful for MMOs
  • [ ] support Windows apps
  • [x] tested working 2023 with Google Play Billing Library 5 for consumables, non-consumables, and subscriptions
  • [x] tested working 2023 with StoreKit for consumables, non-consumables, and subscriptions

More from cozycode.ca

Open Source License

MIT Licensed (MIT)

Copyright © 2023 cozycode.ca

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Package Sidebar

Install

npm i cordova-plugin-inapppurchases

Weekly Downloads

19

Version

3.0.3

License

MIT

Unpacked Size

1.2 MB

Total Files

42

Last publish

Collaborators

  • cozycode