I have a Stripe endpoint set up in Python, looks like this:
def create_checkout_session(request):
donation_amount = request.POST['donationAmount']
donation_name = request.POST['donationName']
try:
checkout_session = stripe.checkout.Session.create(
line_items=[
{
'price_data': {
'unit_amount': donation_amount,
'currency': 'usd',
'product_data': {
'name': donation_name
},
},
'quantity': 1,
},
],
mode='payment',
success_url=settings.DONATION_URL + '?success=true',
cancel_url=settings.DONATION_URL + '?canceled=true',
)
except Exception as e:
return str(e)
return redirect(checkout_session.url, code=303)
And I'm trying to send the donationAmount and donationName via a fetch function.
const goToCheckout = (donation, userHandle) => {
const donationName = "Donated by @" + userHandle;
fetch(url, {
method: "POST",
body: {
donationAmount: donation,
donationName: donationName,
},
})
.then(??)
.catch((e) => {
console.log(e);
});
};
What's the correct way of sending the parameters and opening the Stripe checkout page with the custom data I'm sending?