cordova-plugin-inapppurchases
v3.1.1
Published
Cordova plugin to add in-app-purchases (and subscriptions) into an app, use javascript to view, make, and complete purchases.
Downloads
204
Maintainers
Readme
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 2024 for Cordova with current: Android: Billing Library 7 (released May 2024) (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
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! :grinning:
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.
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 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
- 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
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>" }
- 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:
Add buy buttons (or any UI you make) to your Cordova html code
Add calls to the plugin with the
inAppPurchases
object in your Cordova JavaScript codeTest that your in-app purchases are working with test accounts
Testing Tips
see common error messages to handle other results
Android
- create a test track (closed works) and add an email address with a Google Play account
- 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
- get your base64 billing key in the monetization section to add to the www/manifest.json
- make "products" with ids on the google play store in the in-app products and subscriptions sections
- 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
- create in app-purchases and subscriptions on App Store Connect, takes up to an hour to enable after creating the first one
- 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)
- create test accounts in the TestFlight section of App Store Connect
- 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
- make apps with JavaScript
- how to add ads to an app made with Cordova
- how to make an in-app purchases with Cordova
- a testing app for in-app purchases
- a demo app for in-app purchases
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.