Answer the question
In order to leave comments, you need to log in
Woocommerce and Tinkoff Payment Gateway - how to change a digital product order to the Completed status?
Good day.
Installed the payment module of Tinkoff Bank for Woocommerce https://oplata.tinkoff.ru/documentation/?section=cms
Faced the problem of changing the order status:
- the order status of a digital product does not automatically change after purchase to Complete
I tried all the options found on the Internet (editing functions.php) and plugins like WooCommerce Order Status Control and Autocomplete Orders, but the order status after payment is always Processing.
Here is the content of the success.php file of the payment module:
<?php
set_error_handler('exceptions_error_handler', E_ALL);
function exceptions_error_handler($severity) {
if (error_reporting() == 0) {
return;
}
if (error_reporting() & $severity) {
die('NOTOK');
}
}
try{
require( dirname( __FILE__ ) . '../../../../../wp-blog-header.php' );
//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);
// //log
// $log = $_POST;
// $log['token'] = $token;
// $log['original_token'] = $original_token;
// file_put_contents('log.txt', date('Y.m.d H:i:s') . ' ' . json_encode($log)."\r\n",FILE_APPEND);
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': $new_order_status = 'on-hold'; break; /*Деньги на карте захолдированы. Корзина очищается.*/
case 'CONFIRMED': $new_order_status = 'processing'; break; /*Платеж подтвержден.*/
case 'CANCELED': $new_order_status = 'cancelled'; break; /*Платеж отменен*/
case 'REJECTED': $new_order_status = 'failed'; break; /*Платеж отклонен.*/
case 'REVERSED': $new_order_status = 'cancelled'; break; /*Платеж отменен*/
case 'REFUNDED': $new_order_status = 'refunded'; break; /*Произведен возврат денег клиенту*/
}
$order_id = (int)$_POST['OrderId'];
$order = new WC_Order($order_id);
if( isset( $new_order_status ) ){
$order->update_status( $new_order_status );
die('OK'); } die('NOTOK');
}
else{
die('NOTOK');
}
}
catch(Exception $e){
die('NOTOK');
}
Answer the question
In order to leave comments, you need to log in
Had the same problem, I turned on error logging to a file.
I looked that the script issues NOTOK1 for any error.
deprecated errors can be ignored and excluded from the handler, which I did
, but errors like [2] are warning and they needed to be corrected;
all errors were in the wp-ekam-class.php file
because it is written "not very"
actually
, I corrected them
after
which the warning errors disappeared, as expected, and the script began to behave correctly . how if you fix only ecam, it still wouldn’t work
as a result corrected success php from tinkoff woocommerce
and wp ekam class php
Nikolai, what did the
files look like in the end:
success php from tinkoff woocommerce
and wp ekam class php
??????
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question