Skip to content

Commit

Permalink
minor #195 Build paypal with sylius 1.8 and 1.9 (SirDomin)
Browse files Browse the repository at this point in the history
This PR was merged into the 1.0-dev branch.

Discussion
----------



Commits
-------

29ee6af fix build with sylius 1.9
6a5d721 load config from 1.8 or 1.9 in kernel
ee03f72 edit github actions to run sylius 1.8 and 1.9
2a5c1f6 change objectManager usage
cbdaf00 request error fixed
9864c93 fix psalm
d716b22 pr-fix
  • Loading branch information
SirDomin authored Apr 22, 2021
2 parents b6a3405 + d716b22 commit 5203078
Show file tree
Hide file tree
Showing 25 changed files with 136 additions and 48 deletions.
22 changes: 19 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,24 @@ jobs:
tests:
runs-on: ubuntu-latest

name: "PHP ${{ matrix.php }}, MySQL ${{ matrix.mysql }}"
name: "PHP ${{ matrix.php }}, MySQL ${{ matrix.mysql }}, Sylius ${{ matrix.sylius }}"

strategy:
fail-fast: false
matrix:
php: [7.4, 7.3]
node: [10.x]
mysql: [5.7, 8.0]
symfony: [^4.4, ^5.2]
sylius: [~1.8.0, ~1.9.0]

exclude:
-
php: 7.3
mysql: 8.0

-
sylius: ~1.8.0
symfony: ^5.2
env:
APP_ENV: test
DATABASE_URL: "mysql://root:[email protected]/sylius?serverVersion=${{ matrix.mysql }}"
Expand Down Expand Up @@ -83,6 +87,18 @@ jobs:
restore-keys: |
${{ runner.os }}-php-${{ matrix.php }}-composer-
-
name: Restrict Symfony version
if: matrix.symfony != ''
run: |
composer global require --no-progress --no-scripts --no-plugins "symfony/flex:^1.10"
composer config extra.symfony.require "${{ matrix.symfony }}"
-
name: Restrict Sylius version
if: matrix.sylius != ''
run: composer require "sylius/sylius:${{ matrix.sylius }}" --no-update --no-scripts --no-interaction

-
name: Install PHP dependencies
run: composer install --no-interaction
Expand Down Expand Up @@ -151,7 +167,7 @@ jobs:

-
name: Run Behat
run: vendor/bin/behat --colors --strict -vvv --no-interaction || vendor/bin/behat --colors --strict -vvv --no-interaction --rerun
run: vendor/bin/behat --colors --strict -vvv --no-interaction -f progress || vendor/bin/behat --colors --strict -vvv --no-interaction -f progress --rerun

-
name: Upload Behat logs
Expand Down
16 changes: 9 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"require": {
"php": "^7.3",

"sylius/sylius": "1.8.*",
"sylius/sylius": "^1.8",
"nyholm/append-query-string": "^0.1.1",
"phpseclib/phpseclib": "^2.0",
"sylius-labs/doctrine-migrations-extra-bundle": "^0.1.3",
Expand All @@ -25,6 +25,7 @@
"friends-of-behat/suite-settings-extension": "^1.0",
"friends-of-behat/symfony-extension": "^2.1",
"friends-of-behat/variadic-extension": "^1.3",
"friendsofsymfony/oauth-server-bundle": "^1.6 || >2.0.0-alpha.0 ^2.0@dev",
"lakion/mink-debug-extension": "^1.2.3",
"phpspec/phpspec": "^6.1",
"phpstan/phpstan": "0.12.25",
Expand All @@ -33,16 +34,17 @@
"phpunit/phpunit": "^8.5",
"sensiolabs/security-checker": "^6.0",
"sylius-labs/coding-standard": "^3.1",
"symfony/browser-kit": "^4.4",
"symfony/debug-bundle": "^4.4|^5.0",
"symfony/dotenv": "^4.4|^5.0",
"symfony/intl": "^4.4|^5.0",
"symfony/web-profiler-bundle": "^4.4|^5.0",
"symfony/browser-kit": "^4.4 || ^5.2",
"symfony/debug-bundle": "^4.4 || ^5.2",
"symfony/dotenv": "^4.4 || ^5.2",
"symfony/intl": "^4.4 || ^5.2",
"symfony/web-profiler-bundle": "^4.4 || ^5.2",
"symfony/web-server-bundle": "^4.4|^5.0",
"vimeo/psalm": "3.11.4"
},
"conflict": {
"symfony/doctrine-bridge": "4.4.16"
"symfony/doctrine-bridge": "4.4.16",
"doctrine/doctrine-bundle": "2.3.0"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/CancelPayPalPaymentAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Sylius\PayPalPlugin\Controller;

use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\Persistence\ObjectManager;
use SM\Factory\FactoryInterface;
use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Order\Processor\OrderProcessorInterface;
Expand Down
6 changes: 3 additions & 3 deletions src/Controller/EnableSellerAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ public function __invoke(Request $request): Response
} catch (PaymentMethodCouldNotBeEnabledException $exception) {
$flashBag->add('error', 'sylius.pay_pal.payment_not_enabled');

return new RedirectResponse($request->headers->get('referer'));
return new RedirectResponse((string) $request->headers->get('referer'));
} catch (PayPalWebhookUrlNotValidException $exception) {
$flashBag->add('error', 'sylius.pay_pal.webhook_url_not_valid');

return new RedirectResponse($request->headers->get('referer'));
return new RedirectResponse((string) $request->headers->get('referer'));
}

$flashBag->add('success', 'sylius.pay_pal.payment_enabled');

return new RedirectResponse($request->headers->get('referer'));
return new RedirectResponse((string) $request->headers->get('referer'));
}
}
2 changes: 1 addition & 1 deletion src/Controller/PayPalOrderItemController.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function createFromProductDetailsAction(Request $request): Response
$form = $form->handleRequest($request);

if (!$form->isValid()) {
return new RedirectResponse($request->headers->get('referer'));
return new RedirectResponse((string) $request->headers->get('referer'));
}

/** @var AddToCartCommandInterface $addToCartCommand */
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/ProcessPayPalOrderAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function __invoke(Request $request): Response
/** @var PaymentInterface $payment */
$payment = $order->getLastPayment(PaymentInterface::STATE_CART);

$data = $this->getOrderDetails($request->request->get('payPalOrderId'), $payment);
$data = $this->getOrderDetails((string) $request->request->get('payPalOrderId'), $payment);

/** @var CustomerInterface|null $customer */
$customer = $order->getCustomer();
Expand Down
13 changes: 8 additions & 5 deletions src/Controller/UpdatePayPalOrderAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,25 @@ public function __construct(

public function __invoke(Request $request): Response
{
$payment = $this->paymentProvider->getByPayPalOrderId($request->request->get('orderID'));
$payment = $this->paymentProvider->getByPayPalOrderId((string) $request->request->get('orderID'));
/** @var OrderInterface $order */
$order = $payment->getOrder();

/** @var PaymentMethodInterface $paymentMethod */
$paymentMethod = $payment->getMethod();
$token = $this->authorizeClientApi->authorize($paymentMethod);

/** @var array $shippingAddress */
$shippingAddress = $request->request->get('shipping_address');

/** @var AddressInterface $address */
$address = $this->addressFactory->createNew();
$address->setFirstName('Temp');
$address->setLastName('Temp');
$address->setStreet('Temp');
$address->setCity($request->request->get('shipping_address')['city']);
$address->setPostcode($request->request->get('shipping_address')['postal_code']);
$address->setCountryCode($request->request->get('shipping_address')['country_code']);
$address->setCity((string) $shippingAddress['city']);
$address->setPostcode((string) $shippingAddress['postal_code']);
$address->setCountryCode((string) $shippingAddress['country_code']);
$order->setBillingAddress($address);
$order->setShippingAddress($address);

Expand All @@ -82,7 +85,7 @@ public function __invoke(Request $request): Response

$response = $this->updateOrderApi->update(
$token,
$request->request->get('orderID'),
(string) $request->request->get('orderID'),
$payment,
$payment->getDetails()['reference_id'],
$gatewayConfig->getConfig()['merchant_id'],
Expand Down
2 changes: 1 addition & 1 deletion src/Onboarding/Processor/BasicOnboardingProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function process(
'partner_attribution_id' => $response['partner_attribution_id'],
]);

$permissionsGranted = (bool) $request->query->get('permissionsGranted', true);
$permissionsGranted = $request->query->get('permissionsGranted') === null ? true : (bool) $request->query->get('permissionsGranted');
if (!$permissionsGranted) {
$paymentMethod->setEnabled(false);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Application/.env
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ APP_SECRET=EDITME
# Format described at http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url
# For a sqlite database, use: "sqlite:///%kernel.project_dir%/var/data.db"
# Set "serverVersion" to your server version to avoid edge-case exceptions and extra database calls
DATABASE_URL=mysql://[email protected]/sylius_pay_pal_plugin_%kernel.environment%?serverVersion=5.5
DATABASE_URL=mysql://[email protected]/sylius_pay_pal_plugin_%kernel.environment%
###< doctrine/doctrine-bundle ###

###> symfony/swiftmailer-bundle ###
Expand Down
65 changes: 47 additions & 18 deletions tests/Application/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Tests\Sylius\PayPalPlugin\Application;

use PSS\SymfonyMockerContainer\DependencyInjection\MockerContainer;
use Sylius\Bundle\CoreBundle\Application\Kernel as SyliusKernel;
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Component\Config\Loader\DelegatingLoader;
use Symfony\Component\Config\Loader\LoaderInterface;
Expand All @@ -20,6 +21,7 @@
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\HttpKernel\Config\FileLocator;
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
use Symfony\Component\Routing\RouteCollectionBuilder;
use Webmozart\Assert\Assert;
Expand All @@ -42,33 +44,27 @@ public function getLogDir(): string

public function registerBundles(): iterable
{
$contents = require $this->getProjectDir() . '/config/bundles.php';
foreach ($contents as $class => $envs) {
if (isset($envs['all']) || isset($envs[$this->environment])) {
yield new $class();
}
foreach ($this->getConfigurationDirectories() as $confDir) {
yield from $this->registerBundlesFromFile($confDir . '/bundles.php');
}
}

protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void
{
$container->addResource(new FileResource($this->getProjectDir() . '/config/bundles.php'));
$container->setParameter('container.dumper.inline_class_loader', true);
$confDir = $this->getProjectDir() . '/config';
foreach ($this->getConfigurationDirectories() as $confDir) {
$container->addResource(new FileResource($confDir . '/bundles.php'));
}

$loader->load($confDir . '/{packages}/*' . self::CONFIG_EXTS, 'glob');
$loader->load($confDir . '/{packages}/' . $this->environment . '/**/*' . self::CONFIG_EXTS, 'glob');
$loader->load($confDir . '/{services}' . self::CONFIG_EXTS, 'glob');
$loader->load($confDir . '/{services}_' . $this->environment . self::CONFIG_EXTS, 'glob');
foreach ($this->getConfigurationDirectories() as $confDir) {
$this->loadContainerConfiguration($loader, $confDir);
}
}

protected function configureRoutes(RouteCollectionBuilder $routes): void
{
$confDir = $this->getProjectDir() . '/config';

$routes->import($confDir . '/{routes}/*' . self::CONFIG_EXTS, '/', 'glob');
$routes->import($confDir . '/{routes}/' . $this->environment . '/**/*' . self::CONFIG_EXTS, '/', 'glob');
$routes->import($confDir . '/{routes}' . self::CONFIG_EXTS, '/', 'glob');
foreach ($this->getConfigurationDirectories() as $confDir) {
$this->loadRoutesConfiguration($routes, $confDir);
}
}

protected function getContainerBaseClass(): string
Expand All @@ -85,7 +81,7 @@ protected function getContainerLoader(ContainerInterface $container): LoaderInte
/** @var ContainerBuilder $container */
Assert::isInstanceOf($container, ContainerBuilder::class);

$locator = new FileLocator($this, $this->getRootDir() . '/Resources');
$locator = new FileLocator($this, $this->getProjectDir() . '/Resources');
$resolver = new LoaderResolver(array(
new XmlFileLoader($container, $locator),
new YamlFileLoader($container, $locator),
Expand All @@ -103,4 +99,37 @@ private function isTestEnvironment(): bool
{
return 0 === strpos($this->getEnvironment(), 'test');
}

private function loadContainerConfiguration(LoaderInterface $loader, string $confDir): void
{
$loader->load($confDir . '/{packages}/*' . self::CONFIG_EXTS, 'glob');
$loader->load($confDir . '/{packages}/' . $this->environment . '/**/*' . self::CONFIG_EXTS, 'glob');
$loader->load($confDir . '/{services}' . self::CONFIG_EXTS, 'glob');
$loader->load($confDir . '/{services}_' . $this->environment . self::CONFIG_EXTS, 'glob');
}

private function loadRoutesConfiguration(RouteCollectionBuilder $routes, string $confDir): void
{
$routes->import($confDir . '/{routes}/*' . self::CONFIG_EXTS, '/', 'glob');
$routes->import($confDir . '/{routes}/' . $this->environment . '/**/*' . self::CONFIG_EXTS, '/', 'glob');
$routes->import($confDir . '/{routes}' . self::CONFIG_EXTS, '/', 'glob');
}

/** @return BundleInterface[] */
private function registerBundlesFromFile(string $bundlesFile): iterable
{
$contents = require $bundlesFile;
foreach ($contents as $class => $environments) {
if (isset($environments['all']) || isset($environments[$this->environment])) {
yield new $class();
}
}
}

/** @return string[] */
private function getConfigurationDirectories(): iterable
{
yield $this->getProjectDir() . '/config';
yield $this->getProjectDir() . '/config/sylius/' . SyliusKernel::MAJOR_VERSION . '.' . SyliusKernel::MINOR_VERSION;
}
}
3 changes: 0 additions & 3 deletions tests/Application/config/bundles.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle::class => ['all' => true],
Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true],
Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true],
Doctrine\Bundle\DoctrineCacheBundle\DoctrineCacheBundle::class => ['all' => true],
Sylius\Bundle\OrderBundle\SyliusOrderBundle::class => ['all' => true],
Sylius\Bundle\MoneyBundle\SyliusMoneyBundle::class => ['all' => true],
Sylius\Bundle\CurrencyBundle\SyliusCurrencyBundle::class => ['all' => true],
Expand Down Expand Up @@ -40,12 +39,10 @@
Liip\ImagineBundle\LiipImagineBundle::class => ['all' => true],
Payum\Bundle\PayumBundle\PayumBundle::class => ['all' => true],
Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle::class => ['all' => true],
WhiteOctober\PagerfantaBundle\WhiteOctoberPagerfantaBundle::class => ['all' => true],
Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle::class => ['all' => true],
Sylius\Bundle\FixturesBundle\SyliusFixturesBundle::class => ['all' => true],
Sylius\Bundle\PayumBundle\SyliusPayumBundle::class => ['all' => true],
Sylius\Bundle\ThemeBundle\SyliusThemeBundle::class => ['all' => true],
Symfony\Bundle\WebServerBundle\WebServerBundle::class => ['all' => true],
Sylius\Bundle\AdminBundle\SyliusAdminBundle::class => ['all' => true],
Sylius\Bundle\ShopBundle\SyliusShopBundle::class => ['all' => true],
FOS\OAuthServerBundle\FOSOAuthServerBundle::class => ['all' => true],
Expand Down
1 change: 1 addition & 0 deletions tests/Application/config/packages/_sylius.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ imports:
- { resource: "@SyliusShopBundle/Resources/config/app/config.yml" }

- { resource: "@SyliusPayPalPlugin/Resources/config/config.yaml" }
- { resource: "@SyliusApiBundle/Resources/config/app/config.yaml" }

parameters:
sylius_core.public_dir: '%kernel.project_dir%/public'
Expand Down
1 change: 0 additions & 1 deletion tests/Application/config/packages/framework.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@ framework:
secret: '%env(APP_SECRET)%'
form: true
csrf_protection: true
templating: { engines: ["twig"] }
session:
handler_id: ~
6 changes: 6 additions & 0 deletions tests/Application/config/sylius/1.8/bundles.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php

return [
Doctrine\Bundle\DoctrineCacheBundle\DoctrineCacheBundle::class => ['all' => true],
WhiteOctober\PagerfantaBundle\WhiteOctoberPagerfantaBundle::class => ['all' => true],
];
2 changes: 2 additions & 0 deletions tests/Application/config/sylius/1.8/packages/framework.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
framework:
templating: { engines: ["twig"] }
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ jms_serializer:
visitors:
json:
options:
- JSON_PRETTY_PRINT
- JSON_UNESCAPED_SLASHES
- JSON_PRESERVE_ZERO_FRACTION
6 changes: 6 additions & 0 deletions tests/Application/config/sylius/1.9/bundles.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php

return [
BabDev\PagerfantaBundle\BabDevPagerfantaBundle::class => ['all' => true],
SyliusLabs\Polyfill\Symfony\Security\Bundle\SyliusLabsPolyfillSymfonySecurityBundle::class => ['all' => true],
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
jms_serializer:
visitors:
json_serialization:
options:
- JSON_PRETTY_PRINT
- JSON_UNESCAPED_SLASHES
- JSON_PRESERVE_ZERO_FRACTION
json_deserialization:
options:
- JSON_PRETTY_PRINT
- JSON_UNESCAPED_SLASHES
- JSON_PRESERVE_ZERO_FRACTION
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
jms_serializer:
visitors:
xml_serialization:
format_output: '%kernel.debug%'
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
jms_serializer:
visitors:
json_serialization:
options:
- JSON_UNESCAPED_SLASHES
- JSON_PRESERVE_ZERO_FRACTION
json_deserialization:
options:
- JSON_UNESCAPED_SLASHES
- JSON_PRESERVE_ZERO_FRACTION
Loading

0 comments on commit 5203078

Please sign in to comment.