Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhanced support for DRF #570

Closed
wants to merge 1 commit into from
Closed

Enhanced support for DRF #570

wants to merge 1 commit into from

Conversation

0xZXDX
Copy link

@0xZXDX 0xZXDX commented May 17, 2019

The request.data obtained by the DRF is a dict type.
Is not required to do json.loads

class OrderCallBackViewSet(mixins.CreateModelMixin,
                           viewsets.GenericViewSet):
    ......
    def create(self, request, *args, **kwargs):
        # payload = request.data  => payload==dict Object
        ......

The request.data obtained by the DRF is a dict type. 
Is not required to do json.loads

```python
class OrderCallBackViewSet(mixins.CreateModelMixin,
                           viewsets.GenericViewSet):
    ......
    def create(self, request, *args, **kwargs):
        # payload = request.data  => payload==dict Object
        ......
```
@brandur-stripe
Copy link
Contributor

Will leave this one to you OB :)

Out of curiosity though, does DRF = Django REST Framework?

@0xZXDX
Copy link
Author

0xZXDX commented May 17, 2019

Will leave this one to you OB :)

Out of curiosity though, does DRF = Django REST Framework?

yes, DRF = Django REST Framework

@ob-stripe
Copy link
Contributor

Hi @anshengme, thanks for the contribution.

Regardless of the framework you use (Django or otherwise), you must pass the raw payload (as in, the exact series of bytes sent by Stripe in the request's body) to construct_event. If the payload is already deserialized to a dict by the framework, then it is virtually guaranteed that the signature verification will fail (because JSON does not guarantee formatting, key order, etc.)

If you want to build a stripe.Event instance from a dict without verifying the signature (which is not recommended in production, but can be useful in tests), you can simply do:

event = stripe.Event.construct_from(data, stripe.api_key) # where data is a dict

Hope this helps! Closing the PR, but feel free to reply if you have questions.

@ob-stripe ob-stripe closed this May 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants