Solved

"The receipt is not valid" when posting Stripe receipt to REST API

  • 1 November 2021
  • 1 reply
  • 529 views

Badge +1

I’ve been hitting my head against this all day yesterday and this evening and I’m not sure what I’m doing wrong.  In brief, my use case is purchasing a subscription via Stripe, and then posting the receipt to RevenueCat to record the entitlement against the correct user.

My code to do so is pretty simple.  Here is an isolated test case written in TypeScript:

import { config as dotEnv } from 'dotenv';
dotEnv();
import fetch from 'node-fetch';

export const sendReceiptToRevenueCat = async (data: {
app_user_id: string;
fetch_token: string;
}): Promise<any> => {
const url = 'https://api.revenuecat.com/v1/receipts';
const headers = {
Accept: 'application/json',
'Content-Type': 'application/json',
'X-Platform': 'stripe',
Authorization: 'Bearer ' + process.env.REVENUECAT_PUBLIC_API_KEY,
};

const options = {
method: 'POST',
headers,
body: JSON.stringify(data),
};

return fetch(url, options)
.then((res) => res.json())
.then((json) => json)
.catch((err) => console.error('error:' + err));
};

sendReceiptToRevenueCat({
app_user_id: 'MY_APP_USER_ID',
fetch_token: 'MY_STRIPE_SUBSCRIPTION_ID',
}).then((res) => {
console.log(res);
});

The response I get back is as follows:

{
"code": 7103,
"message": "The receipt is not valid."
}

Googling this error hasn’t been particularly helpful - most cases seem to be related to iOS, but I didn’t find anything that shed any light on the issue for me.

I have checked the following:

  • REVENUECAT_PUBLIC_API_KEY is my public API key in the “Settings” tab of RevenueCat.
  • MY_APP_USER_ID is the correct user ID.  I can’t actually see any Customers in the RC dashboard on the Customers page, but I can navigate directly to the customer via the Find Customer search box.  And this is the value that appears in the App User ID field.
  • MY_STRIPE_SUBSCRIPTION_ID is the Subscription ID from Stripe in the format sub_xxx.  I verified this both in the Stripe webhook payload and in the Stripe dashboard.
  • There is a Product set up in RevenueCat with the same Product ID (prod_xxx) associated with the subscription in Stripe.
  • The subscription I created in Stripe is in the developer sandbox.  It feels like this might be related, but I’m not the account owner, so it will be at least tomorrow morning before I can get this flipped to live in order to rule this out.

Things I have tried:

  1. Disabling the Stripe webhook to RevenueCat in case it was somehow processing the subscription already and it was a one use thing (I don’t think it is, as it’s not mentioned in the docs)
  2. Following the receipts code at https://github.com/RevenueCat-Samples/stripe-no-website-example/blob/master/app.js, which is basically the same as mine, except that it also includes the stripe_customer_id attribute.  I did try including that but it didn’t make a difference.
  3. Stringifying the body and sending it as is.  Both give me the same error.
  4. Querying the subscribers endpoint on RevenueCat.  Here is the response:
    {
    "request_date": "2021-11-01T21:58:37Z",
    "request_date_ms": 1635803917054,
    "subscriber": {
    "entitlements": {},
    "first_seen": "2021-10-31T08:43:30Z",
    "last_seen": "2021-10-31T08:43:30Z",
    "management_url": null,
    "non_subscriptions": {},
    "original_app_user_id": "MY_APP_USER_ID",
    "original_application_version": null,
    "original_purchase_date": null,
    "other_purchases": {},
    "subscriptions": {}
    }
    }

 

 

Things I haven’t tried:

  1. Sacrificing a small animal
  2. Giving up and sinking into depression because the world is unfair
icon

Best answer by Maloric 2 November 2021, 23:56

View original

1 reply

Badge +1

Looks like it was my fault all along.  With a little help from RevenueCat support (thanks Cody!) I discovered that RC was picking up subscriptions from a different Stripe account.  I’d linked the WebHooks using the secret key for the new Stripe account, but had forgotten to update the “Account” page in RevenueCat, which was still linked to the old account.

*facepalm*

Reply