Changeset 3106617
- Timestamp:
- 06/24/2024 11:12:15 AM (22 months ago)
- Location:
- robokassa/trunk
- Files:
-
- 4 edited
-
classes/Robokassa/Payment/RobokassaPayAPI.php (modified) (22 diffs)
-
classes/Robokassa/Payment/WC_WP_robokassa.php (modified) (6 diffs)
-
readme.txt (modified) (2 diffs)
-
wp_robokassa.php (modified) (24 diffs)
Legend:
- Unmodified
- Added
- Removed
-
robokassa/trunk/classes/Robokassa/Payment/RobokassaPayAPI.php
r3026682 r3106617 6 6 7 7 /** 8 * @varstring8 * @var string 9 9 */ 10 10 private $mrh_login; 11 11 12 12 /** 13 * @varstring13 * @var string 14 14 */ 15 15 private $mrh_pass1; 16 16 17 17 /** 18 * @varstring18 * @var string 19 19 */ 20 20 private $mrh_pass2; 21 21 22 22 /** 23 * @varstring23 * @var string 24 24 */ 25 25 private $method; 26 26 27 27 /** 28 * @varstring28 * @var string 29 29 */ 30 30 private $apiUrl; 31 31 32 32 /** 33 * @varstring33 * @var string 34 34 */ 35 35 private $reply = ''; 36 36 37 37 /** 38 * @varstring38 * @var string 39 39 */ 40 40 private $request = ''; 41 41 42 42 /** 43 * @returnstring43 * @return string 44 44 */ 45 45 public function getReply() { … … 48 48 49 49 /** 50 * @returnstring50 * @return string 51 51 */ 52 52 public function getRequest() { … … 55 55 56 56 /** 57 * @returnstring57 * @return string 58 58 */ 59 59 public function getSendResult() { … … 65 65 66 66 /** 67 * @paramstring$login68 * @paramstring$pass169 * @paramstring$pass270 * @paramstring$method67 * @param string $login 68 * @param string $pass1 69 * @param string $pass2 70 * @param string $method 71 71 */ 72 72 public function __construct($login, $pass1, $pass2, $method = 'md5') { … … 80 80 81 81 /** 82 * @paramstring$mthd83 * @paramarray$data84 * 85 * @returnarray82 * @param string $mthd 83 * @param array $data 84 * 85 * @return array 86 86 */ 87 87 private function sendRequest($mthd, $data) { … … 93 93 * он не использоваться, а если не пустой - используем его json-представление 94 94 * 95 * @paramstring$sum96 * @paramstring$invId97 * @paramstring$receiptJson98 * 99 * @returnstring95 * @param string $sum 96 * @param string $invId 97 * @param string $receiptJson 98 * 99 * @return string 100 100 */ 101 101 private function getSignatureString($sum, $invId, $receiptJson, $recurring = false) … … 130 130 * Генерирует хеш для строки $string с помощью метода $method 131 131 * 132 * @paramstring$string133 * @paramstring$method134 * 135 * @returnstring136 * 137 * @throws\Exception132 * @param string $string 133 * @param string $method 134 * 135 * @return string 136 * 137 * @throws \Exception 138 138 */ 139 139 public function getSignature($string, $method = 'md5') { … … 148 148 * Генерирует форму, в Opencart модуле НЕ ИСПОЛЬЗУЕТСЯ! 149 149 * 150 * @paramfloat$sum151 * @paramint$invId152 * @paramstring$invDesc153 * @paramstring$test154 * @paramstring$incCurrLabel155 * @paramarray$receipt156 * 157 * @paramnull$email158 * @returnstring159 * 160 * @throws\Exception150 * @param float $sum 151 * @param int $invId 152 * @param string $invDesc 153 * @param string $test 154 * @param string $incCurrLabel 155 * @param array $receipt 156 * 157 * @param null $email 158 * @return string 159 * 160 * @throws \Exception 161 161 */ 162 162 public function createForm( … … 239 239 240 240 /** 241 * @paramstring$formUrl242 * @paramarray$formData243 * 244 * @returnstring241 * @param string $formUrl 242 * @param array $formData 243 * 244 * @return string 245 245 */ 246 246 private function renderForm($formUrl, array $formData) { … … 261 261 foreach ($formData as $inputName => $inputValue){ 262 262 if($inputName != 'IsTest'){ 263 $value = htmlspecialchars($inputValue, ENT_COMPAT, 'UTF-8');263 $value = htmlspecialchars($inputValue, ENT_COMPAT, 'UTF-8'); 264 264 265 265 if($lastParam == $inputValue){ … … 275 275 $form .= "<script type=\"text/javascript\"> document.getElementById('robokassa').click(); </script>"; 276 276 } 277 elseif (get_option('robokassa_podeli') && $formData['IncCurrLabel'] == 'Podeli') {277 if (get_option('robokassa_podeli') && isset($formData['IncCurrLabel']) && $formData['IncCurrLabel'] == 'Podeli') { 278 278 279 279 $params = ''; … … 282 282 foreach ($formData as $inputName => $inputValue){ 283 283 if($inputName != 'IsTest'){ 284 $value = htmlspecialchars($inputValue, ENT_COMPAT, 'UTF-8');284 $value = htmlspecialchars($inputValue, ENT_COMPAT, 'UTF-8'); 285 285 286 286 if($lastParam == $inputValue){ … … 295 295 $form .= "<script type=\"text/javascript\"> document.getElementById('robokassa').click(); </script>"; 296 296 } 297 elseif (get_option('robokassa_podeli') && $formData['IncCurrLabel'] == 'AlwaysYes') {297 if (get_option('robokassa_podeli') && isset($formData['IncCurrLabel']) && $formData['IncCurrLabel'] == 'AlwaysYes') { 298 298 299 299 $params = ''; … … 302 302 foreach ($formData as $inputName => $inputValue){ 303 303 if($inputName != 'IsTest'){ 304 $value = htmlspecialchars($inputValue, ENT_COMPAT, 'UTF-8');304 $value = htmlspecialchars($inputValue, ENT_COMPAT, 'UTF-8'); 305 305 306 306 if($lastParam == $inputValue){ … … 316 316 }else { 317 317 $form = '<div class="preloader"> 318 <svg class="preloader__image" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">319 <path fill="currentColor"320 d="M304 48c0 26.51-21.49 48-48 48s-48-21.49-48-48 21.49-48 48-48 48 21.49 48 48zm-48 368c-26.51 0-48 21.49-48 48s21.49 48 48 48 48-21.49 48-48-21.49-48-48-48zm208-208c-26.51 0-48 21.49-48 48s21.49 48 48 48 48-21.49 48-48-21.49-48-48-48zM96 256c0-26.51-21.49-48-48-48S0 229.49 0 256s21.49 48 48 48 48-21.49 48-48zm12.922 99.078c-26.51 0-48 21.49-48 48s21.49 48 48 48 48-21.49 48-48c0-26.509-21.491-48-48-48zm294.156 0c-26.51 0-48 21.49-48 48s21.49 48 48 48 48-21.49 48-48c0-26.509-21.49-48-48-48zM108.922 60.922c-26.51 0-48 21.49-48 48s21.49 48 48 48 48-21.49 48-48-21.491-48-48-48z">321 </path>322 </svg>323 </div>324 <style>325 .preloader {326 position: fixed;327 left: 0;328 top: 0;329 right: 0;330 bottom: 0;331 overflow: hidden;332 /* фоновый цвет */333 background: #e0e0e0;334 z-index: 1001;335 }336 337 .preloader__image {338 position: relative;339 top: 50%;340 left: 50%;341 width: 70px;342 height: 70px;343 margin-top: -35px;344 margin-left: -35px;345 text-align: center;346 animation: preloader-rotate 2s infinite linear;347 }348 349 @keyframes preloader-rotate {350 100% {351 transform: rotate(360deg);352 }353 }354 355 .loaded_hiding .preloader {356 transition: 0.3s opacity;357 opacity: 0;358 }359 360 .loaded .preloader {361 display: none;362 }363 </style>364 <script>365 window.onload = function () {366 document.body.classList.add("loaded_hiding");367 window.setTimeout(function () {368 document.body.classList.add("loaded");369 document.body.classList.remove("loaded_hiding");370 }, 1000);371 }372 </script>';318 <svg class="preloader__image" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"> 319 <path fill="currentColor" 320 d="M304 48c0 26.51-21.49 48-48 48s-48-21.49-48-48 21.49-48 48-48 48 21.49 48 48zm-48 368c-26.51 0-48 21.49-48 48s21.49 48 48 48 48-21.49 48-48-21.49-48-48-48zm208-208c-26.51 0-48 21.49-48 48s21.49 48 48 48 48-21.49 48-48-21.49-48-48-48zM96 256c0-26.51-21.49-48-48-48S0 229.49 0 256s21.49 48 48 48 48-21.49 48-48zm12.922 99.078c-26.51 0-48 21.49-48 48s21.49 48 48 48 48-21.49 48-48c0-26.509-21.491-48-48-48zm294.156 0c-26.51 0-48 21.49-48 48s21.49 48 48 48 48-21.49 48-48c0-26.509-21.49-48-48-48zM108.922 60.922c-26.51 0-48 21.49-48 48s21.49 48 48 48 48-21.49 48-48-21.491-48-48-48z"> 321 </path> 322 </svg> 323 </div> 324 <style> 325 .preloader { 326 position: fixed; 327 left: 0; 328 top: 0; 329 right: 0; 330 bottom: 0; 331 overflow: hidden; 332 /* фоновый цвет */ 333 background: #e0e0e0; 334 z-index: 1001; 335 } 336 337 .preloader__image { 338 position: relative; 339 top: 50%; 340 left: 50%; 341 width: 70px; 342 height: 70px; 343 margin-top: -35px; 344 margin-left: -35px; 345 text-align: center; 346 animation: preloader-rotate 2s infinite linear; 347 } 348 349 @keyframes preloader-rotate { 350 100% { 351 transform: rotate(360deg); 352 } 353 } 354 355 .loaded_hiding .preloader { 356 transition: 0.3s opacity; 357 opacity: 0; 358 } 359 360 .loaded .preloader { 361 display: none; 362 } 363 </style> 364 <script> 365 window.onload = function () { 366 document.body.classList.add("loaded_hiding"); 367 window.setTimeout(function () { 368 document.body.classList.add("loaded"); 369 document.body.classList.remove("loaded_hiding"); 370 }, 1000); 371 } 372 </script>'; 373 373 $form .= "<form action=\"$formUrl\" method=\"POST\">"; 374 374 375 375 foreach ($formData as $inputName => $inputValue) { 376 $value = htmlspecialchars($inputValue, ENT_COMPAT, 'UTF-8');376 $value = htmlspecialchars($inputValue, ENT_COMPAT, 'UTF-8'); 377 377 378 378 $form .= "<input type=\"hidden\" name=\"$inputName\" value=\"$value\">"; … … 389 389 * Отправляет СМС с помощью GET-запроса на робокассу 390 390 * 391 * @paramstring$phone392 * @paramstring$message393 * 394 * @returnbool395 * @throws\Exception391 * @param string $phone 392 * @param string $message 393 * 394 * @return bool 395 * @throws \Exception 396 396 */ 397 397 public function sendSms($phone, $message) { … … 417 417 * Запрашиват размер комиссии в процентах для конкретного способа оплаты 418 418 * 419 * @paramstring$incCurrLabelКодовое имя метода оплаты420 * @paramint$sumСтоимость товара421 * 422 * @returnfloat Комиссия метода в %419 * @param string $incCurrLabel Кодовое имя метода оплаты 420 * @param int $sum Стоимость товара 421 * 422 * @return float Комиссия метода в % 423 423 */ 424 424 public function getCommission($incCurrLabel, $sum = 10000) { … … 443 443 * Возвращает сумму к оплате с учетом комиссий. 444 444 * 445 * @paramstring$incCurrLabelКодовое имя метода оплаты446 * @paramint$sumСтоимость товара447 * 448 * @returnfloat Стоимость, которую необходимо передавать в Робокассу.445 * @param string $incCurrLabel Кодовое имя метода оплаты 446 * @param int $sum Стоимость товара 447 * 448 * @return float Стоимость, которую необходимо передавать в Робокассу. 449 449 */ 450 450 public function getCommissionSum($incCurrLabel, $sum) { … … 461 461 * Запрашивает и парсит в массив все возможные способы оплаты для данного магазина 462 462 * 463 * @returnarray463 * @return array 464 464 */ 465 465 public function getCurrLabels() … … 474 474 * Парсит XML в JSON 475 475 * 476 * @paramstring$url477 * 478 * @returnstring476 * @param string $url 477 * 478 * @return string 479 479 */ 480 480 public function parseXmlAndConvertToJson($url) { … … 489 489 * Запрашивает у робокассы подтверждение платежа 490 490 * 491 * @paramint$invId492 * 493 * @returnbool491 * @param int $invId 492 * 493 * @return bool 494 494 */ 495 495 public function reCheck($invId) { … … 513 513 'PreviousInvoiceID' => $parentInvoiceId, 514 514 'Description' => '', 515 'SignatureValue' => $this->getSignature($this->getSignatureString($amount, $invoiceId, $receiptJson, false)),515 'SignatureValue' => md5("{$this->mrh_login}:{$amount}:{$invoiceId}:{$receiptJson}:{$this->mrh_pass1}:shp_label=official_wordpress"), 516 516 'OutSum' => $amount, 517 517 'shp_label' => 'official_wordpress', -
robokassa/trunk/classes/Robokassa/Payment/WC_WP_robokassa.php
r2988879 r3106617 42 42 43 43 44 $this->title = \mb_strlen(get_option('RobokassaOrderPageTitle_' . $this->id, null)) > 044 $this->title = !empty(get_option('RobokassaOrderPageTitle_' . $this->id, null)) 45 45 ? get_option('RobokassaOrderPageTitle_' . $this->id, null) 46 : $this->title 47 ; 48 49 $this->description = \mb_strlen(get_option('RobokassaOrderPageDescription_' . $this->id, null)) > 0 46 : $this->title; 47 48 $this->description = !empty(get_option('RobokassaOrderPageDescription_' . $this->id, null)) 50 49 ? get_option('RobokassaOrderPageDescription_' . $this->id, null) 51 : $this->description 52 ; 50 : $this->description; 53 51 54 52 $this->supports = [ … … 93 91 echo '<p>Спасибо за ваш заказ, пожалуйста, нажмите ниже на кнопку, чтобы заплатить.</p>'; 94 92 95 robokassa_payment_createFormWC($order, $this->id , $this->commission);93 robokassa_payment_createFormWC($order, $this->id); 96 94 } 97 95 … … 116 114 */ 117 115 public function process_subscription_payment( $amount, $renewal_order, $retry = true, $previous_error = false ) { 118 global $woocommerce; 119 $cart = $woocommerce->cart->get_cart(); 120 $taxes = $woocommerce->cart->get_cart_contents_tax(); 121 122 $order_id = $renewal_order->get_id(); 123 $subscribe = reset(wcs_get_subscriptions_for_renewal_order($renewal_order)); 124 $parent = $subscribe->get_parent(); 116 117 $taxes = $renewal_order->get_cart_tax(); 118 $order_id = $renewal_order->get_id(); 119 120 121 $subscriptions = wcs_get_subscriptions_for_renewal_order($renewal_order); 122 $subscribe = reset($subscriptions); 123 124 $parent = $subscribe->get_parent(); 125 125 126 126 $mrhLogin = get_option('robokassa_payment_MerchantLogin'); … … 152 152 $current['quantity'] = (float)$item['quantity']; 153 153 154 $tax_per_item = ($taxes / $ woocommerce->cart->get_cart_contents_count()) * $current['quantity'];154 $tax_per_item = ($taxes / $renewal_order->get_item_count()) * $current['quantity']; 155 155 156 156 $current['cost'] = ($item['line_total'] + $tax_per_item) / $current['quantity']; … … 175 175 $current['cost'] = (double)\sprintf( 176 176 "%01.2f", 177 $renewal_order->get_shipping_total()177 ( $renewal_order->get_shipping_total() + $renewal_order->get_shipping_tax() ) 178 178 ); 179 179 $current['payment_object'] = \get_option('robokassa_payment_paymentObject'); … … 181 181 182 182 if (isset($receipt['sno']) && ($receipt['sno'] == 'osn')) { 183 $current['tax'] = $ tax;183 $current['tax'] = $renewal_order->get_shipping_tax(); 184 184 } else { 185 185 $current['tax'] = 'none'; -
robokassa/trunk/readme.txt
r3092020 r3106617 3 3 Requires at least: 5.7 4 4 Tested up to: 6.5.3 5 Stable tag: 1.6. 05 Stable tag: 1.6.1 6 6 Requires PHP: 5.6.32 7 7 License: GPLv2 or later … … 77 77 == Changelog == 78 78 79 = 1.6.1 = 80 * Исправлены незначительные ошибки 81 79 82 = 1.6.0 = 80 83 * Добавлена поддержка плагина ["WooCommerce Checkout Add-Ons"](https://woocommerce.com/products/woocommerce-checkout-add-ons/) -
robokassa/trunk/wp_robokassa.php
r3096888 r3106617 6 6 * Author: Robokassa 7 7 * Author URI: https://robokassa.com 8 * Version: 1.6. 08 * Version: 1.6.1 9 9 */ 10 10 … … 41 41 \spl_autoload_register( 42 42 function ($className) { 43 $file = __DIR__. '/classes/' . \str_replace('\\', '/', $className) . '.php';43 $file = __DIR__ . '/classes/' . \str_replace('\\', '/', $className) . '.php'; 44 44 45 45 if (file_exists($file)) … … 658 658 } 659 659 660 $order->set_address(array(// Здесь наверное что-то должно быть, но Егорушка малолетний долбоклюй 661 ), 'billing'); 660 $order->set_address(array(), 'billing'); 662 661 663 662 $order->calculate_totals(); … … 700 699 701 700 /** 702 * Формирование формы, перенаправляющей пользователя на сайт робокассы 703 * 704 * Включает в себя подготовку данных и рендеринг самой формы 701 * 702 * Проверка режимы работы 703 * 704 * @return void 705 */ 706 function getRobokassaPasses() 707 { 708 if (get_option('robokassa_payment_test_onoff') == 'true') { 709 return [ 710 'pass1' => get_option('robokassa_payment_testshoppass1'), 711 'pass2' => get_option('robokassa_payment_testshoppass2'), 712 ]; 713 } else { 714 return [ 715 'pass1' => get_option('robokassa_payment_shoppass1'), 716 'pass2' => get_option('robokassa_payment_shoppass2'), 717 ]; 718 } 719 } 720 721 /** 722 * Подготовка товарной номенклатуры для формирования чека 705 723 * 706 724 * @param mixed $order_id 707 * @param $label 708 * @param int $commission 709 * 710 * @return void 711 */ 712 function robokassa_payment_createFormWC($order_id, $label, $commission = 0) 713 { 714 $mrhLogin = get_option('robokassa_payment_MerchantLogin'); 715 716 if (get_option('robokassa_payment_test_onoff') == 'true') { 717 $pass1 = get_option('robokassa_payment_testshoppass1'); 718 $pass2 = get_option('robokassa_payment_testshoppass2'); 719 } else { 720 $pass1 = get_option('robokassa_payment_shoppass1'); 721 $pass2 = get_option('robokassa_payment_shoppass2'); 722 } 723 724 $rb = new RobokassaPayAPI($mrhLogin, $pass1, $pass2); 725 726 $order = wc_get_order($order_id); 725 * 726 * @return void 727 */ 728 function createRobokassaReceipt($order_id) 729 { 730 global $woocommerce; 731 $order = new WC_Order($order_id); 727 732 728 733 $sno = get_option('robokassa_payment_sno'); 729 $tax = get_option('robokassa_payment_tax');730 731 if ($tax == "vat118") $tax = "vat120";732 733 $receipt = array();734 735 734 if ($sno != 'fckoff' && get_option('robokassa_country_code') == 'RU') { 736 735 $receipt['sno'] = $sno; 737 736 } 738 737 739 global $woocommerce; 738 $tax = get_option('robokassa_payment_tax'); 739 if ($tax == "vat118") $tax = "vat120"; 740 740 741 $cart = $woocommerce->cart->get_cart(); 741 $taxes = $woocommerce->cart->get_cart_contents_tax(); 742 743 $receipt = array(); 744 745 $total_order = $order->get_total(); // Сумма OutSum 746 $total_receipt = 0; // Сумма всех $current['sum'] 742 747 743 748 foreach ($cart as $item) { … … 751 756 $current['name'] = $product->get_title(); 752 757 $current['quantity'] = 1; 753 754 // Получаем цену каждого товара 755 $item_price = $product->get_price(); 756 757 // Рассчитываем налог на единицу товара 758 $tax_per_item = ($taxes / $woocommerce->cart->get_cart_contents_count()); 759 760 // Устанавливаем цену и сумму для текущего товара 761 $current['cost'] = $item_price + $tax_per_item; 762 $current['sum'] = $current['cost']; 758 $current['sum'] = $item['line_total']; 759 $current['cost'] = $item['line_total'] / $quantity; 760 761 $total_receipt += $current['cost']; 763 762 764 763 if (get_option('robokassa_country_code') == 'RU') { … … 778 777 $current = []; 779 778 $current['name'] = $product->get_title(); 780 $current['quantity'] = (float)$item['quantity']; 781 782 // Получаем цену каждого товара 783 $item_price = $product->get_price(); 784 785 // Рассчитываем налог на все количество текущего товара 786 $tax_per_item = ($taxes / $woocommerce->cart->get_cart_contents_count()) * $current['quantity']; 787 788 // Устанавливаем цену и сумму для текущего товара 789 $current['cost'] = $item_price + ($tax_per_item / $current['quantity']); 790 $current['sum'] = $current['cost'] * $current['quantity']; 779 $current['quantity'] = $quantity; 780 $current['sum'] = $item['line_total']; 781 $current['cost'] = $item['line_total'] / $quantity; 782 783 $total_receipt += $current['sum']; 791 784 792 785 if (get_option('robokassa_country_code') == 'RU') { … … 805 798 } 806 799 807 808 // Проверяем, активен ли плагин WooCommerce Checkout Add-Ons 800 // Активность плагина WooCommerce Checkout Add-Ons 809 801 if (is_plugin_active('woocommerce-checkout-add-ons/woocommerce-checkout-add-ons.php')) { 810 $ fees = $order->get_items('fee');811 foreach ($fees as $fee) { 812 813 $ fee_name = $fee->get_name();814 $ fee_total = floatval($fee->get_total());815 816 $ fee_data = array(817 'name' => $ fee_name,802 $additional_items = $order->get_items('fee'); 803 804 foreach ($additional_items as $additional_item) { 805 $additional_item_name = $additional_item->get_name(); 806 $additional_item_total = floatval($additional_item->get_total()); 807 808 $additional_item_data = array( 809 'name' => $additional_item_name, 818 810 'quantity' => 1, 819 'cost' => $ fee_total,820 'sum' => $ fee_total,811 'cost' => $additional_item_total, 812 'sum' => $additional_item_total, 821 813 'payment_object' => \get_option('robokassa_payment_paymentObject'), 822 814 'payment_method' => \get_option('robokassa_payment_paymentMethod'), … … 824 816 ); 825 817 826 $receipt['items'][] = $fee_data; 818 $receipt['items'][] = $additional_item_data; 819 $total_receipt += $additional_item_total; 827 820 } 828 821 } … … 837 830 $current['quantity'] = (float)$item->get_quantity(); 838 831 839 $current[' cost'] = number_format($product->get_price(), 2, '.', '');840 $current[' sum'] = $current['cost'] * $current['quantity'];832 $current['sum'] = $item['line_total']; 833 $current['cost'] = $item['line_total'] / $quantity; 841 834 842 835 $current['payment_object'] = \get_option('robokassa_payment_paymentObject'); … … 850 843 851 844 $receipt['items'][] = $current; 845 $total_receipt += $current['sum']; 852 846 } 853 847 … … 862 856 $order->get_shipping_total() 863 857 ); 864 $current['sum'] = $current['cost'] * $current['quantity'];865 866 858 867 859 if (get_option('robokassa_country_code') == 'RU') { … … 877 869 878 870 $receipt['items'][] = $current; 879 } 871 $total_receipt += $current['cost']; 872 } 873 874 if ($total_receipt != $total_order) { 875 error_log('Robokassa: общая сумма чека (' . $total_receipt . ') НЕ совпадает с общей суммой заказа (' . $total_order . ')'); 876 } 877 878 return $receipt; 879 } 880 881 /** 882 * Формирование формы, перенаправляющей пользователя на сайт робокассы 883 * 884 * Включает в себя подготовку данных и рендеринг самой формы 885 * 886 * @param mixed $order_id 887 * @param $label 888 * 889 * @return void 890 */ 891 function processRobokassaPayment($order_id, $label) 892 { 893 $mrhLogin = get_option('robokassa_payment_MerchantLogin'); 894 $passes = getRobokassaPasses(); 895 $order = wc_get_order($order_id); 896 $receipt = createRobokassaReceipt($order_id); 897 898 $rb = new RobokassaPayAPI($mrhLogin, $passes['pass1'], $passes['pass2']); 880 899 881 900 $order_total = $order->get_total(); 882 883 901 $sum = number_format($order_total, 2, '.', ''); 884 902 … … 894 912 } 895 913 } 896 897 914 898 915 echo $rb->createForm( … … 908 925 } 909 926 927 function robokassa_payment_createFormWC($order_id, $label) 928 { 929 processRobokassaPayment($order_id, $label); 930 } 931 910 932 /** 911 933 * Начало оформления заказа … … 1048 1070 */ 1049 1071 function robokassa_2check_send($order_id, $old_status, $new_status) 1050 1051 1052 { 1072 { 1073 1053 1074 $payment_method = get_option('robokassa_payment_paymentMethod'); 1054 1075 $sno = get_option('robokassa_payment_sno'); 1055 1076 $tax = get_option('robokassa_payment_tax'); 1056 1077 1078 1057 1079 if ($payment_method == 'advance' || $payment_method == 'full_prepayment' || $payment_method == 'prepayment') { 1058 1059 1080 if ($sno == 'fckoff') { 1081 error_log("Robokassa: SNO is 'fckoff', exiting function"); 1060 1082 return; 1061 1083 } … … 1064 1086 1065 1087 if ($new_status != $trigger_status) { 1088 error_log("Robokassa: New status ($new_status) does not match trigger status ($trigger_status), exiting function"); 1066 1089 return; 1067 1090 } … … 1070 1093 1071 1094 if (!$order) { 1095 error_log("Robokassa: Order not found for order_id: $order_id, exiting function"); 1072 1096 return; 1073 1097 } 1074 1098 1075 if ($order->get_payment_method_title() != get_option('RobokassaOrderPageTitle_all')) { 1076 return; 1077 } 1099 /* if ($order->get_payment_method_title() != get_option('RobokassaOrderPageTitle_all')) { 1100 error_log("Payment method title does not match: " . $order->get_payment_method_title() . get_option('RobokassaOrderPageTitle_all') . ", exiting function"); 1101 return; 1102 }*/ 1078 1103 1079 1104 /** @var array $fields */ … … 1119 1144 case "vat0": 1120 1145 $fields['vats'][] = ['type' => $tax, 'sum' => 0]; 1146 break; 1121 1147 case "none": 1122 1148 $fields['vats'][] = ['type' => $tax, 'sum' => 0]; 1123 1149 break; 1124 1150 case "vat10": 1151 $fields['vats'][] = ['type' => $tax, 'sum' => ($shipping_total / 100) * 10]; 1152 break; 1153 case "vat20": 1154 $fields['vats'][] = ['type' => $tax, 'sum' => ($shipping_total / 100) * 20]; 1155 break; 1125 1156 default: 1126 1157 $fields['vats'][] = ['type' => 'novat', 'sum' => 0]; 1127 1158 break; 1128 1129 case "vat10":1130 $fields['vats'][] = ['type' => $tax, 'sum' => ($shipping_total / 100) * 10];1131 case "vat20":1132 $fields['vats'][] = ['type' => $tax, 'sum' => ($shipping_total / 100) * 20];1133 break;1134 1159 } 1160 1135 1161 } 1136 1162 … … 1157 1183 case "vat0": 1158 1184 $fields['vats'][] = ['type' => $tax, 'sum' => 0]; 1185 break; 1159 1186 case "none": 1160 1187 $fields['vats'][] = ['type' => $tax, 'sum' => 0]; 1161 1188 break; 1162 1189 case "vat10": 1190 $fields['vats'][] = ['type' => $tax, 'sum' => ($item['line_total'] / 100) * 10]; 1191 break; 1192 case "vat20": 1193 $fields['vats'][] = ['type' => $tax, 'sum' => ($item['line_total'] / 100) * 20]; 1194 break; 1163 1195 default: 1164 1196 $fields['vats'][] = ['type' => 'novat', 'sum' => 0]; 1165 break;1166 1167 case "vat10":1168 $fields['vats'][] = ['type' => $tax, 'sum' => ($item['line_total'] / 100) * 18];1169 case "vat20":1170 $fields['vats'][] = ['type' => $tax, 'sum' => ($item['line_total'] / 100) * 20];1171 1197 break; 1172 1198 } … … 1183 1209 ); 1184 1210 1211 1185 1212 if (get_option('robokassa_payment_test_onoff') == 'true') { 1186 1213 $pass1 = get_option('robokassa_payment_testshoppass1'); … … 1190 1217 $pass2 = get_option('robokassa_payment_shoppass2'); 1191 1218 } 1219 1192 1220 1193 1221 /** @var string $sign */ … … 1201 1229 ); 1202 1230 1231 1203 1232 $curl = curl_init('https://ws.roboxchange.com/RoboFiscal/Receipt/Attach'); 1204 curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");1205 curl_setopt($curl, CURLOPT_POSTFIELDS, $startupHash . '.' . $sign);1206 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);1207 curl_setopt($curl, CURLOPT_HTTPHEADER, array(1233 curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST"); 1234 curl_setopt($curl, CURLOPT_POSTFIELDS, $startupHash . '.' . $sign); 1235 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 1236 curl_setopt($curl, CURLOPT_HTTPHEADER, array( 1208 1237 'Content-Type: application/json', 1209 1238 'Content-Length: ' . strlen($startupHash . '.' . $sign)) 1210 1239 ); 1211 1240 $result = curl_exec($curl); 1241 1242 if ($result === false) { 1243 error_log("Robokassa: cURL error: " . curl_error($curl)); 1244 } else { 1245 error_log("Robokassa: cURL result: " . $result); 1246 } 1247 1212 1248 curl_close($curl); 1213 1249 } else { 1214 1215 } 1216 } 1217 1218 function robokassa_hold_confirm($order_id, $old_status, $new_status, $order) { 1250 error_log("Robokassa: Payment method is not advance, full_prepayment, or prepayment, no action taken"); 1251 } 1252 } 1253 1254 function robokassa_hold_confirm($order_id, $old_status, $new_status, $order) 1255 { 1219 1256 // Проверяем, что статус был изменен с "on-hold" на "processing" (обработка) 1220 1257 if ((get_option('robokassa_payment_hold_onoff') == 'true') … … 1280 1317 } 1281 1318 1282 function robokassa_hold_cancel($order_id, $old_status, $new_status, $order) { 1319 function robokassa_hold_cancel($order_id, $old_status, $new_status, $order) 1320 { 1283 1321 // Проверяем, что статус был изменен с "on-hold" на "Canceled" 1284 1322 if ((get_option('robokassa_payment_hold_onoff') == 'true') && … … 1309 1347 } 1310 1348 1311 function robokassa_hold_cancel_after5($order_id) { 1349 function robokassa_hold_cancel_after5($order_id) 1350 { 1312 1351 // Проверяем, что заказ существует 1313 1352 $order = wc_get_order($order_id);
Note: See TracChangeset
for help on using the changeset viewer.