Skip to content

Instantly share code, notes, and snippets.

@ayberkanilatsiz
Last active August 14, 2017 19:42
Show Gist options
  • Save ayberkanilatsiz/ac32189aab68eebafbf04b72e752f7e4 to your computer and use it in GitHub Desktop.
Save ayberkanilatsiz/ac32189aab68eebafbf04b72e752f7e4 to your computer and use it in GitHub Desktop.
import { NativeModules } from 'react-native'
var InAppUtils = require('NativeModules').InAppUtils;
class inApp {
myProductIds = [
'inApp.product.id'
]
loadProdcts(){
return new Promise((resolve,reject)=>{
InAppUtils.loadProducts(this.myProductIds, (error, products) => {
if(!error){
this.myProducts = products
resolve(products)
}
});
});
}
buyProduct(productId){
return new Promise((resolve,reject)=>{
InAppUtils.purchaseProduct(productId, (error, response) => {
if(response && response.productIdentifier) {
resolve({isSuccess:true,data:response});
}else{
resolve({isSuccess:false,data:response});
}
});
})
}
restorePayment(){
return new Promise((resolve,reject)=>{
InAppUtils.restorePurchases((error, response) => {
if(error) {
alert('Itunes Error', 'Could not connect to itunes store.');
} else {
if (response.length === 0) {
resolve({isSuccess:false,data:response})
}else{
resolve({isSuccess:true,data:response})
}
}
});
});
}
}
const Inapp = new inApp();
export default Inapp;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment