Skip to main content

Summary: 

App Store in-app purchases not pulling correctly with promotional offer (free trial)

Description:

I am trying to offer users a free trial using RevenueCat and in-app purchases. The line of code throwing the error is:

const selectedPackage = offering.availablePackagess0]; // This is the package object
const product = selectedPackage.product; // Extract the product from the package

let discount: any = null;

if (product.discounts) {
await Purchases.restorePurchases().then((res) => {
console.log('Restore purchases:', res);
});
discount = await Purchases
.getPromotionalOffer(product, product.discountss0])
.catch((error) => {
Alert.alert(
'Error',
'An error occurred while fetching the subscription details. Please try again.'
);
console.log('Error getting discount:', error);
setLoading(false);
return null;
});
}

Specifically, the Purchases.getPromotionalOffer() is throwing the error:
Possible Unhandled Promise Rejection (id: 0): Error: The receipt is not valid.

The debug logs are showing the following:

DEBUG: ℹ️ Skipping products request for these products because they were already cached: h"caregiver"]
DEBUG: ℹ️ Local intro eligibility computed locally. Result: "caregiver": IntroEligibilityStatus.noIntroOfferExists]
DEBUG: ℹ️ Caching trial or intro eligibility for products: o"caregiver"]
VERBOSE: Warming up paywall images cache: mhttps://assets.pawwalls.com/1080318_1714143788.heic]
DEBUG: ℹ️ Skipping products request for these products because they were already cached: "caregiver"]
DEBUG: ℹ️ Loaded receipt from url file:///Users/chrisozgo/Library/Developer/CoreSimulator/Devices/F06530A6-3E89-45A2-8670-E02BFEDD4C48/data/Containers/Data/Application/AB43FE27-9C7B-4902-8B5F-97DAAE53D700/StoreKit/receipt
INFO: ℹ️ Parsing receipt
DEBUG: ℹ️ Vending CustomerInfo from cache.
INFO: ℹ️ Receipt parsed successfully
DEBUG: ℹ️ PostOfferForSigningOperation: Started
DEBUG: ℹ️ There are no requests currently running, starting request POST /v1/offers
VERBOSE: Using etag 'b5783d46c6b42663' for request to 'https://api.revenuecat.com/v1/offers'. Validation time: <null>
DEBUG: ℹ️ API request started: POST '/v1/offers'
ERROR: 😿‼️ The receipt is not valid.
DEBUG: ℹ️ API request failed: POST '/v1/offers' (400): The receipt is not valid.
Request-ID: '806e17d4-8504-4fdc-8398-b21bc32b2e18'; Amzn-Trace-ID: 'Root=1-66cfd287-4ccad90d0d5d8b3b03482a1b'
ERROR: 😿‼️ The receipt is not valid.
DEBUG: ℹ️ PostOfferForSigningOperation: Finished
DEBUG: ℹ️ Serial request done: POST /v1/offers, 0 requests left in the queue

So it has something to do with the "The receipt is not valid" error. The community forum has documentation on this issue, but none of the suggestions has proven helpful. I have checked the configurations with regard to Shared Secrets and p8 files. They seem to be in order.

Any suggestions to help solve the issue would be greatly appreciated!

Hi @bbiscoe0218! Often, "The receipt is not valid" error is a sandbox issue that often occurs when a specific sandbox user has made lots of purchases, but it can also occur for other reasons. What we typically suggest is creating a new sandbox user, as this tends to resolve this issue. We also suggest deleting and reinstalling the app, and ensuring that you’re testing on a physical device.

Also, can I ask what you’re doing with this line?

if (product.discounts) {
await Purchases.restorePurchases().then((res) => {
console.log('Restore purchases:', res);
});

It’s possible that the restore is a contributor to this issue as well. Can you try commenting this out and let me know if this error persists?