#rezamirzad
1 messages · Page 1 of 1 (latest)
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?
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
on our end we are just getting timeouts. Do you have a firewall that blocks our IPs https://stripe.com/docs/ips#webhook-notifications ? do you have the settings in Google Cloud to allow incoming external connections?
ah if you look at https://dashboard.stripe.com/test/events/evt_3MdYhJGMR3u9Lz701w5u9sut you can see a more detailed error message from your server.
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
looking at the gogole cloud firewalls and trying to configure it
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
just set the firewall rule to allow 0.0.0.0/0
and still same issue with ""evt_3MdZBlGMR3u9Lz701xZsakiL"
you can see on https://dashboard.stripe.com/test/events/evt_3MdZBlGMR3u9Lz701xZsakiL that it's the same error message I mentioned above about POST data format
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
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
i checked, and i am indeed receiving the request in the correct format
so where in your code is that 'Invalid argument' error getting thrown from?
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' }
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)
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.
removed the response part
evt_3MdZUaGMR3u9Lz701ClSYeZ6 still same error
seems like it would do that
again, there's very little I can do for you here than to rubber-duck with you
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
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
well if you're not deploying any changes to Google Cloud it's not going to change how those events are handled right? 😅
let me deploy then
still deploying
still same error on "evt_3MdZkTGMR3u9Lz700xU6dvDM"
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?
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
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.
well, here is my problem, i do not know where to look for the console.log outputs in google cloud 🥲
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
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?
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
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
Sorry not sure how to help, I'm not familiar with Google Cloud.
How are you triggering the events?
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!
And are you forwarding the event to the correct URL?
what do you mean by that?
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
i am sending it to
listen --forward-to https://staging.spart.life/webhook
"evt_3Mdai2GMR3u9Lz7019IjosTq" is still failing
Assuming the URL is correct, then everything is setup correctly. Now you need to check your server logs to understand what is the issue
i have to add that, the webhook secret on the dashboard is different than the one used by the CLI
You might need to whitelist some of our IP: https://stripe.com/docs/ips#webhook-notifications
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