#vickygiyst
1 messages · Page 1 of 1 (latest)
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.
Invoice object: https://stripe.com/docs/api/invoices/object
Which contains the subscription ID and the customer IR.
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
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.
They will have the IDs of these objects:
- https://stripe.com/docs/api/invoices/object#invoice_object-customer
- https://stripe.com/docs/api/invoices/object#invoice_object-subscription
And then you can make extra API calls to retrieve the full objects
you mean, i have to call the stripe APIs?
Yes
could you please tell me how to call, the URL and payload ,type of APIS
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).
Retrieve the customer with its ID: https://stripe.com/docs/api/customers/retrieve
Retrieve the subscription with its ID: https://stripe.com/docs/api/subscriptions/retrieve
oh great! thank you so much!
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
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 ?
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
So you won't have an invoice.created event.
Can you share the Subscription Id ?
yes, i think so. i thought post payment this would be the event
You are creating Subscription using Stripe Checkout ?
yes
Can you share its Id please ?
const session = await stripe.checkout.sessions.create
i m using this method to make a subscription for a user
sorry, ID of what?
of the subscription created.
Can you share the Checkout Session Id ?
si_Ne3OK5b1D6n6SX
this is the subscription ID of a customer
cs_test_a13lVmtCkyuEk7kQFgcFCz0e4lNgjk3d05trHdZL4POkxzIsyVxl6bmvlO
this is the checkout session id
cs_test_a13lVmtCkyuEk7kQFgcFCz0e4lNgjk3d05trHdZL4POkxzIsyVxl6bmvlO
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
yes, i can share the code
is it running ?
are you using stripe cli in order to listen to the event locally ?
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
What is its API ?
You need to register it in your Stripe Dashboard then:
https://dashboard.stripe.com/test/webhooks/create
okay, i got the event after updating the events on existing webhook end point
Hi! I'm taking over my colleague. Please, give me a moment to catch up.
Is there anything else I can help with?