Last active
August 14, 2017 19:42
-
-
Save ayberkanilatsiz/ac32189aab68eebafbf04b72e752f7e4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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