To receive notifications about purchases on the forum, you need to go to https://opencartforum.com/clients/info/
add Callback URL and Secret Key. On the side of your server, accept data, you can test the work in the personal data section
Example:
<?php namespace OpenCartForum\API; class Purchases { private $private_key; private static $instance = null; private $headers = []; public static function getInstance($private_key) { if (self::$instance !== null) { return self::$instance; } self::$instance = new self($private_key); return self::$instance; } public function getPurchase() { return $this->auth() ? $this->getForm() : false; } private function __construct($private_key) { $this->private_key = $private_key; } private function getForm() { if (empty($this->form)) { $this->form = json_decode(file_get_contents('php://input'), true); } return $this->form; } private function auth() { if (empty($form = $this->getForm()) || empty($form['hash']) || empty($form['order']) ) { $this->addHeader("{$_SERVER['SERVER_PROTOCOL']} 400 Bad Request"); return false; } if ( ! hash_equals( hash_hmac('md5', (\strlen($form['order']['id']) . $form['order']['id'] . \strlen($form['order']['date']) . $form['order']['date']), $this->private_key), $form['hash']) ) { $this->addHeader("{$_SERVER['SERVER_PROTOCOL']} 401 Unauthorized"); $this->addHeader('Content-Type: application/json; charset=UTF-8'); $this->addHeader('State: Unauthorized'); return false; } $this->addHeader("{$_SERVER['SERVER_PROTOCOL']} 200 OK"); $this->addHeader('Content-Type: application/json; charset=UTF-8'); switch ($form['status']) { case 'auth': $this->addHeader('State: Authorized'); return false; case 'success': $this->addHeader('State: Received'); return true; } } private function addHeader($header) { $this->headers[] = $header; } private function output(array $data = []) { if (!headers_sent()) { foreach ($this->headers as $header) { header($header, true); } } echo json_decode($data); die; } public function __destruct() { $this->output(); } } /* Cекретный ключ, указаный на форуме в разделе https://opencartforum.com/clients/info/, там же укажите Callback URL */ $private_key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; $opencartforum_api = \OpenCartForum\API\Purchases::getInstance($private_key); if (($purchase_info = $opencartforum_api->getPurchase())) { $file = $_SERVER['DOCUMENT_ROOT'] . '/ocf-purchase.log'; $f = fopen($file, 'w+'); fwrite($f, print_r($purchase_info, true)); fclose($f); }
The response must contain mandatory headings::
Content-Type: application/json; charset=UTF-8
State: Unauthorized - Неуспешная авторизация
State: Authorized - Успешная авторизация, готов получить форму
State: Received - Форма успешно принята
We send two requests, the first authorization request, the second request with a form. The HTTP status code should be 200.
Sales messages will have the following structure:
Array
(
[marketplace] => (string) opencartforum
[hash] => (string) 74e6f7298a9c2XXXXXXXXXXXXX,
[status] => (string) success | auth,
[order] => Array
(
[id] => (int) 1090XXX
[date] => (int) 1614040731
[domain] => (strinng) domain.com
[test_domain] => (strinng) test.domain.com
[options]=> array (
[1]=> array (
["cost"]=> string(7) 2000.00
["name"]=> string(36) Установка: 2 000.00 руб
)
)
[discount]=> array (
[amount]=> string(4) 1260 // Price
[name]=> string(112) (string) File - 10%
)
[coupon]=> array (
[code]=> string(14) 1237-promo2021
[discount]=> string(4) 1344 // Price
[text]=> string(16) 1344.00 руб
)
[total] => Array
(
[currency] => (string) RUB // Или USD
[amount] => (float) 300
)
[quantity] => (int) 1
[commission] => (int) 30
)
[developer] => Array
(
[id] => (int) XXXX
[name] => (string) developer
[email] => (string) [email protected]
[link] => (string) https://opencartforum.com/profile/XXXX-developer/
[credits] => Array
(
[0] => Array
(
[currency] => (string) RUB
[amount] => (float) 6939.46
)
[1] => Array
(
[currency] => (string) USD
[amount] => (float) 3701.44
)
)
)
[customer] => Array
(
[id] => (int) XXXX
[name] => (string) Customer
[email] => (string) [email protected]
[link] => (string) https://opencartforum.com/profile/XXXX-customer/
)
[file] => Array
(
[id] => (int) XXXX
[name] => (string) File
[basePrice] = Array
(
[0] => Array
(
[currency] => (string) RUB
[amount] => (float) 750.00
)
[1] => Array
(
[currency] => (string) USD
[amount] => (float) 10.00
)
)
[link] => (string) https://opencartforum.com/files/file/XXXX-file/
)
)
Discussion of the forum API takes place in the topic: