N
N
niksamara2016-10-07 10:24:17
WordPress
niksamara, 2016-10-07 10:24:17

Changing order status in woocommerce when using tinkoff bank payment?

Good day.
There is an online store on WordPress + Woocommerce.
Orders come in frequently, operators receive new orders by email notification.
There is an online payment plugin from Tinkoff Bank.
The plugin installed well. Everything passes, the order status changes in accordance with the result of the payment.
BUT. notifications by mail do not come as with a regular order.
As I understand it, the bank plugin simply assigns order status values, and does not change them through update_status. Because of this, order notifications are not received by mail. You need to manually change the statuses in the admin panel so that the letter goes away, but since orders come often, it is very inconvenient.
Here is a piece of code that is responsible for order statuses (if you need more, I can drop or borrow the entire plugin on the bank's website)

//woocommerce_tinkoff_settings
    $settings = $wpdb->get_results("select * from ".$wpdb->prefix."options where option_name='woocommerce_tinkoff_settings'");
    $settings = unserialize($settings[0]->option_value);
    $_POST['Password'] = $settings['secret_key'];
    ksort($_POST);
    $sorted = $_POST;
    $original_token = $sorted['Token'];
    unset($sorted['Token']);
    $values = implode('', array_values($sorted));
    $token = hash('sha256', $values);


    if($token == $original_token){
        $order = $wpdb->get_results("select * from ".$wpdb->prefix."woocommerce_order_items where order_id=". (int) $_POST['OrderId']);
        $order_status = $wpdb->get_results("select * from ".$wpdb->prefix."posts where ID=".  $order[0]->order_id);
        $status = $order_status[0]->post_status;

        switch ($_POST['Status']) {
            case 'AUTHORIZED': $order_status = 'wc-on-hold'; break; /*Деньги на карте захолдированы. Корзина очищается.*/
            case 'CONFIRMED': $order_status = 'wc-processing'; break; /*Платеж подтвержден.*/
            case 'CANCELED': $order_status = 'wc-cancelled'; break; /*Платеж отменен*/
            case 'REJECTED': $order_status = 'wc-failed'; break; /*Платеж отклонен.*/
            case 'REVERSED': $order_status = 'wc-cancelled'; break; /*Платеж отменен*/
            case 'REFUNDED': $order_status = 'wc-refunded'; break; /*Произведен возврат денег клиенту*/
        }
    
        $a = $wpdb->query($wpdb->prepare("UPDATE ".$wpdb->prefix."posts SET post_status='".$order_status."' WHERE ID=%d ", (int) $_POST['OrderId']));
        ($a) ? die('OK') : die('NOTOK');
       
 
    }

I would appreciate your help!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
buyuk, 2016-12-15
@buyuk

There is another problem with tinkoff for woocommerce: in case of successful payment, the gateway redirects to its own thank you page, passing . In the settings, you can register your own page. There, the GET method is passed, among other things, order_id.
(API documentation https://oplata.tinkoff.ru/documentation/?section=p...
In WooCommerce, the standard thank you page is http:///checkout/order-received//?key=wc_order_
So here's the question: how to transfer this data to the standard WooCommerce page using the GET method to form the page http:///checkout/order-received//?key=wc_order_
In my vision (maybe I’m wrong), it looks like this: a page is created on the site that will receive order_id from the payment gateway from the GET request, form the key wc_order from it and redirect to http:///checkout/order-received//?key =wc_order_

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question