#victoria.fabris-webhook-verify
1 messages · Page 1 of 1 (latest)
Hi there, let's use this thread.
Can you post the code in this thread as text using three backticks
That makes it much easier for us to look at
And reference
And are you hitting an error when attempting to verify?
@permission_classes([IsAuthenticated])
def webhook(request: Request, pk=None):
###CHECKING IF WEBHOOK SIGNING IS CONFIGURED###
endpoint_secret = settings.STRIPE_WEBHOOK_SECRET
if endpoint_secret:
# Retrieve the event by verifying the signature using the raw body and secret.
event = None
payload = request.data
signature = request.headers["stripe-signature"]
try:
# getting the event type
event = stripe.Webhook.construct_event(
payload,
signature,
endpoint_secret,
)
except ValueError:
# Invalid payload
raise ValueError("Invalid payload.")
except:
# Invalid signature
return Response(status=status.HTTP_400_BAD_REQUEST)
###CHECKING THE EVENT TYPE###
subscription_id = event["data"]["object"]["schedule"]
delivery: Delivery = Delivery.objects.filter(payment_code=subscription_id).first()
if event["type"] == "invoice.payment_failed":
title = "Pagamento recusado!"
body = "Houve uma falha no seu pagamento. Por favor, reveja os dados inseridos do cartão!"
elif event["type"] == "payment_intent.succeeded":
delivery.success_payment()
title = "Pagamento concluído!"
body = "Seu pagamento da entrega foi bem sucedido."
service = get_push_notification_service_for_provider()
service.send(
to=delivery.requested_by.expo_push_notification_token, title=title, body=body
)
return Response(status=status.HTTP_200_OK)```
so, im testing a path that is going to send me these events that the webhook is looking at
and im using ngrok to do it
im keep getting 401 error, i dont know if its because of my code in webhook or in this path that im trying to access
Can you provide an event ID that you are testing with?
im missing something or doing something wrong?
It should look like evt_xxxxx
i can get this event id in the stripe dashboard?
Yep
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
ok, im doing a new requisition to the endpoint so i can get the event id
👍
ok so i added the endpoint to the webhooks page in my dashboard, but when i do a new requisition, nothing appears there
im watching my terminal where i open the ngrok, im this appears
api/v1/deliveries/payment-checkout/ is the path that im trying to acces, im using the url that ngrok gave me and this path
it should be appearing in my dashboard?
Are you forwarding from the CLI?
With ngrok you shouldn't need to do that
So did you register an endpoint in the Dashboard?
no? im doing additional steps?
how can i test it with ngrok?
Did you "Add endpoint" in your Dashboard here: https://dashboard.stripe.com/test/webhooks?
yes
i added and then i did a requisition to this endpoint
Can you share your account ID?
You can find it in top right here: https://dashboard.stripe.com/settings/account
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
looks like acct_xxxx
acct_1KxU23H2jrwTN4ex
So yeah I'm not seeing any events being sent to that endpoint at all. How are you triggering events?
Your most recent events are from yesterday it looks like?
triggering you mean, watch what response the endpoint give me?
im watching these events in this way
How are you actually sending events? You could just create a test payment in your Dashboard for example. Or you could use the Stripe CLI (https://stripe.com/docs/stripe-cli/trigger)
It looks like you are listening for payment_intent.succeeded as one of the 3 events your endpoint is listening to. So you need to actually have that event sent to the endpoint somehow
right, im going to read this and try to test in this way. But im having a lot of questions
thank you in advance