I'm currently creating a checkout page for my users. The users click on a button on the frontend whilst logged into their account. The checkout session.
let stripe = null
onMounted(async () => {
stripe = await loadStripe(import.meta.env.VITE_STRIPE_KEY)
})
function buyTrialLesson()
{
stripe.redirectToCheckout({
successUrl: "xxxx",
cancelUrl: "xxx",
lineItems: [{
price: "price_xxxxxxxxxxxxxx",
quantity: 1,
}],
mode: "payment"
})
}
When the user pays on checkout the webhook I have setup reads the email address entered when paid for and then finds that user on the database and adds the credits to their account like that. However if the user enters the wrong email at checkout the funds will not be added to their account... I would rather send the account ID directly.
I'm assuming I should create the checkout on the backend and then send it over like that. But I've got no idea where to start and how to send that checkout session to the user... any tips are appreciated.
Many thanks.
CodePudding user response:
You can pass metadata while creating your checkout session:
Accepted flow for your requirement:
- Your backend server will create stripe checkout session (creating this session will pass details like
success_url
,cancel_url
andline_items
) and this will return you one stripe session id. - Your front end will receive this session is via API and pass only session id to complete the payment.
refer doc