Skip to content

Commit

Permalink
Merge pull request #673 from ebanx/fix/complete-on-notification
Browse files Browse the repository at this point in the history
Complete payments on notification arrival
  • Loading branch information
miguelxpn authored Apr 24, 2018
2 parents e4a6104 + 211fe01 commit aa85990
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions gateways/class-wc-ebanx-new-gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -631,23 +631,30 @@ 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',
'PE' => 'Pending',
'OP' => 'Opened',
];
$new_status = null;
$old_status = $order->status;

switch ( $request_status ) {
case 'CO':
if ( method_exists( $order, 'get_payment_method' )
&& 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':
Expand All @@ -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 );
}
Expand Down

0 comments on commit aa85990

Please sign in to comment.