I was develop a custom payment gateway for woocommerce, everything is good but after payment success the order still "pending payment"

In the __construct() function I check for payment provider respond

//when payment done and redirected with payment reference code
    paytabs_set_cookie('transaction_id', $_REQUEST['transaction_id']);
    $order  = new WC_Order($order_id);   
    $this->order = $order;
    $this->complete_transaction($order->get_id(), $_REQUEST['transaction_id']);

and here is the complete_transaction() function

When transaction completed it is check the status 
is transaction completed or rejected
function complete_transaction($order_id, $transaction_id) {
    global $woocommerce;       
    $order = new WC_Order( $order_id );

                'secret_key'        => $_COOKIE['secret_key'],
                'merchant_email'    => $_COOKIE['merchant_email'],
                'transaction_id'    => $transaction_id,
                'order_id'          => $order_id
    $getdataresponse=$this->sendRequest($gateway_url, $request_string);
    $object=json_decode($getdataresponse, true);

    if (isset($object->response_code)) {
        //if get response successfull
        if($object->response_code == '100'){

            // thankyou and set error message 
            $this->msg['class'] = 'woocommerce_message';

            // Reduce stock levels

            // Remove cart

            wc_add_notice( '' . __( 'Thank you for shopping with us. Your account has been charged and your transaction is successful.
            We will be shipping your order to you soon.', 'woocommerce' ), 'success' );     

            wp_redirect( $this->get_checkout_order_received_url( $order ) );


            // Change the status to pending / unpaid
            $order->update_status('failed', __('Payment Cancelled', 'error'));    

            // Add error for the customer when we return back to the cart

            wc_add_notice( '<strong></strong> ' . __($message, 'error' ), 'error' ); 

            // Redirect back to the last step in the checkout process
            wp_redirect( $this->get_cancel_order_url( $order ) );


But the order status still "pending payment"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.