Skip to content

Commit

Permalink
PAYOSWXP-156: set transaction-state to „authorized“ on „appointed“
Browse files Browse the repository at this point in the history
  • Loading branch information
rommelfreddy committed Sep 13, 2024
1 parent bb489ff commit 5b06579
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 319 deletions.
13 changes: 0 additions & 13 deletions src/DependencyInjection/controllers.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,6 @@
</call>
</service>

<service id="PayonePayment\Storefront\Controller\Account\AccountOrderControllerDecorator"
decorates="Shopware\Storefront\Controller\AccountOrderController">
<argument type="service" id="PayonePayment\Storefront\Controller\Account\AccountOrderControllerDecorator.inner" />
<argument type="service" id="order.repository" />

<call method="setContainer">
<argument type="service" id="service_container"/>
</call>
<call method="setTwig">
<argument type="service" id="twig"/>
</call>
</service>

<service id="PayonePayment\Storefront\Controller\Debit\ManageMandateController">
<argument type="service" id="PayonePayment\Payone\RequestParameter\RequestParameterFactory" />
<argument type="service" id="PayonePayment\Payone\Client\PayoneClient" />
Expand Down
4 changes: 4 additions & 0 deletions src/DependencyInjection/webhooks.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
<tag name="payone.webhook.handler" />
</service>

<service id="PayonePayment\Payone\Webhook\Handler\PaymentStatusHandler" autowire="true">
<tag name="payone.webhook.handler" />
</service>

<service id="PayonePayment\Payone\Webhook\MessageBus\MessageHandler\NotificationForwardHandler" autowire="true">
<argument key="$forwardTargetRepository" type="service" id="payone_payment_notification_target.repository" />
<argument key="$notificationForwardRepository" type="service" id="payone_payment_notification_forward.repository" />
Expand Down
50 changes: 50 additions & 0 deletions src/Payone/Webhook/Handler/PaymentStatusHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

declare(strict_types=1);

namespace PayonePayment\Payone\Webhook\Handler;

use PayonePayment\Components\DataHandler\Transaction\TransactionDataHandlerInterface;
use PayonePayment\Struct\PaymentTransaction;
use Shopware\Core\Checkout\Order\Aggregate\OrderTransaction\OrderTransactionDefinition;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
use Shopware\Core\System\StateMachine\Aggregation\StateMachineTransition\StateMachineTransitionActions;
use Shopware\Core\System\StateMachine\StateMachineRegistry;
use Shopware\Core\System\StateMachine\Transition;
use Symfony\Component\HttpFoundation\Request;

class PaymentStatusHandler implements WebhookHandlerInterface
{
public function __construct(
private readonly TransactionDataHandlerInterface $transactionDataHandler,
private readonly StateMachineRegistry $stateMachineRegistry
) {
}

public function process(SalesChannelContext $salesChannelContext, Request $request): void
{
$paymentTransaction = $this->transactionDataHandler->getPaymentTransactionByPayoneTransactionId(
$salesChannelContext->getContext(),
$request->request->getInt('txid')
);

if (!$paymentTransaction instanceof PaymentTransaction) {
return;
}

$this->stateMachineRegistry->transition(
new Transition(
OrderTransactionDefinition::ENTITY_NAME,
$paymentTransaction->getOrderTransaction()->getId(),
StateMachineTransitionActions::ACTION_AUTHORIZE,
'stateId'
),
$salesChannelContext->getContext()
);
}

public function supports(SalesChannelContext $salesChannelContext, array $data): bool
{
return isset($data['txid']) && ($data['txaction'] ?? null) === 'appointed';
}
}

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit 5b06579

Please sign in to comment.