LiqPay 3.0 кто нибудь реализовывал?
xelaxela13
16 марта 2015 г.
Сейчас в системе реализован LiqPay 1.2 а последняя версия 3.0 может кто нибудь подскажет как перейти на новую версию. Версия 3.0 более функциональна.
ferdinant
20 марта 2015 г.
Ну у меня есть модуль этот 6000 р интеграция
Skype:ferdinant1988 ICQ:311960596 E-mail: ferdinant@i.ua
xelaxela13
14 апреля 2015 г.
Написал! Все работает!
Создаем новую платежную систему:
<?php
class LiqPay // API самого LiqPay, ничего придумывать не нужно
{
private $_api_url = 'https://www.liqpay.com/api/';
private $_checkout_url = 'https://www.liqpay.com/api/checkout';
protected $_supportedCurrencies = array('EUR','UAH','USD','RUB','RUR');
private $_public_key;
private $_private_key;
/**
* Constructor.
*
* @param string $public_key
* @param string $private_key
*
* @throws InvalidArgumentException
*/
public function __construct($public_key, $private_key)
{
if (empty($public_key)) {
throw new InvalidArgumentException('public_key is empty');
}
if (empty($private_key)) {
throw new InvalidArgumentException('private_key is empty');
}
$this->_public_key = $public_key;
$this->_private_key = $private_key;
}
/**
* Call API
*
* @param string $url
* @param array $params
*
* @return string
*/
public function api($path, $params = array())
{
if(!isset($params['version'])){
throw new InvalidArgumentException('version is null');
}
$url = $this->_api_url . $path;
$public_key = $this->_public_key;
$private_key = $this->_private_key;
$data = base64_encode(json_encode(array_merge(compact('public_key'), $params)));
$signature = base64_encode(sha1($private_key.$data.$private_key, 1));
$postfields = http_build_query(array(
'data' => $data,
'signature' => $signature
));
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$postfields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$server_output = curl_exec($ch);
curl_close($ch);
return json_decode($server_output);
}
/**
* cnb_form
*
* @param array $params
*
* @return string
*
* @throws InvalidArgumentException
*/
public function cnb_form($params)
{
$language = 'ru';
if (isset($params['language']) && $params['language'] == 'en') {
$language = 'en';
}
$params = $this->cnb_params($params);
$data = base64_encode( json_encode($params) );
$signature = $this->cnb_signature($params);
return sprintf('
<form method="POST" action="%s" accept-charset="utf-8">
%s
%s
<input type="image" src="//static.liqpay.com/buttons/p1%s.radius.png" name="btn_text" /> //кнопка Оплатить
</form>
',
$this->_checkout_url,
sprintf('<input type="hidden" name="%s" value="%s" />', 'data', $data),
sprintf('<input type="hidden" name="%s" value="%s" />', 'signature', $signature),
$language
);
}
/**
* cnb_signature
*
* @param array $params
*
* @return string
*/
public function cnb_signature($params)
{
$params = $this->cnb_params($params);
$private_key = $this->_private_key;
$json = base64_encode( json_encode($params) );
$signature = $this->str_to_sign($private_key . $json . $private_key);
return $signature;
}
/**
* cnb_params
*
* @param array $params
*
* @return array $params
*/
private function cnb_params($params)
{
$params['public_key'] = $this->_public_key;
if (!isset($params['version'])) {
throw new InvalidArgumentException('version is null');
}
if (!isset($params['amount'])) {
throw new InvalidArgumentException('amount is null');
}
if (!isset($params['currency'])) {
throw new InvalidArgumentException('currency is null');
}
if (!in_array($params['currency'], $this->_supportedCurrencies)) {
throw new InvalidArgumentException('currency is not supported');
}
if ($params['currency'] == 'RUR') {
$params['currency'] = 'RUB';
}
if (!isset($params['description'])) {
throw new InvalidArgumentException('description is null');
}
return $params;
}
/**
* str_to_sign
*
* @param string $str
*
* @return string
*/
public function str_to_sign($str)
{
$signature = base64_encode(sha1($str,1));
return $signature;
}
}
/**
* LiqPay
*/
class Shop_Payment_System_Handler22 extends Shop_Payment_System_Handler //помним про идентификатор
{
/**
* Номер мерчанта
* @var string
*/
protected $_merchant_id = '1234567890';
/**
* Пароль мерчанта
* @var string
*/
protected $_merchant_sig = '123445667787112233';
/**
* Международное название валюты из списка валют магазина
* @var string
*/
protected $_currency_name = 'UAH'; //Можно менять 'EUR','UAH','USD','RUB','RUR'
/**
* Идентификатор валюты
* @var string
*/
protected $_currency_id = 1;
/**
* Метод, запускающий выполнение обработчика
* @return self
*/
public function execute()
{
parent::execute();
$this->printNotification();
return $this;
}
// Получаем код текущей валюты
public function __construct(Shop_Payment_System_Model $oShop_Payment_System_Model)
{
parent::__construct($oShop_Payment_System_Model);
$oCurrency = Core_Entity::factory('Shop_Currency')->getByCode($this->_currency_name);
!is_null($oCurrency) && $this->_currency_id = $oCurrency->id;
}
protected function _processOrder()
{
parent::_processOrder();
// Установка XSL-шаблонов в соответствии с настройками в узле структуры
$this->setXSLs();
// Отправка писем клиенту и пользователю
$this->send();
return $this;
}
public function getInvoice()
{
return $this->getNotification();
}
// Получаем сумму в национальной валюте
public function getSumWithCoeff()
{
return Shop_Controller::instance()->round(($this->_currency_id > 0
&& $this->_shopOrder->shop_currency_id > 0
? Shop_Controller::instance()->getCurrencyCoefficientInShopCurrency(
$this->_shopOrder->Shop_Currency,
Core_Entity::factory('Shop_Currency', $this->_currency_id)
)
: 0) * $this->_shopOrder->getAmount());
}
public function getNotification()
{
$oSite_Alias = $this->_shopOrder->Shop->Site->getCurrentAlias();
$sum = $this->getSumWithCoeff();
if (is_null($oSite_Alias))
{
throw new Core_Exception('Site does not have default alias!');
}
$shop_path = $this->_shopOrder->Shop->Structure->getPath();
$handler_url = 'http://' . $oSite_Alias->name . $shop_path . "cart/good-buy/"; // путь куда вернемся после удачной оплаты
$OrderID=$this->_shopOrder->id;
$PurchaseCurrencyName=$this->_currency_name;
$OrderDescription='Zakaz_'.$OrderID;
$merchant_id=$this->_merchant_id;
$signature=$this->_merchant_sig;
$liqpay = new LiqPay($merchant_id, $signature);
$html = $liqpay->cnb_form(array(
'version' => '3',
'amount' => $sum,
'currency' => $PurchaseCurrencyName,
'description' => $OrderDescription,//Название назначения платежа
'result_url' => $handler_url, // URL в Вашем магазине на который покупатель будет переадресован после завершения покупки.
//'server_url' => $handler_url,
'order_id' => $OrderID
));
?>
<h1><p>Сумма к оплате составляет <strong><?php echo $this->_shopOrder->sum()?></strong></p></h1>
<p style="color: rgb(255, 0, 0);">
Внимание! Нажимая «Оплатить» Вы подтверждаете передачу контактных данных на сервер LiqPay ПРИВАТБАНК для оплаты.
</p>
<?php
echo $html; //показываем кнопку оплатить
}
}
Создаем новую платежную систему:
<?php
class LiqPay // API самого LiqPay, ничего придумывать не нужно
{
private $_api_url = 'https://www.liqpay.com/api/';
private $_checkout_url = 'https://www.liqpay.com/api/checkout';
protected $_supportedCurrencies = array('EUR','UAH','USD','RUB','RUR');
private $_public_key;
private $_private_key;
/**
* Constructor.
*
* @param string $public_key
* @param string $private_key
*
* @throws InvalidArgumentException
*/
public function __construct($public_key, $private_key)
{
if (empty($public_key)) {
throw new InvalidArgumentException('public_key is empty');
}
if (empty($private_key)) {
throw new InvalidArgumentException('private_key is empty');
}
$this->_public_key = $public_key;
$this->_private_key = $private_key;
}
/**
* Call API
*
* @param string $url
* @param array $params
*
* @return string
*/
public function api($path, $params = array())
{
if(!isset($params['version'])){
throw new InvalidArgumentException('version is null');
}
$url = $this->_api_url . $path;
$public_key = $this->_public_key;
$private_key = $this->_private_key;
$data = base64_encode(json_encode(array_merge(compact('public_key'), $params)));
$signature = base64_encode(sha1($private_key.$data.$private_key, 1));
$postfields = http_build_query(array(
'data' => $data,
'signature' => $signature
));
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$postfields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$server_output = curl_exec($ch);
curl_close($ch);
return json_decode($server_output);
}
/**
* cnb_form
*
* @param array $params
*
* @return string
*
* @throws InvalidArgumentException
*/
public function cnb_form($params)
{
$language = 'ru';
if (isset($params['language']) && $params['language'] == 'en') {
$language = 'en';
}
$params = $this->cnb_params($params);
$data = base64_encode( json_encode($params) );
$signature = $this->cnb_signature($params);
return sprintf('
<form method="POST" action="%s" accept-charset="utf-8">
%s
%s
<input type="image" src="//static.liqpay.com/buttons/p1%s.radius.png" name="btn_text" /> //кнопка Оплатить
</form>
',
$this->_checkout_url,
sprintf('<input type="hidden" name="%s" value="%s" />', 'data', $data),
sprintf('<input type="hidden" name="%s" value="%s" />', 'signature', $signature),
$language
);
}
/**
* cnb_signature
*
* @param array $params
*
* @return string
*/
public function cnb_signature($params)
{
$params = $this->cnb_params($params);
$private_key = $this->_private_key;
$json = base64_encode( json_encode($params) );
$signature = $this->str_to_sign($private_key . $json . $private_key);
return $signature;
}
/**
* cnb_params
*
* @param array $params
*
* @return array $params
*/
private function cnb_params($params)
{
$params['public_key'] = $this->_public_key;
if (!isset($params['version'])) {
throw new InvalidArgumentException('version is null');
}
if (!isset($params['amount'])) {
throw new InvalidArgumentException('amount is null');
}
if (!isset($params['currency'])) {
throw new InvalidArgumentException('currency is null');
}
if (!in_array($params['currency'], $this->_supportedCurrencies)) {
throw new InvalidArgumentException('currency is not supported');
}
if ($params['currency'] == 'RUR') {
$params['currency'] = 'RUB';
}
if (!isset($params['description'])) {
throw new InvalidArgumentException('description is null');
}
return $params;
}
/**
* str_to_sign
*
* @param string $str
*
* @return string
*/
public function str_to_sign($str)
{
$signature = base64_encode(sha1($str,1));
return $signature;
}
}
/**
* LiqPay
*/
class Shop_Payment_System_Handler22 extends Shop_Payment_System_Handler //помним про идентификатор
{
/**
* Номер мерчанта
* @var string
*/
protected $_merchant_id = '1234567890';
/**
* Пароль мерчанта
* @var string
*/
protected $_merchant_sig = '123445667787112233';
/**
* Международное название валюты из списка валют магазина
* @var string
*/
protected $_currency_name = 'UAH'; //Можно менять 'EUR','UAH','USD','RUB','RUR'
/**
* Идентификатор валюты
* @var string
*/
protected $_currency_id = 1;
/**
* Метод, запускающий выполнение обработчика
* @return self
*/
public function execute()
{
parent::execute();
$this->printNotification();
return $this;
}
// Получаем код текущей валюты
public function __construct(Shop_Payment_System_Model $oShop_Payment_System_Model)
{
parent::__construct($oShop_Payment_System_Model);
$oCurrency = Core_Entity::factory('Shop_Currency')->getByCode($this->_currency_name);
!is_null($oCurrency) && $this->_currency_id = $oCurrency->id;
}
protected function _processOrder()
{
parent::_processOrder();
// Установка XSL-шаблонов в соответствии с настройками в узле структуры
$this->setXSLs();
// Отправка писем клиенту и пользователю
$this->send();
return $this;
}
public function getInvoice()
{
return $this->getNotification();
}
// Получаем сумму в национальной валюте
public function getSumWithCoeff()
{
return Shop_Controller::instance()->round(($this->_currency_id > 0
&& $this->_shopOrder->shop_currency_id > 0
? Shop_Controller::instance()->getCurrencyCoefficientInShopCurrency(
$this->_shopOrder->Shop_Currency,
Core_Entity::factory('Shop_Currency', $this->_currency_id)
)
: 0) * $this->_shopOrder->getAmount());
}
public function getNotification()
{
$oSite_Alias = $this->_shopOrder->Shop->Site->getCurrentAlias();
$sum = $this->getSumWithCoeff();
if (is_null($oSite_Alias))
{
throw new Core_Exception('Site does not have default alias!');
}
$shop_path = $this->_shopOrder->Shop->Structure->getPath();
$handler_url = 'http://' . $oSite_Alias->name . $shop_path . "cart/good-buy/"; // путь куда вернемся после удачной оплаты
$OrderID=$this->_shopOrder->id;
$PurchaseCurrencyName=$this->_currency_name;
$OrderDescription='Zakaz_'.$OrderID;
$merchant_id=$this->_merchant_id;
$signature=$this->_merchant_sig;
$liqpay = new LiqPay($merchant_id, $signature);
$html = $liqpay->cnb_form(array(
'version' => '3',
'amount' => $sum,
'currency' => $PurchaseCurrencyName,
'description' => $OrderDescription,//Название назначения платежа
'result_url' => $handler_url, // URL в Вашем магазине на который покупатель будет переадресован после завершения покупки.
//'server_url' => $handler_url,
'order_id' => $OrderID
));
?>
<h1><p>Сумма к оплате составляет <strong><?php echo $this->_shopOrder->sum()?></strong></p></h1>
<p style="color: rgb(255, 0, 0);">
Внимание! Нажимая «Оплатить» Вы подтверждаете передачу контактных данных на сервер LiqPay ПРИВАТБАНК для оплаты.
</p>
<?php
echo $html; //показываем кнопку оплатить
}
}
kvasiliy
16 апреля 2015 г.
Гы гы...(в свете предыдущего сообщения...) респект вам!)
Авторизация