#Dakpan

1 messages · Page 1 of 1 (latest)

gilded rampartBOT
brave dome
#

This will only give me the charge information, like the paymentmethod/amount etc but not the items

haughty root
#

Hi 👋 line-item level details are not on Charge objects, they'll be on a higher order object. What objects are you using that is causing Charges to be created?

brave dome
#
    const checkoutSession = await stripe.checkout.sessions.create({
        line_items: cartItems,
        mode: 'payment',
        payment_method_types: ["ideal", "paypal", "bancontact", "card"],
        customer: customer.id,
        metadata: {
            data: JSON.stringify(items)
        },
        success_url: 'http://localhost:3000/account',
        cancel_url: 'http://localhost:3000/winkelwagen',
    });
#

Its also not saved in the metadata but it is when I go to the stripe dashboard

haughty root
#

Metadata isn't copied from one object to another, so it's expected that the metadata you provided there is only on the Checkout Session object, it's not carried through to the resulting Charge object that is created.

brave dome
#

Ah alr

#

But how can I get the items of the charges

haughty root
#

Since you're using Checkout Sessions, it seems like that is the object you'll likely want to look at to get line-item details. Are you trying to do this after a customer has completed a purchase?

brave dome
#

So where can I get the list of checkouts?

#

*how

haughty root
#

If you only have the Charge's ID, you'll need to build a flow that gets from the Charge object to the related Checkout Session.

You can retrieve the Charge, and then on the Charge object you'll find a payment_intent field which contains the ID of the related Payment Intent (should have a pi_ prefix).
https://stripe.com/docs/api/charges/object#charge_object-payment_intent

With the Payment Intent ID, you can make a request to list Checkout Sessions:
https://stripe.com/docs/api/checkout/sessions/list
when doing so, provide the ID of the Payment Intent from the Charge to the payment_intent field:
https://stripe.com/docs/api/checkout/sessions/list#list_checkout_sessions-payment_intent
doing so will cause us to only return the Checkout Session that created that Payment Intent (and therefore the Charge you started with). You will also want to use expand to expand the data.line_items field, so that you can see the contents of the sessoin's line items in this response without needing to make another request.
https://stripe.com/docs/api/expanding_objects

brave dome
#

@haughty root After a long session of researching and looking in the docs, I figured out that this doesn't work for me. Because I'm not creating a intent.

haughty root
#

Checkout Sessions automatically create Payment Intents when the customer triggers payment.

brave dome
#

{
id: 'cs_test_a1Fzeo5OkqrRVtbt1RdumkmXvNEgKYlV2hv9yu3wxyTRTTDuH7D9lMYOgT',
object: 'checkout.session',
after_expiration: null,
allow_promotion_codes: null,
amount_subtotal: 3500,
amount_total: 4235,
automatic_tax: [Object],
billing_address_collection: null,
cancel_url: 'https://localhost:3000/winkelwagen',
client_reference_id: null,
client_secret: null,
consent: null,
consent_collection: null,
created: 1698083556,
currency: 'eur',
currency_conversion: null,
custom_fields: [],
custom_text: [Object],
customer: null,
customer_creation: 'if_required',
customer_details: null,
customer_email: null,
expires_at: 1698169956,
invoice: null,
invoice_creation: [Object],
livemode: false,
locale: null,
metadata: {},
mode: 'payment',
payment_intent: null,
payment_link: null,
payment_method_collection: 'if_required',
payment_method_configuration_details: null,
payment_method_options: {},
payment_method_types: [Array],
payment_status: 'unpaid',
phone_number_collection: [Object],
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:3000/account',
total_details: [Object],
ui_mode: 'hosted',
url: 'https://checkout.stripe.com/c/pay/cs_test_a1Fzeo5OkqrRVtbt1RdumkmXvNEgKYlV2hv9yu3wxyTRTTDuH7D9lMYOgT#fidkdWxOYHwnPyd1blpxYHZxWjA0SjFUMW9AS21qb3JHYWZ1YW51QDV8bHx9bkNnMFNiT1RpS2pUb2w8cGNraGM9MVVoQWhzY0Z9YDxcakZsREIycmtufERzYTVOZlROVUNRMEFncWMxUzFpNTVwaVxVSHFjUScpJ2N3amhWYHdzYHcnP3F3cGApJ2lkfGpwcVF8dWAnPyd2bGtiaWBabHFgaCcpJ2BrZGdpYFVpZGZgbWppYWB3dic%2FcXdwYHgl'
},

#

payment_intent: null,

haughty root
#

That Checkout Session hasn't been completed, as it's status is still open

brave dome
#

Ah ur right

#

Yeah my other does have

#

But what are the params

haughty root
#

Doesn't matter.
Edit: sorry, may have sent that too soon. I meant the parameters of the Payment Intent don't matter.

brave dome
#

const session = await stripe.checkout.sessions.list()

#

Thx but what for params should I give with the request so it automatically only filters the object with the specified intent?

haughty root
brave dome
#

Ah oke it works

#

I got the session now but how to retrieve the line_items?

haughty root