#joseph01
1 messages ยท Page 1 of 1 (latest)
When you create the checkout session on your server, the session url will be on the response object here: https://stripe.com/docs/api/checkout/sessions/object#checkout_session_object-url
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
You can grab that and send the email to your customer on your server
After clicking it directly redirects to the checkout session link. How to just grab the link without redirect. And I am checking the link you provided.
You can create a webpage and do it your checkout success. Then you can put crossdomain in Google Analytics, and voilรก! You will see the checkout session
No no I don't have issue with checkout success. I want to grab the payment link.
You control the redirect process
How are you creating checkout sessions? On your server?
no, but I need to get the list of the payouts mades on a customer account
@robust wraith you're in the wrong thread
app.post('/create-checkout-session', async (req, res) => {
const products = req.body.products;
const country = req.body.country;
const session = await stripe.checkout.sessions.create({
payment_method_types: ['card'],
line_items: [
...products.map(p => ({
price_data: {
currency: currency,
product_data: {
name: p.title,
images: [p.image.asset.url]
},
unit_amount: price,
},
quantity: qty,
}))
],
mode: 'payment',
success_url: "http://localhost:3000/services/registration",
cancel_url: "http://localhost:3000/services/registration",
});
res.json({ id: session.id });
});
Hey, like this am creating the link
Ok so in your server just grab session.url
And use that to send to your customer
All server-side
And just don't implement a redirect to the url on your client side
Oh okay. Let me check once then.
Hey, Thank you so much!! I am getting the url. Now how can I make URL open once only for payment and get's disabled if opened the link again. For security purposes.
Or if clicked the back button then the link doesn't work for payment. Either way
There's not a easy way to handle this, but if I can understand your usecase, that might help a bit. What's the specific concern with being able to load the url multiple times? If it is paid, then the link becomes disabled
Yaa this was the case actually. Oh great then. And any way I can handle the link tampering ? Like tampering the payment link to change the price amount.
If you explicitly set the amount when you create the session server-side it can't be tampered
But I saw to validate the link tamper and amount some use-shopping-cart package is used. But the issue is my app is not structured that way to implement right now. Or else would have done so. Any other solutions if you could give.
Oh you're concerned about the amount that's passed from your frontend to the backend? What's your pricing structure look like? Does the amount you're charging vary a lot?
Yeah kind of. ๐
Ok makes sense. Can you explain the pricing structure?
Pricing structure? I didn't understood ๐
So how does the amount vary? Are there a few options? Or does it depend on many factors? Just need more info here
Actually pricing is mainly changed from backend sanity headless cms. And there is multiple pricing according to currency of country.
Ok. I just need to know more about what part of the front end process you're concerned about. If pricing is controlled on the backend, why do you need to handle price tampering?
Now the issue is we are allowing our customers to retain the cart from local storage. And from that the price is also getting stored. That's the only issue.
Hm ok. I don't know how much I can advise on cart tampering specifically, but from the stripe side, if you have pre-defined price objects, that can help with tampering a bit since you'll be referencing price id's not amounts.
Wow that really a nice idea.
But how can I add the price_id's for more than 1 product? I have passed it for one product it's fine from that.
Can you help with that? And thank you for this ๐
price_data: {
currency: currency,
product_data: {
name: p.title,
images: [p.image.asset.url]
},
unit_amount: price,
},
will this work if I give price_id in place of amount for the unit_amount
So you wouldn't pass price_data. You would just pass the price: https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-line_items-price
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Recommend reading: https://stripe.com/docs/products-prices/manage-prices
Oh great! Then how to pass the name of the product and image
๐ stepping in as codename_duchess needs to step away
Hey
The product/image is created ahead of time in this case when you create the Price
Recommend reading fully through the guide shared above and taking a look at the API Reference
Hey, I did saw
const session = await stripe.checkout.sessions.create({
success_url: 'https://example.com/success',
cancel_url: 'https://example.com/cancel',
line_items: [
{price: 'price_H5ggYwtDq4fbrJ', quantity: 2},
],
mode: 'payment',
});
Just asking where to pass the image and name as it's showing in the doc
line_items.price_data.product_data.images
Right but your question was about how to not pass price_data and instead just pass price, right?
So when you create the Price object, you associate it with a Product object. That Product object has a set image/name: https://stripe.com/docs/api/products/create#create_product-name
No no let me be clear, I just want to pass the price_id as mentioned it would be more secure.
so in the process to pass the price_id I also need to pass the image and name of product.
So the image/name is created ahead of time here instead of inline
Yes so just like you create the Price object ahead of time you create the Product ahead of time
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Ohh now I got.
But already I had the setup done in sanity. Now I have to do that in stripe dashboard.
Not sure if that is a question? ๐
Haha. No thank you so much! Really appreciate!