198 lines
7.5 KiB
PHP
198 lines
7.5 KiB
PHP
<?
|
|
|
|
namespace integration;
|
|
|
|
|
|
use integration\ucscards\structure\Amount;
|
|
use integration\ucscards\structure\CustomerInfo;
|
|
use integration\ucscards\structure\OrderID;
|
|
use integration\ucscards\structure\OrderInfo;
|
|
use integration\ucscards\structure\OrderItem;
|
|
use integration\ucscards\structure\PostEntry;
|
|
use integration\ucscards\structure\Register;
|
|
|
|
class UCSCards {
|
|
|
|
|
|
private static $classmap = array(
|
|
"PaymentArray" => "PaymentArray",
|
|
"get_finished" => "get_finished",
|
|
"OrderItem" => "OrderItem",
|
|
"stringArray" => "stringArray",
|
|
"cancelResponse" => "cancelResponse",
|
|
"AttemptArray" => "AttemptArray",
|
|
"rejectResponse" => "rejectResponse",
|
|
"Attempt" => "Attempt",
|
|
"get_status" => "get_status",
|
|
"OnlineResult" => "OnlineResult",
|
|
"cancel" => "cancel",
|
|
"confirmResponse" => "confirmResponse",
|
|
"OrderStatus" => "OrderStatus",
|
|
"Amount" => "Amount",
|
|
"Document" => "Document",
|
|
"confirm" => "confirm",
|
|
"PostEntryArray" => "PostEntryArray",
|
|
"Error" => "Error",
|
|
"OrderItemArray" => "OrderItemArray",
|
|
"Payment" => "PaymentClass",
|
|
"register_deposit" => "register_deposit",
|
|
"OrderInfo" => "OrderInfo",
|
|
"get_finishedResponse" => "get_finishedResponse",
|
|
"CardInfo" => "CardInfo",
|
|
"reject" => "reject",
|
|
"OrderStatusArray" => "OrderStatusArray",
|
|
"CardInfoArray" => "CardInfoArray",
|
|
"refund" => "refund",
|
|
"OrderID" => "OrderID",
|
|
"CustomerInfo" => "CustomerInfo",
|
|
"PostEntry" => "PostEntry",
|
|
"register" => "register",
|
|
"get_statusResponse" => "get_statusResponse",
|
|
"register_onlineResponse" => "register_onlineResponse",
|
|
"refundResponse" => "refundResponse",
|
|
"Taxes" => "Taxes",
|
|
"tax" => "tax",
|
|
);
|
|
|
|
// подготавливаем новое soap-соединение
|
|
public static function newSoap($settings):\SoapClient {
|
|
try {
|
|
return new \SoapClient(
|
|
null,
|
|
array(
|
|
'location' => $settings['shop_url'],
|
|
'uri' => 'http://www.sirena-travel.ru',
|
|
'login' => $settings['shop_login'],
|
|
'password' => $settings['shop_pass'],
|
|
'trace' => 0,
|
|
'features' => SOAP_SINGLE_ELEMENT_ARRAYS,
|
|
'connection_timeout' => 12
|
|
)
|
|
);
|
|
} catch (\SoapFault $e) {
|
|
}
|
|
}
|
|
|
|
|
|
// подготавливаем данные заказа для отправки
|
|
public static function prepareOrder($settings) {
|
|
$request = new Register();
|
|
$order = new OrderID();
|
|
$order->shop_id = $settings['shop_id'];
|
|
$order->number = $settings['order_id'];
|
|
$cost = new Amount();
|
|
$cost->amount = $settings['order_sum'];
|
|
$cost->currency = 'RUB';
|
|
$customer = new CustomerInfo();
|
|
if ($settings['user_id'] != 0) {
|
|
$customer->id = $settings['user_id'];
|
|
}
|
|
$customer->name = $settings['user_name'];
|
|
if (!empty($settings['user_email']) && $settings['user_email']) {
|
|
$customer->email = $settings['user_email'];
|
|
}
|
|
if (!empty($settings['user_phone']) && $settings['user_phone']) {
|
|
$customer->phone = $settings['user_phone'];
|
|
}
|
|
|
|
|
|
$description = new OrderInfo();
|
|
$description->paytype = 'card';
|
|
$arBasketItems = $settings['basket_items'];
|
|
$arItems = array();
|
|
|
|
$sumWithoutBonus = 0;
|
|
foreach ($arBasketItems as $item) {
|
|
$sumWithoutBonus += round($item['PRICE'], 2) * $item['QUANTITY'];
|
|
}
|
|
|
|
$bonus = $sumWithoutBonus - $cost->amount;
|
|
|
|
for ($i = 0; $i < count($arBasketItems); $i++){
|
|
$itemCost = new Amount();
|
|
$itemCost->amount = round($arBasketItems[$i]['PRICE'], 2) * $arBasketItems[$i]['QUANTITY'];
|
|
$itemCost->currency = 'RUB';
|
|
|
|
if ($bonus > 0) {
|
|
var_dump('amount');
|
|
var_dump($itemCost->amount);
|
|
if ($bonus - $itemCost->amount > 0) {
|
|
$bonus -= $itemCost->amount;
|
|
$itemCost->amount = 0;
|
|
} else {
|
|
$itemCost->amount -= $bonus;
|
|
$bonus = 0;
|
|
}
|
|
}
|
|
|
|
// $itemTaxes = array(
|
|
// new SoapVar("<tax type='vat'><percentage>".substr($arBasketItems[$i]['VAT'],0,2)."</percentage><amount><currency>RUB</currency><amount>".round($arBasketItems[$i]['VAT_VALUE'], 2)."</amount></amount></tax>", XSD_ANYXML),
|
|
// );
|
|
|
|
$item = new OrderItem();
|
|
$item->number = $settings['order_id'];
|
|
$item->amount = $itemCost;
|
|
$item->typename = 'goods';
|
|
$item->quantity = $arBasketItems[$i]['QUANTITY'];
|
|
$item->name = $arBasketItems[$i]['NAME'];
|
|
// $item->taxes = new SoapVar($itemTaxes, SOAP_ENC_OBJECT);
|
|
|
|
$arItems[] = new \SoapVar($item, SOAP_ENC_OBJECT, null, null, 'OrderItem');
|
|
}
|
|
|
|
$description->sales = new \SoapVar(
|
|
$arItems,
|
|
SOAP_ENC_OBJECT
|
|
);
|
|
|
|
$language = new PostEntry();
|
|
$language->name = 'Language';
|
|
$language->value = 'ru';
|
|
$returnUrlOk = new PostEntry();
|
|
$returnUrlOk->name = 'ReturnURLOk';
|
|
$returnUrlOk->value = $settings['return_url'] . '&status=ok';
|
|
$returnUrlFault = new PostEntry();
|
|
$returnUrlFault->name = 'ReturnURLFault';
|
|
$returnUrlFault->value = $settings['return_url'] . '&status=fault';
|
|
$cardtype = new PostEntry();
|
|
$cardtype->name = 'ChoosenCardType';
|
|
$cardtype->value = 'VI';
|
|
$request->order = $order;
|
|
$request->cost = $cost;
|
|
$request->customer = $customer;
|
|
$request->description = $description;
|
|
|
|
$postdata = array(
|
|
new \SoapVar($language, SOAP_ENC_OBJECT, null, null, 'PostEntry'),
|
|
new \SoapVar($cardtype, SOAP_ENC_OBJECT, null, null, 'PostEntry'),
|
|
new \SoapVar($returnUrlOk, SOAP_ENC_OBJECT, null, null, 'PostEntry'),
|
|
new \SoapVar($returnUrlFault, SOAP_ENC_OBJECT, null, null, 'PostEntry')
|
|
);
|
|
if (!empty($settings['comment'])) {
|
|
$comment = new PostEntry();
|
|
$comment->name = 'Comment';
|
|
$comment->value = $settings['comment'];
|
|
$postdata[] = new \SoapVar($comment, SOAP_ENC_OBJECT, null, null, 'PostEntry');
|
|
}
|
|
|
|
$request->postdata = new \SoapVar($postdata, SOAP_ENC_OBJECT);
|
|
|
|
|
|
$soap = self::newSoap( $settings );
|
|
$soap->register($request);
|
|
|
|
|
|
$a = $soap->__soapCall('register',[$request]);
|
|
/*
|
|
echo '<pre>';
|
|
echo var_dump($a,$soap);
|
|
echo '</pre>';
|
|
/**/
|
|
return $request;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|