Overview

Webhooks enable you to receive notifications as soon as a payment is made. If a new payment is received or a payment is modified we will send a HTTP request containing a JSON object to an endpoint of your choice. Webhooks are sent instantly and they're a great way to integrate Tebex with your own website, forum or internal database.

Webhooks are available on the Premium, Ultimate and Enterprise Plans. Unfortunately due to the resources required to send webhooks we cannot support them on the Starter Plan.

How To Setup Webhooks

  1. Go to Integrations > Webhooks.
  2. Enter the following options:

Options

  1. Webhook URL - This is the URL where we will send notifications to (For example https://example.com/tebex/webhook.php). You can use any programming language to write your webhook handler as long as it can parse JSON objects (PHP is json_decode() for example).

Once you've entered the options above, click update - now when you receive a new payment, or make a change to a payment, you will receive a notification to the endpoint you've entered. Read on more to find out what information we will send you.

Example Webhook Notification

Below is an example JSON object which is sent with a webhook notification.

{
   "payment":{
      "txn_id":"64104868C95007442",
      "timestamp":1234567890123,
      "date":"2000-01-01T01:00:00Z",
      "price":0.14,
      "currency":"USD",
      "gateway":"PayPal Express Checkout",
      "status":"complete"
   },
   "customer":{
      "email":"joe@bloggs.com",
      "country":"GB",
      "ign":"test0",
      "uuid":"45611b2c5d284dfc96f65fa77d2a4f57",
      "ip":"10.0.0.2",
      "name":"Joe Bloggs",
      "address":"123 Test Road, Test, Testton, Testshire, TE57 1NG"
   },
   "coupons":[
      {
         "code":"NEWCODE123",
         "type":"cart",
         "discount_type":"value",
         "discount_percentage":0,
         "discount_amount":0.01,
         "pivot":{
            "payment":91,
            "coupon":7
         }
      }
   ],
   "gift_cards":[
      {
         "gift_card":900055366539,
         "amount":"1.00"
      }
   ],
   "packages":[
      {
         "package_id":236,
         "name":"Webhook test 1",
         "purchase_data":{
            "payment":91,
            "package":236,
            "quantity":1,
            "expire":0,
            "server":null,
            "price":1.15,
            "notified":"0",
            "base_price":2.50,
         },
         "variables":[
            {
               "identifier":"issue_now",
               "option":"Yes"
            },
            {
               "identifier":"uname",
               "option":"test"
            }
         ]
      },
      {
         "package_id":237,
         "name":"Webhook test 2",
         "purchase_data":{
            "payment":91,
            "package":237,
            "quantity":1,
            "expire":0,
            "server":null,
            "price":0,
            "notified":"0"
         },
         "variables":[
            {
               "identifier":"uname",
               "option":"test"
            }
         ]
      }
   ]
}

How To Validate Incoming Webhook Notifications

To ensure that a webhook notification is actually coming from Tebex you can compare the X-BC-Sig header in the request with a hash generated on your side. An example of generating this hash is listed below in PHP:

hash("sha256", $sharedSecret . $json['payment']['txn_id'] . $json['payment']['status'] . $json['customer']['email']);


The shared secret can be found by going to Integrations > API Keys in your Tebex Store control panel.

Viewing Webhook History And Resending

You can view all webhooks we've sent you by going to Integrations > Webhooks. If you would like to resend a webhook, you can do so by clicking on the individual webhook history log and clicking resend. 

If a webhook response is anything other than HTTP 200 OK we will continue to resend the webhook up to 5 times before no longer attempting to send it again.

Did this answer your question?