Reputation: 157
I've created a POST request to collect payments from customers via Stripe
let data = {
errorMsg:'',
key: process.env.STRIPE_PUBLIC_KEY
}
const session = await stripe.checkout.sessions.create({
payment_method_types: ['card'],
line_items: [
{
price_data: {
currency: 'usd',
product_data: {
name: 'My tools',
},
unit_amount: 10,
},
quantity: 1,
},
],
mode: 'payment',
success_url: 'https://example.com/success',
cancel_url: 'https://example.com/cancel',
});
const sessiondetails = await stripe.checkout.sessions.retrieve(session.id);
console.log("session details", sessiondetails);
res.redirect(303, session.url);
}))
Can someone tell me how can I confirm that the payment is successfully processed before adding credits/allow customers to download digital products or before redirecting the user?
Upvotes: 0
Views: 425
Reputation: 7459
The recommended way to track this is using the checkout.session.completed
webhook to handle fulfillment. Either here or retrieving the session as you've done, you can check if the payment_status
(API ref) is paid
before granting access/credits.
Upvotes: 2