Jump to content
покупайте без комиссии
Search In
  • More options...
Find results that contain...
Find results in...
  • Sign Up

FAQ:
For developer

API каталога дополнений


Support

Для получения уведомлений о покупках на форуме Вам необходимо в разделе https://opencartforum.com/clients/info/
добавить   Callback URL  и  Secret Key. На стороне Вашего сервера сделайте прием данных, оттестировать работу можно в разделе персональные данные

Пример:

<?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);
}

 

Ответ должен содержать обязательные заголовки:

Content-Type: application/json; charset=UTF-8

State: Unauthorized - Неуспешная авторизация
State: Authorized - Успешная авторизация, готов получить форму
State: Received	- Форма успешно принята

Мы отправляем два запроса, первый запрос авторизации, второй запрос с формой. Код состояния HTTP должен быть 200.

Уведомления о продаже будут иметь структуру:

 

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) developer@gmail.com
            [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) customer@gmail.com
            [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/
        )

)

 

Обсуждения API форума происходит в теме

 




×
×
  • Create New...

Important Information

On our site, cookies are used and personal data is processed to improve the user interface. To find out what and what personal data we are processing, please go to the link. If you click "I agree," it means that you understand and accept all the conditions specified in this Privacy Notice.