npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-custom-billing

v2.2.0

Published

Customizable InAppBilling feature for react native application

Downloads

125

Readme

InApp 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),

Getting started

$ npm install react-native-custom-billing --save

Mostly automatic installation (for React Native <= 0.59 only, React Native >= 0.60 skip this as auto-linking should work)

$ react-native link react-native-custom-billing

Manual installation (Skip step 1,2,3 for React Native >= 0.60)

Android

  1. Open up android/app/src/main/java/[...]/MainApplication.java
  • Add import com.customBilling.reactnative.RNCustomBillingPackage; to the imports at the top of the file
  • Add new RNCustomBillingPackage() to the list returned by the getPackages() method
  1. Append the following lines to 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')
  2. Insert the following lines inside the dependencies block in android/app/build.gradle:
      compile project(':react-native-custom-billing')
  3. 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:
<string name="RNCB_VENDOR_NAME">bazaar</string>
or
<string name="RNCB_VENDOR_NAME">myket</string>
or
<string name="RNCB_VENDOR_NAME">google</string>
or
<string name="RNCB_VENDOR_NAME">iranapps</string>
  1. 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:
<string name="RNCB_VENDOR_PUBLIC_KEY">YOUR_CAFE_BAZAAR_PUBLIC_KEY</string>
or
<string name="RNCB_VENDOR_PUBLIC_KEY">YOUR_MYKET_PUBLIC_KEY</string>
or
<string name="RNCB_VENDOR_PUBLIC_KEY">YOUR_IRAN_APPS_PUBLIC_KEY</string>
or
<string name="RNCB_VENDOR_PUBLIC_KEY">YOUR_GOOGLE_PUBLIC_KEY</string>
  1. Add the billing permission as follows to AndroidManifest.xml file based on your Vendor (CafeBazaar/Myket/Google):
Cafe Bazaar: <uses-permission android:name="com.farsitel.bazaar.permission.PAY_THROUGH_BAZAAR"></uses-permission>
or
Myket: <uses-permission android:name="ir.mservices.market.BILLING"></uses-permission>
or
Iran Apps: <uses-permission android:name="ir.tgbs.iranapps.permission.BILLING"/>
or
Google: <uses-permission android:name="com.android.vending.BILLING"></uses-permission>

Javascript API

Most of methods returns a Promise.

open()

Important: Opens the service channel to RNCustomBilling. Must be called (once!) before any other billing methods can be called.

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))

close()

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.

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))

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:
RNCustomBilling.purchase('YOUR_SKU','DEVELOPER_PAYLOAD',RC_REQUEST)
.then((details) => {
  console.log(details)
})
.catch(err => console.log('RNCustomBilling err:', err))

consume('YOUR_SKU')

Parameter(s)
  • productSKU (required): String
Returns:
  • Details: JSONObject:
    • mDeveloperPayload:
    • mItemType:
    • mOrderId:
    • mOriginalJson:
    • mPackageName:
    • mPurchaseState:
    • mPurchaseTime:
    • mSignature:
    • mSku:
    • mToken:
RNCustomBilling.consume('YOUR_SKU')
.then(...)
.catch(err => console.log('Vendor err:', err))

loadOwnedItems()

Returns:
  • items: JSONArray:
RNCustomBilling.loadOwnedItems()
.then((details) => {
  console.log(details)
})
.catch(err => console.log('Vendor err:', err))

loadInventory([item1_SKU,item2_SKU,...])

Parameter(s)
  • productSKUs (required): Array
Returns:
  • mPurchaseMap: JSONObject
  • mSkuMap: JSONObject
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.

purchaseWithEvent('YOUR_SKU','DEVELOPER_PAYLOAD',RC_REQUEST)

consumeWithEvent('YOUR_SKU')

loadOwnedItemsWithEvent()

import {DeviceEventEmitter} from 'react-native';
...
  componentDidMount(){
    DeviceEventEmitter.addListener('Vendor', function(e: Event) {
      // handle event.
      console.log(e);
    });
  }