Skip to content

Commit

Permalink
Merge branch 'bugfix/PP-13303' into bugfix/PP-12519
Browse files Browse the repository at this point in the history
  • Loading branch information
vinothss4u committed Nov 29, 2024
2 parents cd8abf5 + 63f1cd7 commit 4a6453c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 10 deletions.
23 changes: 19 additions & 4 deletions PayrexxPaymentGatewaySW6/src/Handler/PaymentHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,24 @@ public function pay(AsyncPaymentTransactionStruct $transaction, RequestDataBag $
$this->customAsyncException($transactionId, $message);
}

$oldGatewayId = $orderTransaction->getCustomFields()['gateway_id'] ?? '';
if (!empty($oldGatewayId)) {
$this->payrexxApiService->deletePayrexxGateway($salesChannelId, (int) $oldGatewayId);
// Delete gateway from all transactions.
foreach($order->getTransactions() as $transactionGateway) {
$oldGatewayId = $transactionGateway->getCustomFields()['gateway_id'] ?? '';
if ($oldGatewayId) {
$gatewayStatus = $this->payrexxApiService->deletePayrexxGateway(
$salesChannelId,
(int) $oldGatewayId
);
if ($gatewayStatus) {
$this->transactionHandler->saveTransactionCustomFields(
$salesChannelContext,
$transactionGateway->getId(),
[
'gateway_id' => '',
]
);
}
}
}

if (in_array($paymentMean, ['sofortueberweisung_de', 'postfinance_card', 'postfinance_efinance'])) {
Expand Down Expand Up @@ -245,7 +260,7 @@ public function finalize(AsyncPaymentTransactionStruct $shopwareTransaction, Req
$payrexxTransaction = $this->payrexxApiService->getTransactionByGateway($payrexxGateway, $salesChannelId);

if (!$payrexxTransaction && $totalAmount > 0) {
if (!empty($gatewayId)) {
if ($gatewayId) {
$this->payrexxApiService->deletePayrexxGateway($salesChannelId, (int) $gatewayId);
}
$this->customCustomerException($transactionId, 'Customer canceled the payment on the Payrexx page');
Expand Down
8 changes: 6 additions & 2 deletions PayrexxPaymentGatewaySW6/src/Handler/TransactionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,15 @@ public function handleTransactionStatus(OrderTransactionEntity $orderTransaction
case Transaction::CANCELLED:
case Transaction::DECLINED:
case Transaction::EXPIRED:
if ($state !== null && in_array($orderTransaction->getStateMachineState()->getTechnicalName(), [OrderTransactionStates::STATE_CANCELLED, OrderTransactionStates::STATE_PAID])) break;
if ($state !== null && !in_array($orderTransaction->getStateMachineState()->getTechnicalName(), [OrderTransactionStates::STATE_OPEN, OrderTransactionStates::STATE_UNCONFIRMED])) {
break;
}
$this->transactionStateHandler->cancel($orderTransaction->getId(), $context);
break;
case Transaction::ERROR:
if ($state !== null && in_array($orderTransaction->getStateMachineState()->getTechnicalName(), [OrderTransactionStates::STATE_FAILED, OrderTransactionStates::STATE_PAID])) break;
if ($state !== null && !in_array($orderTransaction->getStateMachineState()->getTechnicalName(), [OrderTransactionStates::STATE_OPEN, OrderTransactionStates::STATE_UNCONFIRMED])) {
break;
}
$this->transactionStateHandler->fail($orderTransaction->getId(), $context);
break;
}
Expand Down
15 changes: 11 additions & 4 deletions PayrexxPaymentGatewaySW6/src/Service/PayrexxApiService.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,21 +203,28 @@ public function getPayrexxTransaction(int $payrexxTransactionId, $salesChannelId
*
* @param string $salesChannelId
* @param int $gatewayId
* @return bool
*/
public function deletePayrexxGateway(string $salesChannelId, int $gatewayId): void
public function deletePayrexxGateway(string $salesChannelId, int $gatewayId): bool
{
if (empty($gatewayId)) {
return;
return true;
}

$payrexx = $this->getInterface($salesChannelId);
$gateway = $this->getPayrexxGateway($gatewayId, $salesChannelId);
if ($payrexx && $gateway && !$this->getTransactionByGateway($salesChannelId, $gatewayId)) {

if (!$gateway) {
return true; // Already deleted.
}
if ($payrexx && $gateway && !$this->getTransactionByGateway($gateway, $salesChannelId)) {
try {
$payrexx->delete($gateway);
return true;
} catch (\Payrexx\PayrexxException $e) {
return;
// no action.
}
}
return false;
}
}

0 comments on commit 4a6453c

Please sign in to comment.