#liam_api

1 messages ยท Page 1 of 1 (latest)

brisk sparrowBOT
#

๐Ÿ‘‹ Welcome to your new thread!

โฒ๏ธ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.

โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.

๐Ÿ”— This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1326496249347838044

๐Ÿ“ Have more to share? Add more details, code, screenshots, videos, etc. below.

Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.

subtle berry
#

Hi,

I think this should be a simple answee but I am calling a Stripe.Checdkout.Sessions.Create like this:

const session = await stripe.checkout.sessions.create({
  payment_method_types: ['card'],
  line_items: [
      {
          price_data: {
              currency: 'gbp',
              product_data: {
                  name: 'Buffer Solutions',
              },
              unit_amount: totalCostInPence,
          },
          quantity: 1,
      },
  ],
  mode: 'payment',
  success_url: 'https://oceangenesis.co.uk/payment-success',
  cancel_url: 'https://oceangenesis.co.uk/payment-cancel',

});

I am then trying to look at data in the charge.succeeded webhook. But i cant compare any common data between the two to know which event corresponds to which trnaaciton. I thought it would be payment intent ID or checkout session ID but this does not seem to be appearing in the response.

This is the response i am getting from charge.succeeded:

#

TLDR how do i find a common data point between tripe.checkout.sessions.create and charge.succeeded webhook.

near crane
#

This doesn't look right since charge.succeeded has a Charge object in the payload, but I see a Checkout Session object instead.

#

Oh, I see the correct payload when I fully open your snippet..

subtle berry
#

Sorry think i accidntly copy and pasted the enture terminal.

near crane
#

Is there a specific reason you're listening to charge.succeeded and not checkout.session.completed events?

brisk sparrowBOT
subtle berry
#
  1. I send the checkout URL to the website. 2. Customer fills in details and goes to success url. 3. Once payment is successful Stripe Calls my webhook with charge.succedded. 4. I take certain information from the payload such as card last 4 and brand.

However, i dont know how to idenitfy which customer the charge.succeeded has come from.

#

I am new to Stripe Webhooks as well.

real urchin
#

I wouldn't use charge.succeeded for fulfilment. If you're using Checkout then checkout.session.completed is what you need, and you can get additional objects from the fields on that event

subtle berry
#

ahh ok I need to put the last 4 digits and the card brand into the database though. So i can display the details to the customer on the website if they check.

#

So basically once the customer has been charged I can pop the payment infornation into the database. Then the fullfillment staff will ship the customers order.

real urchin
#

Yep, and you can get them via the payment_intent[payment_method] field

subtle berry
#

ahh ok thanks. I will give this ago now.

real urchin
#

You'll need to make an API request to retrieve the Payment Intent and expand the payment_method field

subtle berry
#

{
id: 'evt_1QewcXP7mRUqpFzxgCUOKrp8',
object: 'event',
api_version: '2024-06-20',
created: 1736332576,
data: {
object: {
id: 'cs_test_a10M1vd6UMxBfd9K7yrNmze1aREkvcK0WyC6e2iIHWFoUOlGUcApP3xsbo',
object: 'checkout.session',
adaptive_pricing: [Object],
after_expiration: null,
allow_promotion_codes: null,
amount_subtotal: 2797,
amount_total: 2797,
automatic_tax: [Object],
billing_address_collection: null,
cancel_url: 'https://oceangenesis.co.uk/payment-cancel',
client_reference_id: null,
client_secret: null,
consent: null,
consent_collection: null,
created: 1736332548,
currency: 'gbp',
currency_conversion: null,
custom_fields: [],
custom_text: [Object],
customer: null,
customer_creation: 'if_required',
customer_details: [Object],
customer_email: null,
expires_at: 1736418948,
invoice: null,
invoice_creation: [Object],
livemode: false,
locale: null,
metadata: {},
mode: 'payment',
payment_intent: 'pi_3QewcWP7mRUqpFzx1lJ1eLPv',
payment_link: null,
payment_method_collection: 'if_required',
payment_method_configuration_details: null,
payment_method_options: [Object],
payment_method_types: [Array],
payment_status: 'paid',
phone_number_collection: [Object],
recovered_from: null,
saved_payment_method_options: null,
setup_intent: null,
shipping_address_collection: null,
shipping_cost: null,
shipping_details: null,
shipping_options: [],
status: 'complete',
submit_type: null,
subscription: null,
success_url: 'https://oceangenesis.co.uk/payment-success',
total_details: [Object],
ui_mode: 'hosted',
url: null
}
},
livemode: false,
pending_webhooks: 2,
request: { id: null, idempotency_key: null },
type: 'checkout.session.completed'
}

#

ahhh i got this response from checkout.session.completed. Is this correct?

#

3

#

But i cant find payment_method ??

I found data.object.payment_method_types & data.object.payment_method_options

But these contain

{ card: { request_three_d_secure: 'automatic' } }
[ 'card' ]

real urchin
#

Yes, you need to take the pi_xxx ID from the payment_intent field and retrieve that object from the API, expanding the payment_method field