#tomh0027
1 messages · Page 1 of 1 (latest)
Not sure I fully grasp the question, can you elaborate?
here is my code
const session = await stripe.checkout.sessions.create({
line_items: [{ price: priceId, quantity: 1 }],
mode: "payment",
success_url: "http://localhost:5173/checkout",
customer: customerId,
});
the return value says payment status is unpaid
The code above only creates a Checkout Session object.
You'll need to redirect your customers to checkout URL and have them complete the flow
We have a step by step guide here
https://stripe.com/docs/payments/accept-a-payment?platform=web
success url you mean?
No, checkout URL.
What are you seeing in the response when you run the code you've shared?
{
id: 'cs_test_a18k4hdMEHWfspibY7FVVwqX3nErKqNBBJDPJU0oi7f6FYvek0JRXmmNSx',
object: 'checkout.session',
after_expiration: null,
allow_promotion_codes: null,
amount_subtotal: 100000,
amount_total: 100000,
automatic_tax: { enabled: false, status: null },
billing_address_collection: null,
cancel_url: null,
client_reference_id: null,
consent: null,
consent_collection: null,
created: 1693944790,
currency: 'usd',
currency_conversion: null,
custom_fields: [],
custom_text: { shipping_address: null, submit: null },
customer: 'cus_OYkePstGKJwZE9',
customer_creation: null,
customer_details: {
address: null,
email: 'lucas.wong.1118@gmail.com',
name: null,
phone: null,
tax_exempt: 'none',
tax_ids: null
},
customer_email: null,
expires_at: 1694031190,
invoice: null,
invoice_creation: { enabled: false, invoice_data: [Object] },
livemode: false,
locale: null,
metadata: {},
mode: 'payment',
payment_intent: null,
payment_link: null,
payment_method_collection: 'always',
payment_method_options: {},
payment_method_types: [ 'card', 'link' ],
payment_status: 'unpaid',
phone_number_collection: { enabled: false },
recovered_from: null,
setup_intent: null,
shipping_address_collection: null,
shipping_cost: null,
shipping_details: null,
shipping_options: [],
status: 'open',
submit_type: null,
subscription: null,
success_url: 'http://localhost:5173/checkout',
total_details: { amount_discount: 0, amount_shipping: 0, amount_tax: 0 },
url: 'https://checkout.stripe.com/c/pay/cs_test_a18k4hdMEHWfspibY7FVVwqX3nErKqNBBJDPJU0oi7f6FYvek0JRXmmNSx#fidkdWxOYHwnPyd1blpxYHZxWjA0SFxRdFFManJTZlZ9d0w9bXdwXG12TFRcMTA2Snc9fGFDRnFoXUZwXUhDRkpAMGtxPXFRblZMfzNtc3NUQFRLQzdjZ1dcNDxAcWBDTDJpdjBVMFZrUE50NTVRZHM8VH1nNicpJ2N3amhWYHdzYHcnP3F3cGApJ2lkfGpwcVF8dWAnPyd2bGtiaWBabHFgaCcpJ2BrZGdpYFVpZGZgbWppYWB3dic%2FcXdwYHgl'
}
see the url param
redirect user to the url?
this is same as creating payment link and use it, am I right?
PaymentLink is different as the URL for a Payment link doesn't change.
The code you're using above creates separate checkout session each time you call the API
is there a way I can use custom checkout page?
what I am trying to do is pay directly on this custom checkout page
You can't use/combine Checkout with Stripe Element. You can either use Stripe Checkout (stripe hosted payment page) OR create PaymentIntents and use them with Elements.
That looks like PaymentElement, we have a step-by-step guide here
https://stripe.com/docs/payments/accept-a-payment?platform=web&ui=elements
but I am going to let users buy premade product using price id
I tried this, but this seems not compatible with price id
Yeah Prices are not compatible with PaymentIntents.
You can either use Stripe Checkout
OR
1/ you can create a one-off invoice with price IDs as line items
2/ finalize the invoice
3/ use the client-secret of the PaymentIntent generated by the invoice with the PaymentElement
https://stripe.com/docs/api/invoices/object#invoice_object-payment_intent
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
so I need to create an invoice using price id?
Yes
but I can't find any parameter to pass price id
Ah you'd need to create an invoice item
https://stripe.com/docs/api/invoiceitems/create
We have a guide here
https://stripe.com/docs/invoicing/integration
so first create invoice and then invoice item with the invoice id and price id?
Yeah please follow the guide
and how can I apply promo code here?
👋 Stepping in for my teammate. You can add a coupon to the invoice: https://stripe.com/docs/api/invoices/create#create_invoice-discounts
what do I have to pass?
coupon id?
I have already created coupon and promo code for customers
on the stripe dashboard
If you've already created a coupon that applies to certain products only, I recommend passing that coupon ID when you create the invoice. If you've already created a coupon and added that coupon to the customer, there's no need to pass the coupon ID again; the coupon on the customer will be used automatically as long as you include that customer's ID when creating the invoice: https://stripe.com/docs/api/invoices/create#create_invoice-customer
This is mentioned in the description included in the screenshot you shared above
when finalizing invoice, whice id do I have to pass? id of invoice or invoice item?
I really recommend testing this all out. Finalizing an invoice requires the invoice ID: https://stripe.com/docs/api/invoices/finalize
then what's the different between invoice and invoice item?
An invoice is the parent object. An invoice can have many items. For example, if you're receiving an invoice for a furniture order, you'll get a single invoice with multiple items items: 1 sofa, 3 rugs, 3 lamps
I have this error
"Payment details were collected through Stripe Elements using automatic payment methods and cannot be confirmed with a Payment Intent configured with payment_method_types."
Can you share the request ID for that request, or the Payment Intent ID you tried to confirm?
here it is
pi_3Nn6xlIowVcSxrI81Fxx79r4
I grabbed this payment id from the invoice
const finalizedInvoice = await stripe.invoices.finalizeInvoice(
invoice?.id
);
from the above finalized invoice
looking
Okay, I see you're using the deferred intent flow when rendering the PaymentElement: https://stripe.com/docs/payments/accept-a-payment-deferred
You shouldn't use this flow for this particular scenario. When you finalize an invoice, Stripe automatically creates the PaymentIntent associated with that invoice (if the invoice has an amount due). You should use that PaymentIntent's client secret to create the PaymentElement.
Threads in this channel aren't long lived. We typically keep threads open for ~15 min