From 211fe019070b7c7b5b84981dad8546a34ccdcf84 Mon Sep 17 00:00:00 2001 From: Anderson Campanha Date: Tue, 24 Apr 2018 13:03:38 -0300 Subject: [PATCH] Complete payments on notification arrival --- gateways/class-wc-ebanx-new-gateway.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/gateways/class-wc-ebanx-new-gateway.php b/gateways/class-wc-ebanx-new-gateway.php index bfccb802..a157a9cb 100644 --- a/gateways/class-wc-ebanx-new-gateway.php +++ b/gateways/class-wc-ebanx-new-gateway.php @@ -631,6 +631,10 @@ final public function process_hook( array $codes, $notification_type ) { final public function update_payment( $order, $data ) { $request_status = strtoupper( $data['payment']['status'] ); + if ( 'completed' === $order->status && 'CA' !== $request_status ) { + return; + } + $status = [ 'CO' => 'Confirmed', 'CA' => 'Canceled', @@ -638,6 +642,7 @@ final public function update_payment( $order, $data ) { 'OP' => 'Opened', ]; $new_status = null; + $old_status = $order->status; switch ( $request_status ) { case 'CO': @@ -645,9 +650,11 @@ final public function update_payment( $order, $data ) { && strpos( $order->get_payment_method(), 'ebanx-credit-card' ) === 0 ) { return; } + $order->payment_complete( $data['payment']['hash'] ); $new_status = 'processing'; break; case 'CA': + $order->payment_complete(); $new_status = 'failed'; break; case 'PE': @@ -658,13 +665,8 @@ final public function update_payment( $order, $data ) { break; } - if ( 'completed' === $order->status && 'CA' !== $request_status ) { - return; - } - - if ( $new_status !== $order->status ) { + if ( $new_status !== $old_status ) { $payment_status = $status[ $data['payment']['status'] ]; - // translators: placeholder contains payment status. $order->add_order_note( sprintf( __( 'EBANX: The payment has been updated to: %s.', 'woocommerce-gateway-ebanx' ), $payment_status ) ); $order->update_status( $new_status ); }