cordova-plugin-purchase
v13.12.0
Published
Cordova Purchase plugin for iOS, Android, Windows (AppStore, Play, UWP)
Downloads
32,787
Maintainers
Readme
Cordova Purchase Plugin
In-App Purchases for Cordova
Need professional help and support? Contact Me.
Summary
This plugin allows In-App Purchases to be made from Cordova, Ionic and Capacitor applications.
It lets you handle in-app purchases on many platforms with a single codebase.
This is a plugin for the Apache Cordova framework that provides an easy and flexible way to integrate in-app purchases into Cordova-based mobile applications, including popular frameworks such as Ionic and PhoneGap. With this plugin, you can easily add support for in-app purchases of digital content, such as subscriptions, consumables, and non-consumables, using the store-specific purchase APIs provided by the major mobile platforms. The plugin also supports requesting payments through popular payment providers such as Braintree, allowing you to easily accept payments from your users.
The Cordova-Plugin-Purchase plugin is designed to be easy to use and integrate into your Cordova app, and it provides a consistent API across all supported platforms, so you can focus on building your app without worrying about platform-specific differences. Whether you are building a subscription-based app, a freemium app, or any other app that requires in-app purchases, the Cordova-Plugin-Purchase plugin can help you get started quickly and easily.
Features
| | AppStore (iOS / macOS) | Google Play | Braintree (iOS / Android) | |--|--|--|--| | consumables | ✅ | ✅ | ✅ | | non consumables | ✅ | ✅ | | | subscriptions | ✅ | ✅ | | | restore purchases | ✅ | ✅ | ✅ | | payment requests | | | ✅ | | receipt validation | ✅ | ✅ | ✅ |
Installation
Install the plugin (Cordova)
cordova plugin add "cordova-plugin-purchase"
Recommended plugins
Sometimes, the plugin cannot connect to the app store because it has no network connection. It will then retry either:
- periodically after a certain amount of time;
- when the device fires an 'online' event.
The cordova-plugin-network-information plugin is required in order for the 'online'
event to be properly received in the Cordova application. Without it, this plugin will only be able to use the periodic check to determine if the device is back online.
When making receipt validation requests, the purchase plugin uses, by default, the browser's ajax capabilities. This sometime causes issues with CORS restriction. CORS also imposes an extra back-and-forth with the server (the CORS preflight request) to ensure the server allows for such request to be made. By installing the advanced-http plugin, you get rid of those issue and benefit from the extra feature of the the plugin, like advanced authentication option. Read the advanced-http plugin documentation for details.
Note for ionic 3
Since version 13 of the plugin, it should be used without @ionic-native/in-app-purchase-2
.
ionic 3 doesn't support recent typescript notations, but the plugin can be used without typings by just declaring it:
declare var CdvPurchase: any
Note for Capacitor users
Capacitor users can install the latest version of the plugin without the help of the awesome-cordova-plugins wrapper. Just install the cordova-plugin-purchase
module and import "cordova-plugin-purchase"
in files where it's needed. (some user reported using import "cordova-plugin-purchase/www/store.d"
to get it working).
As with other plugins, you should wait for Capacitor this.platform.ready()
before using the plugin.
import 'cordova-plugin-purchase';
@Injectable()
export class AppStoreService {
// DO NOT initialize to CdvPurchase.store here
store?: CdvPurchase.Store;
constructor() {
this.platform.ready().then(() => {
// MUST WAIT for Cordova to initialize before referencing CdvPurchase namespace
this.store = CdvPurchase.store
});
}
}
Setup your Application
See Setup iOS Applications and Setup Android Applications.
Getting Started
Learning about In-App Purchases
If you wish to learn more about In-App Purchases (IAP), you'll find a good overview on the subject from the various platforms documentation:
- Apple:
- Google:
- Microsoft
All platforms share the same concepts, so they are a good reads in all cases.
Using the Plugin
To ease the beginning of your journey into the intimidating world of In-App Purchase with Cordova, we wrote a guide which hopefully will help you get things done:
You'll have two main tasks to accomplish:
- Setup your application and In-App Products on AppStore, Play, Braintree or Azure platforms using their respective web interfaces.
- Add In-App Purchase code to your application.
For platform setup, the wiki is a good starting point.
There's a specific page for the version 13.
API documentation can be found here: cordova-plugin-purchase API
Upgrading to Version 13
There's been some changes to the API with version 13 of the plugin. This document should help existing apps with the migration: Migrate to version 13.
Extra Resources
For iOS
- In-App Purchase Configuration Guide for AppStore Connect
- Learn how to set up and manage In-App Purchases with AppStore Connect.
Extensions
- Braintree SDK
- Add the Braintree SDK to your application, enable Braintree on iOS and Android.
Subscriptions
For proper subscription support, you need a receipt validation server. You can implement your own or use Iaptic's receipt validation service.
Here is a full example of a cordova application implementing subscriptions, with and without a backend server:
- Client: https://github.com/j3k0/cordova-subscription-example
- Server: https://github.com/iaptic/iaptic-example-nodejs-backend
Contribute
Contributors:
- Jean-Christophe Hoelt, Author
- Josef Fröhle, Support
- Guillaume Charhon, (now defunct) v1 for android
- Matt Kane, initial iOS code
- Mohammad Naghavi, original unification attempt
- Dave Alden @dpa99c (Apple-hosted IAPs for iOS)
Sponsors
- For sponsoring most of JC's work on the plugin.
- Ionic Framework Team (http://ionicframework.com/)
- For sponsoring the UWP platform.
- Maxwell C. Moore (MCM Consulting, LLC)
- Justin Noel @calendee
- Those guys
Licence
The MIT License
Copyright (c) 2014-, Jean-Christophe HOELT and contributors
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.