alex
alex

Reputation: 4914

How to use paypal Sandbox webhooks on local setup?

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?

Upvotes: 13

Views: 6244

Answers (4)

nabby27
nabby27

Reputation: 63

An option I use is https://smee.io/, you generate a permanent URL and you can use it with docker or docker compose thanks to this project https://github.com/deltaprojects/smee-client-docker:

docker run -d --name smee-client deltaprojects/smee-client -u https://smee.io/XXXXXX -t http://localhost:PORT/endpoint
  opire_smee:
    image: deltaprojects/smee-client
    container_name: opire_smee
    network_mode: "host"
    command: "-u https://smee.io/XXXXXX -t http://localhost:${API_PORT}/endpoint"
    env_file:
      - .env

Upvotes: 0

TOPKAT
TOPKAT

Reputation: 8638

The simplest: receive webhook online

https://webhook.site/ is a single page, simple, no login. It will receive webhooks in real time and display all details about the received payload (body, headers...)

webhook.site image


Second method: forward webhooks to localhost

With just a bit more setup you can forward received webhooks with a free service like ngrok to a localhost address. You need to login for security concerns.
On one cli command, it will then put online any localhost address (should be used for development only).

Upvotes: 7

SRack
SRack

Reputation: 12203

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.

Upvotes: 8

Zeyu Wang
Zeyu Wang

Reputation: 65

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.

Upvotes: 6

Related Questions