#mboras_webhook-payments-subscriptions

1 messages ยท Page 1 of 1 (latest)

ocean shellBOT
#

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

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

brittle oceanBOT
sterile lantern
#

Hi ๐Ÿ‘‹

Whether or not to create a new webhook endpoint is up to you. However, as long as you can build logic to handle multiple types of events there is nothing wrong with listening to multiple events on a single webhook endpoint.

#

As long as you are able to return a 200 status response quickly

fading comet
#

Is event
invoice.payment_succeeded
legit for listening on succesfful payment in stripe checkout?

#

I'll see in my logs difference between subscription and one-time payment and I'll handle that logic

sterile lantern
#

Only if you have configured Stripe Checkout to generate invoices

fading comet
#

where I can see that?

sterile lantern
#

Otherwise you should listen to payment_intent.succeeded

fading comet
#

I've been assigned this project and I'm now checking

sterile lantern
fading comet
sterile lantern
#

No. But that simply indicates the customer completed the checkout session

fading comet
sterile lantern
#

For asynchronous payment methods they can still fail after the customer has cmpleted the session

#

Correct

fading comet
sterile lantern
#

Okay but I would still recommend listening to payment_intent.succeeded

fading comet
#

To summarize
I'll then create another webhook to listen on payment_intent.succeeded and in creation of checkout I'll pass send of invoice and that's it

sterile lantern
#

You can create another webhook or simply add logic to handle events with the different type to your current webhook

#

payment_intent.succeeded is triggered both from successful one-time and subscription payments

fading comet
#

I'll create another one and I'll ignore in that one subscription payments.

How can I differentiate one-tiome a

#

one-time and subscription payment

#

export const paymentSuccessEndpoint = functions.https.onRequest(
async (request, response) => {
response.set('Access-Control-Allow-Origin', '*');
response.set('Access-Control-Allow-Credentials', 'true'); // vital

if (request.method === 'OPTIONS') {
  // Send response to OPTIONS requests
  response.set('Access-Control-Allow-Methods', 'GET');
  response.set('Access-Control-Allow-Headers', 'Content-Type');
  response.set('Access-Control-Max-Age', '3600');
  response.status(204).send('');
  return;
}

try {
  console.log('Data', request.body.data.object);
  response
    .set('Access-Control-Allow-Origin', '*')
    .status(200)
    .send();
  return;
} catch (e) {
  console.error(e);
  response
    .set('Access-Control-Allow-Origin', '*')
    .status(500)
    .send();
  return;
}

},
);

#

if you have that information prepared somewhere?

#

before I manually check in logs ๐Ÿ˜„

sterile lantern
#

Subscription payments will come from a Invoice and the Invoice object will include the ID of a subscription

fading comet
#

"data": {
"object": {
"id": "in_xxx",
"object": "invoice",

Like this?

sterile lantern
#

The data object will be an invoice only for invoice.* events

fading comet
#

"data": {
"object": {
"id": "cs_live_123",
"object": "checkout.session",

and this for one-time paymnet

sterile lantern
#

Only if your integration only uses Checkout Sessions in mode payment

#

If you use them for mode subscription then it could contain payments for subscriptions

fading comet
#

ok

#

I'll handle this

#

tnx

#

โค๏ธ

#

you were really helpful

sterile lantern
#

Great ๐ŸŽ‰ Happy to help ๐Ÿ™‚

ocean shellBOT