dsirr48088 2014-10-27 04:51
浏览 67

WooCommerce中的订单状态错误

I'm trying to make a Gateway Plugin for my Merchant Account but I got stuck.

when i try echo order id, i got this error message.

notifiy response:'<br />
<b>Catchable fatal error</b>:  Object of class WC_Order could not be converted to string in <b>/wp-content/plugins/wing/index_wc.php</b> on line <b>213</b><br /> 

if not echo order id, i got this message.

[info] [application] notifiy response:'IPN Processed OK. Payment Successfully! tstatus OK!'

Here my code

/**
         * Verify a successful Payment!
        **/
        function check_wingpay_response( $posted ){
            global $woocommerce;

            //$data = file_get_contents("php://input");

            if( $data = file_get_contents("php://input"))
            {
                $data = file_get_contents("php://input");
                $json=json_decode($data,true);              

                if($json['tstatus'] == '200')
                {
                    $transaction_id = $json['tid'];
                    $trans_account  = $json['account'];
                    $order_id       = $json['merchant_ref'];
                    $order_id       = (int) $order_id;

                    $order          = new WC_Order($order_id);
                    $order_total    = $order->get_total();

                    //update_post_meta( $order_id, '_wc_paymentwing_transaction_id', wc_clean( $data ) );

                    $amount_paid    = $json['amount'];

                    //echo $order .': Order ID <br/>';
                    //echo $order_id .': merchant_ref <br/>';
                    //echo $amount_paid .': amount paid <br/>';

                    //after payment hook
                    do_action('wc_wingpay_after_payment', $json);

                    // check if the amount paid is equal to the order amount.
                    if($order_total != $amount_paid) {
                        //Update the order status
                        $order->update_status('on-hold', '');

                        //Error Note
                        $message = 'Thank you for shopping with us.<br />Your payment transaction was successful, but the amount paid is not the same as the total order amount.<br />Your order is currently on-hold.<br />Kindly contact us for more information regarding your order and payment status.';
                        $message_type = 'notice';

                        //Add Customer Order Note
                        $order->add_order_note($message.'<br />Wing Transaction ID: '.$transaction_id, 1);

                        //Add Admin Order Note
                        $order->add_order_note('Look into this order. <br />This order is currently on hold.<br />Reason: Amount paid is less than the total order amount.<br />Amount Paid was &#8358; '.$amount_paid.' while the total order amount is &#8358; '.$order_total.'<br />Wing Transaction ID: '.$transaction_id);

                        // Reduce stock levels
                        $order->reduce_order_stock();
                        // Empty cart
                        $woocommerce->cart->empty_cart();
                    } else {
                        /* start processing state */
                        if($order->status == 'processing'){
                            $order->add_order_note('Payment Via Wing<br />Transaction ID: '.$transaction_id);

                            //Add customer order note
                            $order->add_order_note('Payment Received.<br />Your order is currently being processed.<br />We will be shipping your order to you soon.<br />Wing Transaction ID: '.$transaction_id, 1);

                            // Reduce stock levels
                            $order->reduce_order_stock();

                            // Empty cart
                            WC()->cart->empty_cart();

                            $message = 'Thank you for shopping with us.<br />Your transaction was successful, payment was received.<br />Your order is currently being processed.';
                            $message_type = 'success';
                        } else {
                            if( $order->has_downloadable_item() ){
                                //Update order status
                                $order->update_status( 'completed', 'Payment received, your order is now complete.' );

                                //Add admin order note
                                $order->add_order_note('Payment Via Wing Payment Gateway<br />Transaction ID: '.$transaction_id);

                                //Add customer order note
                                $order->add_order_note('Payment Received.<br />Your order is now complete.<br />Wing Transaction ID: '.$transaction_id, 1);

                                $message = 'Thank you for shopping with us.<br />Your transaction was successful, payment was received.<br />Your order is now complete.';
                                $message_type = 'success';
                            } else {
                                //Update order status
                                $order->update_status( 'processing', 'Payment received, your order is currently being processed.' );

                                //Add admin order noote
                                $order->add_order_note('Payment Via Wing Payment Gateway<br />Transaction ID: '.$transaction_id);

                                //Add customer order note
                                $order->add_order_note('Payment Received.<br />Your order is currently being processed.<br />We will be shipping your order to you soon.<br />Wing Transaction ID: '.$transaction_id, 1);

                                $message = 'Thank you for shopping with us.<br />Your transaction was successful, payment was received.<br />Your order is currently being processed.';
                                $message_type = 'success';
                            }
                            // Reduce stock levels
                            $order->reduce_order_stock();

                            // Empty cart
                            WC()->cart->empty_cart();
                        }
                    }                   

                    $wingpay_message = array(
                        'message'   => $message,
                        'message_type' => $message_type
                    );

                    if ( version_compare( WOOCOMMERCE_VERSION, "2.2" ) >= 0 ) {
                        add_post_meta( $order_id, '_transaction_id', $transaction_id, true );
                    }

                    update_post_meta( $order_id, '_wc_wingpay_message', $wingpay_message );

                    die( 'IPN Processed OK. Payment Successfully! tstatus OK!' );

                } //end tstaus == 200
                else
                {
                    $message =  'Thank you for shopping with us. <br />However, the transaction wasn\'t successful, payment wasn\'t recieved.';
                    $message_type = 'error';

                    $transaction_id = $json['tid'];

                    //Add Customer Order Note
                    $order->add_order_note($message.'<br />Wing Transaction ID: '.$transaction_id, 1);

                    //Add Admin Order Note
                    $order->add_order_note($message.'<br />Wing Transaction ID: '.$transaction_id);


                    //Update the order status
                    $order->update_status('failed', '');

                    $wingpay_message = array(
                        'message'   => $message,
                        'message_type' => $message_type
                    );

                    update_post_meta( $order_id, '_wc_wingpay_message', $wingpay_message );

                    die( 'IPN Processed OK! tstatus Failed!' );
                }
            }
            else
            {
                $message =  'Thank you for shopping with us. <br />However, the transaction wasn\'t successful, payment wasn\'t recieved.';
                $message_type = 'error';

                $wingpay_message = array(
                    'message'   => $message,
                    'message_type' => $message_type
                );

                update_post_meta( $order_id, '_wc_wingpay_message', $wingpay_message );

                die( 'IPN Processed OK! No Json data!' );
            }

        }

I don't know what my code is wrong. I can go third party payment website and received order in backend but After i checkout, return this page with defualt "thankyou message" (Thank you. Your order has been received.).

but not change "order-status" and never show 'add_order_note' & 'message' in back-end. and then not showing my thank message and not reduce order stock.

Hopefully, you can help me!!!!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
    • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
    • ¥16 mybatis的代理对象无法通过@Autowired装填
    • ¥15 可见光定位matlab仿真
    • ¥15 arduino 四自由度机械臂
    • ¥15 wordpress 产品图片 GIF 没法显示
    • ¥15 求三国群英传pl国战时间的修改方法
    • ¥15 matlab代码代写,需写出详细代码,代价私
    • ¥15 ROS系统搭建请教(跨境电商用途)
    • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。