Skip to content

Commit

Permalink
Merge pull request #239 from payplug/qa
Browse files Browse the repository at this point in the history
Release 1.9.1
  • Loading branch information
lacan1 authored Apr 28, 2023
2 parents 818f7f1 + e827f2f commit 9fd4457
Show file tree
Hide file tree
Showing 48 changed files with 230 additions and 224 deletions.
Empty file removed .github/workflows/ci.yaml
Empty file.
124 changes: 0 additions & 124 deletions spec/Action/CaptureActionSpec.php

This file was deleted.

42 changes: 36 additions & 6 deletions src/Action/CaptureAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
use PayPlug\SyliusPayPlugPlugin\ApiClient\PayPlugApiClientInterface;
use PayPlug\SyliusPayPlugPlugin\Entity\Card;
use PayPlug\SyliusPayPlugPlugin\Exception\UnknownApiErrorException;
use PayPlug\SyliusPayPlugPlugin\Gateway\ApplePayGatewayFactory;
use PayPlug\SyliusPayPlugPlugin\Gateway\OneyGatewayFactory;
use PayPlug\SyliusPayPlugPlugin\Gateway\PayPlugGatewayFactory;
use PayPlug\SyliusPayPlugPlugin\PaymentProcessing\AbortPaymentProcessor;
use Payum\Core\Action\ActionInterface;
Expand Down Expand Up @@ -79,8 +81,19 @@ public function execute($request): void
Assert::isInstanceOf($this->tokenFactory, GenericTokenFactoryInterface::class);
RequestNotSupportedException::assertSupports($this, $request);

$paymentModel = $request->getFirstModel();
Assert::isInstanceOf($paymentModel, PaymentInterface::class);

$details = ArrayObject::ensureArrayObject($request->getModel());

if (isset($details['payment_method']) &&
ApplePayGatewayFactory::PAYMENT_METHOD_APPLE_PAY === $details['payment_method']) {
$this->abortPaymentProcessor->process($paymentModel);
$details['status'] = PayPlugApiClientInterface::STATUS_CANCELED;

return;
}

if (isset($details['status']) && PayPlugApiClientInterface::FAILED === $details['status']) {
// Unset current status to allow to use payplug to change payment method
unset($details['status']);
Expand All @@ -93,12 +106,9 @@ public function execute($request): void
return;
}

$paymentModel = $request->getFirstModel();
Assert::isInstanceOf($paymentModel, PaymentInterface::class);

/** @var Capture $request */
/* @var Capture $request */
if (array_key_exists('status', $paymentModel->getDetails())
&& $paymentModel->getDetails()['status'] === PayPlugApiClientInterface::STATUS_CAPTURED) {
&& PayPlugApiClientInterface::STATUS_CAPTURED === $paymentModel->getDetails()['status']) {
return;
}

Expand All @@ -118,6 +128,24 @@ public function execute($request): void
unset($details['status']);
}

if (!in_array(
$details['payment_method'],
array_merge(
[ApplePayGatewayFactory::PAYMENT_METHOD_APPLE_PAY],
OneyGatewayFactory::PAYMENT_CHOICES
),
true
)) {
// clean other detail values
if ($details->offsetExists('payment_context')) {
unset($details['payment_context']);
}

if ($details->offsetExists('merchant_session')) {
unset($details['merchant_session']);
}
}

try {
// gateway payplug case: open many browsers and pay by save card in any of these browsers
$cardId = $this->requestStack->getSession()->get('payplug_payment_method');
Expand Down Expand Up @@ -233,7 +261,9 @@ private function createPayment(ArrayObject $details, PaymentInterface $paymentMo
{
try {
if ($details->offsetExists('payment_id')
&& $details->offsetExists('status')) {
&& $details->offsetExists('status')
&& $details->offsetExists('is_live')
) {
$this->abortPaymentProcessor->process($paymentModel);
unset($details['status'], $details['payment_id'], $details['is_live']);
// the parameter allow_save_card must be false when payment_method parameter is provided
Expand Down
5 changes: 5 additions & 0 deletions src/Controller/IpnAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ public function __invoke(Request $request): JsonResponse
$content = json_decode($input, true);
$details = ArrayObject::ensureArrayObject($content);

// if we are too fast canceling a payment before we got an answer from PayPlug gateway
if (null === $details['payment_id']) {
return new JsonResponse(null, Response::HTTP_UNAUTHORIZED);
}

$payment = $this->paymentRepository->findOneByPayPlugPaymentId($details['payment_id']);
$paymentMethod = $payment->getMethod();

Expand Down
17 changes: 12 additions & 5 deletions src/Controller/OrderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
use Sylius\Bundle\ResourceBundle\Controller\ViewHandlerInterface;
use Sylius\Bundle\ResourceBundle\Event\ResourceControllerEvent;
use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Core\OrderCheckoutStates;
use Sylius\Component\Core\OrderCheckoutTransitions;
use Sylius\Component\Core\OrderPaymentStates;
use Sylius\Component\Payment\Model\PaymentInterface;
use Sylius\Component\Resource\Exception\UpdateHandlingException;
use Sylius\Component\Resource\Factory\FactoryInterface;
Expand All @@ -36,6 +38,7 @@
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\Lock\LockFactory;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Webmozart\Assert\Assert;

final class OrderController extends BaseOrderController
Expand Down Expand Up @@ -105,6 +108,10 @@ public function initiateApplePaySessionAction(Request $request): Response
/** @var OrderInterface $resource */
$resource = $this->findOr404($configuration);

if (OrderPaymentStates::STATE_PAID === $resource->getPaymentState()) {
throw new AccessDeniedException();
}

/** @var ResourceControllerEvent $event */
$event = $this->eventDispatcher->dispatchPreEvent(ResourceActions::UPDATE, $configuration, $resource);

Expand Down Expand Up @@ -173,7 +180,7 @@ public function initiateApplePaySessionAction(Request $request): Response
]);
}

$this->addFlash('error', 'sylius.payment.cancelled');
$request->getSession()->getFlashBag()->add('error', 'sylius.payment.cancelled');
$dataResponse = [];
$redirect = $this->redirectToRoute('sylius_shop_checkout_select_payment');
$dataResponse['returnUrl'] = $redirect->getTargetUrl();
Expand Down Expand Up @@ -231,7 +238,7 @@ public function confirmApplePayPaymentAction(Request $request): Response
]);
}

$this->addFlash('error', 'sylius.payment.cancelled');
$request->getSession()->getFlashBag()->add('error', 'sylius.payment.cancelled');
$redirect = $this->redirectToRoute('sylius_shop_checkout_select_payment');
$dataResponse = [];
$dataResponse['returnUrl'] = $redirect->getTargetUrl();
Expand Down Expand Up @@ -351,12 +358,12 @@ public function cancelApplePaySessionAction(Request $request): Response

$this->manager->flush();

$this->addFlash('error', 'sylius.payment.cancelled');
$request->getSession()->getFlashBag()->add('error', 'sylius.payment.cancelled');

$dataResponse = [];
$redirect = $this->redirectToRoute('sylius_shop_checkout_select_payment', ['_locale' => $resource->getLocaleCode()]);

if (OrderInterface::STATE_NEW === $resource->getState()) {
if (OrderCheckoutStates::STATE_COMPLETED === $resource->getCheckoutState()) {
$redirect = $this->redirectToRoute('sylius_shop_order_show', [
'tokenValue' => $resource->getTokenValue(),
'_locale' => $resource->getLocaleCode(),
Expand Down Expand Up @@ -391,7 +398,7 @@ public function cancelApplePaySessionAction(Request $request): Response
'trace' => $exception->getTraceAsString(),
]);

$this->addFlash('error', 'sylius.payment.cancelled');
$request->getSession()->getFlashBag()->add('error', 'sylius.payment.cancelled');

$dataResponse = [];

Expand Down
2 changes: 1 addition & 1 deletion src/PayPlugSyliusPayPlugPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

final class PayPlugSyliusPayPlugPlugin extends Bundle
{
public const VERSION = '1.9.0';
public const VERSION = '1.9.1';

use SyliusPluginTrait;
}
Loading

0 comments on commit 9fd4457

Please sign in to comment.