Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
useEffect(() => {
purchaseUpdateSubscription.current = purchaseUpdatedListener(
async (purchase: ProductPurchase) => {
const info = await findCurrentSubInfoFromPurchases([purchase])
// This is not a requirement on iOS
const wasAcknowledged = await maybeAcknowledgePurchaseAndroid(
purchase,
)
if (!wasAcknowledged) {
// TODO: what do we do in this case? the purchase has still gone through but will
// be cancelled in a few days
onWarning('Purchase was not acknowledged')
}
setCurrentSubscriptionInfo(info)
onPurchase(info)
_purchaseUpdatedListener = () => {
const {
currentAccount: { name },
intl,
fetchData,
} = this.props;
this.purchaseUpdateSubscription = purchaseUpdatedListener(purchase => {
const receipt = get(purchase, 'transactionReceipt');
const token = get(purchase, 'purchaseToken');
if (receipt) {
const data = {
platform: Platform.OS === 'android' ? 'play_store' : 'app_store',
product: get(purchase, 'productId'),
receipt: Platform.OS === 'android' ? token : receipt,
user: name,
};
purchaseOrder(data)
.then(() => {
if (Platform.OS === 'ios') {
RNIap.finishTransactionIOS(get(purchase, 'transactionId'));
} else if (Platform.OS === 'android') {