mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-05 20:57:12 +00:00
Merge 295047812c into 9b6799e2b8
This commit is contained in:
commit
d7b8e3f8e5
19 changed files with 124 additions and 95 deletions
|
|
@ -71,6 +71,72 @@
|
|||
> and their default parameters include Payment Request-specific values (e.g. `hash: paymentRequest.getHash()`).
|
||||
> Do not use them to configure the Payum after-pay redirect.
|
||||
|
||||
4. The `RequestConfiguration` type has been replaced by `Request` in all payment processing interfaces and their implementations.
|
||||
|
||||
If you implemented or decorated any of the following interfaces, update your method signatures accordingly:
|
||||
|
||||
- `Sylius\Bundle\CoreBundle\OrderPay\Provider\PayResponseProviderInterface`:
|
||||
```diff
|
||||
-public function getResponse(RequestConfiguration $requestConfiguration, OrderInterface $order): Response;
|
||||
-public function supports(RequestConfiguration $requestConfiguration, OrderInterface $order): bool;
|
||||
+public function getResponse(Request $request, OrderInterface $order): Response;
|
||||
+public function supports(Request $request, OrderInterface $order): bool;
|
||||
```
|
||||
|
||||
- `Sylius\Bundle\CoreBundle\OrderPay\Provider\AfterPayResponseProviderInterface`:
|
||||
```diff
|
||||
-public function getResponse(RequestConfiguration $requestConfiguration): Response;
|
||||
-public function supports(RequestConfiguration $requestConfiguration): bool;
|
||||
+public function getResponse(Request $request): Response;
|
||||
+public function supports(Request $request): bool;
|
||||
```
|
||||
|
||||
- `Sylius\Bundle\PaymentBundle\Provider\HttpResponseProviderInterface`:
|
||||
```diff
|
||||
-public function supports(RequestConfiguration $requestConfiguration, PaymentRequestInterface $paymentRequest): bool;
|
||||
-public function getResponse(RequestConfiguration $requestConfiguration, PaymentRequestInterface $paymentRequest): Response;
|
||||
+public function supports(Request $request, PaymentRequestInterface $paymentRequest): bool;
|
||||
+public function getResponse(Request $request, PaymentRequestInterface $paymentRequest): Response;
|
||||
```
|
||||
|
||||
- `Sylius\Bundle\PaymentBundle\Processor\HttpResponseProcessorInterface`:
|
||||
```diff
|
||||
-public function process(RequestConfiguration $requestConfiguration, PaymentRequestInterface $paymentRequest): ?Response;
|
||||
+public function process(Request $request, PaymentRequestInterface $paymentRequest): ?Response;
|
||||
```
|
||||
|
||||
- `Sylius\Bundle\CoreBundle\OrderPay\Handler\PaymentStateFlashHandlerInterface`:
|
||||
```diff
|
||||
-public function handle(RequestConfiguration $requestConfiguration, string $state): void;
|
||||
+public function handle(Request $request, string $state): void;
|
||||
```
|
||||
|
||||
5. `MetadataInterface` and `RequestConfigurationFactoryInterface` have been removed from the constructors of `OrderPayController` and `PaymentRequestPayAction`.
|
||||
|
||||
If you extended or decorated either of these classes, update their constructors:
|
||||
|
||||
- `Sylius\Bundle\CoreBundle\OrderPay\Controller\OrderPayController`:
|
||||
```diff
|
||||
public function __construct(
|
||||
private OrderRepositoryInterface $orderRepository,
|
||||
- private MetadataInterface $orderMetadata,
|
||||
- private RequestConfigurationFactoryInterface $requestConfigurationFactory,
|
||||
private iterable $payResponseProviders,
|
||||
private iterable $afterPayResponseProviders,
|
||||
) {}
|
||||
```
|
||||
|
||||
- `Sylius\Bundle\CoreBundle\OrderPay\Action\PaymentRequestPayAction`:
|
||||
```diff
|
||||
public function __construct(
|
||||
- private MetadataInterface $paymentRequestMetadata,
|
||||
- private RequestConfigurationFactoryInterface $requestConfigurationFactory,
|
||||
private PaymentRequestRepositoryInterface $paymentRequestRepository,
|
||||
private HttpResponseProcessorInterface $httpResponseProcessor,
|
||||
private UrlProviderInterface $afterPayUrlProvider,
|
||||
) {}
|
||||
```
|
||||
|
||||
## Dependencies
|
||||
|
||||
1. The `behat/transliterator` package has been **deprecated** and will be removed in Sylius 3.0.
|
||||
|
|
|
|||
|
|
@ -15,10 +15,8 @@ namespace Sylius\Bundle\CoreBundle\OrderPay\Action;
|
|||
|
||||
use Sylius\Bundle\CoreBundle\OrderPay\Provider\UrlProviderInterface;
|
||||
use Sylius\Bundle\PaymentBundle\Processor\HttpResponseProcessorInterface;
|
||||
use Sylius\Bundle\ResourceBundle\Controller\RequestConfigurationFactoryInterface;
|
||||
use Sylius\Component\Payment\Model\PaymentRequestInterface;
|
||||
use Sylius\Component\Payment\Repository\PaymentRequestRepositoryInterface;
|
||||
use Sylius\Resource\Metadata\MetadataInterface;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
|
@ -31,8 +29,6 @@ final class PaymentRequestPayAction
|
|||
* @param PaymentRequestRepositoryInterface<PaymentRequestInterface> $paymentRequestRepository
|
||||
*/
|
||||
public function __construct(
|
||||
private MetadataInterface $paymentRequestMetadata,
|
||||
private RequestConfigurationFactoryInterface $requestConfigurationFactory,
|
||||
private PaymentRequestRepositoryInterface $paymentRequestRepository,
|
||||
private HttpResponseProcessorInterface $httpResponseProcessor,
|
||||
private UrlProviderInterface $afterPayUrlProvider,
|
||||
|
|
@ -41,15 +37,13 @@ final class PaymentRequestPayAction
|
|||
|
||||
public function __invoke(Request $request, string $hash): Response
|
||||
{
|
||||
$requestConfiguration = $this->requestConfigurationFactory->create($this->paymentRequestMetadata, $request);
|
||||
|
||||
$paymentRequest = $this->paymentRequestRepository->find($hash);
|
||||
|
||||
if (null === $paymentRequest) {
|
||||
throw new NotFoundHttpException(sprintf('No payment request found with hash "%s".', $hash));
|
||||
}
|
||||
|
||||
$response = $this->httpResponseProcessor->process($requestConfiguration, $paymentRequest);
|
||||
$response = $this->httpResponseProcessor->process($request, $paymentRequest);
|
||||
|
||||
return $response ?? new RedirectResponse($this->afterPayUrlProvider->getUrl($paymentRequest));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,10 +16,8 @@ namespace Sylius\Bundle\CoreBundle\OrderPay\Controller;
|
|||
use LogicException;
|
||||
use Sylius\Bundle\CoreBundle\OrderPay\Provider\AfterPayResponseProviderInterface;
|
||||
use Sylius\Bundle\CoreBundle\OrderPay\Provider\PayResponseProviderInterface;
|
||||
use Sylius\Bundle\ResourceBundle\Controller\RequestConfigurationFactoryInterface;
|
||||
use Sylius\Component\Core\Model\OrderInterface;
|
||||
use Sylius\Component\Order\Repository\OrderRepositoryInterface;
|
||||
use Sylius\Resource\Metadata\MetadataInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
|
@ -34,8 +32,6 @@ final class OrderPayController
|
|||
*/
|
||||
public function __construct(
|
||||
private OrderRepositoryInterface $orderRepository,
|
||||
private MetadataInterface $orderMetadata,
|
||||
private RequestConfigurationFactoryInterface $requestConfigurationFactory,
|
||||
private iterable $payResponseProviders,
|
||||
private iterable $afterPayResponseProviders,
|
||||
) {
|
||||
|
|
@ -43,8 +39,6 @@ final class OrderPayController
|
|||
|
||||
public function payAction(Request $request, string $tokenValue): Response
|
||||
{
|
||||
$configuration = $this->requestConfigurationFactory->create($this->orderMetadata, $request);
|
||||
|
||||
/** @var OrderInterface|null $order */
|
||||
$order = $this->orderRepository->findOneByTokenValue($tokenValue);
|
||||
|
||||
|
|
@ -55,8 +49,8 @@ final class OrderPayController
|
|||
$request->getSession()->set('sylius_order_id', $order->getId());
|
||||
|
||||
foreach ($this->payResponseProviders as $provider) {
|
||||
if ($provider->supports($configuration, $order)) {
|
||||
return $provider->getResponse($configuration, $order);
|
||||
if ($provider->supports($request, $order)) {
|
||||
return $provider->getResponse($request, $order);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -65,11 +59,9 @@ final class OrderPayController
|
|||
|
||||
public function afterPayAction(Request $request): Response
|
||||
{
|
||||
$configuration = $this->requestConfigurationFactory->create($this->orderMetadata, $request);
|
||||
|
||||
foreach ($this->afterPayResponseProviders as $provider) {
|
||||
if ($provider->supports($configuration)) {
|
||||
return $provider->getResponse($configuration);
|
||||
if ($provider->supports($request)) {
|
||||
return $provider->getResponse($request);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,8 +13,8 @@ declare(strict_types=1);
|
|||
|
||||
namespace Sylius\Bundle\CoreBundle\OrderPay\Handler;
|
||||
|
||||
use Sylius\Bundle\ResourceBundle\Controller\RequestConfiguration;
|
||||
use Sylius\Component\Payment\Model\PaymentInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Session\FlashBagAwareSessionInterface;
|
||||
|
||||
/** @experimental */
|
||||
|
|
@ -24,10 +24,8 @@ final class PaymentStateFlashHandler implements PaymentStateFlashHandlerInterfac
|
|||
{
|
||||
}
|
||||
|
||||
public function handle(RequestConfiguration $requestConfiguration, string $state): void
|
||||
public function handle(Request $request, string $state): void
|
||||
{
|
||||
$request = $requestConfiguration->getRequest();
|
||||
|
||||
if (!$request->hasSession()) {
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,10 +13,10 @@ declare(strict_types=1);
|
|||
|
||||
namespace Sylius\Bundle\CoreBundle\OrderPay\Handler;
|
||||
|
||||
use Sylius\Bundle\ResourceBundle\Controller\RequestConfiguration;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
/** @experimental */
|
||||
interface PaymentStateFlashHandlerInterface
|
||||
{
|
||||
public function handle(RequestConfiguration $requestConfiguration, string $state): void;
|
||||
public function handle(Request $request, string $state): void;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,13 +13,13 @@ declare(strict_types=1);
|
|||
|
||||
namespace Sylius\Bundle\CoreBundle\OrderPay\Provider;
|
||||
|
||||
use Sylius\Bundle\ResourceBundle\Controller\RequestConfiguration;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
/** @experimental */
|
||||
interface AfterPayResponseProviderInterface
|
||||
{
|
||||
public function getResponse(RequestConfiguration $requestConfiguration): Response;
|
||||
public function getResponse(Request $request): Response;
|
||||
|
||||
public function supports(RequestConfiguration $requestConfiguration): bool;
|
||||
public function supports(Request $request): bool;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,9 +14,9 @@ declare(strict_types=1);
|
|||
namespace Sylius\Bundle\CoreBundle\OrderPay\Provider;
|
||||
|
||||
use Sylius\Bundle\CoreBundle\OrderPay\Resolver\PaymentToPayResolverInterface;
|
||||
use Sylius\Bundle\ResourceBundle\Controller\RequestConfiguration;
|
||||
use Sylius\Component\Core\Model\OrderInterface;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
/** @experimental */
|
||||
|
|
@ -28,12 +28,12 @@ final class NoPaymentPayResponseProvider implements PayResponseProviderInterface
|
|||
) {
|
||||
}
|
||||
|
||||
public function getResponse(RequestConfiguration $requestConfiguration, OrderInterface $order): Response
|
||||
public function getResponse(Request $request, OrderInterface $order): Response
|
||||
{
|
||||
return new RedirectResponse($this->orderPayFinalUrlProvider->getUrl(null));
|
||||
}
|
||||
|
||||
public function supports(RequestConfiguration $requestConfiguration, OrderInterface $order): bool
|
||||
public function supports(Request $request, OrderInterface $order): bool
|
||||
{
|
||||
return null === $this->paymentToPayResolver->getPayment($order);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,9 +15,9 @@ namespace Sylius\Bundle\CoreBundle\OrderPay\Provider\Offline;
|
|||
|
||||
use Sylius\Bundle\CoreBundle\OrderPay\Provider\FinalUrlProviderInterface;
|
||||
use Sylius\Bundle\PaymentBundle\Provider\HttpResponseProviderInterface;
|
||||
use Sylius\Bundle\ResourceBundle\Controller\RequestConfiguration;
|
||||
use Sylius\Component\Payment\Model\PaymentRequestInterface;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
/** @experimental */
|
||||
|
|
@ -28,14 +28,14 @@ final class StatusHttpResponseProvider implements HttpResponseProviderInterface
|
|||
}
|
||||
|
||||
public function supports(
|
||||
RequestConfiguration $requestConfiguration,
|
||||
Request $request,
|
||||
PaymentRequestInterface $paymentRequest,
|
||||
): bool {
|
||||
return $paymentRequest->getAction() === PaymentRequestInterface::ACTION_STATUS;
|
||||
}
|
||||
|
||||
public function getResponse(
|
||||
RequestConfiguration $requestConfiguration,
|
||||
Request $request,
|
||||
PaymentRequestInterface $paymentRequest,
|
||||
): Response {
|
||||
// Force null payment to go to the thank you page
|
||||
|
|
|
|||
|
|
@ -13,14 +13,14 @@ declare(strict_types=1);
|
|||
|
||||
namespace Sylius\Bundle\CoreBundle\OrderPay\Provider;
|
||||
|
||||
use Sylius\Bundle\ResourceBundle\Controller\RequestConfiguration;
|
||||
use Sylius\Component\Core\Model\OrderInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
/** @experimental */
|
||||
interface PayResponseProviderInterface
|
||||
{
|
||||
public function getResponse(RequestConfiguration $requestConfiguration, OrderInterface $order): Response;
|
||||
public function getResponse(Request $request, OrderInterface $order): Response;
|
||||
|
||||
public function supports(RequestConfiguration $requestConfiguration, OrderInterface $order): bool;
|
||||
public function supports(Request $request, OrderInterface $order): bool;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,15 +15,14 @@ namespace Sylius\Bundle\CoreBundle\OrderPay\Provider;
|
|||
|
||||
use Sylius\Bundle\CoreBundle\OrderPay\Handler\PaymentStateFlashHandlerInterface;
|
||||
use Sylius\Bundle\PaymentBundle\Processor\HttpResponseProcessorInterface;
|
||||
use Sylius\Bundle\ResourceBundle\Controller\RequestConfiguration;
|
||||
use Sylius\Component\Core\Model\PaymentInterface;
|
||||
use Sylius\Component\Payment\Factory\PaymentRequestFactoryInterface;
|
||||
use Sylius\Component\Payment\Model\PaymentRequestInterface;
|
||||
use Sylius\Component\Payment\Repository\PaymentRequestRepositoryInterface;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
/** @experimental */
|
||||
final class PaymentRequestAfterPayResponseProvider implements AfterPayResponseProviderInterface
|
||||
|
|
@ -41,10 +40,9 @@ final class PaymentRequestAfterPayResponseProvider implements AfterPayResponsePr
|
|||
) {
|
||||
}
|
||||
|
||||
public function getResponse(RequestConfiguration $requestConfiguration): Response
|
||||
public function getResponse(Request $request): Response
|
||||
{
|
||||
$hash = $this->getPaymentRequestHash($requestConfiguration);
|
||||
Assert::notNull($hash, 'A request attribute "hash" is required to retrieve the related order.');
|
||||
$hash = $request->attributes->getString('hash');
|
||||
|
||||
/** @var PaymentRequestInterface|null $previousPaymentRequest */
|
||||
$previousPaymentRequest = $this->paymentRequestRepository->find($hash);
|
||||
|
|
@ -57,24 +55,19 @@ final class PaymentRequestAfterPayResponseProvider implements AfterPayResponsePr
|
|||
|
||||
$this->paymentRequestRepository->add($paymentRequest);
|
||||
|
||||
$response = $this->httpResponseProcessor->process($requestConfiguration, $paymentRequest);
|
||||
$response = $this->httpResponseProcessor->process($request, $paymentRequest);
|
||||
|
||||
/** @var PaymentInterface $payment */
|
||||
$payment = $paymentRequest->getPayment();
|
||||
$this->paymentStateFlashHandler->handle($requestConfiguration, $payment->getState());
|
||||
$this->paymentStateFlashHandler->handle($request, $payment->getState());
|
||||
|
||||
return $response ?? new RedirectResponse($this->orderPayFinalUrlProvider->getUrl($payment));
|
||||
}
|
||||
|
||||
public function supports(RequestConfiguration $requestConfiguration): bool
|
||||
public function supports(Request $request): bool
|
||||
{
|
||||
$hash = $this->getPaymentRequestHash($requestConfiguration);
|
||||
$hash = $request->attributes->get('hash');
|
||||
|
||||
return null !== $hash && '' !== $hash;
|
||||
}
|
||||
|
||||
private function getPaymentRequestHash(RequestConfiguration $requestConfiguration): mixed
|
||||
{
|
||||
return $requestConfiguration->getRequest()->attributes->get('hash');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@ use Sylius\Bundle\CoreBundle\OrderPay\Resolver\PaymentToPayResolverInterface;
|
|||
use Sylius\Bundle\PaymentBundle\Checker\FinalizedPaymentRequestCheckerInterface;
|
||||
use Sylius\Bundle\PaymentBundle\Provider\DefaultActionProviderInterface;
|
||||
use Sylius\Bundle\PaymentBundle\Provider\DefaultPayloadProviderInterface;
|
||||
use Sylius\Bundle\ResourceBundle\Controller\RequestConfiguration;
|
||||
use Sylius\Component\Core\Model\OrderInterface;
|
||||
use Sylius\Component\Payment\Factory\PaymentRequestFactoryInterface;
|
||||
use Sylius\Component\Payment\Model\PaymentInterface;
|
||||
|
|
@ -25,6 +24,7 @@ use Sylius\Component\Payment\Model\PaymentMethodInterface;
|
|||
use Sylius\Component\Payment\Model\PaymentRequestInterface;
|
||||
use Sylius\Component\Payment\Repository\PaymentRequestRepositoryInterface;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
|
|
@ -46,7 +46,7 @@ final class PaymentRequestPayResponseProvider implements PayResponseProviderInte
|
|||
) {
|
||||
}
|
||||
|
||||
public function getResponse(RequestConfiguration $requestConfiguration, OrderInterface $order): Response
|
||||
public function getResponse(Request $request, OrderInterface $order): Response
|
||||
{
|
||||
$payment = $this->paymentToPayResolver->getPayment($order);
|
||||
Assert::notNull($payment, sprintf('Order (id %s) must have last payment in state "new".', $order->getId()));
|
||||
|
|
@ -62,7 +62,7 @@ final class PaymentRequestPayResponseProvider implements PayResponseProviderInte
|
|||
return new RedirectResponse($this->paymentRequestPayUrlProvider->getUrl($paymentRequest));
|
||||
}
|
||||
|
||||
public function supports(RequestConfiguration $requestConfiguration, OrderInterface $order): bool
|
||||
public function supports(Request $request, OrderInterface $order): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ namespace Symfony\Component\DependencyInjection\Loader\Configurator;
|
|||
|
||||
use Sylius\Bundle\CoreBundle\OrderPay\Action\PaymentRequestPayAction;
|
||||
use Sylius\Bundle\CoreBundle\OrderPay\Controller\OrderPayController;
|
||||
use Sylius\Component\Resource\Metadata\MetadataInterface;
|
||||
|
||||
return static function (ContainerConfigurator $container) {
|
||||
$services = $container->services();
|
||||
|
|
@ -24,10 +23,6 @@ return static function (ContainerConfigurator $container) {
|
|||
->set('sylius.controller.order_pay', OrderPayController::class)
|
||||
->args([
|
||||
service('sylius.repository.order'),
|
||||
inline_service(MetadataInterface::class)
|
||||
->args(['sylius.order'])
|
||||
->factory([service('sylius.resource_registry'), 'get']),
|
||||
service('sylius.resource_controller.request_configuration_factory'),
|
||||
])
|
||||
->abstract()
|
||||
;
|
||||
|
|
@ -35,10 +30,6 @@ return static function (ContainerConfigurator $container) {
|
|||
$services
|
||||
->set('sylius.controller.payment_request_pay', PaymentRequestPayAction::class)
|
||||
->args([
|
||||
inline_service(MetadataInterface::class)
|
||||
->args(['sylius.payment_request'])
|
||||
->factory([service('sylius.resource_registry'), 'get']),
|
||||
service('sylius.resource_controller.request_configuration_factory'),
|
||||
service('sylius.repository.payment_request'),
|
||||
service('sylius.processor.payment_request.http_response'),
|
||||
])
|
||||
|
|
|
|||
|
|
@ -15,8 +15,8 @@ namespace Sylius\Bundle\PaymentBundle\Processor;
|
|||
|
||||
use Sylius\Bundle\PaymentBundle\Announcer\PaymentRequestAnnouncerInterface;
|
||||
use Sylius\Bundle\PaymentBundle\Provider\ServiceProviderAwareProviderInterface;
|
||||
use Sylius\Bundle\ResourceBundle\Controller\RequestConfiguration;
|
||||
use Sylius\Component\Payment\Model\PaymentRequestInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
final class HttpResponseProcessor implements HttpResponseProcessorInterface
|
||||
|
|
@ -28,13 +28,13 @@ final class HttpResponseProcessor implements HttpResponseProcessorInterface
|
|||
}
|
||||
|
||||
public function process(
|
||||
RequestConfiguration $requestConfiguration,
|
||||
Request $request,
|
||||
PaymentRequestInterface $paymentRequest,
|
||||
): ?Response {
|
||||
$this->paymentRequestAnnouncer->dispatchPaymentRequestCommand($paymentRequest);
|
||||
|
||||
if ($this->httpResponseProvider->supports($requestConfiguration, $paymentRequest)) {
|
||||
return $this->httpResponseProvider->getResponse($requestConfiguration, $paymentRequest);
|
||||
if ($this->httpResponseProvider->supports($request, $paymentRequest)) {
|
||||
return $this->httpResponseProvider->getResponse($request, $paymentRequest);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -13,14 +13,14 @@ declare(strict_types=1);
|
|||
|
||||
namespace Sylius\Bundle\PaymentBundle\Processor;
|
||||
|
||||
use Sylius\Bundle\ResourceBundle\Controller\RequestConfiguration;
|
||||
use Sylius\Component\Payment\Model\PaymentRequestInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
interface HttpResponseProcessorInterface
|
||||
{
|
||||
public function process(
|
||||
RequestConfiguration $requestConfiguration,
|
||||
Request $request,
|
||||
PaymentRequestInterface $paymentRequest,
|
||||
): ?Response;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,8 +14,8 @@ declare(strict_types=1);
|
|||
namespace Sylius\Bundle\PaymentBundle\Provider;
|
||||
|
||||
use Sylius\Bundle\PaymentBundle\Exception\PaymentRequestNotSupportedException;
|
||||
use Sylius\Bundle\ResourceBundle\Controller\RequestConfiguration;
|
||||
use Sylius\Component\Payment\Model\PaymentRequestInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Contracts\Service\ServiceProviderInterface;
|
||||
|
||||
|
|
@ -26,7 +26,7 @@ abstract class AbstractServiceProvider implements ServiceProviderAwareProviderIn
|
|||
protected ServiceProviderInterface $locator;
|
||||
|
||||
public function supports(
|
||||
RequestConfiguration $requestConfiguration,
|
||||
Request $request,
|
||||
PaymentRequestInterface $paymentRequest,
|
||||
): bool {
|
||||
$index = $this->getHttpResponseProviderIndex($paymentRequest);
|
||||
|
|
@ -35,11 +35,11 @@ abstract class AbstractServiceProvider implements ServiceProviderAwareProviderIn
|
|||
return false;
|
||||
}
|
||||
|
||||
return $httpResponseProvider->supports($requestConfiguration, $paymentRequest);
|
||||
return $httpResponseProvider->supports($request, $paymentRequest);
|
||||
}
|
||||
|
||||
public function getResponse(
|
||||
RequestConfiguration $requestConfiguration,
|
||||
Request $request,
|
||||
PaymentRequestInterface $paymentRequest,
|
||||
): Response {
|
||||
$index = $this->getHttpResponseProviderIndex($paymentRequest);
|
||||
|
|
@ -52,7 +52,7 @@ abstract class AbstractServiceProvider implements ServiceProviderAwareProviderIn
|
|||
));
|
||||
}
|
||||
|
||||
return $httpResponseProvider->getResponse($requestConfiguration, $paymentRequest);
|
||||
return $httpResponseProvider->getResponse($request, $paymentRequest);
|
||||
}
|
||||
|
||||
public function getProviderIndexes(): array
|
||||
|
|
|
|||
|
|
@ -13,20 +13,20 @@ declare(strict_types=1);
|
|||
|
||||
namespace Sylius\Bundle\PaymentBundle\Provider;
|
||||
|
||||
use Sylius\Bundle\ResourceBundle\Controller\RequestConfiguration;
|
||||
use Sylius\Component\Payment\Model\PaymentRequestInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
/** @experimental */
|
||||
interface HttpResponseProviderInterface
|
||||
{
|
||||
public function supports(
|
||||
RequestConfiguration $requestConfiguration,
|
||||
Request $request,
|
||||
PaymentRequestInterface $paymentRequest,
|
||||
): bool;
|
||||
|
||||
public function getResponse(
|
||||
RequestConfiguration $requestConfiguration,
|
||||
Request $request,
|
||||
PaymentRequestInterface $paymentRequest,
|
||||
): Response;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,8 +21,8 @@ use Sylius\Bundle\CoreBundle\OrderPay\Handler\PaymentStateFlashHandlerInterface;
|
|||
use Sylius\Bundle\CoreBundle\OrderPay\Provider\AfterPayResponseProviderInterface;
|
||||
use Sylius\Bundle\PayumBundle\Factory\GetStatusFactoryInterface;
|
||||
use Sylius\Bundle\PayumBundle\Factory\ResolveNextRouteFactoryInterface;
|
||||
use Sylius\Bundle\ResourceBundle\Controller\RequestConfiguration;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\RouterInterface;
|
||||
|
||||
|
|
@ -38,9 +38,9 @@ final class PayumAfterPayResponseProvider implements AfterPayResponseProviderInt
|
|||
) {
|
||||
}
|
||||
|
||||
public function getResponse(RequestConfiguration $requestConfiguration): Response
|
||||
public function getResponse(Request $request): Response
|
||||
{
|
||||
$token = $this->getHttpRequestVerifier()->verify($requestConfiguration->getRequest());
|
||||
$token = $this->getHttpRequestVerifier()->verify($request);
|
||||
|
||||
/** @var GetStatusInterface&Generic $status */
|
||||
$status = $this->getStatusRequestFactory->createNewWithModel($token);
|
||||
|
|
@ -49,7 +49,7 @@ final class PayumAfterPayResponseProvider implements AfterPayResponseProviderInt
|
|||
$resolveNextRoute = $this->resolveNextRouteRequestFactory->createNewWithModel($status->getFirstModel());
|
||||
$this->payum->getGateway($token->getGatewayName())->execute($resolveNextRoute);
|
||||
|
||||
$this->paymentStatusFlashHandler->handle($requestConfiguration, (string) $status->getValue());
|
||||
$this->paymentStatusFlashHandler->handle($request, (string) $status->getValue());
|
||||
|
||||
$url = $this->router->generate(
|
||||
$resolveNextRoute->getRouteName(),
|
||||
|
|
@ -61,9 +61,8 @@ final class PayumAfterPayResponseProvider implements AfterPayResponseProviderInt
|
|||
return new RedirectResponse($url);
|
||||
}
|
||||
|
||||
public function supports(RequestConfiguration $requestConfiguration): bool
|
||||
public function supports(Request $request): bool
|
||||
{
|
||||
$request = $requestConfiguration->getRequest();
|
||||
$hash = $request->attributes->get('payum_token', $request->query->get('payum_token', $request->request->get('payum_token', false)));
|
||||
|
||||
return false !== $hash;
|
||||
|
|
|
|||
|
|
@ -18,11 +18,11 @@ use Payum\Core\Security\TokenInterface;
|
|||
use Sylius\Bundle\CoreBundle\OrderPay\Provider\PayResponseProviderInterface;
|
||||
use Sylius\Bundle\CoreBundle\OrderPay\Resolver\PaymentToPayResolverInterface;
|
||||
use Sylius\Bundle\PayumBundle\Model\GatewayConfigInterface as PayumGatewayConfigInterface;
|
||||
use Sylius\Bundle\ResourceBundle\Controller\RequestConfiguration;
|
||||
use Sylius\Component\Core\Model\OrderInterface;
|
||||
use Sylius\Component\Core\Model\PaymentInterface;
|
||||
use Sylius\Component\Payment\Model\GatewayConfigInterface;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
|
|
@ -41,7 +41,7 @@ final class PayumPayResponseProvider implements PayResponseProviderInterface
|
|||
}
|
||||
|
||||
public function getResponse(
|
||||
RequestConfiguration $requestConfiguration,
|
||||
Request $request,
|
||||
OrderInterface $order,
|
||||
): Response {
|
||||
$payment = $this->paymentToPayResolver->getPayment($order);
|
||||
|
|
@ -53,7 +53,7 @@ final class PayumPayResponseProvider implements PayResponseProviderInterface
|
|||
}
|
||||
|
||||
public function supports(
|
||||
RequestConfiguration $requestConfiguration,
|
||||
Request $request,
|
||||
OrderInterface $order,
|
||||
): bool {
|
||||
$payment = $this->paymentToPayResolver->getPayment($order);
|
||||
|
|
|
|||
|
|
@ -21,11 +21,11 @@ use PHPUnit\Framework\TestCase;
|
|||
use Sylius\Bundle\CoreBundle\OrderPay\Resolver\PaymentToPayResolverInterface;
|
||||
use Sylius\Bundle\PayumBundle\Model\GatewayConfig;
|
||||
use Sylius\Bundle\PayumBundle\OrderPay\Provider\PayumPayResponseProvider;
|
||||
use Sylius\Bundle\ResourceBundle\Controller\RequestConfiguration;
|
||||
use Sylius\Component\Core\Model\OrderInterface;
|
||||
use Sylius\Component\Core\Model\PaymentInterface;
|
||||
use Sylius\Component\Core\Model\PaymentMethodInterface;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
final class PayumPayResponseProviderTest extends TestCase
|
||||
{
|
||||
|
|
@ -53,7 +53,6 @@ final class PayumPayResponseProviderTest extends TestCase
|
|||
|
||||
public function testItCreatesCaptureTokenWithConfiguredAfterPayRouteAndParameters(): void
|
||||
{
|
||||
$requestConfiguration = $this->createStub(RequestConfiguration::class);
|
||||
$order = $this->createOrder();
|
||||
$payment = $this->createPaymentWithGatewayConfig(['use_authorize' => false]);
|
||||
$token = $this->createMock(TokenInterface::class);
|
||||
|
|
@ -79,7 +78,7 @@ final class PayumPayResponseProviderTest extends TestCase
|
|||
$this->tokenFactory->expects(self::never())->method('createAuthorizeToken');
|
||||
$token->expects(self::once())->method('getTargetUrl')->willReturn('/payum/capture');
|
||||
|
||||
$response = $this->provider->getResponse($requestConfiguration, $order);
|
||||
$response = $this->provider->getResponse(new Request(), $order);
|
||||
|
||||
self::assertInstanceOf(RedirectResponse::class, $response);
|
||||
self::assertSame('/payum/capture', $response->getTargetUrl());
|
||||
|
|
@ -87,7 +86,6 @@ final class PayumPayResponseProviderTest extends TestCase
|
|||
|
||||
public function testItCreatesAuthorizeTokenWithConfiguredAfterPayRouteAndParameters(): void
|
||||
{
|
||||
$requestConfiguration = $this->createStub(RequestConfiguration::class);
|
||||
$order = $this->createOrder();
|
||||
$payment = $this->createPaymentWithGatewayConfig(['use_authorize' => true]);
|
||||
$token = $this->createMock(TokenInterface::class);
|
||||
|
|
@ -113,7 +111,7 @@ final class PayumPayResponseProviderTest extends TestCase
|
|||
$this->tokenFactory->expects(self::never())->method('createCaptureToken');
|
||||
$token->expects(self::once())->method('getTargetUrl')->willReturn('/payum/authorize');
|
||||
|
||||
$response = $this->provider->getResponse($requestConfiguration, $order);
|
||||
$response = $this->provider->getResponse(new Request(), $order);
|
||||
|
||||
self::assertInstanceOf(RedirectResponse::class, $response);
|
||||
self::assertSame('/payum/authorize', $response->getTargetUrl());
|
||||
|
|
@ -121,7 +119,6 @@ final class PayumPayResponseProviderTest extends TestCase
|
|||
|
||||
public function testItSupportsOrdersWithPayumEnabledPayment(): void
|
||||
{
|
||||
$requestConfiguration = $this->createStub(RequestConfiguration::class);
|
||||
$order = $this->createOrder();
|
||||
$payment = $this->createPaymentWithGatewayConfig([]);
|
||||
|
||||
|
|
@ -132,12 +129,11 @@ final class PayumPayResponseProviderTest extends TestCase
|
|||
->willReturn($payment)
|
||||
;
|
||||
|
||||
self::assertTrue($this->provider->supports($requestConfiguration, $order));
|
||||
self::assertTrue($this->provider->supports(new Request(), $order));
|
||||
}
|
||||
|
||||
public function testItDoesNotSupportOrdersWithPayumDisabledPayment(): void
|
||||
{
|
||||
$requestConfiguration = $this->createStub(RequestConfiguration::class);
|
||||
$order = $this->createOrder();
|
||||
$gatewayConfig = new GatewayConfig();
|
||||
$gatewayConfig->setUsePayum(false);
|
||||
|
|
@ -150,7 +146,7 @@ final class PayumPayResponseProviderTest extends TestCase
|
|||
->willReturn($payment)
|
||||
;
|
||||
|
||||
self::assertFalse($this->provider->supports($requestConfiguration, $order));
|
||||
self::assertFalse($this->provider->supports(new Request(), $order));
|
||||
}
|
||||
|
||||
private function createOrder(): MockObject&OrderInterface
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue