#k-nicholas_webhooks

1 messages ยท Page 1 of 1 (latest)

glossy flickerBOT
#

๐Ÿ‘‹ 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/1465632516638507098

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

buoyant hazel
#

here's how we create our checkout session

const session = await stripe.checkout.sessions.create(
        {
            client_reference_id: cartId,
            metadata: {
                ...
            },
            line_items: [
                ...
            ],
            payment_intent_data: {
                application_fee_amount: calculateApplicationFee(
                    ...
                ),
                metadata: {
                    ...
                },
            },
            mode: "payment",
            ui_mode: "custom",
            return_url: ...,
        },
        {
            stripeAccount: connectedAccStripeAccId,
        },
    );
crude kestrel
#

๐Ÿ‘‹ Hi there! Let me take a look

buoyant hazel
#

opsss forgot to mentioned. we cant find the value in the following webhook event:

- checkout.session.async_payment_failed
- checkout.session.async_payment_succeeded
- checkout.session.completed
- checkout.session.expired
crude kestrel
#

Yeah, I don't believe you will be able to get charge information from those webhook event types.

You would have to listen to other event types, like payment_intent.succeeded. Though there you should be aware that the fee information won't be available immediately by default, due to asynchronous capture: https://docs.stripe.com/payments/payment-intents/asynchronous-capture

buoyant hazel
#

yeap, we are happy to listen to a different event to get the fees info. we dont need this information immediately, as it more for daily reporting.

crude kestrel
#

But even there, you would still need to look up the Balance Transaction object associated with the payment. This isn't something that's included directly in webhook events

buoyant hazel
#

yea, you are right. i just had a look at "payment_intent.succeeded" event and i dont see the card processing fee.

i can see the "application_fee_amount": 375 only. but the main thing we need is actually the card processing fee

crude kestrel
#

Let me find you an example

#

So if I use the Stripe CLI to make an API call, looking up a particular Payment Intent, I can see the balance_transaction object (txn_โ€ฆ) which contains the fee details:
stripe get pi_3Su88A6oEAX7HoXL17swNCM4 --expand latest_charge.balance_transaction

    "balance_transaction": {
      "id": "txn_3Su88A6oEAX7HoXL1CSYFUbE",
      "object": "balance_transaction",
      "amount": 3000,
      "available_on": 1770076800,
      "balance_type": "payments",
      "created": 1769504415,
      "currency": "eur",
      "description": "Subscription creation",
      "exchange_rate": null,
      "fee": 123,
      "fee_details": [
        {
          "amount": 123,
          "application": null,
          "currency": "eur",
          "description": "Stripe processing fees",
          "type": "stripe_fee"
        }
      ],
      "net": 2877,
      "reporting_category": "charge",
      "source": "ch_3Su88A6oEAX7HoXL11P6NxPq",
      "status": "pending",
      "type": "charge"
    },
#

Balance Transactions just aren't included in any webhook payloads, I believe. So you need to fetch them via the API, based on a Payment Intent or Charge ID

buoyant hazel
#

thanks! btw, is there any api limit that we can hit this stripe.paymentIntents.retrieve() API? we just want to make sure we dont cause outage for our normal using thats trying to pay.

we will make sure to store the fees value in DB, once we retrieve it. (so will only be calling once per payment_intent)

crude kestrel
#

But either approach is fine ๐Ÿ™‚

buoyant hazel
#

btw, if we want to use the balance transactions list API. what value do we use to correlate back to the transaction?

#

the example is showing

"id": "txn_1MiN3gLkdIwHu7ixxapQrznl"
"source": "tr_1MiN3gLkdIwHu7ixNCZvFdgA",

but i dont see those value in checkout_session / paymetn_intent webhook

crude kestrel
#

Yeah, it's the source field, like in my example above you can see the associated Charge. Your example looks like that was a balance transaction for an application fee, rather than the actual payment. You can differentiate based on the Balance Transaction type.

buoyant hazel
#

ohh okay so we will get the ch_ value back in source field

crude kestrel
#

Something like this would get you Balance Transactions for payments, while also including the Charge, with its Payment Method ID:
stripe balance_transactions list --type charge --expand data.source

buoyant hazel
#

nice. yea that works too

#

btw, when we call --expand. is that two API call or one? like in term of rate limits

crude kestrel
#

It's a single API call ๐Ÿ™‚

buoyant hazel
#

nice. and also doesnt matter how many transactions was returned. is count as one API call right? (main thing, im trying to work out here, is there any other limits i should know)

#

and how many transactions can it return? is there pagination on this that we need to call for next page?

crude kestrel
#

Yup, it's one API call. By default the limit is 10 results, but you can set it to 100. There is then pagination: https://docs.stripe.com/pagination
If you're using a Stripe SDK, I recommend using auto-pagination

buoyant hazel
#

got it. thank you!

#

thanks for the help!

crude kestrel
#

You're welcome! ๐Ÿ™‚