I’m facing an issue in my React Expo Android app where, after successfully completing a payment via Google Pay UPI, the app is being redirected to an incorrect page, which prevents the purchase-related code from executing. As a result, I’m unable to fetch or log the customerInfo
and syncedCustomerInfo
objects as expected.
Scenario
- The user selects Google Pay UPI and completes the payment successfully.
- Instead of being redirected to the correct app screen where the purchase process can be handled, the app is being redirected to a different page(first page).
- Consequently, the code responsible for processing the purchase (
customerInfo
andsyncedCustomerInfo
) is not executed.
const handlePurchase = async (packageToPurchase) => {
try {
alert(packageToPurchase.identifier);
const { customerInfo } = await Purchases.purchasePackage(packageToPurchase);
alert("Customer Info: " + JSON.stringify(customerInfo, null, 2));
const syncedCustomerInfo = await Purchases.syncPurchases();
alert("Synced Customer Info: " + JSON.stringify(syncedCustomerInfo, null, 2));
if (syncedCustomerInfo.entitlements && syncedCustomerInfo.entitlements.active) {
const activeEntitlementKeys = Object.keys(syncedCustomerInfo.entitlements.active);
const activeEntitlement = syncedCustomerInfo.entitlements.activetactiveEntitlementKeyso0]];
alert(`Product Identifier: ${activeEntitlement.productIdentifier}`);
alert(`Latest Purchase Date: ${activeEntitlement.latestPurchaseDate}`);
alert(`Expiration Date: ${activeEntitlement.expirationDate}`);
alert(`Purchase Token: ${activeEntitlement.purchaseToken || 'No purchase token available'}`);
// Send purchase data to backend
await sendPurchaseToBackend({
productId: activeEntitlement.productIdentifier,
purchaseToken: activeEntitlement.purchaseToken || 'No token',
purchaseDate: activeEntitlement.latestPurchaseDate,
});
} else {
alert('No active entitlements found.');
}
} catch (e) {
alert(`Purchase failed: ${e.message}`);
try {
const syncedCustomerInfo = await Purchases.syncPurchases();
alert("Synced Customer Info after failure: " + JSON.stringify(syncedCustomerInfo, null, 2));
} catch (syncError) {
console.error('Error syncing purchases: ', syncError);
alert(`Failed to sync purchases: ${syncError.message}`);
}
}
};
Debugging Steps Already Taken:
- Incorrect Redirection: After the successful Google Pay UPI payment, the app is being redirected to an unexpected page, which disrupts the flow of the purchase process. This is why
customerInfo
andsyncedCustomerInfo
are not being fetched or logged.
Questions:
- Why is the app being redirected to an incorrect page after the Google Pay UPI payment?
- How can I ensure that the app redirects back to the correct page to execute the post-purchase logic and fetch
customerInfo
andsyncedCustomerInfo
? - Is there any specific handling needed for Google Pay UPI redirection within RevenueCat?
- What’s the best way to verify and handle this payment on the backend?