437 lines
15 KiB
PHP
437 lines
15 KiB
PHP
|
|
<?
|
||
|
|
|
||
|
|
namespace common\payment\structure;
|
||
|
|
|
||
|
|
use common\Payment;
|
||
|
|
use integration\Kaspi;
|
||
|
|
use integration\Robokassa;
|
||
|
|
use integration\ucscards\structure\Amount;
|
||
|
|
use integration\ucscards\structure\OrderItem;
|
||
|
|
use integration\YooKassa;
|
||
|
|
use shop\Cart;
|
||
|
|
use shop\coupon\structure\eShopCouponType;
|
||
|
|
use shop\Item;
|
||
|
|
use shop\Order;
|
||
|
|
use shop\cart\Item as CartItem;
|
||
|
|
use shop\order\Pay;
|
||
|
|
|
||
|
|
class paymentLink {
|
||
|
|
|
||
|
|
|
||
|
|
const URL_SUCCESS = 1;
|
||
|
|
const URL_FAIL = 2;
|
||
|
|
const PAYMENT_ID = 3;
|
||
|
|
const URL_NOTIFICATION = 4;
|
||
|
|
const PAYMENT_DATA = 5;
|
||
|
|
const DATA = 6;
|
||
|
|
|
||
|
|
|
||
|
|
static function YooKassa($order,$payment,$pay,$options){
|
||
|
|
$payment_options = json_decode($payment[Payment::$DATA],true);
|
||
|
|
$yookassa = new YooKassa($payment_options['shop_id'],$payment_options['token']);
|
||
|
|
$ORDER_ID = $order[Order::$ID];
|
||
|
|
$SHOP_URL_SUCCESS = $options[paymentLink::URL_SUCCESS];
|
||
|
|
$SHOP_URL_FAIL = $options[paymentLink::URL_FAIL];
|
||
|
|
return $yookassa->getPaymentLink($ORDER_ID,$pay[Pay::$ID],$SHOP_URL_SUCCESS);
|
||
|
|
}
|
||
|
|
|
||
|
|
static function Kaspi($order,$payment,$pay,$options){
|
||
|
|
$payment_options = json_decode($payment[Payment::$DATA],true);
|
||
|
|
$kaspi = new Kaspi($payment_options['shop_id']);
|
||
|
|
$ORDER_ID = $order[Order::$ID];
|
||
|
|
$ORDER_TOTAL = cfloatval($pay[Pay::$VALUE]);
|
||
|
|
$SHOP_URL_SUCCESS = $options[paymentLink::URL_SUCCESS];
|
||
|
|
$SHOP_URL_FAIL = $options[paymentLink::URL_FAIL];
|
||
|
|
return $kaspi->getPaymentLink($ORDER_ID,$ORDER_TOTAL,$SHOP_URL_SUCCESS,$SHOP_URL_FAIL,$SHOP_URL_FAIL);
|
||
|
|
}
|
||
|
|
|
||
|
|
static function Robokassa($order,$payment,$pay,$options){
|
||
|
|
$payment_options = json_decode($payment[Payment::$DATA],true);
|
||
|
|
$is_test = boolval($payment_options['is_test']);
|
||
|
|
$robo = new Robokassa(
|
||
|
|
$payment_options['shop_id'],
|
||
|
|
$payment_options[($is_test?'test_':'').'pass1'],
|
||
|
|
$payment_options[($is_test?'test_':'').'pass2'],
|
||
|
|
$is_test
|
||
|
|
);
|
||
|
|
$ORDER_TOTAL = cfloatval($pay[Pay::$VALUE]);
|
||
|
|
$ORDER_ID = $order[Order::$ID];
|
||
|
|
$EMAIL = $order[Order::$EMAIL];
|
||
|
|
|
||
|
|
$PAY_ID = $pay[Pay::$ID];
|
||
|
|
|
||
|
|
$items = [];
|
||
|
|
|
||
|
|
$CART = Cart::getData($order[Order::$CART]);
|
||
|
|
|
||
|
|
foreach ($CART['citems'] as $v) {
|
||
|
|
$item = $CART['items'][$v[CartItem::$ITEM]];
|
||
|
|
$count = $v[CartItem::$COUNT];
|
||
|
|
$sum = $count * $v[CartItem::$PRICE];
|
||
|
|
$items[] = [
|
||
|
|
"name" => Item::getName($item),
|
||
|
|
"quantity" => $count,
|
||
|
|
"sum" => floatval($sum),
|
||
|
|
"payment_method" => "full_payment",
|
||
|
|
"payment_object" => "commodity",
|
||
|
|
"tax" => "none"
|
||
|
|
];
|
||
|
|
}
|
||
|
|
$receipt = [
|
||
|
|
"sno" => "usn_income_outcome",
|
||
|
|
"items" => $items,
|
||
|
|
];;
|
||
|
|
|
||
|
|
$link = $robo->getLink($ORDER_TOTAL,$PAY_ID,null,$receipt,$EMAIL);
|
||
|
|
return $link;
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
static function UCSCard($order,$payment,$pay,$options){
|
||
|
|
$payment_options = json_decode($payment[Payment::$DATA],true);
|
||
|
|
|
||
|
|
$ORDER_ID = $order[Order::$ID];
|
||
|
|
$ORDER_TOTAL = cfloatval($pay[Pay::$VALUE]);
|
||
|
|
|
||
|
|
$CUSTOMER_ID = 'customer'.intval($order[Order::$PROFILE]).'_'.time();
|
||
|
|
$CUSTOMER_NAME = $order[Order::$NAME];
|
||
|
|
$CUSTOMER_PHONE = $order[Order::$PHONE];
|
||
|
|
$CUSTOMER_EMAIL = $order[Order::$EMAIL];
|
||
|
|
|
||
|
|
|
||
|
|
$SHOP_URL_SUCCESS = $options[paymentLink::URL_SUCCESS];
|
||
|
|
$SHOP_URL_FAIL = $options[paymentLink::URL_FAIL];
|
||
|
|
|
||
|
|
//*
|
||
|
|
$SHOP_ID = $payment_options['shop_id'] ;
|
||
|
|
$SHOP_LOCATION = 'https://ws.egopay.ru/';
|
||
|
|
$SHOP_LOGIN = $payment_options['shop_login'];
|
||
|
|
$SHOP_PASSWORD = $payment_options['shop_password'];
|
||
|
|
/*/
|
||
|
|
$SHOP_ID = 25803 ;
|
||
|
|
$SHOP_LOCATION = 'https://tws.egopay.ru/';
|
||
|
|
$SHOP_LOGIN = 'jullifloru';
|
||
|
|
$SHOP_PASSWORD = 'v74DZvAJGv';
|
||
|
|
/**/
|
||
|
|
//$SHOP_URI = 'https://julliflo.ru';
|
||
|
|
$SHOP_URI = 'http://www.sirena-travel.ru';
|
||
|
|
//$SHOP_URI = '';
|
||
|
|
// $SHOP_URL_SUCCESS = 'https://julliflo.ru/personal/order/payment/?ORDER_ID=318&status=ok';
|
||
|
|
// $SHOP_URL_FAIL = 'https://julliflo.ru/personal/order/payment/?ORDER_ID=318&status=fault';
|
||
|
|
|
||
|
|
$soap = [
|
||
|
|
'login' => $SHOP_LOGIN,
|
||
|
|
'password' => $SHOP_PASSWORD,
|
||
|
|
'location' => $SHOP_LOCATION,
|
||
|
|
'uri' => $SHOP_URI,
|
||
|
|
'trace' => 1,
|
||
|
|
'features' => SOAP_SINGLE_ELEMENT_ARRAYS,
|
||
|
|
'connection_timeout' => 12
|
||
|
|
];
|
||
|
|
$soapClient = new \UcsCards\Client(null, $soap);
|
||
|
|
$order = new \UcsCards\Order\OrderId();
|
||
|
|
$order->shop_id = $SHOP_ID;//$settings['shop_id'];
|
||
|
|
$order->number = $ORDER_ID; // Your shop's order ID
|
||
|
|
|
||
|
|
$cost = new \UcsCards\Cost();
|
||
|
|
$cost->amount = $ORDER_TOTAL; // Order price
|
||
|
|
$cost->currency = 'RUB';
|
||
|
|
|
||
|
|
//*
|
||
|
|
$customer = new \UcsCards\Customer();
|
||
|
|
$customer->id = $CUSTOMER_ID;
|
||
|
|
$customer->name = $CUSTOMER_NAME;
|
||
|
|
$customer->phone = $CUSTOMER_PHONE;
|
||
|
|
$customer->email = $CUSTOMER_EMAIL;
|
||
|
|
|
||
|
|
$description = new \UcsCards\Order\OrderDescription();
|
||
|
|
$description->paytype = 'card';
|
||
|
|
|
||
|
|
|
||
|
|
/*
|
||
|
|
$CART = Cart::getData($order[Order::$CART]);
|
||
|
|
|
||
|
|
foreach ($CART['citems'] as $v) {
|
||
|
|
|
||
|
|
$itemCost = new Amount();
|
||
|
|
$itemCost->amount = round($v[ShopItem::$PRICE], 2) * $v[ShopItem::$COUNT];
|
||
|
|
$itemCost->currency = 'RUB';
|
||
|
|
|
||
|
|
$item = new OrderItem();
|
||
|
|
$item->number = 1;
|
||
|
|
$item->amount = $itemCost;
|
||
|
|
$item->typename = 'goods';
|
||
|
|
$item->quantity = cfloatval($v[ShopItem::$COUNT]);
|
||
|
|
$item->name = "test";
|
||
|
|
|
||
|
|
$arItems[] = new \SoapVar($item, SOAP_ENC_OBJECT, null, null, 'OrderItem');
|
||
|
|
$description->sales = new \SoapVar(
|
||
|
|
$arItems,
|
||
|
|
SOAP_ENC_OBJECT
|
||
|
|
);
|
||
|
|
}
|
||
|
|
/**/
|
||
|
|
|
||
|
|
|
||
|
|
$postData = new \UcsCards\PostData\PostData();
|
||
|
|
//*
|
||
|
|
$language = new \UcsCards\PostData\PostEntry();
|
||
|
|
$language->name = 'language';
|
||
|
|
$language->value = 'ru';
|
||
|
|
$postData->addEntry($language);
|
||
|
|
|
||
|
|
$ChoosenCardType = new \UcsCards\PostData\PostEntry();
|
||
|
|
$ChoosenCardType->name = 'ChoosenCardType';
|
||
|
|
$ChoosenCardType->value = 'VI';
|
||
|
|
$postData->addEntry($ChoosenCardType);
|
||
|
|
/**/
|
||
|
|
//*
|
||
|
|
|
||
|
|
$returnUrlOk = new \UcsCards\PostData\PostEntry();
|
||
|
|
$returnUrlOk->name = \UcsCards\PostData\PostEntry::ENTRY_NAME_RETURN_URL_OK;
|
||
|
|
$returnUrlOk->value = $SHOP_URL_SUCCESS;
|
||
|
|
$postData->addEntry($returnUrlOk);
|
||
|
|
|
||
|
|
$returnUrlFault = new \UcsCards\PostData\PostEntry();
|
||
|
|
$returnUrlFault->name = \UcsCards\PostData\PostEntry::ENTRY_NAME_RETURN_URL_FAULT;
|
||
|
|
$returnUrlFault->value = $SHOP_URL_FAIL;
|
||
|
|
$postData->addEntry($returnUrlFault);
|
||
|
|
|
||
|
|
/**/
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
$request = new \UcsCards\Request\Register();
|
||
|
|
$request->order = $order;
|
||
|
|
$request->cost = $cost;
|
||
|
|
$request->customer = $customer;
|
||
|
|
$request->description = $description;
|
||
|
|
$request->postdata = $postData->result();
|
||
|
|
|
||
|
|
|
||
|
|
try {
|
||
|
|
$info = $soapClient->register($request);
|
||
|
|
//echo "Result: ".json_encode($info).PHP_EOL;
|
||
|
|
$redirectUrl = "{$info->redirect_url}?session={$info->session}";
|
||
|
|
//echo "Here we need redirect a customer to ".$redirectUrl.PHP_EOL;
|
||
|
|
return $redirectUrl;
|
||
|
|
} catch (\SoapFault $fault) {
|
||
|
|
echo "SOAP error. ".$fault->faultcode.': '.$fault->faultstring.PHP_EOL;
|
||
|
|
} catch (\Exception $fault) {
|
||
|
|
echo "PHP Exception: ".$fault->__toString().PHP_EOL;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
static function getUUID($order_id){
|
||
|
|
$path = __DIR__.'/uuid.txt';
|
||
|
|
$orders = json_decode(file_get_contents($path),true);
|
||
|
|
return $orders[$order_id];
|
||
|
|
}
|
||
|
|
static function generateCorrelationId($order_id)
|
||
|
|
{
|
||
|
|
$res = sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
|
||
|
|
mt_rand(0, 0xffff), mt_rand(0, 0xffff),
|
||
|
|
mt_rand(0, 0xffff),
|
||
|
|
mt_rand(0, 0x0fff) | 0x4000,
|
||
|
|
mt_rand(0, 0x3fff) | 0x8000,
|
||
|
|
mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff)
|
||
|
|
);
|
||
|
|
$path = __DIR__.'/uuid.txt';
|
||
|
|
$orders = json_decode(file_get_contents($path),true);
|
||
|
|
$orders[$order_id] = $res;
|
||
|
|
file_put_contents($path,je($orders));
|
||
|
|
return $res;
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
static function Dolyami($order,$payment,$pay,$options){
|
||
|
|
$payment_options = json_decode($payment[Payment::$DATA],true);
|
||
|
|
|
||
|
|
|
||
|
|
$url = 'https://partner.dolyame.ru/v1/orders/create';
|
||
|
|
$login =$payment_options['login'];
|
||
|
|
$pass = $payment_options['pass'];
|
||
|
|
|
||
|
|
$ORDER_ID = $order[Order::$ID].'_'.time();
|
||
|
|
|
||
|
|
$uuid = self::generateCorrelationId($ORDER_ID);
|
||
|
|
$headers = [
|
||
|
|
'X-Correlation-ID: '.$uuid,
|
||
|
|
'Authorization: Basic '.base64_encode($login.':'.$pass),
|
||
|
|
'Content-Type: application/json',
|
||
|
|
];
|
||
|
|
$notification_url = $options[self::URL_NOTIFICATION];
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
$items = [];
|
||
|
|
|
||
|
|
$CART = Cart::getData($order[Order::$CART]);
|
||
|
|
|
||
|
|
$ORDER_TOTAL = $CART['total']+$order[Order::$DELIVERY_PRICE]-$order[Order::$TOTAL_PAID];
|
||
|
|
|
||
|
|
foreach ($CART['citems'] as $v) {
|
||
|
|
$item = $CART['items'][$v[CartItem::$ITEM]];
|
||
|
|
$count = $v[CartItem::$COUNT];
|
||
|
|
$sum = $count * $v[CartItem::$PRICE];
|
||
|
|
$items[] = [
|
||
|
|
"name" => Item::getName($item),
|
||
|
|
"quantity" => $count,
|
||
|
|
"price" => floatval($v[CartItem::$PRICE]),
|
||
|
|
];
|
||
|
|
}
|
||
|
|
if($order[Order::$DELIVERY_PRICE]){
|
||
|
|
$items[] = [
|
||
|
|
"name" => "Доставка",
|
||
|
|
"quantity" => 1,
|
||
|
|
"price" => floatval($order[Order::$DELIVERY_PRICE]),
|
||
|
|
];
|
||
|
|
}
|
||
|
|
|
||
|
|
/*
|
||
|
|
if($CART['cart'][Cart::$COUPON_NAME]) {
|
||
|
|
switch ($CART['cart'][Cart::$COUPON_TYPE]) {
|
||
|
|
case eShopCouponType::VALUE:
|
||
|
|
$left = $CART['cart'][Cart::$COUPON_VALUE];
|
||
|
|
break;
|
||
|
|
case eShopCouponType::PERCENT:
|
||
|
|
default:
|
||
|
|
//$total_base *= (100-cfloatval($cart[Cart::$COUPON_VALUE]))/100;
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
*/
|
||
|
|
|
||
|
|
$data = [
|
||
|
|
'order'=>[
|
||
|
|
'id'=>$ORDER_ID,
|
||
|
|
'amount'=>cfloatval($ORDER_TOTAL),
|
||
|
|
'items'=>$items,
|
||
|
|
'prepaid_amount'=>cfloatval($order[Order::$TOTAL_PAID] + $CART['cart'][Cart::$COUPON_VALUE]),
|
||
|
|
],
|
||
|
|
'client_info'=>[
|
||
|
|
///'phone'=>$order[Order::$PHONE],
|
||
|
|
'email'=>$order[Order::$EMAIL],
|
||
|
|
],
|
||
|
|
'notification_url'=>$notification_url,
|
||
|
|
'fail_url' =>$options[self::URL_FAIL],
|
||
|
|
'success_url' =>$options[self::URL_SUCCESS],
|
||
|
|
'data' => [
|
||
|
|
'uuid'=>$uuid
|
||
|
|
]
|
||
|
|
];
|
||
|
|
if ($curl = curl_init()){
|
||
|
|
curl_setopt($curl, CURLOPT_URL, $url);
|
||
|
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
|
||
|
|
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER,0);
|
||
|
|
curl_setopt($curl, CURLOPT_POST,1);
|
||
|
|
|
||
|
|
//curl_setopt($curl, CURLOPT_CAINFO, __DIR__.'\open-api-cert.pem');
|
||
|
|
//curl_setopt($curl, CURLOPT_CAPATH , __DIR__.'');
|
||
|
|
//curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);
|
||
|
|
//curl_setopt($curl, CURLOPT_SSLCERTTYPE, 'PEM');
|
||
|
|
curl_setopt($curl, CURLOPT_SSLCERT, $options[self::PAYMENT_DATA]['crt']);
|
||
|
|
curl_setopt($curl, CURLOPT_SSLKEY, $options[self::PAYMENT_DATA]['key']);
|
||
|
|
//curl_setopt($curl, CURLOPT_SSLCERTPASSWD, $password);
|
||
|
|
|
||
|
|
|
||
|
|
curl_setopt($curl, CURLOPT_HTTPHEADER,$headers);
|
||
|
|
curl_setopt($curl, CURLOPT_POSTFIELDS,je($data));
|
||
|
|
|
||
|
|
$out = curl_exec($curl);
|
||
|
|
curl_close($curl);
|
||
|
|
$res = json_decode($out,true);
|
||
|
|
|
||
|
|
}
|
||
|
|
return $res['link'];
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
static function getTinkoffToken($args,$password) {
|
||
|
|
|
||
|
|
$token = '';
|
||
|
|
$args['Password'] = $password;
|
||
|
|
ksort($args);
|
||
|
|
|
||
|
|
foreach ($args as $arg) {
|
||
|
|
if (!is_array($arg)) {
|
||
|
|
$token .= $arg;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
$token = hash('sha256', $token);
|
||
|
|
|
||
|
|
return $token;
|
||
|
|
}
|
||
|
|
static function Tinkoff($order,$payment,$pay,$options){
|
||
|
|
$payment_options = json_decode($payment[Payment::$DATA],true);
|
||
|
|
$is_test = boolval($payment_options['is_test']);
|
||
|
|
|
||
|
|
|
||
|
|
$terminal = $payment_options[($is_test?'test_':'').'terminal'];
|
||
|
|
$password = $payment_options[($is_test?'test_':'').'pass'];
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
$ORDER_TOTAL = cfloatval($pay[Pay::$VALUE]);
|
||
|
|
$ORDER_ID = $order[Order::$ID];
|
||
|
|
$EMAIL = $order[Order::$EMAIL];
|
||
|
|
|
||
|
|
$PAY_ID = $pay[Pay::$ID];
|
||
|
|
|
||
|
|
|
||
|
|
$url = 'https://securepay.tinkoff.ru/v2/Init';
|
||
|
|
$data = [
|
||
|
|
'TerminalKey'=>$terminal,
|
||
|
|
'Amount'=>intval($ORDER_TOTAL*100),
|
||
|
|
'OrderId'=>$ORDER_ID."_".time(),
|
||
|
|
"DATA"=> ["pay_id"=>$PAY_ID],
|
||
|
|
"data"=> ["pay_id"=>$PAY_ID],
|
||
|
|
];
|
||
|
|
|
||
|
|
//if($c = $options[self::URL_NOTIFICATION]) $data['NotificationURL'] = $c;
|
||
|
|
//if($c = $options[self::URL_SUCCESS]) $data['SuccessURL'] = $c;
|
||
|
|
//if($c = $options[self::URL_FAIL]) $data['FailURL'] = $c;
|
||
|
|
|
||
|
|
$token_data = [
|
||
|
|
'TerminalKey'=>$data['TerminalKey'],
|
||
|
|
'Amount'=>$data['Amount'],
|
||
|
|
'OrderId'=>$data['OrderId'],
|
||
|
|
];
|
||
|
|
$data['Token'] = self::getTinkoffToken($token_data,$password);
|
||
|
|
|
||
|
|
|
||
|
|
if ($curl = curl_init()){
|
||
|
|
curl_setopt($curl, CURLOPT_URL, $url);
|
||
|
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
|
||
|
|
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER,0);
|
||
|
|
curl_setopt($curl, CURLOPT_POST,1);
|
||
|
|
//curl_setopt($curl, CURLOPT_FRESH_CONNECT,1);
|
||
|
|
curl_setopt($curl, CURLOPT_POSTFIELDS,json_encode($data));
|
||
|
|
//curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 3);
|
||
|
|
//curl_setopt($curl, CURLOPT_VERBOSE , true);
|
||
|
|
//curl_setopt($curl, CURLOPT_STDERR , fopen(__DIR__.'/curl.log', 'w+'));
|
||
|
|
curl_setopt($curl, CURLOPT_HTTPHEADER,[
|
||
|
|
'Content-type:application/json',
|
||
|
|
]);
|
||
|
|
$out = curl_exec($curl);
|
||
|
|
if (curl_errno($curl)) {
|
||
|
|
// echo 'Error:' . curl_error($curl);
|
||
|
|
}
|
||
|
|
curl_close($curl);
|
||
|
|
$res = json_decode($out,true);
|
||
|
|
$link = $res['PaymentURL'];
|
||
|
|
$res['link'] = $link;
|
||
|
|
}
|
||
|
|
return $res;
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
}
|