WooCommerce中的订单状态错误

时间:2014-10-27 04:51:10

标签: php wordpress wordpress-plugin woocommerce payment-gateway

我试图为我的商家帐户制作网关插件,但我遇到了问题。

当我尝试echo order id时,我收到了此错误消息。

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 /> 

如果不是echo order id,我收到了这条消息。

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

这是我的代码

/**
         * 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!' );
            }

        }

我不知道我的代码是错的。我可以去第三方支付网站,并在后端收到订单,但在我结账后,返回此页面与defualt&#34; thankyou message&#34; (谢谢。您的订单已收到。)。

但不是改变&#34;订单状态&#34;并且从不显示&#39; add_order_note&#39; &安培; &#39;消息&#39;在后端。然后没有显示我的感谢信息而不是减少订单库存。

希望你能帮帮我!!!!

0 个答案:

没有答案