#vickygiyst

1 messages · Page 1 of 1 (latest)

twilit tartanBOT
dull yew
#

Hi there!

#

For this you would use webhook events

#

For example listen to invoice.paid, which contains an invoice object. And from there you can retrieve all the information you need.

fast briar
#

okay

#

this is my webhook code

#

// Handle the event
switch (event.type) {
case 'payment_intent.succeeded':
const paymentIntent = event.data.object;
console.log('PaymentIntent was successful!');
break;
case 'payment_method.attached':
const paymentMethod = event.data.object;
console.log('PaymentMethod was attached to a Customer!');
break;
// ... handle other event types
default:
console.log(Unhandled event type ${event.type});
}

#

and everytime i make a payment ,it goes to default one and shows customer created event, i dont have any other event related to subscription

dull yew
#

Check your webhook endpoint in your. Stripe dashboard to make sure you are listening to invoice.paid. Then update your code to add a case for invoice.paid.

fast briar
#

okay

#

so this invoice paid will have both subscription and customer object?

dull yew
fast briar
#

you mean, i have to call the stripe APIs?

dull yew
#

Yes

fast briar
#

could you please tell me how to call, the URL and payload ,type of APIS

dull yew
#

The webhook payloads contain an invoice object, which has a customer ID and subscripiton ID. Then you make API calls to Stripe to retrieve the customer object (with its ID) and the subscription object (with its ID).

fast briar
#

oh great! thank you so much!

twilit tartanBOT
fast briar
#

Hi There

#

i have used the event, invoice.paid, but i didnt get that event on my consold after webhook called

#

switch (event.type) {
case 'invoice.paid':
const invoicePaid = event.data.object;
console.log(invoicePaid,invoicePaid);
// Then define and call a function to handle the event invoice.paid
break;
case 'payment_intent.succeeded':
const paymentIntent = event.data.object;
console.log('PaymentIntent was successful!');
break;
case 'payment_method.attached':
const paymentMethod = event.data.object;
console.log('PaymentMethod was attached to a Customer!');
break;
case 'invoice.created':
const invoiceCreated = event.data.object;
console.log(invoiceCreated,invoiceCreated);
// Then define and call a function to handle the event invoice.created
break;

// ... handle other event types
default:
  console.log(`Unhandled event type ${event.type}`);

}

#

this is my code

#

this is my console

#

POST /payment/create-checkout-session 303 - - 544.153 ms
Unhandled event type customer.created
Unhandled event type customer.updated
PaymentIntent was successful!
Unhandled event type payment_intent.created

ripe flume
#

i tried to get the invoice paid event from webhook, but everytime a pyment is successful, i get payment intent successful event
You are creating a Checkout Session here, without invoice no ?

#

Can you share the invoice Id ?

fast briar
#

You are creating a Checkout Session here, without invoice no ?--yes

#

where i will get the invoice ID

#

i was told above to use this event to get the subscription and custimer object

#

post payment is successful

ripe flume
ripe flume
fast briar
#

yes, i think so. i thought post payment this would be the event

ripe flume
#

You are creating Subscription using Stripe Checkout ?

fast briar
#

yes

ripe flume
#

Can you share its Id please ?

fast briar
#

const session = await stripe.checkout.sessions.create

#

i m using this method to make a subscription for a user

#

sorry, ID of what?

ripe flume
#

Can you share the Checkout Session Id ?

fast briar
#

si_Ne3OK5b1D6n6SX

#

this is the subscription ID of a customer

#

cs_test_a13lVmtCkyuEk7kQFgcFCz0e4lNgjk3d05trHdZL4POkxzIsyVxl6bmvlO

#

this is the checkout session id

fast briar
ripe flume
#

thanks for sharing let me check ..

#

I can see that there is an event invoice.created generated for that Subscription, this is its Id evt_1MslHgKGE0YlJ015k5SMak9K

#

Are you having a webhook endpoint listening to that event ?

#

it looks no

fast briar
#

yes, i can share the code

ripe flume
#

are you using stripe cli in order to listen to the event locally ?

fast briar
#

yes, i can see the console

#

no, the webhook api is live

#

its not local

#

POST /payment/create-checkout-session 303 - - 527.119 ms
Unhandled event type customer.created
Unhandled event type customer.updated
PaymentIntent was successful!
Unhandled event type payment_intent.created

#

this is the log of webhook

ripe flume
twilit tartanBOT
fast briar
#

this is the webhook api end point created on my server

ripe flume
fast briar
#

okay, i got the event after updating the events on existing webhook end point

icy grail
#

Hi! I'm taking over my colleague. Please, give me a moment to catch up.

icy grail