Question

Issues with Purchases Rest API Internal Server Error

  • 4 December 2023
  • 4 replies
  • 103 views

Badge

PROBLEM

After I create a stripe.checkout.sessions.create(), I take the sessionID to make a REST API request to RevenueCat. But I keep getting this internal server error, after checking through all of it. I am sure my authentication key is correct, because I altered it and it showed an auth error.

 

Here is my code:

 

const session = await stripe.checkout.sessions.create({

line_items: [

{

// Provide the exact Price ID (for example, pr_1234) of the product you want to sell

price: priceId,

 

quantity: 1,

},

],

mode: 'subscription',

//subscription_data: { on_behalf_of: store.stripeSellerId },

customer: customer,

client_reference_id: store?._id,

success_url: `${process.env.NEXT_PUBLIC_BASE_URL}store-dashboard/${storeId}/pay-confirm?success=true`,

cancel_url: `${process.env.NEXT_PUBLIC_BASE_URL}store-dashboard/${storeId}/pay-confirm?canceled=true`,

})

console.log('session', session)

if (session.id) {

const API_URL = 'https://api.revenuecat.com/v1/receipts'

const body = {

app_user_id: store?.subscriptionId || '',

fetch_token: session.id,

}

console.log('revenueCat body', body)

const response = await fetch(API_URL, {

method: 'POST',

headers: {

accept: 'application/json',

'X-Platform': 'stripe',

'content-type': 'application/json',

authorization: 'Bearer ' + process.env.REVENUE_CAT_STRIPE,

},

body: JSON.stringify(body),

})

const result = await response.json()

console.log('revenueCat response', result)

}

 

Here is the response:

 

 

revenueCat body {

  app_user_id: 'XdtiXMQEmD87x3fFPe3Vj',

  fetch_token: 'cs_test_a1mM0GxaIVTHpQY9kQ8hdR5elDKpUA4mq7KtzT2H1KEnXellw7g7qzKnzT'

}

revenueCat response { code: 7110, message: 'Internal server error.' }


4 replies

Badge

Also, everything goes through Stripe successfully, which is why I feel very stuck on this. I’ve changed the body syntax and various error codes have arisen. This one just really doesn’t tell me what’s going on.

Userlevel 5
Badge +9

Hello,

RevenueCat won’t prevent Stripe purchases from going through so that’s expected. I’m looking into this now on our end to see if I can find anything. Can you double check the basics like making sure you have the correct Stripe account connected to RevenueCat and you use only per unit or recurring quantity?

Also, can you run this curl command in a terminal and see if you get that error? (don’t forget to put in your real API key)

curl -X POST \
https://api.revenuecat.com/v1/receipts \
-H 'Content-Type: application/json' \
-H 'X-Platform: stripe' \
-H 'Authorization: Bearer YOUR_REVENUECAT_STRIPE_APP_PUBLIC_API_KEY' \
-d '{ "app_user_id": "XdtiXMQEmD87x3fFPe3Vj",
"fetch_token": "cs_test_a1mM0GxaIVTHpQY9kQ8hdR5elDKpUA4mq7KtzT2H1KEnXellw7g7qzKnzT"
}'

 

Badge

I am having the same problem. Using the fetch_token and app_user_id in Sharif’s post gave an Invalid Receipt error which I guess is an improvement. I’m using Flutterflow’s API interface and this happens in testing the API.

Headers are:

 "X-Platform": "stripe",
  "Content-Type": "application/json",
  "Authorization": "Bearer [STRIPE API PUBLIC KEY]"

Body is:

{
  "fetch_token": "cs_test_a1A9WAnUJhjpKiFxFmbJMyX6MOojJbyrDpyV3Wi6k8wxEmKr3haWncE3Dz",
  "app_user_id": "VgYC2jVJzZY1zThbTjrLjmbeik32"
}

 

The response header is:

{
  "connection": "keep-alive",
  "date": "Wed, 13 Dec 2023 16:46:30 GMT",
  "access-control-allow-origin": "*",
  "access-control-expose-headers": "date,content-type,content-length,connection,server,access-control-allow-origin,x-amzn-trace-id,x-envoy-upstream-service-time,x-request-id,x-final-url",
  "report-to": "{\"group\":\"heroku-nel\",\"max_age\":3600,\"endpoints\":[{\"url\":\"https://nel.heroku.com/reports?ts=1702485990&sid=1b10b0ff-8a76-4548-befa-353fc6c6c045&s=6ddz4nDDMZeUwMiAUGv5dtgTcgCMXMxkNtWLIjmXiCQ%3D\"}]}",
  "content-type": "application/json",
  "server": "envoy",
  "x-request-id": "ff04c592-c816-4c06-a8fd-335abec39a7e",
  "x-amzn-trace-id": "Root=1-6579dfe6-77f32a2d5db0415940a32c1f",
  "x-envoy-upstream-service-time": "301",
  "reporting-endpoints": "heroku-nel=https://nel.heroku.com/reports?ts=1702485990&sid=1b10b0ff-8a76-4548-befa-353fc6c6c045&s=6ddz4nDDMZeUwMiAUGv5dtgTcgCMXMxkNtWLIjmXiCQ%3D",
  "content-length": "49",
  "nel": "{\"report_to\":\"heroku-nel\",\"max_age\":3600,\"success_fraction\":0.005,\"failure_fraction\":0.05,\"response_headers\":[\"Via\"]}",
  "x-request-url": "https://api.revenuecat.com/v1/receipts",
  "via": "1.1 vegur",
  "x-final-url": "https://api.revenuecat.com/v1/receipts"
}

Userlevel 5
Badge +9

Hey @aagin sorry for missing your message. This may be a different issue but I found the following:

  1. I took a look at your app and it looks like sometimes you were using your Apple SDK key. The fix for that is to just use your Stripe SDK key (which it looks like you corrected.)
  2. It seems we’re returning an internal server error in some of your requests. I’d like to take a look into that but can you just confirm that you’re using the correct Stripe account? The Stripe checkout session should come from the same Stripe account that’s connected to RevenueCat.

Reply