cordova-plugin-inapp-purchase-winphone
v1.1.1
Published
A phonegap/cordova plugin that enable WP8 and WP8.1 In-App Purchases.
Downloads
3
Readme
Windows Phone 8 and Windows Phone 8.1 In-App Purchase plugin
Allows In-App Purchases to be made from Phonegap/cordova.
Adding the Plugin to your project
Visual Studio 2015
Adding the plugin to your project by adding zip file as plugin to your Visual Studio 2015 project
Phonegap Build
Add plugin to config.xml:
<gap:plugin name="cordova-plugin-inapp-purchase-winphone" source="npm" />
or for Windows Phone only:
<gap:plugin name="cordova-plugin-inapp-purchase-winphone" gap:platform="winphone" source="npm" />
Using the plugin
You can read Windows Phone 8 In-App purchase MSDN.
This plugin use the same method signature as cordova-plugin-appleiap cordova plugin to let you easily port your iOS and Android app to Windows Phone
The plugin creates the object window.InAppPurchaseManager
with the following methods:
requestProductData(productId, successCallback, failCallback)
makePurchase(productId)
restoreCompletedTransactions()
You can also register the following callbacks:
window.InAppPurchaseManager.onPurchased = function(transactionIdentifier, productId, transactionReceipt) {}
window.InAppPurchaseManager.onFulFilled = function(productId) {}
window.InAppPurchaseManager.onRestored = function(productId) {}
window.InAppPurchaseManager.onFailed = function(errorCode, errorText);
To retrieve price of inapp purchase, you need to call requestProductData
A basic usage example is below:
// transactionIdentifier is null for now
window.InAppPurchaseManager.onPurchased = function(transactionIdentifier, productId, transactionReceipt) {
console.log('purchased: ' + productId);
/* Give coins etc */
window.InAppPurchaseManager.reportProductFulfillment(productId); // If consumable
}
window.InAppPurchaseManager.onRestored = function(productId) {
console.log('restored: ' + productId);
}
window.InAppPurchaseManager.onFailed = function(errno, errtext) {
console.log('failed: ' + errtext);
}
// title and description are null for now
window.InAppPurchaseManager.requestProductData("com.example.test", function(productId, title, description, price) {
console.log("productId: " + productId + " title: " + title + " description: " + description + " price: " + price);
window.plugins.InAppPurchaseManager.makePurchase(productId, 1);
}, function(id) {
console.log("Invalid product id: " + id);
}
);
To start a purchase you just have to call:
window.InAppPurchaseManager.makePurchase("com.myapp.mypurchase");
Licence
The MIT License
Copyright (c) 2015 RONCE Wandrille
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.