Skip to content

Commit

Permalink
ECS fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Prometee committed Nov 11, 2024
1 parent 0bd8c3d commit 6a32626
Show file tree
Hide file tree
Showing 19 changed files with 96 additions and 86 deletions.
2 changes: 1 addition & 1 deletion src/Command/Checkout/RefundPaymentRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@

use FluxSE\SyliusStripePlugin\Command\AbstractRefundPaymentRequest;

class RefundPaymentRequest extends AbstractRefundPaymentRequest
class RefundPaymentRequest extends AbstractRefundPaymentRequest
{
}
2 changes: 1 addition & 1 deletion src/Command/WebElements/RefundPaymentRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@

use FluxSE\SyliusStripePlugin\Command\AbstractRefundPaymentRequest;

class RefundPaymentRequest extends AbstractRefundPaymentRequest
class RefundPaymentRequest extends AbstractRefundPaymentRequest
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use FluxSE\SyliusStripePlugin\Processor\PaymentTransitionProcessorInterface;
use Sylius\Abstraction\StateMachine\StateMachineInterface;
use Sylius\Bundle\PaymentBundle\Provider\PaymentRequestProviderInterface;
use Sylius\Component\Payment\Model\PaymentRequestInterface;
use Sylius\Component\Payment\PaymentRequestTransitions;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
use Webmozart\Assert\Assert;
Expand Down
8 changes: 5 additions & 3 deletions src/CommandHandler/Checkout/RefundPaymentRequestHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,20 @@ public function __invoke(RefundPaymentRequest $refundPaymentRequest): void
$reason = sprintf(
'Checkout Session payment status is "%s" instead of "%s".',
$session->payment_status,
$session::PAYMENT_STATUS_PAID
$session::PAYMENT_STATUS_PAID,
);
$this->setFailed($paymentRequest, $reason);

return;
}

if (0 >= $session->amount_total) {
$reason = sprintf(
'Checkout Session amount total is not greater than 0 (amount_total: %s)',
$session->amount_total
$session->amount_total,
);
$this->setFailed($paymentRequest, $reason);

return;
}

Expand All @@ -77,7 +79,7 @@ public function __invoke(RefundPaymentRequest $refundPaymentRequest): void

private function setFailed(
PaymentRequestInterface $paymentRequest,
string $reason
string $reason,
): void {
$paymentRequest->setResponseData([
'reason' => $reason,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,20 @@ public function __invoke(RefundPaymentRequest $refundPaymentRequest): void
$reason = sprintf(
'Payment Intent status is "%s" instead of "%s".',
$paymentIntent->status,
$paymentIntent::STATUS_SUCCEEDED
$paymentIntent::STATUS_SUCCEEDED,
);
$this->setFailed($paymentRequest, $reason);

return;
}

if (0 >= $paymentIntent->amount) {
$reason = sprintf(
'Payment Intent amount is not greater than 0 (amount: %s)',
$paymentIntent->amount
$paymentIntent->amount,
);
$this->setFailed($paymentRequest, $reason);

return;
}

Expand All @@ -77,7 +79,7 @@ public function __invoke(RefundPaymentRequest $refundPaymentRequest): void

private function setFailed(
PaymentRequestInterface $paymentRequest,
string $reason
string $reason,
): void {
$paymentRequest->setResponseData([
'reason' => $reason,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

final class PaymentCompletedStateListener
{

public function __construct(
private PaymentStateProcessorInterface $paymentStateProcessor,
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ private function isCanceledStatus(?string $status): bool
/**
* @see https://stripe.com/docs/payments/paymentintents/lifecycle
*/
protected function isSpecialCanceledStatus(PaymentIntent $paymentIntent): bool
private function isSpecialCanceledStatus(PaymentIntent $paymentIntent): bool
{
$status = $paymentIntent->status;
$lastPaymentError = $paymentIntent->last_payment_error;
Expand Down
17 changes: 10 additions & 7 deletions src/StateMachine/PaymentStateProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,12 @@ public function __construct(
public function __invoke(PaymentInterface $payment, string $fromState): void
{
if (
$this->allowedPaymentFromStates !== []
&& false === in_array($fromState, $this->allowedPaymentFromStates, true
)) {
$this->allowedPaymentFromStates !== [] &&
false === in_array(
$fromState,
$this->allowedPaymentFromStates,
true,
)) {
return;
}

Expand All @@ -59,17 +62,17 @@ public function __invoke(PaymentInterface $payment, string $fromState): void
sprintf(
'The payment must have state "%s" at this point, found "%s".',
$this->requiredPaymentState,
$payment->getState()
)
$payment->getState(),
),
);

$paymentRequest = $this->paymentRequestRepository->findOneByActionPaymentAndMethod(
$this->paymentRequestAction,
$payment,
$paymentMethod
$paymentMethod,
);

if ( null === $paymentRequest || $this->finalizedPaymentRequestChecker->isFinal($paymentRequest)) {
if (null === $paymentRequest || $this->finalizedPaymentRequestChecker->isFinal($paymentRequest)) {
$paymentRequest = $this->paymentRequestFactory->create($payment, $paymentMethod);
$paymentRequest->setAction($this->paymentRequestAction);

Expand Down
10 changes: 5 additions & 5 deletions tests/Behat/Context/Setup/ManagingOrdersContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ManagingOrdersContext implements Context
public function __construct(
private StateMachineInterface $stateMachine,
private ObjectManager $objectManager,
private StripeCheckoutMocker $stripeCheckoutSessionMocker
private StripeCheckoutMocker $stripeCheckoutSessionMocker,
) {
}

Expand All @@ -42,7 +42,7 @@ public function thisOrderIsAlreadyPaid(OrderInterface $order, string $stripePaym
$this->stateMachine->apply(
$payment,
PaymentTransitions::GRAPH,
PaymentTransitions::TRANSITION_COMPLETE
PaymentTransitions::TRANSITION_COMPLETE,
);

$this->objectManager->flush();
Expand All @@ -67,7 +67,7 @@ public function thisOrderIsAlreadyAuthorized(OrderInterface $order, string $stri
$this->stateMachine->apply(
$payment,
PaymentTransitions::GRAPH,
PaymentTransitions::TRANSITION_AUTHORIZE
PaymentTransitions::TRANSITION_AUTHORIZE,
);

$this->objectManager->flush();
Expand Down Expand Up @@ -121,7 +121,7 @@ public function thisOrderPaymentHasBeenCancelled(OrderInterface $order): void
$this->stateMachine->apply(
$payment,
PaymentTransitions::GRAPH,
PaymentTransitions::TRANSITION_CANCEL
PaymentTransitions::TRANSITION_CANCEL,
);

$this->objectManager->flush();
Expand Down Expand Up @@ -157,7 +157,7 @@ public function iAmPreparedToExpireThePaymentIntentOnThisOrder(): void
{
$this->stripeCheckoutSessionMocker->mockCancelPayment(
PaymentIntent::STATUS_REQUIRES_PAYMENT_METHOD,
PaymentIntent::CAPTURE_METHOD_AUTOMATIC
PaymentIntent::CAPTURE_METHOD_AUTOMATIC,
);
}

Expand Down
14 changes: 7 additions & 7 deletions tests/Behat/Context/Setup/StripeContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ public function __construct(
public function theStoreHasAPaymentMethodWithACodeAndStripeCheckoutSessionPaymentGateway(
string $paymentMethodName,
string $paymentMethodCode,
bool $useAuthorize = false
bool $useAuthorize = false,
): void {
$paymentMethod = $this->createPaymentMethodStripe(
$paymentMethodName,
$paymentMethodCode,
'stripe_checkout',
'Stripe (Checkout)'
'Stripe (Checkout)',
);

$this->createPaymentMethod($paymentMethod, $useAuthorize);
Expand All @@ -50,7 +50,7 @@ public function theStoreHasAPaymentMethodWithACodeAndStripeCheckoutSessionPaymen
*/
public function theStoreHasAPaymentMethodWithACodeAndStripeCheckoutSessionPaymentGatewayUsingAuthorize(
string $paymentMethodName,
string $paymentMethodCode
string $paymentMethodCode,
): void {
$this->theStoreHasAPaymentMethodWithACodeAndStripeCheckoutSessionPaymentGateway($paymentMethodName, $paymentMethodCode, true);
}
Expand All @@ -62,13 +62,13 @@ public function theStoreHasAPaymentMethodWithACodeAndStripeCheckoutSessionPaymen
public function theStoreHasAPaymentMethodWithACodeAndStripeJsPaymentGateway(
string $paymentMethodName,
string $paymentMethodCode,
bool $useAuthorize = false
bool $useAuthorize = false,
): void {
$paymentMethod = $this->createPaymentMethodStripe(
$paymentMethodName,
$paymentMethodCode,
'stripe_web_elements',
'Stripe (Web Elements)'
'Stripe (Web Elements)',
);

$this->createPaymentMethod($paymentMethod, $useAuthorize);
Expand All @@ -79,7 +79,7 @@ public function theStoreHasAPaymentMethodWithACodeAndStripeJsPaymentGateway(
*/
public function theStoreHasAPaymentMethodWithACodeAndStripeJsPaymentGatewayUsingAuthorize(
string $paymentMethodName,
string $paymentMethodCode
string $paymentMethodCode,
): void {
$this->theStoreHasAPaymentMethodWithACodeAndStripeJsPaymentGateway($paymentMethodName, $paymentMethodCode, true);
}
Expand All @@ -90,7 +90,7 @@ private function createPaymentMethodStripe(
string $factoryName,
string $description = '',
bool $addForCurrentChannel = true,
int $position = null
int $position = null,
): PaymentMethodInterface {
/** @var PaymentMethodInterface $paymentMethod */
$paymentMethod = $this->paymentMethodExampleFactory->create([
Expand Down
6 changes: 3 additions & 3 deletions tests/Behat/Context/Ui/Shop/StripeCheckoutContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function __construct(
private StripeCheckoutMocker $stripeCheckoutSessionMocker,
private CompletePageInterface $summaryPage,
private ShowPageInterface $orderDetails,
private StripePage $stripePage
private StripePage $stripePage,
) {
}

Expand Down Expand Up @@ -63,7 +63,7 @@ function () {
},
function () {
$this->stripePage->captureOrAuthorizeThenGoToAfterUrl();
}
},
);
}

Expand Down Expand Up @@ -95,7 +95,7 @@ function () {
},
function () {
$this->stripePage->captureOrAuthorizeThenGoToAfterUrl();
}
},
);
}

Expand Down
7 changes: 3 additions & 4 deletions tests/Behat/Context/Ui/Shop/StripeWebElementsContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Tests\FluxSE\SyliusStripePlugin\Behat\Context\Ui\Shop;

use Behat\Behat\Context\Context;
use Behat\MinkExtension\Context\MinkContext;
use FluxSE\SyliusStripePlugin\Provider\MetadataProviderInterface;
use RuntimeException;
Expand All @@ -21,7 +20,7 @@ public function __construct(
private StripeWebElementsMocker $stripeJsMocker,
private CompletePageInterface $summaryPage,
private ShowPageInterface $orderDetails,
private StripePage $stripePage
private StripePage $stripePage,
) {
}

Expand Down Expand Up @@ -53,7 +52,7 @@ function () {
},
function () {
$this->stripePage->captureOrAuthorizeThenGoToAfterUrl();
}
},
);
}

Expand Down Expand Up @@ -85,7 +84,7 @@ function () {
},
function () {
$this->stripePage->captureOrAuthorizeThenGoToAfterUrl();
}
},
);
}

Expand Down
24 changes: 13 additions & 11 deletions tests/Behat/Mocker/Api/CheckoutSessionMocker.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ public function mockCreateAction(): void
'object' => Session::OBJECT_NAME,
'payment_intent' => 'pi_test_1',
'url' => 'https://checkout.stripe.com/c/pay/cs_1',
], $params), JSON_THROW_ON_ERROR),
], $params), \JSON_THROW_ON_ERROR),
200,
[]
[],
];
});
}
Expand All @@ -38,19 +38,20 @@ public function mockRetrieveAction(string $status, string $paymentStatus): void
{
$this->mockClient
->expects('request')
->withArgs(['get', \Mockery::pattern('#^'.Session::classUrl().'/cs_test_[^/]+$#')])
->withArgs(['get', \Mockery::pattern('#^' . Session::classUrl() . '/cs_test_[^/]+$#')])
->andReturnUsing(function ($method, $absUrl) use ($status, $paymentStatus) {
$id = str_replace(Session::classUrl().'/', '', $absUrl);
$id = str_replace(Session::classUrl() . '/', '', $absUrl);

return [
json_encode([
'id' => $id,
'object' => Session::OBJECT_NAME,
'status' => $status,
'payment_status' => $paymentStatus,
'payment_intent' => 'pi_test_1',
], JSON_THROW_ON_ERROR),
], \JSON_THROW_ON_ERROR),
200,
[]
[],
];
});
}
Expand All @@ -68,9 +69,9 @@ public function mockAllAction(string $status): void
'object' => Session::OBJECT_NAME,
'status' => $status,
],
]], JSON_THROW_ON_ERROR),
]], \JSON_THROW_ON_ERROR),
200,
[]
[],
];
});
}
Expand All @@ -79,17 +80,18 @@ public function mockExpireAction(): void
{
$this->mockClient
->expects('request')
->withArgs(['get', \Mockery::pattern('#^'.Session::classUrl().'/cs_test_[^/]+/expire$#')])
->withArgs(['get', \Mockery::pattern('#^' . Session::classUrl() . '/cs_test_[^/]+/expire$#')])
->andReturnUsing(function ($method, $absUrl, $params) {
$id = str_replace([Session::classUrl() . '/', '/expire'], '', $absUrl);

return [
json_encode([
'id' => $id,
'object' => Session::OBJECT_NAME,
'status' => Session::STATUS_EXPIRED,
], JSON_THROW_ON_ERROR),
], \JSON_THROW_ON_ERROR),
200,
[]
[],
];
});
}
Expand Down
Loading

0 comments on commit 6a32626

Please sign in to comment.