mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-14 17:10:53 +00:00
3/5 behat tests ok
This commit is contained in:
parent
be639b907c
commit
18358d107b
6 changed files with 56 additions and 29 deletions
|
|
@ -57,21 +57,20 @@ final class PaypalContext implements Context
|
|||
|
||||
/**
|
||||
* @When I sign in to PayPal and authorize successfully
|
||||
*/
|
||||
public function iSignInToPaypalAndAuthorizeSuccessfully(): void
|
||||
{
|
||||
$this->paypalApiMocker->performActionInApiSuccessfulScope(function () {
|
||||
$this->putPaymentRequest($this->sharedStorage->get('payment_request_uri'));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I sign in to PayPal and pay successfully
|
||||
*/
|
||||
public function iSignInToPaypalAndPaySuccessfully(): void
|
||||
public function iSignInToPaypalAndAuthorizeOrPaySuccessfully(): void
|
||||
{
|
||||
$this->paypalApiMocker->performActionInApiSuccessfulScope(function () {
|
||||
$this->paypalExpressCheckoutPage->pay();
|
||||
$this->putPaymentRequest(
|
||||
$this->sharedStorage->get('payment_request_uri'),
|
||||
[
|
||||
'query' => [
|
||||
'token' => 'EC-2d9EV13959UR209410U',
|
||||
'PayerID' => 'UX8WBNYWGBVMG',
|
||||
]
|
||||
]
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -81,7 +80,15 @@ final class PaypalContext implements Context
|
|||
*/
|
||||
public function iCancelMyPaypalPayment(): void
|
||||
{
|
||||
$this->paypalExpressCheckoutPage->cancel();
|
||||
$this->putPaymentRequest(
|
||||
$this->sharedStorage->get('payment_request_uri'),
|
||||
[
|
||||
'query' => [
|
||||
'token' => 'EC-2d9EV13959UR209410U',
|
||||
'cancelled' => 1,
|
||||
]
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -89,8 +96,15 @@ final class PaypalContext implements Context
|
|||
*/
|
||||
public function iTryToPayAgain(): void
|
||||
{
|
||||
$this->client->show(Resources::ORDERS, $this->sharedStorage->get('cart_token'));
|
||||
|
||||
$this->paypalApiMocker->performActionInApiInitializeScope(function () {
|
||||
$this->orderDetails->pay();
|
||||
$payments = $this->responseChecker->getValue($this->client->getLastResponse(), 'payments');
|
||||
$payment = end($payments);
|
||||
$this->postPaymentRequest($payment);
|
||||
|
||||
$uri = $this->responseChecker->getValue($this->client->getLastResponse(), '@id');
|
||||
$this->sharedStorage->set('payment_request_uri', $uri);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -99,7 +113,13 @@ final class PaypalContext implements Context
|
|||
*/
|
||||
public function iShouldBeNotifiedThatMyPaymentHasBeenCancelled(): void
|
||||
{
|
||||
$this->assertNotification('Payment has been cancelled.');
|
||||
Assert::true(
|
||||
$this->responseChecker->isUpdateSuccessful($this->client->getLastResponse()),
|
||||
sprintf(
|
||||
'Payment request could not be updated: %s',
|
||||
$this->responseChecker->getError($this->client->getLastResponse()),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -110,7 +130,7 @@ final class PaypalContext implements Context
|
|||
Assert::true(
|
||||
$this->responseChecker->isUpdateSuccessful($this->client->getLastResponse()),
|
||||
sprintf(
|
||||
'Payment request could not be edited: %s',
|
||||
'Payment request could not be updated: %s',
|
||||
$this->responseChecker->getError($this->client->getLastResponse()),
|
||||
),
|
||||
);
|
||||
|
|
@ -160,7 +180,7 @@ final class PaypalContext implements Context
|
|||
$this->client->executeCustomRequest($request);
|
||||
}
|
||||
|
||||
function putPaymentRequest(string $paymentRequestUri): void
|
||||
function putPaymentRequest(string $paymentRequestUri, array $httpRequest = []): void
|
||||
{
|
||||
$request = $this->requestFactory->custom(
|
||||
$paymentRequestUri,
|
||||
|
|
@ -173,12 +193,7 @@ final class PaypalContext implements Context
|
|||
'requestPayload' => [
|
||||
'target_path' => 'https://myshop.tld/target-path',
|
||||
'after_path' => 'https://myshop.tld/after-path',
|
||||
'http_request' => [
|
||||
'query' => [
|
||||
'token' => 'EC-2d9EV13959UR209410U',
|
||||
'PayerID' => 'UX8WBNYWGBVMG',
|
||||
]
|
||||
],
|
||||
'http_request' => $httpRequest,
|
||||
],
|
||||
]);
|
||||
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ namespace Sylius\Bundle\PayumBundle\CommandHandler;
|
|||
use Sylius\Bundle\PaymentBundle\Command\PaymentRequestHashAwareInterface;
|
||||
use Sylius\Bundle\PayumBundle\Factory\TokenAggregateRequestFactoryInterface;
|
||||
use Sylius\Bundle\PayumBundle\PaymentRequest\Factory\PayumTokenFactoryInterface;
|
||||
use Sylius\Bundle\PayumBundle\PaymentRequest\Processor\AfterTokenizedRequestProcessorInterface;
|
||||
use Sylius\Bundle\PayumBundle\PaymentRequest\Processor\AfterTokenRequestProcessorInterface;
|
||||
use Sylius\Bundle\PayumBundle\PaymentRequest\Processor\RequestProcessorInterface;
|
||||
use Sylius\Bundle\PayumBundle\PaymentRequest\Provider\PaymentRequestProviderInterface;
|
||||
use Symfony\Component\Messenger\Handler\MessageHandlerInterface;
|
||||
|
|
@ -28,7 +28,7 @@ final class TokenPaymentRequestHandler implements MessageHandlerInterface
|
|||
private PaymentRequestProviderInterface $paymentRequestProvider,
|
||||
private PayumTokenFactoryInterface $payumTokenFactory,
|
||||
private RequestProcessorInterface $requestProcessor,
|
||||
private AfterTokenizedRequestProcessorInterface $afterTokenizedRequestProcessor,
|
||||
private AfterTokenRequestProcessorInterface $afterTokenRequestProcessor,
|
||||
private TokenAggregateRequestFactoryInterface $payumRequestFactory,
|
||||
) {
|
||||
}
|
||||
|
|
@ -47,6 +47,6 @@ final class TokenPaymentRequestHandler implements MessageHandlerInterface
|
|||
|
||||
$this->requestProcessor->process($paymentRequest, $request, $token->getGatewayName());
|
||||
|
||||
$this->afterTokenizedRequestProcessor->process($paymentRequest, $token);
|
||||
$this->afterTokenRequestProcessor->process($paymentRequest, $token);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ use Sylius\Bundle\PaymentBundle\CommandDispatcher\PaymentRequestCommandDispatche
|
|||
use Sylius\Component\Payment\Factory\PaymentRequestFactoryInterface;
|
||||
use Sylius\Component\Payment\Model\PaymentRequestInterface;
|
||||
|
||||
final class AfterTokenizedRequestProcessor implements AfterTokenizedRequestProcessorInterface
|
||||
final class AfterTokenRequestProcessor implements AfterTokenRequestProcessorInterface
|
||||
{
|
||||
public function __construct(
|
||||
private PaymentRequestFactoryInterface $paymentRequestFactory,
|
||||
|
|
@ -16,7 +16,7 @@ namespace Sylius\Bundle\PayumBundle\PaymentRequest\Processor;
|
|||
use Payum\Core\Security\TokenInterface;
|
||||
use Sylius\Component\Payment\Model\PaymentRequestInterface;
|
||||
|
||||
interface AfterTokenizedRequestProcessorInterface
|
||||
interface AfterTokenRequestProcessorInterface
|
||||
{
|
||||
public function process(
|
||||
PaymentRequestInterface $paymentRequest,
|
||||
|
|
@ -14,6 +14,7 @@ declare(strict_types=1);
|
|||
namespace Sylius\Bundle\PayumBundle\PaymentRequest\Processor;
|
||||
|
||||
use Payum\Core\Payum;
|
||||
use Payum\Core\Security\TokenAggregateInterface;
|
||||
use Sylius\Bundle\PayumBundle\PaymentRequest\PaymentRequestContextInterface;
|
||||
use Sylius\Component\Payment\Model\PaymentRequestInterface;
|
||||
|
||||
|
|
@ -41,5 +42,16 @@ final class RequestProcessor implements RequestProcessorInterface
|
|||
}
|
||||
|
||||
$paymentRequest->setState(PaymentRequestInterface::STATE_COMPLETED);
|
||||
|
||||
if (false === $request instanceof TokenAggregateInterface) {
|
||||
return;
|
||||
}
|
||||
|
||||
$token = $request->getToken();
|
||||
if (null === $token) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->payum->getHttpRequestVerifier()->invalidate($token);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@
|
|||
<argument type="service" id="sylius.payment_request.payum.context" />
|
||||
</service>
|
||||
|
||||
<service id="Sylius\Bundle\PayumBundle\PaymentRequest\Processor\AfterTokenizedRequestProcessorInterface" class="Sylius\Bundle\PayumBundle\PaymentRequest\Processor\AfterTokenizedRequestProcessor">
|
||||
<service id="Sylius\Bundle\PayumBundle\PaymentRequest\Processor\AfterTokenRequestProcessorInterface" class="Sylius\Bundle\PayumBundle\PaymentRequest\Processor\AfterTokenRequestProcessor">
|
||||
<argument type="service" id="sylius.custom_factory.payment_request" />
|
||||
<argument type="service" id="Sylius\Bundle\PaymentBundle\CommandDispatcher\PaymentRequestCommandDispatcherInterface" />
|
||||
</service>
|
||||
|
|
@ -41,7 +41,7 @@
|
|||
<argument type="service" id="Sylius\Bundle\PayumBundle\PaymentRequest\Provider\PaymentRequestProviderInterface" />
|
||||
<argument type="service" id="Sylius\Bundle\PayumBundle\PaymentRequest\Factory\PayumTokenFactoryInterface" />
|
||||
<argument type="service" id="Sylius\Bundle\PayumBundle\PaymentRequest\Processor\RequestProcessorInterface" />
|
||||
<argument type="service" id="Sylius\Bundle\PayumBundle\PaymentRequest\Processor\AfterTokenizedRequestProcessorInterface" />
|
||||
<argument type="service" id="Sylius\Bundle\PayumBundle\PaymentRequest\Processor\AfterTokenRequestProcessorInterface" />
|
||||
</service>
|
||||
|
||||
<service id="sylius.payment_request.payum.capture" parent="Sylius\Bundle\PayumBundle\CommandHandler\TokenPaymentRequestHandler">
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue