#victoria.fabris-webhook-verify

1 messages · Page 1 of 1 (latest)

dense wind
#

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?

jade jasper
# dense wind Can you post the code in this thread as text using ```three backticks```
@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)```
jade jasper
#

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

dense wind
#

Can you provide an event ID that you are testing with?

jade jasper
#

im missing something or doing something wrong?

dense wind
#

It should look like evt_xxxxx

jade jasper
#

i can get this event id in the stripe dashboard?

dense wind
#

Yep

jade jasper
#

ok, im doing a new requisition to the endpoint so i can get the event id

dense wind
#

👍

jade jasper
#

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?

dense wind
#

Are you forwarding from the CLI?

#

With ngrok you shouldn't need to do that

#

So did you register an endpoint in the Dashboard?

jade jasper
#

how can i test it with ngrok?

dense wind
jade jasper
#

i added and then i did a requisition to this endpoint

dense wind
#

Can you share your account ID?

#

looks like acct_xxxx

jade jasper
#

acct_1KxU23H2jrwTN4ex

dense wind
#

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?

jade jasper
jade jasper
dense wind
#

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

jade jasper
#

thank you in advance