React Native Cafe Bazaar is built to provide an easy interface to InApp Billing for Cafe Bazaar,
npm install --save react-native-cafe-bazaar
oryarn add 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 {
...
implementation 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:
@Override protected List<ReactPackage> getPackages() { return Arrays.<ReactPackage>asList( new MainReactPackage(), // add package here new CafeBazaarPackage() ); }
- 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:
<string name="CAFE_BAZAAR_PUBLIC_KEY">YOUR_CAFE_BAZAAR_PUBLIC_KEY_HERE</string>
Alternatively, you can add your license key as a parameter when registering the CafeBazaarPackage
, like so:
.addPackage(new CafeBazaarPackage("YOUR_CAFE_BAZAAR_PUBLIC_KEY_HERE"))
or for React Native 29+
new CafeBazaarPackage("YOUR_CAFE_BAZAAR_PUBLIC_KEY_HERE")
Add the billing permission as follows to AndroidManifest.xml file:
<uses-permission android:name="com.farsitel.bazaar.permission.PAY_THROUGH_BAZAAR"></uses-permission>
- 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.
Most of methods returns a Promise
.
Important: Opens the service channel to CafeBazaar. Must be called (once!) before any other billing methods can be called.
import CafeBazaar from 'react-native-cafe-bazaar'
...
CafeBazaar.open()
.then(() => CafeBazaar.purchase('YOUR_SKU','DEVELOPER_PAYLOAD',RC_REQUEST))
.catch(err => console.log('CafeBazaar err:', err))
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.open()
.then(() => CafeBazaar.purchase('YOUR_SKU','DEVELOPER_PAYLOAD',RC_REQUEST))
.then((details) => {
console.log(details)
return CafeBazaar.close()
})
.catch(err => console.log('CafeBazaar err:', err))
- productSKU (required): String
- developerPayload: String
- rcRequest: Integer
- Details: JSONObject:
- mDeveloperPayload:
- mItemType:
- mOrderId:
- mOriginalJson:
- mPackageName:
- mPurchaseState:
- mPurchaseTime:
- mSignature:
- mSku:
- mToken:
CafeBazaar.purchase('YOUR_SKU','DEVELOPER_PAYLOAD',RC_REQUEST)
.then((details) => {
console.log(details)
})
.catch(err => console.log('CafeBazaar err:', err))
- productSKU (required): String
- Details: JSONObject:
- mDeveloperPayload:
- mItemType:
- mOrderId:
- mOriginalJson:
- mPackageName:
- mPurchaseState:
- mPurchaseTime:
- mSignature:
- mSku:
- mToken:
CafeBazaar.consume('YOUR_SKU')
.then(...)
.catch(err => console.log('CafeBazaar err:', err))
- items: JSONArray:
CafeBazaar.loadOwnedItems()
.then((details) => {
console.log(details)
})
.catch(err => console.log('CafeBazaar err:', err))
- productSKUs (required): Array
- mPurchaseMap: JSONObject
- mSkuMap: JSONObject
CafeBazaar.loadInventory([])
.then(...)
.catch(err => console.log('CafeBazaar err:', err))
Below function dispatch Event instead of Promise and return value is same.
import {DeviceEventEmitter} from 'react-native';
...
componentDidMount(){
DeviceEventEmitter.addListener('CafeBazaar', function(e: Event) {
// handle event.
console.log(e);
});
}
Upload the updated APK to Bazaar Developer Panel