PHP SDK Sample: Webhook that uses REST API to process order

This sample webhook consumes order_create events. One event is generated for each new order placed in your store. You may then examine some detail about the order and take action. Alternatively, you could feed each new order to a third party marketing site or add the order to a custom in-house database.

  1. Create your API Key.

  2. Deploy the sample app to digital ocean (or your own cloud provider). We chose Digital Ocean because we’ve worked with some merchants using their service and we had experience with them. And their process is very simple to use. Follow the README to deploy the sample application.

  3. Once you have a working url for your webhook, configure your webhook in the UltraCart back end.

Configure a Webhook

  • Login to secure.ultracart.com and navigate to Home  →  Configuration  →  Development →  Webhooks.

  • Click the + New Webhook button.

  • Enter the Target URL.  This is the full URL of your server.   For this example, we entered https://ultracart-sdk-ifuy6.ondigitalocean.app/order_webhook.php

  • API Version: Leave this at Latest Version if possible.  If your webhook is mission critical, then specify a version to avoid changes.

  • Authentication:  For this example, we used no Authentication.  You may configure Basic authentication if desired.

  • Events: Select which events to receive for this webhook. For this sample, toggle Order to on, and choose Order Create as well. Set the Expansion for Order Create to “checkout”. This will ensure that custom fields are included in the webhook payload, which are used in our arbitrary business logic. For your actual webhook, you are likely to need many other fields.

  • Click the Create Webhook button


At this point, your webhook should be ready to receive payloads. You can test this out by placing a test order on your website. A simple way to add custom fields to your order is to use the UCEditor page and specify the custom fields in the url. Here’s an example you can modify with your Merchant ID and own Item ID to add a custom field to an order:

http://secure.ultracart.com/cgi-bin/UCEditor?merchantID=DEMO&Add=simple_teapot&CustomField1=HeardFromFriend