Reputation: 1479
I integrated the REST API into our system. Only thing missing is a response to a webhook I created.
The webhook is registered in my app for the sandbox, but when I create a payment in the sandbox using the apps keys, I don't get a call to the webhook receiver. Using the webhook simulator works just fine.
The steps I do:
Is there anything I am doing wrong? Is there some problem with using this in the sandbox?
Upvotes: 13
Views: 4188
Reputation: 1
If you use the button code form provided by paypal, you must select your credentials when creating a button code.
Upvotes: 0
Reputation: 47
In Django Paypal Webhook with Sandbox
Create url for webhook in django application or you can create from Paypal dashboard I'm creating from application because we are using sandbox
url('createWebhook', CreateWebhookAPIView.as_view(), name='create-webhook'),
then write a class API to Create Class for creation of webhook
class CreateWebhookAPIView(CreateAPIView):
"""
Subscribes your webhook listener to events.
"""
authentication_classes = ()
permission_classes = ()
serializer_class = BrandListSerializer
def __init__(self, **kwargs):
self.response_format = ResponseInfo().response
super(CreateWebhookAPIView, self).__init__(**kwargs)
def post(self, request, *args, **kwargs):
try:
webhook = URL+'v1/notifications/webhooks'
response = requests.post(webhook, headers=headers, json=request.data)
self.response_format = return_response(
response.json(), None, status.HTTP_200_OK, messages.SUCCESS)
return Response(self.response_format)
except Exception as e:
print(e, "error")
return Response(self.response_format)
and create another class where you want to perform the event specific operation make sure that you have created separate class to perform operation for each EVENT if you try to use same url for different event it will give error.I have created following class as if now just printing the event response you can do operation
class UpdateSubscriptionWebhookAPIView(CreateAPIView):
"""
Subscribes your webhook listener to events.
"""
authentication_classes = ()
permission_classes = ()
serializer_class = BrandListSerializer
def __init__(self, **kwargs):
self.response_format = ResponseInfo().response
super(UpdateSubscriptionWebhookAPIView, self).__init__(**kwargs)
def post(self, request, *args, **kwargs):
try:
event_json = json.loads(request.body)
print(event_json)
self.response_format = return_response(
event_json, None, status.HTTP_200_OK, messages.SUCCESS)
return Response(self.response_format)
except Exception as e:
print(e, "error")
return Response(self.response_format)
add url for the same
url('updateSubscriptionWebhook', UpdateSubscriptionWebhookAPIView.as_view(), name='update-webhook')
After that from post create on request and hit it with respective Event and you can see webhook created and once event occurred you will get respective output as followed
Output on console which print in Class
Upvotes: 0
Reputation: 1
Same issue happened to me; turns out it was a firewall issue. Paypal webhook simulator (and webhook calls from sandbox operations) actually tried but failed to send the webhook message.
Paypal sandbox webhook simulator simply gives a message that the webhook call has been "successfully" queued. Though "success" here is misleading as it wasn't one in the end.
Would be nice if Paypal can provide the call status of the simulated webhook calls that were being made. Then at least we could have some immediate clue of what was going on.
Upvotes: 0
Reputation: 151
To use Webhooks in the Sandbox or Live environment, do the following:
Looks like you have done till step 3 for sure. If you haven't subscribed to webhook events yet, do subscribe to them.
You can also check your webhook URL, and see if it is getting data generated from Webhooks simulator, if not you may need to update that as well. For webhook URL, you may use a tool like Runscope and create buckets there to capture response.
Upvotes: -1