#nacho_446

1 messages · Page 1 of 1 (latest)

graceful jacinthBOT
craggy fern
#

hi! the error message seems self explanatory

#

you need to create a recurring Price inside price_data.

wooden copper
#

Hold on so I check that

#

So with this now I set

recurring: { interval: 'month' },

I normally set a metadata to transfer the user before, but I don’t know if the metadata will return on the next payment

#

How can u track the payment to the user when the next payment in a month comes

craggy fern
#

use subscription_data.metadata instead

#

then when you get recurring Invoice webhooks, you can look at the Subscription object to find that metadata

wooden copper
#

The reoccurring invoice webhook is on invoice.paid right?

wooden copper
#

The only problem am having now is handling the webhook

public static handleStripeWebHook = async (req: Request, res: Response) => {
const result = await SchoolService.stripeWebHook({
data: req.body,
sig: req.headers['stripe-signature'] as string,
});

return res.send(
  successResponse({
    status: 200,
    data: result,
  }),
);

};

Instead the stripeWebhook

export default wrapServiceAction({
schema: StripeEvent,
handler: async (params: StripeEvent) => {
const { sig, data } = params;

console.log(data.body);
console.log(sig);
switch (data.body.type) {
  case 'checkout.session.completed':
   
    break;
  case 'checkout.session.successed':
    // const paymentMethod = event.data.object;

    break;
  default:
    // Unexpected event type
    console.log(`Unhandled event type ${data.body.type as string}.`);
}

},
});

craggy fern
#

and what problem would you be having?

wooden copper
#

I don’t know if this is the right way to receive the webhook body

graceful jacinthBOT
craggy fern
#

did it work when you ran the code or tested it? 🙂

wooden copper
#

I tried setting up the webhook locally on my Mac but couldn’t and we’ll it’s live it’s harder to manage

craggy fern
#

I tried setting up the webhook locally on my Mac but couldn’t
then I suggest trying to fix that! if you have more information about what you tried, what didn't work, what errors you got etc, that's what we are here to help with.

wooden copper
#

Ok thanks this has been very helpful I will try the local webhook again

#

Is it subscription_details or subscription_data ?

obsidian sleet
#

subscription_data is the parent hash

wooden copper
#

On the response for invoice.paid I can see subscription_details that has metadata in it

#

Ok

obsidian sleet
#

Yes, we include a snapshot of the metadata from the Subscription on Invoices

wooden copper
#

Ok for that invoice.paid webhook I should be looking for subscription_data not subscription_details

obsidian sleet
#

No, on the invoice.paid event the metdata will be in a subscription_details hash

#

The subscription_data is the parameter/hash you pass on your metadata to on Checkout Session creation

wooden copper
#

Ok understood

#

My webhook fails for checkout.session.completed

obsidian sleet
#

What error(s) are you seeing?

wooden copper
#

When the user makes his first payment that starts the recurring payment what webhook should I check customer.subscription.created?

#

Http 500

obsidian sleet
# wooden copper Http 500

Sounds like an error thrown by your webhook code. You should add logging yo your code to determine where that is thrown

obsidian sleet
#

Depends what data you want/need I guess

wooden copper
#

I just need the metadata so I can get the userId from it.

The error is on the stripe dashboard, under webhook that’s where am getting the 500

obsidian sleet
#

Yep, that 500 is what your webhook endpoint is returning to us. A 500 error is generally indicative of code throwing an error, so I suspect there's an issue in your webhook logic

#

You'll need to add logging to your code to determine what the issue is

wooden copper
#

Can this error occur when am using one test details for two different applications.

On one application am check for checkout.session.completed, so it hitting that endpoint with this details will try 500

obsidian sleet
#

Sure, potentially. Hard to know without seeing the code

#

But you should probably add proper error handling in your code and that will help you determine the issue. Otherwise you're just going to be guessing