Forked from Electrica/gist:b9c54a93f1a05ba593777629e8484400
Last active
February 9, 2022 16:57
-
-
Save Sentinel-7/3bbb48249af09dff1f0d927b11094b13 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
Класс оплаты в кредит или рассрочку для Тинькофф | |
*/ | |
require_once MODX_CORE_PATH . 'components/minishop2/model/minishop2/mspaymenthandler.class.php'; | |
class Tinkoff extends msPaymentHandler implements msPaymentInterface{ | |
public $demo; | |
public $shopId; //Идентификатор магазина | |
public $showcaseId; | |
/** | |
* name Название товарной позиции | |
* quantity Количество единиц товара в позиции | |
* price Цена одной единицы товара | |
*/ | |
public $items = []; //Список товаров | |
public $OrderId; //Идентификатор заказа в системе партнера | |
public $Language = 'ru'; | |
public $SuccessURL; | |
public $FailURL; | |
private $createOrder; | |
public function __construct(xPDOObject $object, $config = array()) | |
{ | |
$this->demo = $object->xpdo->getOption('ms2_tinkoff_demo'); | |
if($this->demo){ | |
$this->createOrder = 'https://forma.tinkoff.ru/api/partners/v2/orders/create-demo'; | |
}else{ | |
$this->createOrder = 'https://forma.tinkoff.ru/api/partners/v2/orders/create'; | |
} | |
$this->shopId = $object->xpdo->getOption('ms2_tinkoff_shopId'); | |
$this->showcaseId = $object->xpdo->getOption('ms2_tinkoff_showcaseId'); | |
parent::__construct($object, $config); | |
} | |
public function send(msOrder $order) | |
{ | |
$this->OrderId = $order->get('num'); | |
// Собираем данные для отправки | |
$products = $order->Products; | |
foreach ($products as $item) { | |
$items[] = [ | |
'name' => $item->name, | |
'quantity' => $item->count, | |
'price' => $item->price | |
]; | |
} | |
$user = $order->User; | |
$profile = $user->Profile; | |
$profile = $profile->toArray(); | |
$data = [ | |
'shopId' => $this->shopId, | |
'showcaseId' => $this->showcaseId, | |
'sum' => $order->get('cost'), | |
'orderNumber' => $this->OrderId, | |
'successURL' => $this->SuccessURL, | |
'failURL' => $this->FailURL, | |
'items' => $items | |
]; | |
$links =$this->init($data); | |
return $this->success('', array('redirect' => $links['link'])); | |
} | |
public function init($data = []){ | |
if($curl = curl_init()){ | |
curl_setopt($curl, CURLOPT_URL, $this->createOrder); | |
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); | |
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); | |
curl_setopt($curl, CURLOPT_POST, true); | |
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data, JSON_UNESCAPED_UNICODE)); | |
curl_setopt($curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); | |
curl_setopt($curl, CURLOPT_HTTPHEADER, array( | |
'Content-Type: application/json', | |
//'Content-Length: ' . strlen($data), | |
)); | |
$result = curl_exec($curl); | |
$httpcode = curl_getinfo($curl, CURLINFO_HTTP_CODE); | |
curl_close($curl); | |
if (!empty($result)) { | |
return json_decode($result, true); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment