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 ₦ '.$amount_paid.' while the total order amount is ₦ '.$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!!!!