Skip to content

Commit

Permalink
bugfix/PP-13303: improved gateway delete
Browse files Browse the repository at this point in the history
  • Loading branch information
vinothss4u committed Nov 28, 2024
1 parent f82e423 commit 1b0addc
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions PayrexxPaymentGatewaySW6/src/Handler/PaymentHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,15 @@ public function pay(AsyncPaymentTransactionStruct $transaction, RequestDataBag $
$this->customAsyncException($transactionId, $message);
}

$oldGatewayId = $orderTransaction->getCustomFields()['gateway_id'] ?? '';
if (!empty($oldGatewayId)) {
$this->payrexxApiService->deletePayrexxGateway($salesChannelId, (int) $oldGatewayId);
}

if (in_array($paymentMean, ['sofortueberweisung_de', 'postfinance_card', 'postfinance_efinance'])) {
throw new Exception('Unavailable payment method error');
}

// Create Payrexx Gateway link for checkout and redirect user
try {
$payrexxGateway = $this->payrexxApiService->createPayrexxGateway(
Expand All @@ -174,17 +180,13 @@ public function pay(AsyncPaymentTransactionStruct $transaction, RequestDataBag $
if (!$payrexxGateway) {
throw new Exception('Gateway creation error');
}
$oldGatewayId = $orderTransaction->getCustomFields()['gateway_id'] ?? '';
$this->transactionHandler->saveTransactionCustomFields($salesChannelContext, $transactionId, ['gateway_id' => $payrexxGateway->getId()]);
$this->transactionHandler->handleTransactionStatus(
$orderTransaction,
OrderTransactionStates::STATE_UNCONFIRMED,
$salesChannelContext->getContext()
);
$redirectUrl = $payrexxGateway->getLink();
if (!empty($oldGatewayId)) {
$this->payrexxApiService->deletePayrexxGateway($salesChannelId, (int) $oldGatewayId);
}
} catch (\Exception $e) {
$message = 'An error occurred during the communication with external payment gateway' . PHP_EOL . $e->getMessage();
$this->customAsyncException($transactionId, $message);
Expand Down

0 comments on commit 1b0addc

Please sign in to comment.