13

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:

  1. https://api.sandbox.paypal.com/v1/oauth2/token
  2. https://api.sandbox.paypal.com/v1/payments/payment
  3. Redirect to the result link with method: "REDIRECT"
  4. Complete payment with sandbox account

Is there anything I am doing wrong? Is there some problem with using this in the sandbox?

Dominik G
  • 1,459
  • 3
  • 17
  • 37
  • 3
    Were you able to solve the problem? I have got a trouble with webhooks both in Sandbox and Live mode. The paypal sucks by the way... – Doctiger Jun 01 '21 at 10:02

4 Answers4

0

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.

0

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 enter image description here

Output on console which print in Class enter image description here

Arti
  • 39
  • 2
0

If you use the button code form provided by paypal, you must select your credentials when creating a button code.

-1

To use Webhooks in the Sandbox or Live environment, do the following:

  1. Go to the My Apps & Credentials page.
  2. Create an application if you haven't done so already.
  3. Add a webhook URL
  4. Subscribe to the event types of interest.

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.

VJ-PP
  • 151
  • 8
  • 7
    Thanks for your answer. I already subscribe to ALL events for test. The only thing I do in my URL is to write the request into a log. It works with the simulator, however. – Dominik G Mar 10 '16 at 07:08
  • Hi, Can you share which Event do you want to trigger and how did you made payments for that ? Will look into it and get back to you. – VJ-PP Mar 11 '16 at 19:37
  • I expect a "payment completed" event, but I listen for every event for test reasons. You can find the steps for creating a payment in my original post. The payment is completed on the site redirected to in step 3. – Dominik G Mar 14 '16 at 12:32
  • 7
    Hi @DominikG, able to solve the problem ? I configured as suggested, still unable to get event my web hook in sandbox – Satish Jul 30 '17 at 11:28