#tomh0027

1 messages · Page 1 of 1 (latest)

devout remnantBOT
violet hinge
#

Not sure I fully grasp the question, can you elaborate?

median hatch
#

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

violet hinge
median hatch
#

success url you mean?

violet hinge
#

No, checkout URL.

What are you seeing in the response when you run the code you've shared?

median hatch
#
{
  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'
}
violet hinge
#

see the url param

median hatch
#

redirect user to the url?

violet hinge
#

yes

#

that's where they'll provide there payment method information

median hatch
#

this is same as creating payment link and use it, am I right?

violet hinge
#

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

median hatch
#

is there a way I can use custom checkout page?

#

what I am trying to do is pay directly on this custom checkout page

violet hinge
median hatch
#

but I am going to let users buy premade product using price id

median hatch
violet hinge
#

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

median hatch
#

so I need to create an invoice using price id?

devout remnantBOT
violet hinge
#

Yes

median hatch
#

but I can't find any parameter to pass price id

violet hinge
median hatch
#

so first create invoice and then invoice item with the invoice id and price id?

violet hinge
#

Yeah please follow the guide

median hatch
#

and how can I apply promo code here?

hollow yoke
median hatch
#

what do I have to pass?
coupon id?

#

I have already created coupon and promo code for customers

#

on the stripe dashboard

hollow yoke
#

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

median hatch
#

when finalizing invoice, whice id do I have to pass? id of invoice or invoice item?

hollow yoke
median hatch
#

then what's the different between invoice and invoice item?

hollow yoke
#

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

median hatch
#

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."
hollow yoke
#

Can you share the request ID for that request, or the Payment Intent ID you tried to confirm?

median hatch
#

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

hollow yoke
#

looking

median hatch
#

will you please leave this thread open?

#

I need to be off for some time

hollow yoke
#

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.

hollow yoke