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.' }