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!