Plugin Directory

Changeset 3026682


Ignore:
Timestamp:
01/25/2024 10:00:03 AM (2 years ago)
Author:
robokassa
Message:

1.5.8

Location:
robokassa/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • robokassa/trunk/classes/Robokassa/Payment/RobokassaPayAPI.php

    r2988879 r3026682  
    66
    77    /**
    8      * @var string
     8     *@varstring
    99     */
    1010    private $mrh_login;
    1111
    1212    /**
    13      * @var string
     13     *@varstring
    1414     */
    1515    private $mrh_pass1;
    1616
    1717    /**
    18      * @var string
     18     *@varstring
    1919     */
    2020    private $mrh_pass2;
    2121
    2222    /**
    23      * @var string
     23     *@varstring
    2424     */
    2525    private $method;
    2626
    2727    /**
    28      * @var string
     28     *@varstring
    2929     */
    3030    private $apiUrl;
    3131
    3232    /**
    33      * @var string
     33     *@varstring
    3434     */
    3535    private $reply = '';
    3636
    3737    /**
    38      * @var string
     38     *@varstring
    3939     */
    4040    private $request = '';
    4141
    4242    /**
    43      * @return string
     43     *@returnstring
    4444     */
    4545    public function getReply() {
     
    4848
    4949    /**
    50      * @return string
     50     *@returnstring
    5151     */
    5252    public function getRequest() {
     
    5555
    5656    /**
    57      * @return string
     57     *@returnstring
    5858     */
    5959    public function getSendResult() {
     
    6565
    6666    /**
    67      * @param string $login
    68      * @param string $pass1
    69      * @param string $pass2
    70      * @param string $method
     67     *@paramstring$login
     68     *@paramstring$pass1
     69     *@paramstring$pass2
     70     *@paramstring$method
    7171     */
    7272    public function __construct($login, $pass1, $pass2, $method = 'md5') {
     
    8080
    8181    /**
    82      * @param string $mthd
    83      * @param array  $data
    84      *
    85      * @return array
     82     *@paramstring$mthd
     83     *@paramarray$data
     84     *
     85     *@returnarray
    8686     */
    8787    private function sendRequest($mthd, $data) {
     
    9393     * он не использоваться, а если не пустой - используем его json-представление
    9494     *
    95      * @param string $sum
    96      * @param string $invId
    97      * @param string $receiptJson
    98      *
    99      * @return string
     95     *@paramstring$sum
     96     *@paramstring$invId
     97     *@paramstring$receiptJson
     98     *
     99     *@returnstring
    100100     */
    101101    private function getSignatureString($sum, $invId, $receiptJson, $recurring = false)
    102102    {
    103 
    104 
    105103        $outCurrency = get_option('robokassa_out_currency');
     104        $holdPaymentParam = (get_option('robokassa_payment_hold_onoff') == 'true') ? 'true' : '';
    106105
    107106        return \implode(
     
    114113                    $outCurrency,
    115114                    $receiptJson,
     115                    $holdPaymentParam,
     116                    urlencode((site_url('/?robokassa=result'))),
    116117                    $this->mrh_pass1,
    117118                    'shp_label=official_wordpress',
     
    129130     * Генерирует хеш для строки $string с помощью метода $method
    130131     *
    131      * @param string $string
    132      * @param string $method
    133      *
    134      * @return string
    135      *
    136      * @throws \Exception
     132     *@paramstring$string
     133     *@paramstring$method
     134     *
     135     *@returnstring
     136     *
     137     *@throws\Exception
    137138     */
    138139    public function getSignature($string, $method = 'md5') {
     
    147148     * Генерирует форму, в Opencart модуле НЕ ИСПОЛЬЗУЕТСЯ!
    148149     *
    149      * @param float $sum
    150      * @param int $invId
    151      * @param string $invDesc
    152      * @param string $test
    153      * @param string $incCurrLabel
    154      * @param array $receipt
    155      *
    156      * @param null $email
    157      * @return string
    158      *
    159      * @throws \Exception
     150     *@paramfloat$sum
     151     *@paramint$invId
     152     *@paramstring$invDesc
     153     *@paramstring$test
     154     *@paramstring$incCurrLabel
     155     *@paramarray$receipt
     156     *
     157     *@paramnull$email
     158     *@returnstring
     159     *
     160     *@throws\Exception
    160161     */
    161162    public function createForm(
     
    188189            'OutSum' => $sum,
    189190            'InvId' => $invId,
     191            'ResultUrl2' => urlencode(site_url('/?robokassa=result')),
    190192            'Desc' => $invDesc,
    191193            'shp_label' => 'official_wordpress',
     
    193195            'SignatureValue' => $this->getSignature($this->getSignatureString($sum, $invId, $receiptJson)),
    194196        );
     197
     198        if (get_option('robokassa_payment_hold_onoff') == 'true') {
     199            $formData['StepByStep'] = 'true';
     200        }
    195201
    196202        $formData['OutSumCurrency'] = get_option('robokassa_out_currency');
     
    233239
    234240    /**
    235      * @param string $formUrl
    236      * @param array  $formData
    237      *
    238      * @return string
     241     *@paramstring$formUrl
     242     *@paramarray$formData
     243     *
     244     *@returnstring
    239245     */
    240246    private function renderForm($formUrl, array $formData) {
     
    255261            foreach ($formData as $inputName => $inputValue){
    256262                if($inputName != 'IsTest'){
    257                     $value = htmlspecialchars($inputValue, ENT_COMPAT, 'UTF-8');
     263                    $value = htmlspecialchars($inputValue,ENT_COMPAT, 'UTF-8');
    258264
    259265                    if($lastParam == $inputValue){
     
    276282            foreach ($formData as $inputName => $inputValue){
    277283                if($inputName != 'IsTest'){
    278                     $value = htmlspecialchars($inputValue, ENT_COMPAT, 'UTF-8');
     284                    $value = htmlspecialchars($inputValue,ENT_COMPAT, 'UTF-8');
    279285
    280286                    if($lastParam == $inputValue){
     
    296302            foreach ($formData as $inputName => $inputValue){
    297303                if($inputName != 'IsTest'){
    298                     $value = htmlspecialchars($inputValue, ENT_COMPAT, 'UTF-8');
     304                    $value = htmlspecialchars($inputValue,ENT_COMPAT, 'UTF-8');
    299305
    300306                    if($lastParam == $inputValue){
     
    310316        }else {
    311317            $form = '<div class="preloader">
    312               <svg class="preloader__image" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">
    313                 <path fill="currentColor"
    314                   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">
    315                 </path>
    316               </svg>
    317             </div>
    318             <style>
    319             .preloader {
    320               position: fixed;
    321               left: 0;
    322               top: 0;
    323               right: 0;
    324               bottom: 0;
    325               overflow: hidden;
    326               /* фоновый цвет */
    327               background: #e0e0e0;
    328               z-index: 1001;
    329             }
    330 
    331             .preloader__image {
    332               position: relative;
    333               top: 50%;
    334               left: 50%;
    335               width: 70px;
    336               height: 70px;
    337               margin-top: -35px;
    338               margin-left: -35px;
    339               text-align: center;
    340               animation: preloader-rotate 2s infinite linear;
    341             }
    342 
    343             @keyframes preloader-rotate {
    344               100% {
    345                 transform: rotate(360deg);
    346               }
    347             }
    348 
    349             .loaded_hiding .preloader {
    350               transition: 0.3s opacity;
    351               opacity: 0;
    352             }
    353 
    354             .loaded .preloader {
    355               display: none;
    356             }
    357             </style>
    358             <script>
    359               window.onload = function () {
    360                 document.body.classList.add("loaded_hiding");
    361                 window.setTimeout(function () {
    362                   document.body.classList.add("loaded");
    363                   document.body.classList.remove("loaded_hiding");
    364                 }, 1000);
    365               }
    366             </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>';
    367373            $form .= "<form action=\"$formUrl\" method=\"POST\">";
    368374
    369375            foreach ($formData as $inputName => $inputValue) {
    370                 $value = htmlspecialchars($inputValue, ENT_COMPAT, 'UTF-8');
     376                $value = htmlspecialchars($inputValue,ENT_COMPAT, 'UTF-8');
    371377
    372378                $form .= "<input type=\"hidden\" name=\"$inputName\" value=\"$value\">";
     
    383389     * Отправляет СМС с помощью GET-запроса на робокассу
    384390     *
    385      * @param string $phone
    386      * @param string $message
    387      *
    388      * @return bool
    389      * @throws \Exception
     391     *@paramstring$phone
     392     *@paramstring$message
     393     *
     394     *@returnbool
     395     *@throws\Exception
    390396     */
    391397    public function sendSms($phone, $message) {
     
    411417     * Запрашиват размер комиссии в процентах для конкретного способа оплаты
    412418     *
    413      * @param string $incCurrLabel Кодовое имя метода оплаты
    414      * @param int    $sum          Стоимость товара
    415      *
    416      * @return float Комиссия метода в %
     419     *@paramstring$incCurrLabelКодовое имя метода оплаты
     420     *@paramint$sumСтоимость товара
     421     *
     422     *@returnfloat Комиссия метода в %
    417423     */
    418424    public function getCommission($incCurrLabel, $sum = 10000) {
     
    437443     * Возвращает сумму к оплате с учетом комиссий.
    438444     *
    439      * @param string $incCurrLabel Кодовое имя метода оплаты
    440      * @param int    $sum          Стоимость товара
    441      *
    442      * @return float Стоимость, которую необходимо передавать в Робокассу.
     445     *@paramstring$incCurrLabelКодовое имя метода оплаты
     446     *@paramint$sumСтоимость товара
     447     *
     448     *@returnfloat Стоимость, которую необходимо передавать в Робокассу.
    443449     */
    444450    public function getCommissionSum($incCurrLabel, $sum) {
     
    455461     * Запрашивает и парсит в массив все возможные способы оплаты для данного магазина
    456462     *
    457      * @return array
     463     *@returnarray
    458464     */
    459465    public function getCurrLabels()
     
    468474     * Парсит XML в JSON
    469475     *
    470      * @param string $url
    471      *
    472      * @return string
     476     *@paramstring$url
     477     *
     478     *@returnstring
    473479     */
    474480    public function parseXmlAndConvertToJson($url) {
     
    483489     * Запрашивает у робокассы подтверждение платежа
    484490     *
    485      * @param int $invId
    486      *
    487      * @return bool
     491     *@paramint$invId
     492     *
     493     *@returnbool
    488494     */
    489495    public function reCheck($invId) {
  • robokassa/trunk/labelsClasses.php

    r2983991 r3026682  
    5353function robokassa_payment_add_WC_WP_robokassa_class($methods = null) {
    5454    $methods[] = 'payment_robokassa_pay_method_request_all';
    55     if (get_option('robokassa_podeli') == '1' && WC()->cart !== null && isset(WC()->cart->total) && WC()->cart->total >= 300 && WC()->cart->total <= 30000) {
     55    if (get_option('robokassa_podeli') == '1' && WC()->cart !== null && isset(WC()->cart->total) && WC()->cart->total >= 300 && WC()->cart->total <= 35000) {
    5656        $methods[] = 'payment_robokassa_pay_method_request_Podeli';
    5757    }
  • robokassa/trunk/payment-widget.php

    r3002256 r3026682  
    1212    $podeli_6w_date = strftime('%d %b', strtotime('+6 weeks'));
    1313
    14     if (get_option('robokassa_payment_podeli_widget_onoff') === 'true' && $price > 300 && $price < 30000) {
     14    if (get_option('robokassa_payment_podeli_widget_onoff') === 'true' && $price > 300 && $price < 35000) {
    1515        if (get_option('robokassa_podeli_widget_style') == 0) {
    1616            echo '
     
    628628    $podeli_6w_date = strftime('%d %b', strtotime('+6 weeks'));
    629629
    630     if (get_option('robokassa_payment_podeli_widget_onoff') === 'true' && $price > 300 && $price < 30000) {
     630    if (get_option('robokassa_payment_podeli_widget_onoff') === 'true' && $price > 300 && $price < 35000) {
    631631        echo '
    632632<div class="wiget-block-wrapper">
     
    732732    $podeli_6w_date = strftime('%d %b', strtotime('+6 weeks'));
    733733
    734     if (get_option('robokassa_payment_podeli_widget_onoff') === 'true' && $price > 300 && $price < 30000) {
     734    if (get_option('robokassa_payment_podeli_widget_onoff') === 'true' && $price > 300 && $price < 35000) {
    735735        echo '
    736736<div class="wiget-block__prompt">
     
    798798    $monthlyPayment = round($monthlyPayment);
    799799
    800     if (get_option('robokassa_payment_podeli_widget_onoff') === 'true' && $price > 300 && $price < 30000) {
     800    if (get_option('robokassa_payment_podeli_widget_onoff') === 'true' && $price > 300 && $price < 35000) {
    801801        echo '
    802802<div class="wiget-block" style="margin-bottom: 0px">
  • robokassa/trunk/readme.txt

    r3002256 r3026682  
    7878== Changelog ==
    7979
     80= 1.5.8 =
     81* Добавлена функционал отложенных платежей (холдирование)
     82* Изменена максимальная сумма корзины для "Подели"
     83* Переработана логика работы параметра OutSumCurrency
     84
    8085= 1.5.7 =
    8186* Добавлена возможность установить валюту по умолчанию из настроек WooCommerce
    8287* Устранены ошибки
    83 
    8488
    8589= 1.5.6 =
  • robokassa/trunk/wp_robokassa.php

    r3002256 r3026682  
    66 * Author: Robokassa
    77 * Author URI: https://robokassa.com
    8  * Version: 1.5.7
     8 * Version: 1.5.8
    99 */
    1010
     
    4141\spl_autoload_register(
    4242    function ($className) {
    43         $file = __DIR__ . '/classes/' . \str_replace('\\', '/', $className) . '.php';
     43        $file =__DIR__. '/classes/' . \str_replace('\\', '/', $className) . '.php';
    4444
    4545        if (file_exists($file))
     
    9797
    9898add_action('woocommerce_order_status_changed', 'robokassa_2check_send', 10, 3);
     99add_action('woocommerce_order_status_changed', 'robokassa_hold_confirm', 10, 4);
     100add_action('woocommerce_order_status_changed', 'robokassa_hold_cancel', 10, 4);
     101add_action('robokassa_cancel_payment_event', 'robokassa_hold_cancel_after5', 10, 1);
    99102
    100103
     
    171174        $debug .= "order_id = $order_id \r\n";
    172175
    173         $roboDataBase = new RoboDataBase(mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME));
     176        $roboDataBase = new RoboDataBase(mysqli_connect(DB_HOST,DB_USER,DB_PASSWORD,DB_NAME));
    174177        $robokassa = new RobokassaPayAPI($mrhLogin, get_option('robokassa_payment_shoppass1'), get_option('robokassa_payment_shoppass2'));
    175178
     
    309312
    310313                        (new RobokassaSms(
    311                             (new RoboDataBase(mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME))),
     314                            (new RoboDataBase(mysqli_connect(DB_HOST,DB_USER,DB_PASSWORD,DB_NAME))),
    312315                            (new RobokassaPayAPI(
    313316                                get_option('robokassa_payment_MerchantLogin'),
     
    325328                    }
    326329                }
     330            } elseif ((get_option('robokassa_payment_hold_onoff') == 'true') &&
     331                strpos($_SERVER['CONTENT_TYPE'], 'application/json') !== false) {
     332
     333                $input_data = file_get_contents('php://input');
     334
     335                // Разбиваем JWT на три части
     336                $token_parts = explode('.', $input_data);
     337
     338                // Проверяем, что есть три части
     339                if (count($token_parts) === 3) {
     340                    // Декодируем вторую часть (полезные данные)
     341                    $json_data = json_decode(base64_decode($token_parts[1]), true);
     342
     343                    // Проверяем наличие ключевого поля "state" со значением "HOLD"
     344                    if (isset($json_data['data']['state']) && $json_data['data']['state'] === 'HOLD') {
     345                        // Изменяем статус заказа
     346                        $order = new WC_Order($json_data['data']['invId']);
     347                        $date_in_five_days = date('Y-m-d H:i:s', strtotime('+5 days'));
     348                        $order->add_order_note("Robokassa: Платеж успешно подтвержден. Он ожидает подтверждения до {$date_in_five_days}, после чего автоматически отменится");
     349                        $order->update_status('on-hold');
     350
     351                        // Добавляем событие, которое делает unhold через 5 дней
     352                        wp_schedule_single_event(strtotime('+5 days'), 'robokassa_cancel_payment_event', array($order->get_id()));
     353                    }
     354                    if (isset($json_data['data']['state']) && $json_data['data']['state'] === 'OK') {
     355                        // Изменяем статус заказа
     356                        $order = new WC_Order($json_data['data']['invId']);
     357                        $order->add_order_note("Robokassa: Платеж успешно подтвержден");
     358                        $order->update_status('processing');
     359
     360                    }
     361                    http_response_code(200);
     362                } else {
     363                    http_response_code(400);
     364                }
    327365            } else {
    328 
    329366                $order = new WC_Order($_REQUEST['InvId']);
    330367                $order->add_order_note('Bad CRC');
     
    11071144
    11081145        $curl = curl_init('https://ws.roboxchange.com/RoboFiscal/Receipt/Attach');
    1109         curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
    1110         curl_setopt($curl, CURLOPT_POSTFIELDS, $startupHash . '.' . $sign);
    1111         curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    1112         curl_setopt($curl, CURLOPT_HTTPHEADER, array(
     1146        curl_setopt($curl,CURLOPT_CUSTOMREQUEST, "POST");
     1147        curl_setopt($curl,CURLOPT_POSTFIELDS, $startupHash . '.' . $sign);
     1148        curl_setopt($curl,CURLOPT_RETURNTRANSFER, true);
     1149        curl_setopt($curl,CURLOPT_HTTPHEADER, array(
    11131150                'Content-Type: application/json',
    11141151                'Content-Length: ' . strlen($startupHash . '.' . $sign))
     
    11201157    }
    11211158}
     1159
     1160function robokassa_hold_confirm($order_id, $old_status, $new_status, $order) {
     1161    // Проверяем, что статус был изменен с "on-hold" на "processing" (обработка)
     1162    if ((get_option('robokassa_payment_hold_onoff') == 'true')
     1163        && $old_status === 'on-hold' && $new_status === 'processing') {
     1164
     1165        $order = wc_get_order($order_id);
     1166        $order_items = $order->get_items();
     1167        $shipping_total = $order->get_shipping_total();
     1168
     1169        $receipt_items = array();
     1170        foreach ($order_items as $item) {
     1171            $item_name = $item->get_name();
     1172            $item_quantity = $item->get_quantity();
     1173            $item_sum = $item->get_total();
     1174            $receipt_items[] = array(
     1175                'name' => $item_name,
     1176                'quantity' => $item_quantity,
     1177                'sum' => $item_sum,
     1178                'tax' => get_option('robokassa_payment_tax'),
     1179                'payment_method' => \get_option('robokassa_payment_paymentMethod'),
     1180                'payment_object' => \get_option('robokassa_payment_paymentObject'),
     1181                'tax' => get_option('robokassa_payment_tax'),
     1182            );
     1183        }
     1184
     1185        if ($shipping_total > 0) {
     1186            $receipt_items[] = array(
     1187                'name' => 'Доставка',
     1188                'quantity' => 1,
     1189                'cost' => $shipping_total,
     1190                'sum' => $shipping_total * 1,
     1191                'tax' => get_option('robokassa_payment_tax'),
     1192                'payment_method' => 'full_payment',
     1193                'payment_object' => get_option('robokassa_payment_paymentObject'),
     1194            );
     1195        }
     1196
     1197        $request_data = array(
     1198            'MerchantLogin' => get_option('robokassa_payment_MerchantLogin'),
     1199            'InvoiceID' => $order_id,
     1200            'OutSum' => $order->get_total(),
     1201            'Receipt' => json_encode(array('items' => $receipt_items)),
     1202        );
     1203
     1204        $merchant_login = get_option('robokassa_payment_MerchantLogin');
     1205        $password1 = get_option('robokassa_payment_shoppass1');
     1206
     1207        $signature_value = md5("{$merchant_login}:{$request_data['OutSum']}:{$request_data['InvoiceID']}:{$request_data['Receipt']}:{$password1}");
     1208        $request_data['SignatureValue'] = $signature_value;
     1209
     1210        $response = wp_remote_post('https://auth.robokassa.ru/Merchant/Payment/Confirm', array(
     1211            'body' => $request_data,
     1212        ));
     1213
     1214        /*        if (is_wp_error($response)) {
     1215                    error_log('Error sending payment request: ' . $response->get_error_message());
     1216                    $order->add_order_note('Error sending payment request: ' . $response->get_error_message());
     1217                } else {
     1218                    $body = wp_remote_retrieve_body($response);
     1219                    $order->add_order_note('Robokassa: ошибка проведения платежа' . json_encode($request_data) . $body);
     1220                }*/
     1221    }
     1222}
     1223
     1224function robokassa_hold_cancel($order_id, $old_status, $new_status, $order) {
     1225    // Проверяем, что статус был изменен с "on-hold" на "Canceled"
     1226    if ((get_option('robokassa_payment_hold_onoff') == 'true') &&
     1227        $old_status === 'on-hold' && $new_status === 'cancelled') {
     1228
     1229        $request_data = array(
     1230            'MerchantLogin' => get_option('robokassa_payment_MerchantLogin'),
     1231            'InvoiceID' => $order_id,
     1232            'OutSum' => $order->get_total(),
     1233        );
     1234
     1235        $merchant_login = get_option('robokassa_payment_MerchantLogin');
     1236        $password1 = get_option('robokassa_payment_shoppass1');
     1237
     1238        $signature_value = md5("{$merchant_login}::{$request_data['InvoiceID']}:{$password1}");
     1239        $request_data['SignatureValue'] = $signature_value;
     1240
     1241        $response = wp_remote_post('https://auth.robokassa.ru/Merchant/Payment/Cancel', array(
     1242            'body' => $request_data,
     1243        ));
     1244
     1245        if (is_wp_error($response)) {
     1246            $order->add_order_note('Error sending payment request: ' . $response->get_error_message());
     1247        } else {
     1248            $order->add_order_note('Robokassa: холдирование было отменено вами, либо автоматически после 5 дней ожидания');
     1249        }
     1250    }
     1251}
     1252
     1253function robokassa_hold_cancel_after5($order_id) {
     1254    // Проверяем, что заказ существует
     1255    $order = wc_get_order($order_id);
     1256    if ($order) {
     1257        // Проверяем текущий статус заказа
     1258        if ($order->get_status() === 'on-hold') {
     1259            // Отменяем заказ и добавляем соответствующее уведомление
     1260            $request_data = array(
     1261                'MerchantLogin' => get_option('robokassa_payment_MerchantLogin'),
     1262                'InvoiceID' => $order_id,
     1263                'OutSum' => $order->get_total(),
     1264            );
     1265
     1266            $merchant_login = get_option('robokassa_payment_MerchantLogin');
     1267            $password1 = get_option('robokassa_payment_shoppass1');
     1268
     1269            $signature_value = md5("{$merchant_login}::{$request_data['InvoiceID']}:{$password1}");
     1270            $request_data['SignatureValue'] = $signature_value;
     1271
     1272            $response = wp_remote_post('https://auth.robokassa.ru/Merchant/Payment/Cancel', array(
     1273                'body' => $request_data,
     1274            ));
     1275
     1276            if (is_wp_error($response)) {
     1277                $order->add_order_note('Error sending payment request: ' . $response->get_error_message());
     1278            }
     1279
     1280            $order->update_status('cancelled');
     1281        }
     1282    }
     1283}
     1284
Note: See TracChangeset for help on using the changeset viewer.