#meldin6167
1 messages · Page 1 of 1 (latest)
hi there, do you have the event ID?
Hi
"id": "evt_1NpNb7GXOanXaNm0ANZlO296",
I am not sure but maybe the problem is in api version
Thanks for the ID. The webhook delivery wasn't succeeded because your endpoint responded 500
have you checked you server log to find out why it returned 500 instead of 200?
I was running this localy and on the server log I have all 200 for invoice_payment_succed but for chekout.session.completed I dont see anything
Wait I thing is api version
No its not
same thing
500
Ok, have you checked your server log and look for 500?
I mean the logs in your server, not Stripe Dashboard logs
Yes I understand, there is no 500 on server log.
https://dashboard.stripe.com/test/events/evt_1NpNb7GXOanXaNm0ANZlO296 The Stripe event log shows your server returned 500
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
Perhaps you want to check your server configuration and make sure it logs 500s?
That's your local webhook endpoint running in dev server, if you check the log that I sent earlier, it's the webhook endpoint that you hosted in another URL that returned 500
Thats correct, this is in dev mode. But the same thing is on Live mode trust me
Let me summarize, you have two endpoints that are currently listening to webhook events
- The local dev server through stripe listen command)
- The webhook endpoint that deployed in another URL
Now the local webhook is acknowleding webhooks successfully (it returns 200), but the other endpoint doesn't (returns 500)
You should check the other endpoint, have you checked its server log?
const session = event.data.object;
// Handle the checkout.session.completed event
if (event.type === 'checkout.session.completed') {
const subscription = await stripe.subscriptions.retrieve(session.subscription);
if(!session?.metadata?.userId){
return new NextResponse("UserId is required ", { status: 400 });
}
// Add the user subscription to the database
await prisma_db.userSubscription.create({
data: {
userId: session?.metadata?.userId,
stripeCustomerId: subscription.customer,
stripeSubscriptionId: subscription.id,
stripePriceId: subscription.items.data[0].price.id,
stripeCurrentPeriodEnd: new Date(subscription.current_period_end * 1000),
},
});
}
if(event.type === "invoice_payment_succeeded"){
const subscription = await stripe.subscriptions.retrieve(
session.subscription
);
await prisma_db.userSubscription.update({
where: {
stripeSubscriptionId: subscription.id,
},
data:{
stripePriceId: subscription.items.data[0].price.id,
stripeCurrentPeriodEnd: new Date(
subscription.current_period_end * 1000),
}
});
}
I checked both endpoints
I hate to repeat but I mean have you checked your server log?
Sorry about that here is the server error: error StripeInvalidRequestError: No such subscription: 'sub_1NpNNPGXOanXaNm0kWutEydh'; a similar object exists in test mode, but a live mode key was used to make this request.
at StripeError.generate (/var/task/.next/server/chunks/3854.js:2648:20)
at res.toJSON.then.StripeAPIError.message (/var/task/.next/server/chunks/3854.js:6351:43)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
OK, looks like your endpoint is using live mode API key to access a resource created in test mode
How to fix this?
Is this endpoint for test mode or live mode? If it's for test mode, you should use test mode API key
localy when I run the app I am using stripe listen --forward-to localhost:3000/api/webhook
and I am using test api key
in production I have live key with the live webhook
But you registered the production webhook endpoint (we_1NnyEoGXOanXaNm0U05Mjn0l) in test mode.
Can I change that
Sure, you can remove this webhook endpoint and create a new one in live mode
Let me ask you this, when the user subscribe I can see his details on stripe dashboard. How long does it takes for money to get deposited on my bank account?
yes you can view subscription details in Dashboard https://dashboard.stripe.com/subscriptions
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
https://stripe.com/docs/payouts#payout-speed and here you can learn more about payout speed
Thank you very much for your time