InApp Billing for Cafe Bazaar (Android)
React Native Cafe Bazaar is built to provide an easy interface to InApp Billing for Cafe Bazaar,
Installation
npm install --save react-native-cafe-bazaar
- Add the following in
android/settings.gradle
...include ':react-native-cafe-bazaar', ':app'project(':react-native-cafe-bazaar').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-cafe-bazaar/android/app')
- And the following in
android/app/build.gradle
...dependencies { ... compile project(':react-native-cafe-bazaar')}
- Update MainActivity or MainApplication depending on React Native version.
- React Native version >= 0.29
Edit
MainApplication.java
.- Add
import com.contoriel.cafebazaar.CafeBazaarPackage;
in the top of the file. - Register package:
@Overrideprotected List<ReactPackage> {return Arrays.<ReactPackage>;} - Add
- Add your CafeBazaar Public key as a line to your
android/app/src/main/res/values/strings.xml
with the nameCAFE_BAZAAR_PUBLIC_KEY
. For example:
YOUR_CAFE_BAZAAR_PUBLIC_KEY_HERE
Alternatively, you can add your license key as a parameter when registering the CafeBazaarPackage
, like so:
.
or for React Native 29+
new CafeBazaarPackage("YOUR_CAFE_BAZAAR_PUBLIC_KEY_HERE")
Add the billing permission as follows to AndroidManifest.xml file:
ON THE BAZAAR DEVELOPER PANEL
- Upload the application to the Developer Panel.
-
Using the Enter button in In-app Billing column of the created app, go to In-app Billing Panel.
-
In that app, create your in-app items
-
Grab the application's public key (a base-64 string) You can find the application's public key in the Dealer Apps page for your application.
Javascript API
Most of methods returns a Promise
.
open()
Important: Opens the service channel to CafeBazaar. Must be called (once!) before any other billing methods can be called.
... CafeBazaar
close()
Important: Must be called to close the service channel to CafeBazaar, when you are done doing billing related work. Failure to close the service channel may degrade the performance of your app.
CafeBazaar
purchase('YOUR_SKU','DEVELOPER_PAYLOAD',RC_REQUEST)
Parameter(s)
- productSKU (required): String
- developerPayload: String
- rcRequest: Integer
Returns:
- Details: JSONObject:
- mDeveloperPayload:
- mItemType:
- mOrderId:
- mOriginalJson:
- mPackageName:
- mPurchaseState:
- mPurchaseTime:
- mSignature:
- mSku:
- mToken:
CafeBazaar
consume('YOUR_SKU')
Parameter(s)
- productSKU (required): String
Returns:
- Details: JSONObject:
- mDeveloperPayload:
- mItemType:
- mOrderId:
- mOriginalJson:
- mPackageName:
- mPurchaseState:
- mPurchaseTime:
- mSignature:
- mSku:
- mToken:
CafeBazaar
loadOwnedItems()
Returns:
- items: JSONArray:
CafeBazaar
loadInventory([item1_SKU,item2_SKU,...])
Parameter(s)
- productSKUs (required): Array
Returns:
- mPurchaseMap: JSONObject
- mSkuMap: JSONObject
CafeBazaar
Use event listener
Below function dispatch Event instead of Promise and return value is same.
purchaseWithEvent('YOUR_SKU','DEVELOPER_PAYLOAD',RC_REQUEST)
consumeWithEvent('YOUR_SKU')
loadOwnedItemsWithEvent()
;... { DeviceEventEmitter; }
BACK TO BAZAAR DEVELOPER PANEL
- Upload the updated APK to Bazaar Developer Panel