Customizable InAppBilling feature for react native application
npm install react-native-custom-billingInApp Billing for CafeBazaar/Myket/IranApps/Google (Android)
=============
React Native Custom Billing is built to provide an easy interface to InApp Billing for CafeBazaar/Myket/IranApps/Google (Android),
$ npm install react-native-custom-billing --save
$ react-native link react-native-custom-billing
android/app/src/main/java/[...]/MainApplication.java
import com.customBilling.reactnative.RNCustomBillingPackage; to the imports at the top of the file
new RNCustomBillingPackage() to the list returned by the getPackages() method
android/settings.gradle:
include ':react-native-custom-billing'
project(':react-native-custom-billing').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-custom-billing/android')
`
3. Insert the following lines inside the dependencies block in android/app/build.gradle:
`
compile project(':react-native-custom-billing')
`
4. Add your Vendor Name (CafeBazaar/Myket/IranApps/Google) as a line to your android/app/src/main/res/values/strings.xml with the name RNCB_VENDOR_NAME. For example:
`xml
bazaar
or
myket
or
google
or
iranapps
`
5. Add your Vendor Public key as a line to your android/app/src/main/res/values/strings.xml with the name RNCB_VENDOR_PUBLIC_KEY. For example:
`xml
YOUR_CAFE_BAZAAR_PUBLIC_KEY
or
YOUR_MYKET_PUBLIC_KEY
or
YOUR_IRAN_APPS_PUBLIC_KEY
or
YOUR_GOOGLE_PUBLIC_KEY
`
6. Add the billing permission as follows to AndroidManifest.xml file based on your Vendor (CafeBazaar/Myket/Google):
`xml
Cafe Bazaar:
or
Myket:
or
Iran Apps:
or
Google:
`
Javascript API
Most of methods returns a Promise.
$3
Important: Opens the service channel to RNCustomBilling. Must be called (once!) before any other billing methods can be called.
`javascript
import RNCustomBilling from 'react-native-custom-billing'
...
RNCustomBilling.open()
.then(() => RNCustomBilling.purchase('YOUR_SKU','DEVELOPER_PAYLOAD',RC_REQUEST))
.catch(err => console.log('Vendor err:', err))
`
$3
Important: Must be called to close the service channel to RNCustomBilling, when you are done doing billing related work. Failure to close the service channel may degrade the performance of your app.
`javascript
RNCustomBilling.open()
.then(() => RNCustomBilling.purchase('YOUR_SKU','DEVELOPER_PAYLOAD',RC_REQUEST))
.then((details) => {
console.log(details)
return RNCustomBilling.close()
})
.catch(err => console.log('Vendor err:', err))
`
$3
##### Parameter(s)
* productSKU (required): String
* developerPayload: String
* rcRequest: Integer
##### Returns:
* Details: JSONObject:
* mDeveloperPayload:
* mItemType:
* mOrderId:
* mOriginalJson:
* mPackageName:
* mPurchaseState:
* mPurchaseTime:
* mSignature:
* mSku:
* mToken:
`javascript
RNCustomBilling.purchase('YOUR_SKU','DEVELOPER_PAYLOAD',RC_REQUEST)
.then((details) => {
console.log(details)
})
.catch(err => console.log('RNCustomBilling err:', err))
`
$3
##### Parameter(s)
* productSKU (required): String
##### Returns:
* Details: JSONObject:
* mDeveloperPayload:
* mItemType:
* mOrderId:
* mOriginalJson:
* mPackageName:
* mPurchaseState:
* mPurchaseTime:
* mSignature:
* mSku:
* mToken:
`javascript
RNCustomBilling.consume('YOUR_SKU')
.then(...)
.catch(err => console.log('Vendor err:', err))
`
$3
##### Returns:
* items: JSONArray:
`javascript
RNCustomBilling.loadOwnedItems()
.then((details) => {
console.log(details)
})
.catch(err => console.log('Vendor err:', err))
`
$3
##### Parameter(s)
* productSKUs (required): Array
##### Returns:
* mPurchaseMap: JSONObject
* mSkuMap: JSONObject
`javascript
RNCustomBilling.loadInventory([])
.then(...)
.catch(err => console.log('Vendor err:', err))
`
Use event listener
Below function dispatch Event instead of Promise and return value is same.
$3
$3
$3
`javascript
import {DeviceEventEmitter} from 'react-native';
...
componentDidMount(){
DeviceEventEmitter.addListener('Vendor', function(e: Event) {
// handle event.
console.log(e);
});
}
``