Plugin Directory

Changeset 3106617


Ignore:
Timestamp:
06/24/2024 11:12:15 AM (22 months ago)
Author:
robokassa
Message:

1.6.1

Location:
robokassa/trunk
Files:
4 edited

Legend:

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

    r3026682 r3106617  
    66
    77    /**
    8      *@varstring
     8     * @var string
    99     */
    1010    private $mrh_login;
    1111
    1212    /**
    13      *@varstring
     13     * @var string
    1414     */
    1515    private $mrh_pass1;
    1616
    1717    /**
    18      *@varstring
     18     * @var string
    1919     */
    2020    private $mrh_pass2;
    2121
    2222    /**
    23      *@varstring
     23     * @var string
    2424     */
    2525    private $method;
    2626
    2727    /**
    28      *@varstring
     28     * @var string
    2929     */
    3030    private $apiUrl;
    3131
    3232    /**
    33      *@varstring
     33     * @var string
    3434     */
    3535    private $reply = '';
    3636
    3737    /**
    38      *@varstring
     38     * @var string
    3939     */
    4040    private $request = '';
    4141
    4242    /**
    43      *@returnstring
     43     * @return string
    4444     */
    4545    public function getReply() {
     
    4848
    4949    /**
    50      *@returnstring
     50     * @return string
    5151     */
    5252    public function getRequest() {
     
    5555
    5656    /**
    57      *@returnstring
     57     * @return string
    5858     */
    5959    public function getSendResult() {
     
    6565
    6666    /**
    67      *@paramstring$login
    68      *@paramstring$pass1
    69      *@paramstring$pass2
    70      *@paramstring$method
     67     * @param string $login
     68     * @param string $pass1
     69     * @param string $pass2
     70     * @param string $method
    7171     */
    7272    public function __construct($login, $pass1, $pass2, $method = 'md5') {
     
    8080
    8181    /**
    82      *@paramstring$mthd
    83      *@paramarray$data
    84      *
    85      *@returnarray
     82     * @param string $mthd
     83     * @param array  $data
     84     *
     85     * @return array
    8686     */
    8787    private function sendRequest($mthd, $data) {
     
    9393     * он не использоваться, а если не пустой - используем его json-представление
    9494     *
    95      *@paramstring$sum
    96      *@paramstring$invId
    97      *@paramstring$receiptJson
    98      *
    99      *@returnstring
     95     * @param string $sum
     96     * @param string $invId
     97     * @param string $receiptJson
     98     *
     99     * @return string
    100100     */
    101101    private function getSignatureString($sum, $invId, $receiptJson, $recurring = false)
     
    130130     * Генерирует хеш для строки $string с помощью метода $method
    131131     *
    132      *@paramstring$string
    133      *@paramstring$method
    134      *
    135      *@returnstring
    136      *
    137      *@throws\Exception
     132     * @param string $string
     133     * @param string $method
     134     *
     135     * @return string
     136     *
     137     * @throws \Exception
    138138     */
    139139    public function getSignature($string, $method = 'md5') {
     
    148148     * Генерирует форму, в Opencart модуле НЕ ИСПОЛЬЗУЕТСЯ!
    149149     *
    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
     150     * @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
    161161     */
    162162    public function createForm(
     
    239239
    240240    /**
    241      *@paramstring$formUrl
    242      *@paramarray$formData
    243      *
    244      *@returnstring
     241     * @param string $formUrl
     242     * @param array  $formData
     243     *
     244     * @return string
    245245     */
    246246    private function renderForm($formUrl, array $formData) {
     
    261261            foreach ($formData as $inputName => $inputValue){
    262262                if($inputName != 'IsTest'){
    263                     $value = htmlspecialchars($inputValue,ENT_COMPAT, 'UTF-8');
     263                    $value = htmlspecialchars($inputValue, ENT_COMPAT, 'UTF-8');
    264264
    265265                    if($lastParam == $inputValue){
     
    275275            $form .= "<script type=\"text/javascript\"> document.getElementById('robokassa').click(); </script>";
    276276        }
    277         elseif (get_option('robokassa_podeli') && $formData['IncCurrLabel'] == 'Podeli' ) {
     277        if (get_option('robokassa_podeli') && isset($formData['IncCurrLabel']) && $formData['IncCurrLabel'] == 'Podeli') {
    278278
    279279            $params = '';
     
    282282            foreach ($formData as $inputName => $inputValue){
    283283                if($inputName != 'IsTest'){
    284                     $value = htmlspecialchars($inputValue,ENT_COMPAT, 'UTF-8');
     284                    $value = htmlspecialchars($inputValue, ENT_COMPAT, 'UTF-8');
    285285
    286286                    if($lastParam == $inputValue){
     
    295295            $form .= "<script type=\"text/javascript\"> document.getElementById('robokassa').click(); </script>";
    296296        }
    297         elseif (get_option('robokassa_podeli') && $formData['IncCurrLabel'] == 'AlwaysYes' ) {
     297        if (get_option('robokassa_podeli') && isset($formData['IncCurrLabel']) && $formData['IncCurrLabel'] == 'AlwaysYes') {
    298298
    299299            $params = '';
     
    302302            foreach ($formData as $inputName => $inputValue){
    303303                if($inputName != 'IsTest'){
    304                     $value = htmlspecialchars($inputValue,ENT_COMPAT, 'UTF-8');
     304                    $value = htmlspecialchars($inputValue, ENT_COMPAT, 'UTF-8');
    305305
    306306                    if($lastParam == $inputValue){
     
    316316        }else {
    317317            $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>';
    373373            $form .= "<form action=\"$formUrl\" method=\"POST\">";
    374374
    375375            foreach ($formData as $inputName => $inputValue) {
    376                 $value = htmlspecialchars($inputValue,ENT_COMPAT, 'UTF-8');
     376                $value = htmlspecialchars($inputValue, ENT_COMPAT, 'UTF-8');
    377377
    378378                $form .= "<input type=\"hidden\" name=\"$inputName\" value=\"$value\">";
     
    389389     * Отправляет СМС с помощью GET-запроса на робокассу
    390390     *
    391      *@paramstring$phone
    392      *@paramstring$message
    393      *
    394      *@returnbool
    395      *@throws\Exception
     391     * @param string $phone
     392     * @param string $message
     393     *
     394     * @return bool
     395     * @throws \Exception
    396396     */
    397397    public function sendSms($phone, $message) {
     
    417417     * Запрашиват размер комиссии в процентах для конкретного способа оплаты
    418418     *
    419      *@paramstring$incCurrLabelКодовое имя метода оплаты
    420      *@paramint$sumСтоимость товара
    421      *
    422      *@returnfloat Комиссия метода в %
     419     * @param string $incCurrLabel Кодовое имя метода оплаты
     420     * @param int    $sum          Стоимость товара
     421     *
     422     * @return float Комиссия метода в %
    423423     */
    424424    public function getCommission($incCurrLabel, $sum = 10000) {
     
    443443     * Возвращает сумму к оплате с учетом комиссий.
    444444     *
    445      *@paramstring$incCurrLabelКодовое имя метода оплаты
    446      *@paramint$sumСтоимость товара
    447      *
    448      *@returnfloat Стоимость, которую необходимо передавать в Робокассу.
     445     * @param string $incCurrLabel Кодовое имя метода оплаты
     446     * @param int    $sum          Стоимость товара
     447     *
     448     * @return float Стоимость, которую необходимо передавать в Робокассу.
    449449     */
    450450    public function getCommissionSum($incCurrLabel, $sum) {
     
    461461     * Запрашивает и парсит в массив все возможные способы оплаты для данного магазина
    462462     *
    463      *@returnarray
     463     * @return array
    464464     */
    465465    public function getCurrLabels()
     
    474474     * Парсит XML в JSON
    475475     *
    476      *@paramstring$url
    477      *
    478      *@returnstring
     476     * @param string $url
     477     *
     478     * @return string
    479479     */
    480480    public function parseXmlAndConvertToJson($url) {
     
    489489     * Запрашивает у робокассы подтверждение платежа
    490490     *
    491      *@paramint$invId
    492      *
    493      *@returnbool
     491     * @param int $invId
     492     *
     493     * @return bool
    494494     */
    495495    public function reCheck($invId) {
     
    513513            'PreviousInvoiceID' => $parentInvoiceId,
    514514            '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"),
    516516            'OutSum'            => $amount,
    517517            'shp_label'         => 'official_wordpress',
  • robokassa/trunk/classes/Robokassa/Payment/WC_WP_robokassa.php

    r2988879 r3106617  
    4242
    4343
    44         $this->title = \mb_strlen(get_option('RobokassaOrderPageTitle_' . $this->id, null)) > 0
     44        $this->title = !empty(get_option('RobokassaOrderPageTitle_' . $this->id, null))
    4545            ? 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))
    5049            ? get_option('RobokassaOrderPageDescription_' . $this->id, null)
    51             : $this->description
    52         ;
     50            : $this->description;
    5351
    5452        $this->supports = [
     
    9391        echo '<p>Спасибо за ваш заказ, пожалуйста, нажмите ниже на кнопку, чтобы заплатить.</p>';
    9492
    95         robokassa_payment_createFormWC($order, $this->id, $this->commission);
     93        robokassa_payment_createFormWC($order, $this->id);
    9694    }
    9795
     
    116114     */
    117115    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();
    125125
    126126        $mrhLogin  = get_option('robokassa_payment_MerchantLogin');
     
    152152            $current['quantity'] = (float)$item['quantity'];
    153153
    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'];
    155155
    156156            $current['cost'] = ($item['line_total'] + $tax_per_item) / $current['quantity'];
     
    175175            $current['cost'] = (double)\sprintf(
    176176                "%01.2f",
    177                 $renewal_order->get_shipping_total()
     177                ( $renewal_order->get_shipping_total() + $renewal_order->get_shipping_tax() )
    178178            );
    179179            $current['payment_object'] = \get_option('robokassa_payment_paymentObject');
     
    181181
    182182            if (isset($receipt['sno']) && ($receipt['sno'] == 'osn')) {
    183                 $current['tax'] = $tax;
     183                $current['tax'] = $renewal_order->get_shipping_tax();
    184184            } else {
    185185                $current['tax'] = 'none';
  • robokassa/trunk/readme.txt

    r3092020 r3106617  
    33Requires at least: 5.7
    44Tested up to: 6.5.3
    5 Stable tag: 1.6.0
     5Stable tag: 1.6.1
    66Requires PHP: 5.6.32
    77License: GPLv2 or later
     
    7777== Changelog ==
    7878
     79= 1.6.1 =
     80* Исправлены незначительные ошибки
     81
    7982= 1.6.0 =
    8083* Добавлена поддержка плагина ["WooCommerce Checkout Add-Ons"](https://woocommerce.com/products/woocommerce-checkout-add-ons/)
  • robokassa/trunk/wp_robokassa.php

    r3096888 r3106617  
    66 * Author: Robokassa
    77 * Author URI: https://robokassa.com
    8  * Version: 1.6.0
     8 * Version: 1.6.1
    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))
     
    658658            }
    659659
    660             $order->set_address(array(// Здесь наверное что-то должно быть, но Егорушка малолетний долбоклюй
    661             ), 'billing');
     660            $order->set_address(array(), 'billing');
    662661
    663662            $order->calculate_totals();
     
    700699
    701700/**
    702  * Формирование формы, перенаправляющей пользователя на сайт робокассы
    703  *
    704  * Включает в себя подготовку данных и рендеринг самой формы
     701 *
     702 * Проверка режимы работы
     703 *
     704 * @return void
     705 */
     706function 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 * Подготовка товарной номенклатуры для формирования чека
    705723 *
    706724 * @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 */
     728function createRobokassaReceipt($order_id)
     729{
     730    global $woocommerce;
     731    $order = new WC_Order($order_id);
    727732
    728733    $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 
    735734    if ($sno != 'fckoff' && get_option('robokassa_country_code') == 'RU') {
    736735        $receipt['sno'] = $sno;
    737736    }
    738737
    739     global $woocommerce;
     738    $tax = get_option('robokassa_payment_tax');
     739    if ($tax == "vat118") $tax = "vat120";
     740
    740741    $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']
    742747
    743748    foreach ($cart as $item) {
     
    751756                $current['name'] = $product->get_title();
    752757                $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'];
    763762
    764763                if (get_option('robokassa_country_code') == 'RU') {
     
    778777            $current = [];
    779778            $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'];
    791784
    792785            if (get_option('robokassa_country_code') == 'RU') {
     
    805798    }
    806799
    807 
    808     // Проверяем, активен ли плагин WooCommerce Checkout Add-Ons
     800    // Активность плагина WooCommerce Checkout Add-Ons
    809801    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,
    818810                'quantity' => 1,
    819                 'cost' => $fee_total,
    820                 'sum' => $fee_total,
     811                'cost' => $additional_item_total,
     812                'sum' => $additional_item_total,
    821813                'payment_object' => \get_option('robokassa_payment_paymentObject'),
    822814                'payment_method' => \get_option('robokassa_payment_paymentMethod'),
     
    824816            );
    825817
    826             $receipt['items'][] = $fee_data;
     818            $receipt['items'][] = $additional_item_data;
     819            $total_receipt += $additional_item_total;
    827820        }
    828821    }
     
    837830            $current['quantity'] = (float)$item->get_quantity();
    838831
    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;
    841834
    842835            $current['payment_object'] = \get_option('robokassa_payment_paymentObject');
     
    850843
    851844            $receipt['items'][] = $current;
     845            $total_receipt += $current['sum'];
    852846        }
    853847
     
    862856            $order->get_shipping_total()
    863857        );
    864         $current['sum'] = $current['cost'] * $current['quantity'];
    865 
    866858
    867859        if (get_option('robokassa_country_code') == 'RU') {
     
    877869
    878870        $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 */
     891function 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']);
    880899
    881900    $order_total = $order->get_total();
    882 
    883901    $sum = number_format($order_total, 2, '.', '');
    884902
     
    894912        }
    895913    }
    896 
    897914
    898915    echo $rb->createForm(
     
    908925}
    909926
     927function robokassa_payment_createFormWC($order_id, $label)
     928{
     929    processRobokassaPayment($order_id, $label);
     930}
     931
    910932/**
    911933 * Начало оформления заказа
     
    10481070 */
    10491071function robokassa_2check_send($order_id, $old_status, $new_status)
    1050 
    1051 
    1052 {
     1072{
     1073
    10531074    $payment_method = get_option('robokassa_payment_paymentMethod');
    10541075    $sno = get_option('robokassa_payment_sno');
    10551076    $tax = get_option('robokassa_payment_tax');
    10561077
     1078
    10571079    if ($payment_method == 'advance' || $payment_method == 'full_prepayment' || $payment_method == 'prepayment') {
    1058 
    10591080        if ($sno == 'fckoff') {
     1081            error_log("Robokassa: SNO is 'fckoff', exiting function");
    10601082            return;
    10611083        }
     
    10641086
    10651087        if ($new_status != $trigger_status) {
     1088            error_log("Robokassa: New status ($new_status) does not match trigger status ($trigger_status), exiting function");
    10661089            return;
    10671090        }
     
    10701093
    10711094        if (!$order) {
     1095            error_log("Robokassa: Order not found for order_id: $order_id, exiting function");
    10721096            return;
    10731097        }
    10741098
    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                }*/
    10781103
    10791104        /** @var array $fields */
     
    11191144                case "vat0":
    11201145                    $fields['vats'][] = ['type' => $tax, 'sum' => 0];
     1146                    break;
    11211147                case "none":
    11221148                    $fields['vats'][] = ['type' => $tax, 'sum' => 0];
    11231149                    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;
    11251156                default:
    11261157                    $fields['vats'][] = ['type' => 'novat', 'sum' => 0];
    11271158                    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;
    11341159            }
     1160
    11351161        }
    11361162
     
    11571183                case "vat0":
    11581184                    $fields['vats'][] = ['type' => $tax, 'sum' => 0];
     1185                    break;
    11591186                case "none":
    11601187                    $fields['vats'][] = ['type' => $tax, 'sum' => 0];
    11611188                    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;
    11631195                default:
    11641196                    $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];
    11711197                    break;
    11721198            }
     
    11831209        );
    11841210
     1211
    11851212        if (get_option('robokassa_payment_test_onoff') == 'true') {
    11861213            $pass1 = get_option('robokassa_payment_testshoppass1');
     
    11901217            $pass2 = get_option('robokassa_payment_shoppass2');
    11911218        }
     1219
    11921220
    11931221        /** @var string $sign */
     
    12011229        );
    12021230
     1231
    12031232        $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(
    12081237                'Content-Type: application/json',
    12091238                'Content-Length: ' . strlen($startupHash . '.' . $sign))
    12101239        );
    12111240        $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
    12121248        curl_close($curl);
    12131249    } 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
     1254function robokassa_hold_confirm($order_id, $old_status, $new_status, $order)
     1255{
    12191256    // Проверяем, что статус был изменен с "on-hold" на "processing" (обработка)
    12201257    if ((get_option('robokassa_payment_hold_onoff') == 'true')
     
    12801317}
    12811318
    1282 function robokassa_hold_cancel($order_id, $old_status, $new_status, $order) {
     1319function robokassa_hold_cancel($order_id, $old_status, $new_status, $order)
     1320{
    12831321    // Проверяем, что статус был изменен с "on-hold" на "Canceled"
    12841322    if ((get_option('robokassa_payment_hold_onoff') == 'true') &&
     
    13091347}
    13101348
    1311 function robokassa_hold_cancel_after5($order_id) {
     1349function robokassa_hold_cancel_after5($order_id)
     1350{
    13121351    // Проверяем, что заказ существует
    13131352    $order = wc_get_order($order_id);
Note: See TracChangeset for help on using the changeset viewer.