1.0.10 • Published 1 month ago

iab-myket-reactnative v1.0.10

Weekly downloads
-
License
MIT
Repository
github
Last release
1 month ago

Myket IAB React native

React native in app billing SDK for React native.

Dependency

npm i iab-myket-reactnative

Configuration

To activate Myket reactNative Billing SDK, open the android directory located in your root project and add this piece of code to app level build.gradle file:

def marketApplicationId = "ir.mservices.market"
def marketBindAddress = "ir.mservices.market.InAppBillingService.BIND"
manifestPlaceholders = [marketApplicationId: "${marketApplicationId}",
marketBindAddress : "${marketBindAddress}",
marketPermission : "${marketApplicationId}.BILLING"]

if your project doesn't have and android directory, make one using the command below:

expo eject

Note that application must have the same application Id as you definded in the Myket panel.

Functional Components

import  myket  from  'myket-iab-reactnative';

function MyComponent() {
  const myketInstance = useMyket(myInAppBillingKey);
  // ...
  const someHandler = async () => {
    const inventory = await myket.queryPurchaseProduct(true, productIds);
    console.log(JSON.JSON.stringify(inventory));
  };
  // ...
}

Class Components

import  myket  from  'myket-iab-reactnative';
class  App extends Component 
	componentDidMount() {
		this.didMount = true;
			myket.connect(base64RSA).catch((error) => {
				/**
				* myket is not installed or RSA public key is null or empty
				*/

				this.log(error)
		    }).then(this.retrieverProducts);

	}
	componentWillUnmount() {
		myket.disconnect().catch(() =>  this.log);
	}
}

Complete Example

For better understanding see the Trivial drive app in here which provided a complete react-native implementation.

API Documentation

connect/disconnect

  • Connect and initialize myket billing , take RSA public key as a parameter, find more information about public key here.
  • disconnect will release the resources occupied by the SDK and mhelper.

enableDebugging(isEnable:boolean):void

  • Enable Debugging in Android logcat.

purchaseProduct( sku:Boolean , developerPayload :String ):Promise <Purchase>

  • Launches an Activity and shows the myket billing dialog.

  • developerPayload : Generate a string and pass it to the function and compare to the response of purchase for security reasons.

  • sku : The SKU of the item that user intended to buy.

consumePurchase( purchase ): Promise<Void>

  • Consume a Purchase, the result of purchasing the product must be consumed by the application.

queryPurchaseProduct(querySkuDetails,moreSku):Promise <Inventory >

  • query inventory for details of sku's and previously bought items that hasn't consumed. for some reasons , user may bought a SKU but hasn't consumed by the application , make sure you call consumed purchases immediately after calling queryPurchaseProduct.
  • moreSkus : list of array to define wich skuItem's details need to get fetched.
  • querySkuDetails : pass true if you want to get the sku details,pass false if you want to avoid calling another service.
export  type  Inventory = {
	allProducts: SkuDetails[];
	allPurchases: Purchase[];
};

export  type  SkuDetails = {
	itemType: string;
	sku: string;
	type: string;
	price: string;
	title: string;
	description: string;
	json: string;
};

export  type  Purchase = {
	itemType: string;
	orderId: string;
	packageName: string;
	sku: string;
	purchaseTime: string;
	purchaseState: number;
	developerPayload: string;
	token: string;
	originalJson: string;
	signature: string;
};

Error schema

the following is the error schema returned from almost every API of the SDK; in case you want to handle errors for more customized scenario :

{
	"message":"String"
	"responseCode":"Int"
}

License

MIT

1.0.10

1 month ago

1.0.9

12 months ago

1.0.8

12 months ago

1.0.7

12 months ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago