10
votes

I am playing around with Paypal REST(php) enviroment and i like to play around with the sandbox webhooks. Is it possible to use paypal sandbox webhooks with a local setup? http://localhost/test

is a invalid url

any suggestions?

3
We have a free tool for this: runscope.com/docs/passagewayJohn Sheehan

3 Answers

7
votes

As @zeyu says, you can't do it directly. Another service that you can use to achieve this is https://ngrok.com/. Hope it's useful for someone!

It will give you a link something like this: http://75z929f4.ngrok.io, which I set to a development ENV variable of APP_HOST.

And popped into the webhook as such:

  def generate_url
    values = {
      business: ENV["PAYPAL_ACCOUNT"],
      cmd: '_xclick',
      return: ENV["APP_HOST"] + @return_path,
      custom: @user.id,
      upload: 1,
      invoice: Time.now,
      currency_code: 'GBP',
      amount: @price,
      no_shipping: 1,
      item_name: self.purchase_name,
      item_number: @product_id,
      quantity: 1,
      notify_url: ENV["APP_HOST"] + @notify_path,
      on0: ('Coupon Code' if @coupon_code.present?),
      os0: @coupon_code
    }

    "#{ENV["PAYPAL_URL"]}/cgi-bin/websr?" + values.to_query
  end

Final note, you'll need to update the APP_HOST every time you re-run ngrok as you'll get a new identifier from them. That'll link everything up so you can send this request from localhost and have the response return successfully.

6
votes

no, it doesn't work in this way, cuz localhost is not a valid address for paypal webhook. however, you can try it with requestbin, requestbin . remember using https instead of http while setting the webhook url up.

1
votes

The simplest way to test a webhook for me is https://webhook.site/. The services proposed in other answer was overkill to me.

It is a single page, simple, no login. It will receiver webhooks in real time and provide needed informations (body, headers...)

webhook.site image