Executing an external script after an User completes a purchase.
support, ws.webtv, home, store, user, integration, external, script, call, webhooks, callbacks
Since WS.WebTV 2.1.0.1 it is possible to call an external script when an User completes a purchase.
How does it works?
If you specify the URL of the script in the WebTV configuration file (config/Config.inc.php), the system will call the script when an User completes a purchase.
This functionality can be complemented with the API extension. For example,
after an User completes a purchase you may want to perform certain actions on its account or over its content using the WebTV API..
This script is called when an User completes a purchase.
Data sent by the WebTV as POST variables:
• user_id (int): The User (buyer) ID.
• order_id (int): ID of the Order.
• order_number (string): The Order number.
• products (string): array of the purchased products in JSON format.
Each entry of the products array will contain the following data (indexes):
• sku (string): Product SKU
• content_id (int): Content ID (if applicable)
• content_type_id (int): Content type ID
• content_type_name (string): Content type name
• product_type_id (int): Product type ID
• product_type_name (string): Product type name
Variable in configuration File:
$STORE_ON_PURCHASE_SCRIPT_URL = ""; // Must be an absolute URL, starting with http:// or https://
Example of data contained in the POST variables for a purchase of a Contribution Membership product by an User with ID 54:
// PHP CODE
echo $_POST["user_id"]; // (int) 54
echo $_POST["order_id"]; // (int) 235
echo $_POST["order_number"]; // (string) ORD00235
echo $_POST["products"]; // (string) [{"sku":"USRMBRCONTPER","content_id":-1,"content_type_id":"0","content_type_name":"SITE","product_type_id":"10","product_type_name":"MEMBERSHIPPERIODCONTRIBUTING"}]
print_r( json_decode($_POST["products"], true) );
/*
array (
0 =>
array (
'sku' => 'USRMBRCONTPER',
'content_id' => -1,
'content_type_id' => '0',
'content_type_name' => 'SITE',
'product_type_id' => '10',
'product_type_name' => 'MEMBERSHIPPERIODCONTRIBUTING',
),
)
*/