Skip to content

Commit

Permalink
OP-377 - Apply ECS Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
SzymonKostrubiec committed Jul 25, 2024
1 parent ebaf6f2 commit 4f5bd4f
Show file tree
Hide file tree
Showing 21 changed files with 242 additions and 334 deletions.
36 changes: 12 additions & 24 deletions src/Action/CaptureAction.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* This file was created by the developers from BitBag.
* Feel free to contact us once you face any issues or want to start
Expand All @@ -10,42 +12,31 @@

namespace BitBag\MercanetBnpParibasPlugin\Action;

use BitBag\MercanetBnpParibasPlugin\Legacy\SimplePayment;
use BitBag\MercanetBnpParibasPlugin\Bridge\MercanetBnpParibasBridgeInterface;
use BitBag\MercanetBnpParibasPlugin\Legacy\SimplePayment;
use Payum\Core\Action\ActionInterface;
use Payum\Core\ApiAwareInterface;
use Payum\Core\Bridge\Spl\ArrayObject;
use Payum\Core\Exception\RequestNotSupportedException;
use Payum\Core\Exception\UnsupportedApiException;
use Payum\Core\GatewayAwareTrait;
use Payum\Core\Payum;
use Payum\Core\Request\Capture;
use Payum\Core\Security\TokenInterface;
use Sylius\Component\Core\Model\PaymentInterface;
use Sylius\Component\Order\Model\OrderInterface;
use Webmozart\Assert\Assert;
use Payum\Core\Payum;

/**
* @author Mikołaj Król <[email protected]>
* @author Patryk Drapik <[email protected]>
*/
final class CaptureAction implements ActionInterface, ApiAwareInterface
{
use GatewayAwareTrait;

/**
* @var Payum
*/
/** @var Payum */
private $payum;

/**
* @var MercanetBnpParibasBridgeInterface
*/
/** @var MercanetBnpParibasBridgeInterface */
private $mercanetBnpParibasBridge;

/**
* @param Payum $payum
*/
public function __construct(Payum $payum)
{
$this->payum = $payum;
Expand All @@ -61,7 +52,7 @@ public function setApi($mercanetBnpParibasBridge): void
}

/**
* {@inheritDoc}
* @inheritDoc
*
* @param Capture $request
*/
Expand All @@ -78,12 +69,10 @@ public function execute($request): void
/** @var TokenInterface $token */
$token = $request->getToken();

$transactionReference = isset($model['transactionReference']) ? $model['transactionReference'] : null;
$transactionReference = $model['transactionReference'] ?? null;

if ($transactionReference !== null) {

if ($this->mercanetBnpParibasBridge->isPostMethod()) {

$model['status'] = $this->mercanetBnpParibasBridge->paymentVerification() ?
PaymentInterface::STATE_COMPLETED : PaymentInterface::STATE_CANCELLED
;
Expand All @@ -96,7 +85,6 @@ public function execute($request): void
}

if ($model['status'] === PaymentInterface::STATE_COMPLETED) {

return;
}
}
Expand All @@ -121,7 +109,7 @@ public function execute($request): void
/** @var OrderInterface $order */
$order = $payment->getOrder();

$transactionReference = "MercanetWS" . uniqid() . "OR" . $order->getNumber();
$transactionReference = 'MercanetWS' . uniqid() . 'OR' . $order->getNumber();

$model['transactionReference'] = $transactionReference;

Expand All @@ -134,7 +122,7 @@ public function execute($request): void
$targetUrl,
$currencyCode,
$transactionReference,
$automaticResponseUrl
$automaticResponseUrl,
);

$request->setModel($model);
Expand All @@ -151,12 +139,12 @@ private function createNotifyToken($gatewayName, $model)
{
return $this->payum->getTokenFactory()->createNotifyToken(
$gatewayName,
$model
$model,
);
}

/**
* {@inheritDoc}
* @inheritDoc
*/
public function supports($request)
{
Expand Down
12 changes: 5 additions & 7 deletions src/Action/ConvertPaymentAction.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* This file was created by the developers from BitBag.
* Feel free to contact us once you face any issues or want to start
Expand All @@ -10,23 +12,19 @@

namespace BitBag\MercanetBnpParibasPlugin\Action;

use Payum\Core\GatewayAwareInterface;
use Payum\Core\GatewayAwareTrait;
use Payum\Core\Action\ActionInterface;
use Payum\Core\Exception\RequestNotSupportedException;
use Payum\Core\GatewayAwareInterface;
use Payum\Core\GatewayAwareTrait;
use Payum\Core\Model\PaymentInterface;
use Payum\Core\Request\Convert;

/**
* @author Mikołaj Król <[email protected]>
* @author Patryk Drapik <[email protected]>
*/
final class ConvertPaymentAction implements ActionInterface, GatewayAwareInterface
{
use GatewayAwareTrait;

/**
* {@inheritDoc}
* @inheritDoc
*
* @param Convert $request
*/
Expand Down
14 changes: 7 additions & 7 deletions src/Action/NotifyAction.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* This file was created by the developers from BitBag.
* Feel free to contact us once you face any issues or want to start
Expand All @@ -16,15 +18,12 @@
use Payum\Core\Exception\RequestNotSupportedException;
use Payum\Core\Exception\UnsupportedApiException;
use Payum\Core\GatewayAwareTrait;
use Sylius\Component\Core\Model\PaymentInterface;
use Payum\Core\Request\Notify;
use SM\Factory\FactoryInterface;
use Sylius\Component\Core\Model\PaymentInterface;
use Sylius\Component\Payment\PaymentTransitions;
use Webmozart\Assert\Assert;
use SM\Factory\FactoryInterface;

/**
* @author Patryk Drapik <[email protected]>
*/
final class NotifyAction implements ActionInterface, ApiAwareInterface
{
use GatewayAwareTrait;
Expand All @@ -38,13 +37,14 @@ public function __construct(FactoryInterface $stateMachineFactory)
$this->stateMachineFactory = $stateMachineFactory;
}

/**
* @param $request Notify
*/
public function execute($request): void
{
/** @var $request Notify */
RequestNotSupportedException::assertSupports($this, $request);

if ($this->mercanetBnpParibasBridge->paymentVerification()) {

/** @var PaymentInterface $payment */
$payment = $request->getFirstModel();

Expand Down
23 changes: 7 additions & 16 deletions src/Action/StatusAction.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* This file was created by the developers from BitBag.
* Feel free to contact us once you face any issues or want to start
Expand All @@ -11,32 +13,24 @@
namespace BitBag\MercanetBnpParibasPlugin\Action;

use Payum\Core\Action\ActionInterface;
use Payum\Core\Request\GetStatusInterface;
use Payum\Core\Bridge\Spl\ArrayObject;
use Payum\Core\Exception\RequestNotSupportedException;
use Payum\Core\Request\GetStatusInterface;
use Sylius\Component\Core\Model\PaymentInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;

/**
* @author Mikołaj Król <[email protected]>
* @author Patryk Drapik <[email protected]>
*/
final class StatusAction implements ActionInterface
{

private RequestStack $requestStack;

/**
* @param RequestStack $requestStack
*/
public function __construct(RequestStack $requestStack)
{
$this->requestStack = $requestStack;
}

/**
* {@inheritDoc}
* @inheritDoc
*
* @param GetStatusInterface $request
*/
Expand All @@ -49,25 +43,22 @@ public function execute($request): void
/** @var Request $requestCurrent */
$requestCurrent = $this->requestStack->getCurrentRequest();

$transactionReference = isset($model['transactionReference']) ? $model['transactionReference'] : null;
$transactionReference = $model['transactionReference'] ?? null;

$status = isset($model['status']) ? $model['status'] : null;
$status = $model['status'] ?? null;

if ((null === $transactionReference) && !$requestCurrent->isMethod('POST')) {

$request->markNew();

return;
}

if ($status === PaymentInterface::STATE_CANCELLED) {

$request->markCanceled();

return;
}
if ($status === PaymentInterface::STATE_COMPLETED) {

$request->markCaptured();

return;
Expand All @@ -77,7 +68,7 @@ public function execute($request): void
}

/**
* {@inheritDoc}
* @inheritDoc
*/
public function supports($request)
{
Expand Down
7 changes: 3 additions & 4 deletions src/BitBagMercanetBnpParibasPlugin.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* This file was created by the developers from BitBag.
* Feel free to contact us once you face any issues or want to start
Expand All @@ -13,10 +15,7 @@
use Sylius\Bundle\CoreBundle\Application\SyliusPluginTrait;
use Symfony\Component\HttpKernel\Bundle\Bundle;

/**
* @author Mikołaj Król <[email protected]>
*/
final class BitBagMercanetBnpParibasPlugin extends Bundle
{
use SyliusPluginTrait;
}
}
9 changes: 3 additions & 6 deletions src/Bridge/MercanetBnpParibasBridge.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* This file was created by the developers from BitBag.
* Feel free to contact us once you face any issues or want to start
Expand All @@ -11,16 +13,12 @@
namespace BitBag\MercanetBnpParibasPlugin\Bridge;

use BitBag\MercanetBnpParibasPlugin\Legacy\Mercanet;
use BitBag\MercanetBnpParibasPlugin\Legacy\ShaComposer;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use BitBag\MercanetBnpParibasPlugin\Legacy\ShaComposer;

/**
* @author Patryk Drapik <[email protected]>
*/
final class MercanetBnpParibasBridge implements MercanetBnpParibasBridgeInterface
{

private RequestStack $requestStack;

/** @phpstan-ignore-next-line We should not change our business logic now*/
Expand Down Expand Up @@ -48,7 +46,6 @@ public function createMercanet(ShaComposer $secretKey): Mercanet
public function paymentVerification(): bool
{
if ($this->isPostMethod()) {

$this->mercanet = new Mercanet($this->secretKey);
$this->mercanet->setResponse($_POST);

Expand Down
5 changes: 2 additions & 3 deletions src/Bridge/MercanetBnpParibasBridgeInterface.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* This file was created by the developers from BitBag.
* Feel free to contact us once you face any issues or want to start
Expand All @@ -13,9 +15,6 @@
use BitBag\MercanetBnpParibasPlugin\Legacy\Mercanet;
use BitBag\MercanetBnpParibasPlugin\Legacy\ShaComposer;

/**
* @author Patryk Drapik <[email protected]>
*/
interface MercanetBnpParibasBridgeInterface
{
/** @phpstan-ignore-next-line We should not change our business logic now*/
Expand Down
7 changes: 3 additions & 4 deletions src/DependencyInjection/BitBagMercanetBnpParibasExtension.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* This file was created by the developers from BitBag.
* Feel free to contact us once you face any issues or want to start
Expand All @@ -15,13 +17,10 @@
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;

/**
* @author Mikołaj Król <[email protected]>
*/
final class BitBagMercanetBnpParibasExtension extends Extension
{
/**
* {@inheritdoc}
* @inheritdoc
*/
public function load(array $configs, ContainerBuilder $container)
{
Expand Down
Loading

0 comments on commit 4f5bd4f

Please sign in to comment.