#Dakpan
1 messages · Page 1 of 1 (latest)
This will only give me the charge information, like the paymentmethod/amount etc but not the items
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?
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
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.
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?
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
@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.
Checkout Sessions automatically create Payment Intents when the customer triggers payment.
{
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,
That Checkout Session hasn't been completed, as it's status is still open
Doesn't matter.
Edit: sorry, may have sent that too soon. I meant the parameters of the Payment Intent don't matter.
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?
You'll provide the ID of the Payment Intent to the payment_intent field.
https://stripe.com/docs/api/checkout/sessions/list#list_checkout_sessions-payment_intent
If you use expand as part of that list request to expand data.line_items, then they should be included in the response. Please let me know if that doesn't align with what you're seeing.
https://stripe.com/docs/api/expanding_objects
Otherwise you'll need to make another request to retrieve the line items specifically:
https://stripe.com/docs/api/checkout/sessions/line_items