Skip to content

Commit

Permalink
Avoid updating payment many times
Browse files Browse the repository at this point in the history
  • Loading branch information
Cezar Luiz committed May 25, 2017
1 parent 4ca5b0e commit 1ef4210
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions woocommerce-gateway-ebanx/gateways/class-wc-ebanx-gateway.php
Expand Up @@ -965,16 +965,26 @@ final public function process_hook(array $codes, $notificationType)
* @return void
*/
final public function update_payment($order, $data) {
$requestStatus = strtoupper($data->payment->status);

$status = array(
'CO' => 'Confirmed',
'CA' => 'Canceled',
'PE' => 'Pending',
'OP' => 'Opened'
);

$order->add_order_note(sprintf(__('EBANX: The payment has been updated to: %s.', 'woocommerce-gateway-ebanx'), $status[$data->payment->status]));
$paymentStatus = $status[$data->payment->status];

// Avoid updating payment many times
if (
in_array($order->status, array('processing', 'completed'))
&& $requestStatus !== 'CA'
) return;

$order->add_order_note(sprintf(__('EBANX: The payment has been updated to: %s.', 'woocommerce-gateway-ebanx'), $paymentStatus));

switch (strtoupper($data->payment->status)) {
switch ($requestStatus) {
case 'CO':
$order->update_status('processing');
break;
Expand Down

0 comments on commit 1ef4210

Please sign in to comment.