InAppPurchases example

SDK Version: 38, ejected to iOS

I’ve been struggling how to validate transaction/purchases from Apple from my server, have read all the documentation on expo-in-app-purchases. Is there a good example of how to do this?

I’m running locally (Payments.js) and globally (App.js) the following code:

const { responseCode, results } = await getProductsAsync(items);
if (responseCode === IAPResponseCode.OK) {
this.setState({ items: results });
console.log('there are results ’ + JSON.stringify(this.state.items));
}

    await setPurchaseListener(({ responseCode, results, errorCode }) => {
        // Purchase was successful
        if (responseCode === IAPResponseCode.OK) {
            results.forEach(purchase => {
                if (!purchase.acknowledged) {
                   finishTransactionAsync(purchase, false);
                    console.log(`Successfully purchased ${purchase.productId}`);
                    // Process transaction here and unlock content...
                }
            });
        }

        // Else find out what went wrong
        if (responseCode === IAPResponseCode.USER_CANCELED) {
            console.log('User canceled the transaction');
        } else if (responseCode === IAPResponseCode.DEFERRED) {
            console.log('User does not have permissions to buy but requested parental approval (iOS only)');
        } else {
            console.warn(`Something went wrong with the purchase. Received errorCode ${errorCode}`);
        }
    });
    // To replace an existing subscription on Android
    //await purchaseItemAsync('I_1_Month', 'I_3_Month');

}

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.