React Native Cafe Bazaar is built to provide an easy interface to InApp Billing for Cafe Bazaar,
⚠️ Notice: This library is not being actively updated. You might want to use the RN library of the cafebazaar itself.
npm install --save react-native-cafe-bazaar
or yarn add react-native-cafe-bazaar
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')
android/app/build.gradle
...
dependencies {
...
implementation project(':react-native-cafe-bazaar')
}
MainApplication.java
.import com.contoriel.cafebazaar.CafeBazaarPackage;
in the top of the file. @Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
// add package here
new CafeBazaarPackage()
);
}
android/app/src/main/res/values/strings.xml
with the name CAFE_BAZAAR_PUBLIC_KEY
. For example:
```xmlAlternatively, you can add your license key as a parameter when registering the `CafeBazaarPackage`, like so:
```java
.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>
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))
CafeBazaar.purchase('YOUR_SKU','DEVELOPER_PAYLOAD',RC_REQUEST)
.then((details) => {
console.log(details)
})
.catch(err => console.log('CafeBazaar err:', err))
CafeBazaar.consume('YOUR_SKU')
.then(...)
.catch(err => console.log('CafeBazaar err:', err))
CafeBazaar.loadOwnedItems()
.then((details) => {
console.log(details)
})
.catch(err => console.log('CafeBazaar err:', err))
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