#squirez - Webhook Endpoint
1 messages ยท Page 1 of 1 (latest)
hello
so the question is this
ive set up a webhook using stripe CLI
and its working perfectly fine
now i trying to set up a webhook using a https url
but i keep getting this error message
AttributeError at /payments/webhook/
'NoneType' object has no attribute 'type'
im using python / Django
i understand the error message
but im not sure why im getting it
as this is the same code i've used
when i use the webhook via the stripe CLI
Can you share the code that's throwing that error?
sure
once second
@csrf_exempt
@api_view(['POST'])
@permission_classes([AllowAny])
def webhook(request):
payload = request.body
sig_header = request.META['HTTP_STRIPE_SIGNATURE']
event = None
try:
event = stripe.Webhook.construct_event(
payload, sig_header, endpoint_secert
)
except ValueError as e:
Invalid payload
return Response(status=status.HTTP_400_BAD_REQUEST, data={"message": "invaild Payload"})
except stripe.error.SignatureVerificationError as e:
Invalid signature
return Response(status=status.HTTP_400_BAD_REQUEST, data={"message": "invaild Payload"})
except AttributeError as e:
pass
return Response(status=status.HTTP_400_BAD_REQUEST, data={"message": "Attribute Error {}".format(e)})
Can you edit your message and put that in a code block with indentation? You can use three backticks (```) to start and end a code block.
sure
@csrf_exempt
@api_view(['POST'])
@permission_classes([AllowAny])
def webhook(request):
payload = request.body
sig_header = request.META['HTTP_STRIPE_SIGNATURE']
event = None
try:
event = stripe.Webhook.construct_event(
payload, sig_header, endpoint_secert
)
except ValueError as e:
# Invalid payload
return Response(status=status.HTTP_400_BAD_REQUEST, data={"message": "invaild Payload"})
except stripe.error.SignatureVerificationError as e:
# Invalid signature
return Response(status=status.HTTP_400_BAD_REQUEST, data={"message": "invaild Payload"})
except AttributeError as e:
# pass
return Response(status=status.HTTP_400_BAD_REQUEST, data={"message": "Attribute Error {}".format(e)})
is that better
?
Yep, that's easier to read.
On your keyboard, the key to the left of the 1 key. If you type that three times you can then write multiline code.
For example, like this:
@csrf_exempt
@api_view(['POST'])
@permission_classes([AllowAny])
This is how I wrote that:
\`\`\`python
@csrf_exempt
@api_view(['POST'])
@permission_classes([AllowAny])
Err, without the backslashes.
oh ok
Which line of that code you shared is throwing the "AttributeError at /payments/webhook/ 'NoneType' object has no attribute 'type'" error?
so at the moment i'm handling that error message
by using the
except AttributeError as e:
# pass
return Response(status=status.HTTP_400_BAD_REQUEST, data={"message": "Attribute Error {}".format(e)})
without this line
that error message will appear
Can you log out the values for payload and sig_header and make sure they're being set correctly?
ok sure
let me try that
this might take me a few minutes as i need to re-upload code into the cloud
hello again
i've got the output
'''python
2021-10-25T22:45:01.727206842Z Bad Request: /payments/webhook/
2021-10-25T22:45:01.727731845Z payload value is b'{\n "created": 1326853478,\n "livemode": false,\n "id": "evt_00000000000000",\n "type": "payment_intent.created",\n "object": "event",\n "request": null,\n "pending_webhooks": 1,\n "api_version": "2020-08-27",\n "data": {\n "object": {\n "id": "pi_00000000000000",\n "object": "payment_intent",\n "amount": 1000,\n "amount_capturable": 0,\n "amount_received": 0,\n "application": null,\n "application_fee_amount": null,\n "canceled_at": null,\n "cancellation_reason": null,\n "capture_method": "automatic",\n "charges": {\n "object": "list",\n "data": [\n\n ],\n "has_more": false,\n "url": "/v1/charges?payment_intent=pi_1J5AKyImr5PkOfF3q0jGpbTX"\n },\n "client_secret": "pi_1J5AKyImr5PkOfF3q0jGpbTX_secret_lYouigHyrDmSEd0kA9XsU4hQK",\n "confirmation_method": "automatic",\n "created": 1624371144,\n "currency": "pln",\n "customer": null,\n "description": null,\n "invoice": null,\n "last_payment_error": null,\n "livemode": false,\n "metadata": {\n },\n "next_action": null,\n "on_behalf_of": null,\n "payment_method": null,\n "payment_method_options": {\n "card": {\n "installments": null,\n "network": null,\n "request_three_d_secure": "automatic"\n }\n },\n "payment_method_types": [\n "card"\n ],\n "receipt_email": "test@example.com",\n "review": null,\n "setup_future_usage": null,\n "shipping": null,\n "statement_descriptor": null,\n "statement_descriptor_suffix": null,\n "status": "requires_payment_method",\n "transfer_data": null,\n "transfer_group": null\n }\n }\n}โ
2021-10-25T22:45:01.727789345Z sig_header value is t=1635201900,v1=42e96dd5c3a92de2f1a8c373995a04b1653300b5ee4042073ce0a728747d043d,v0=24b39147b87808bdc30612207c0d12f77fd8666cba1cc19cf4a94f3e2aa755e6
2021-10-25T22:45:01.727797245Z payload value is b'{\n "created": 1326853478,\n "livemode": false,\n "id": "evt_00000000000000",\n "type": "payment_intent.created",\n "object": "event",\n "request": null,\n "pending_webhooks": 1,\n "api_version": "2020-08-27",\n "data": {\n "object": {\n "id": "pi_00000000000000",\n "object": "payment_intent",\n "amount": 1000,\n "amount_capturable": 0,\n "amount_received": 0,\n "application": null,\n "application_fee_amount": null,\n "canceled_at": null,\n "cancellation_reason": null,\n "capture_method": "automatic",\n "charges": {\n "object": "list",\n "data": [\n\n ],\n "has_more": false,\n "url": "/v1/charges?payment_intent=pi_1J5AKyImr5PkOfF3q0jGpbTX"\n },\n "client_secret": "pi_1J5AKyImr5PkOfF3q0jGpbTX_secret_lYouigHyrDmSEd0kA9XsU4hQK",\n "confirmation_method": "automatic",\n "created": 1624371144,\n "currency": "pln",\n "customer": null,\n "description": null,\n "invoice": null,\n "last_payment_error": null,\n "livemode": false,\n "metadata": {\n },\n "next_action": null,\n "on_behalf_of": null,\n "payment_method": null,\n "payment_method_options": {\n "card": {\n "installments": null,\n "network": null,\n "request_three_d_secure": "automatic"\n }\n },\n "payment_method_types": [\n "card"\n ],\n "receipt_email": "test@example.com",\n "review": null,\n "setup_future_usage": null,\n "shipping": null,\n "statement_descriptor": null,\n "statement_descriptor_suffix": null,\n "status": "requires_payment_method",\n "transfer_data": null,\n "transfer_group": null\n }\n }\n}'
2021-10-25T22:45:01.727923446Z sig_header value is t=1635201900,v1=42e96dd5c3a92de2f1a8c373995a04b1653300b5ee4042073ce0a728747d043d,v0=24b39147b87808bdc30612207c0d12f77fd8666cba1cc19cf4a94f3e2aa755e6
thats the output from the object that been populated with data
So we can't do much with the payload, we can't verify it for you. Rubeus was simply trying to make sure you had values in them
ok
Unfortunately, this means something is changing the data/payload somewhere in your stack. It can be extremely painful to debug this but that's what you need to track down
it's hard to say. What is your stack? Usually it means something on your end is "tampering" with the raw body we send you
Have you first made this work locally?
yes
okay so it works fine locally and doesn't on your host?
i was using stripe cli
and it works fine
now i've tried setting up the webhook using the https url
im getting this error message
hum that's strange if it's the same code, it should just work. But like I was saying it can be really painful to debug ๐ฆ
i think i may know what the problem is
oh that's good to hear!
Hi
so i've fixed it
you was right
there was a problem on my end
i was using the Signing secret that the CLI had provided me
ohhhhhh
nice that it wasn't a "raw payload issue" and was just the secret, I should have asked you to double check
it's so hard to debug those ๐ฆ
yeah
once i was able to output the error message properly
i could see the problem
Thank you for the support
Glad you got unblocked, congrats ๐