#meldin6167

1 messages · Page 1 of 1 (latest)

ashen oceanBOT
green scaffold
#

hi there, do you have the event ID?

umbral whale
#

Hi

#

"id": "evt_1NpNb7GXOanXaNm0ANZlO296",

#

I am not sure but maybe the problem is in api version

green scaffold
#

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?

umbral whale
#

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

green scaffold
#

Ok, have you checked your server log and look for 500?

umbral whale
#

There is no 500 on server log

#

only 200 for invoice_payment_succesed

green scaffold
#

I mean the logs in your server, not Stripe Dashboard logs

umbral whale
#

Yes I understand, there is no 500 on server log.

green scaffold
#

Perhaps you want to check your server configuration and make sure it logs 500s?

umbral whale
#

500 I can see only on Stripe Dashboard

green scaffold
#

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

umbral whale
#

Thats correct, this is in dev mode. But the same thing is on Live mode trust me

green scaffold
#

Let me summarize, you have two endpoints that are currently listening to webhook events

  1. The local dev server through stripe listen command)
  2. 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)

umbral whale
#

That's why I am working all day long to fix this problem

#

it's wierd

green scaffold
#

You should check the other endpoint, have you checked its server log?

umbral whale
#

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

green scaffold
#

I hate to repeat but I mean have you checked your server log?

umbral whale
#

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) {

green scaffold
#

OK, looks like your endpoint is using live mode API key to access a resource created in test mode

umbral whale
#

How to fix this?

green scaffold
#

Is this endpoint for test mode or live mode? If it's for test mode, you should use test mode API key

umbral whale
#

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

green scaffold
#

But you registered the production webhook endpoint (we_1NnyEoGXOanXaNm0U05Mjn0l) in test mode.

umbral whale
#

Can I change that

green scaffold
#

Sure, you can remove this webhook endpoint and create a new one in live mode

umbral whale
#

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?

green scaffold
umbral whale
#

Thank you very much for your time