#rezamirzad

1 messages · Page 1 of 1 (latest)

whole viperBOT
echo goblet
#

hi! well the main thing is to create the webhook on your Stripe dashboard. https://stripe.com/docs/webhooks/go-live

do you have more details, which part specifically is not working, do you have an example Event ID evt_xxx with a problem?

somber aspen
#

an example: evt_3MdW3YGMR3u9Lz7012LP256Q

here is my code:

`async webhookPost(ctx: Koa.ParameterizedContext): Promise<void> {
const webhook = ctx.request.body as {
type?: string;
data?: {
object: {
id: string;
description: string;
status: string;
};
};
};
const quotation = await this.ctx.plugins.prisma.quotation.findUnique({
where: {
uuid: webhook.data.object.description,
},
});
if (quotation) {
const club = await this.ctx.plugins.prisma.club.create({
data: {
name: quotation.clubName,
program: {
create: {},
},
},
});
}

ctx.status = 200;
ctx.response.status = 200;
ctx.response.set('Content-Type', 'application/json');
ctx.response.body = JSON.stringify({received: true});
console.log(ctx.response);

}`

#

it seems that the code does not even enter this function.
while the exact same code runs perfectly in local environment

#

this one "evt_3MdW3YGMR3u9Lz7012LP256Q"

comes directly from my deployed web application

echo goblet
#

maybe your server is misconfigured or this Koa server framework (?) you're using needs to be configured differently. If it helps, Stripe sends the request to you using Content-Type: application/json; charset=utf-8

somber aspen
#

looking at the gogole cloud firewalls and trying to configure it

echo goblet
#

well the timeout was more when you were using :8080 in your URL

#

it seems after you changed that, we can connect to the server, but you're returning this error about the POST data format now

somber aspen
#

just set the firewall rule to allow 0.0.0.0/0

and still same issue with ""evt_3MdZBlGMR3u9Lz701xZsakiL"

echo goblet
somber aspen
#

yes, and what might be the reason?
i am sorry to insist, but I have been struggling with this for the past few days, and getting desperate

echo goblet
#

the reason would seem to be that this Koa server framework (?) you're using needs to be configured differently so it can accept a Content-Type other than form-data. If it helps, Stripe sends the request to you using Content-Type: application/json; charset=utf-8

somber aspen
#

i checked, and i am indeed receiving the request in the correct format

echo goblet
#

so where in your code is that 'Invalid argument' error getting thrown from?

somber aspen
#

with a console.log, I see this as the request body received:

{ id: 'evt_3MdZRSGMR3u9Lz701Dvu8PSC', object: 'event', api_version: '2022-11-15', created: 1676899808, data: { object: { id: 'pi_3MdZRSGMR3u9Lz701G0PN7gm', object: 'payment_intent', amount: 2000, amount_capturable: 0, amount_details: [Object], amount_received: 2000, application: null, application_fee_amount: null, automatic_payment_methods: null, canceled_at: null, cancellation_reason: null, capture_method: 'automatic', client_secret: 'pi_3MdZRSGMR3u9Lz701G0PN7gm_secret_zVevKGFiMsDGgLFXvs5sFFbHh', confirmation_method: 'automatic', created: 1676899806, currency: 'usd', customer: null, description: '(created by Stripe CLI)', invoice: null, last_payment_error: null, latest_charge: 'ch_3MdZRSGMR3u9Lz701o1ZULI8', livemode: false, metadata: {}, next_action: null, on_behalf_of: null, payment_method: 'pm_1MdZRSGMR3u9Lz70GaRrsPD0', payment_method_options: [Object], payment_method_types: [Array], processing: null, receipt_email: null, review: null, setup_future_usage: null, shipping: [Object], source: null, statement_descriptor: null, statement_descriptor_suffix: null, status: 'succeeded', transfer_data: null, transfer_group: null } }, livemode: false, pending_webhooks: 3, request: { id: 'req_SlQJu9lDBGxGMu', idempotency_key: '4fbb593c-897b-4427-8dd4-f6fa88d7984c' }, type: 'payment_intent.succeeded' }

echo goblet
#

cool so that part works then

#

so is the error coming from later, when you try to send us a response?

 ctx.response.set('Content-Type', 'application/json');
    ctx.response.body = JSON.stringify({received: true});
    console.log(ctx.response);
#

you can remove all that code if you want, we don't use the response you send us(other than to show it to you on the Stripe dashboard)

somber aspen
#

all i need my code to be able to do, is to get the value of "description", which would actually be a UUID, and perform some actions on my data base.

somber aspen
echo goblet
#

it's your code, all I see is what Stripe sends your server and what your server responds, you have access to the code to debug and add logs etc

somber aspen
#

one thing though

i am trigegring the staging webhook via the CLI, and all the modifications you told me, are done locally

i am not sure if this is the way to test

echo goblet
somber aspen
#

let me deploy then

#

still deploying

#

still same error on "evt_3MdZkTGMR3u9Lz700xU6dvDM"

echo goblet
#

have you made progress determining what causes that or where exactly the code throws that error?

#

for example does the webhookPost function even get called(a log line at the very start of it, and check for that in your logs), does it throw this error later when you're returning the response, something else?

somber aspen
#

well, all the code that is deployed is this

async webhookPost(ctx: Koa.ParameterizedContext): Promise<void> { console.log(ctx.request.body); const webhook = ctx.request.body as { type?: string; data?: { object: { id: string; description: string; status: string; }; }; }; if (webhook.type === 'payment_intent.succeeded') { console.log('SUCEEDED'); const quotation = await this.ctx.plugins.prisma.quotation.findUnique({ where: { uuid: webhook.data.object.description, }, }); if (quotation) { const club = await this.ctx.plugins.prisma.club.create({ data: { name: quotation.clubName, }, }); } }

i do not see anywhere that would cause any problem or error

echo goblet
#

console.log(ctx.request.body);
does that line print something you see in your logs?

#

i do not see anywhere that would cause any problem or error
that snippet of code you show might be fine, but the if the error message is coming from how your server is handling the incoming request at a lower level, the problem might be more in configuration things with how your Koa server is set up, you should try to consult documentation there to see how you can adjust the Content-Types it can accept if that seems to be what's happening.

somber aspen
#

well, here is my problem, i do not know where to look for the console.log outputs in google cloud 🥲

echo goblet
#

neither do I

#

you're the developer working with Google Cloud so you'll need to research this so you can more effectively debug your software deployed on that platform

somber aspen
#

what if the console.log is not in the logs?
it means that the webhook does not even get triggered, right?
if yes, any ideas why it might be?

grizzled bluff
#

Hi! I'm taking over this thread.

#

it means that the webhook does not even get triggered, right?
Yes, or there's an error that happens before the console.log

somber aspen
#

hi

i changed the console.log to this:

async webhookPost(ctx: Context): Promise<void> { console.log(JSON.stringify('TRIGGERED!!!'));

so it would be printed just when the webhook is triggered

but still nothing

grizzled bluff
#

Sorry not sure how to help, I'm not familiar with Google Cloud.

#

How are you triggering the events?

somber aspen
#

with the payment_intent.succeeded trigger

#

it works perfectly in local, but the same code does not event get called on google cloud deployed version of the same code!

grizzled bluff
#

And are you forwarding the event to the correct URL?

somber aspen
#

what do you mean by that?

grizzled bluff
#

If you are using the CLI to trigger events, you want the events to be forwarded to a public URL. So it works in two steps:

// Forward the events
stripe listen -f https://www.example.com

// Then trigger the events, that will be sent to example.com
stripe trigger payment_intent.succeeded

somber aspen
#

"evt_3Mdai2GMR3u9Lz7019IjosTq" is still failing

grizzled bluff
#

Assuming the URL is correct, then everything is setup correctly. Now you need to check your server logs to understand what is the issue

somber aspen
#

i have to add that, the webhook secret on the dashboard is different than the one used by the CLI

grizzled bluff
#

i have to add that, the webhook secret on the dashboard is different than the one used by the CLI
If you use the CLI, then you need to use the CLI secret

somber aspen
#

well i am not actually securing the webhook
just using the request.body to perform some other actions

#

so, i believe that does not need any endpoint_secret right?