Skip to content

Commit

Permalink
Also update payment transaction ID for cancelled orders.
Browse files Browse the repository at this point in the history
  • Loading branch information
remcotolsma committed Oct 19, 2023
1 parent 0223045 commit 27488b9
Showing 1 changed file with 33 additions and 11 deletions.
44 changes: 33 additions & 11 deletions src/Gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -646,28 +646,50 @@ private function handle_merchant_order_status_changed( Notification $notificatio
private function update_payment_transaction_id_from_order_result( $payment, $order_result ) {
$transaction_id = (string) $payment->get_transaction_id();

Check failure on line 647 in src/Gateway.php

View workflow job for this annotation

GitHub Actions / phpcs / phpcs

Unused variable $transaction_id.

if ( '' !== $transaction_id ) {
return;
}
$transaction_statuses = [
TransactionStatus::SUCCESS,
TransactionStatus::ACCEPTED,
TransactionStatus::CANCELLED,
TransactionStatus::EXPIRED,
TransactionStatus::FAILURE,
];

if ( 'COMPLETED' !== $order_result->get_order_status() ) {
return;
switch ( $order_result->get_order_status() ) {
case OrderStatus::COMPLETED:
$transaction_statuses = [
TransactionStatus::SUCCESS,
TransactionStatus::ACCEPTED,
];

break;
case OrderStatus::CANCELLED:
$transaction_statuses = [
TransactionStatus::CANCELLED,
];

break;
case OrderStatus::EXPIRED:
$transaction_statuses = [
TransactionStatus::EXPIRED,
];

break;
}

$successful_transactions = \array_filter(
$transactions = \array_filter(
$order_result->get_transactions(),
static function ( $transaction ) {
return 'SUCCESS' === $transaction->get_status();
function ( $transaction ) use ( $transaction_statuses ) {

Check failure on line 681 in src/Gateway.php

View workflow job for this annotation

GitHub Actions / phpcs / phpcs

Closure not using "$this" should be declared static.
return \in_array( $transaction->get_status(), $transaction_statuses, true );
}
);

$successful_transaction = \array_shift( $successful_transactions );
$transaction = \array_shift( $transactions );

if ( null === $successful_transaction ) {
if ( null === $transaction ) {
return;
}

$payment->set_transaction_id( $successful_transaction->get_id() );
$payment->set_transaction_id( $transaction->get_id() );
}

/**
Expand Down

0 comments on commit 27488b9

Please sign in to comment.