Last active
May 3, 2024 10:39
-
-
Save Sentinel-7/9b11c6d1c50bd222a079fb613d8da18f 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 | |
// строка 32,38,39,40 создаем поля в системных и прописываем там идентификаторы | |
// ini_set('display_errors', 1); | |
// ini_set('error_reporting', -1); | |
require_once MODX_CORE_PATH . 'components/minishop2/model/minishop2/mspaymenthandler.class.php'; | |
class TinkoffCredit extends msPaymentHandler implements msPaymentInterface{ | |
public $demo; | |
public $shopId; //Идентификатор магазина | |
public $showcaseId; | |
public $promoCode; // Идентификатор кредитного продукта(кредит/рассрочка) | |
/** | |
* 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'); | |
$this->promoCode = $object->xpdo->getOption('ms2_tinkoff_promocode'); | |
parent::__construct($object, $config); | |
} | |
public function send(msOrder $order) | |
{ | |
$this->OrderId = $order->get('num'); | |
// Собираем данные для отправки | |
$products = $order->Products; | |
foreach ($products as $item) { | |
$price = round($item->price, 2); | |
$items[] = [ | |
'name' => $item->name, | |
'quantity' => $item->count, | |
'price' => $price | |
]; | |
} | |
$user = $order->User; | |
$profile = $user->Profile; | |
$profile = $profile->toArray(); | |
$data = [ | |
'shopId' => $this->shopId, | |
'showcaseId' => $this->showcaseId, | |
'promoCode' => $this->promoCode, | |
'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