Cafebazaar In app billing for cordova
- If you have any questions, please contact me. +98 914 777 4887
Requirements
Phonegap 3.0, Android 2.2.1+
Installation
- Get Billing key from cafebazaar In-app Billing documentation.
We recommend this way to install the plugin into your project.
- Clone this project into your repository
- Run at the root of your project:
cordova plugin add /path/to/your/cloned/plugin/AndroidInAppBilling --variable BILLING_KEY="MIIBIjANBgk...AQAB"
Using
Initialization
Initialize the billing plugin. The plugin must be inialized before calling any other methods.
inappbilling.init(success, error, options)
parameters
- success : The success callback.
- error : The error callback.
- options : Sets the options for the plugin
- Available Options :
- showLog [true,false] : showLog enables plugin JS debug messages. Default : true
- Available Options :
Optional Initialization
inappbilling.init(success, error, options, skus)
parameters
- success : The success callback.
- error : The error callback.
- options : Sets the options for the plugin
- Available Options :
- showLog [true,false] : showLog enables plugin JS debug messages. Default : true
- Available Options :
- skus : string or string[] of product skus. ie. "prod1" or ["prod1","prod2]
Retrieve owned products
The list of owned products are retrieved from the local database.
inappbilling.getPurchases(success, fail)
parameters
- success : The success callback. It provides an array of json object representing the owned products as a parameter. Example:
[{"purchaseToken":"tokenabc","developerPayload":"mypayload1", "packageName":"com.example.MyPackage","purchaseState":0,"orderId":"12345.6789", "purchaseTime":1382517909216,"productId":"example_subscription"}, {"purchaseToken":"tokenxyz","developerPayload":"mypayload2", "packageName":"com.example.MyPacakge","purchaseState":0,"orderId":"98765.4321", "purchaseTime":1382435077000,"productId":"example_product"}]
- error : The error callback.
Purchase
Purchase an item. You cannot buy an item that you already own.
inappbilling.buy(success, fail, productId)
parameters
- success : The success callback. It provides a json object representing the purchased item as first parameter. Example :
{"orderId":"12999763169054705758.1385463868367493",
"packageName":"com.example.myPackage",
"productId":"example_subscription",
"purchaseTime":1397590291362,
"purchaseState":0,
"purchaseToken":"ndglbpnjmbfccnaocnppjjfa.AO-J1Ozv857LtAk32HbtVNaK5BVnDm9sMyHFJkl-R_hJ7dCSVTazsnPGgnwNOajDm-Q3DvKEXLRWQXvucyW2rrEvAGr3wiG3KnMayn5yprqYCkMNhFl4KgZWt-4-b4Gr29_Lq8kcfKCkI57t5rUmFzTdj5fAdvX5KQ",
"receipt": "{...}",
"signature": "qs54SGHgjGSJHSKJHIU"}
The receipt and signature are available in the object for server side validation.
- error : The error callback.
- productId : The in app billing product id (example "example_subscription")
Subscribe
Subscribe to an item
inappbilling.subscribe(success, fail, subcriptionId)
parameters
- success : The success callback.
- error : The error callback.
- productId : The in app billing product id (example "premium_001")
Consume
Consume an item. You can consume an item that you own. Example of consumable items : food, additional life pack, etc. Example of non-consumable item: levels pack. Once an item is consumed, it is not owned anymore.
inappbilling.consumePurchase(success, fail, productId)
parameters
-
success : The success callback. It provides a json object with the transaction details. Example :
{ "orderId":"12999763169054705758.1321583410745163", "packageName":"com.smartmobilesoftware.trivialdrivePhonegap", "productId":"gas", "purchaseTime":1369402680000, "purchaseState":0, "purchaseToken":"ccroltzduesqaxtuuopnqcsc.AO-J1Oyao-HWamJo_6a4OQSlhflhOjQgYWbb-99VF2gcj_CB1dd1Sfp5d-olgouTWJ13Q6vc5zbl0SFfpofmpyuyeEmJ" } -
error : The error callback.
-
productId : The in app billing product id (example "5_lifes")
Get Product(s) Details
Load the available product(s) to inventory. Not needed if you use the init(success, error, options, skus) method. Can be used to update inventory if you need to add more skus.
inappbilling.getProductDetails(success, fail, skus)
- success : The success callback.
- error : The error callback.
- skus : string or string[] of product skus. ie. "prod1" or ["prod1","prod2]
Get Available Product(s)
The list of the available product(s) in inventory.
inappbilling.getAvailableProducts(success, fail)
-
success : The success callback. It provides a json array of the list of owned products as a parameter. Example :
{index: { "title":"Infinite Gas", "price":"2.99", "type":"subs", "description":"Lots of Infinite Gas", "productId":"infinite_gas", "price_currency_code":"USD" }} -
error : The error callback.
Quick example
inappbilling { // display the extracted text ; // make the purchase inappbilling; } { ; } { ;}
Full example
In App Billing Hello World Initalize the billing plugin Purchase Owned products Consume purchase Subscribe Query Details Get Available Products
Common issues
If you have an issue, make sure that you can answer to theses questions:
Did you create your item in the Developer Console?
Is the id for your item the same in the Developer Console and in your app?
Is your item active?
Have you uploaded and published your apk in the alpha or beta channels? You can no longer test in app purchases with an apk in draft mode.
Have you waited at least a few hours since you activated your item and published your apk on the Developer Console?
Are you using a different Google account than your developer account to make the purchase?
Is the Google account part of a google+ community or group that you invited in the alpha or beta channel?
Using the Google account, did you follow the link that appears in the channel where you published your apk, and accept the invitation to test?
Are you testing on a real device, rather than the emulator?
Are you using a signed apk?
Is the version code of your app the same as the one uploaded on the Developer Console?
If any of these questions is answered with a "no", you probably need to fix that.
MIT License
Copyright (c) 2012-2014 Guillaume Charhon - Smart Mobile Software
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.