Add required status action handling

This commit is contained in:
Francis Hilaire 2024-11-09 14:01:15 +01:00
parent 1601b57eb3
commit aed8bcbf7c
No known key found for this signature in database
GPG key ID: 3392F830BF33D421
5 changed files with 111 additions and 0 deletions

View file

@ -0,0 +1,27 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Sylius\Bundle\PaymentBundle\Command\Offline;
use Sylius\Bundle\PaymentBundle\Command\PaymentRequestHashAwareInterface;
use Sylius\Bundle\PaymentBundle\Command\PaymentRequestHashAwareTrait;
/** @experimental */
class StatusPaymentRequest implements PaymentRequestHashAwareInterface
{
use PaymentRequestHashAwareTrait;
public function __construct(protected ?string $hash)
{
}
}

View file

@ -0,0 +1,42 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Sylius\Bundle\PaymentBundle\CommandHandler\Offline;
use Sylius\Abstraction\StateMachine\StateMachineInterface;
use Sylius\Bundle\PaymentBundle\Command\Offline\StatusPaymentRequest;
use Sylius\Bundle\PaymentBundle\Provider\PaymentRequestProviderInterface;
use Sylius\Component\Payment\PaymentRequestTransitions;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
/** @experimental */
#[AsMessageHandler]
final readonly class StatusPaymentRequestHandler
{
public function __construct(
private PaymentRequestProviderInterface $paymentRequestProvider,
private StateMachineInterface $stateMachine,
) {
}
public function __invoke(StatusPaymentRequest $statusPaymentRequest): void
{
$paymentRequest = $this->paymentRequestProvider->provide($statusPaymentRequest);
$this->stateMachine->apply(
$paymentRequest,
PaymentRequestTransitions::GRAPH,
PaymentRequestTransitions::TRANSITION_COMPLETE,
);
}
}

View file

@ -0,0 +1,33 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Sylius\Bundle\PaymentBundle\CommandProvider\Offline;
use Sylius\Bundle\PaymentBundle\Command\Offline\CapturePaymentRequest;
use Sylius\Bundle\PaymentBundle\Command\Offline\StatusPaymentRequest;
use Sylius\Bundle\PaymentBundle\CommandProvider\PaymentRequestCommandProviderInterface;
use Sylius\Component\Payment\Model\PaymentRequestInterface;
/** @experimental */
final class StatusPaymentRequestCommandProvider implements PaymentRequestCommandProviderInterface
{
public function supports(PaymentRequestInterface $paymentRequest): bool
{
return $paymentRequest->getAction() === PaymentRequestInterface::ACTION_STATUS;
}
public function provide(PaymentRequestInterface $paymentRequest): object
{
return new StatusPaymentRequest($paymentRequest->getId());
}
}

View file

@ -22,5 +22,10 @@
<argument type="service" id="sylius_abstraction.state_machine" /> <argument type="service" id="sylius_abstraction.state_machine" />
<tag name="messenger.message_handler" bus="sylius.payment_request.command_bus" /> <tag name="messenger.message_handler" bus="sylius.payment_request.command_bus" />
</service> </service>
<service id="sylius.command_handler.offline.status_payment_request" class="Sylius\Bundle\PaymentBundle\CommandHandler\Offline\StatusPaymentRequestHandler">
<argument type="service" id="sylius.provider.payment_request" />
<argument type="service" id="sylius_abstraction.state_machine" />
<tag name="messenger.message_handler" bus="sylius.payment_request.command_bus" />
</service>
</services> </services>
</container> </container>

View file

@ -32,5 +32,9 @@
<service id="sylius.command_provider.payment_request.offline.capture" class="Sylius\Bundle\PaymentBundle\CommandProvider\Offline\CapturePaymentRequestCommandProvider"> <service id="sylius.command_provider.payment_request.offline.capture" class="Sylius\Bundle\PaymentBundle\CommandProvider\Offline\CapturePaymentRequestCommandProvider">
<tag name="sylius.command_provider.payment_request.offline" action="capture" /> <tag name="sylius.command_provider.payment_request.offline" action="capture" />
</service> </service>
<service id="sylius.command_provider.payment_request.offline.status" class="Sylius\Bundle\PaymentBundle\CommandProvider\Offline\StatusPaymentRequestCommandProvider">
<tag name="sylius.command_provider.payment_request.offline" action="status" />
</service>
</services> </services>
</container> </container>