Skip to content

Commit 2f37117

Browse files
authored
Merge pull request payplug#196 from payplug/qa
Release 1.5
2 parents 6b8dbde + 8865c41 commit 2f37117

File tree

20 files changed

+1107
-3410
lines changed

20 files changed

+1107
-3410
lines changed

.github/workflows/ci.yaml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ jobs:
8282
fail-fast: false
8383
matrix:
8484
php: [7.4, 8.0]
85-
sylius: [1.9.0, 1.10.0]
86-
symfony: [4.4, 5.2, 5.3]
85+
sylius: [1.9.0, 1.10.0, 1.11.0]
86+
symfony: [4.4, 5.2, 5.3, 5.4]
8787
node: [10.x]
8888
exclude:
8989
- sylius: 1.9.0
@@ -95,9 +95,14 @@ jobs:
9595
symfony: 5.3
9696
- sylius: 1.10.0
9797
symfony: 4.4
98-
#TODO: rollback this exclusion when fixed
9998
- sylius: 1.10.0
10099
symfony: 5.2
100+
- sylius: 1.11.0
101+
php: 7.4
102+
- sylius: 1.11.0
103+
symfony: 5.2
104+
- sylius: 1.11.0
105+
symfony: 5.3
101106

102107
env:
103108
APP_ENV: test
@@ -110,7 +115,7 @@ jobs:
110115
php-version: "${{ matrix.php }}"
111116
ini-values: date.timezone=UTC
112117
extensions: intl
113-
tools: symfony, flex
118+
tools: symfony
114119
coverage: none
115120

116121
- name: Setup Node
@@ -162,7 +167,7 @@ jobs:
162167
- name: Install Sylius-Standard and Plugin
163168
env:
164169
SYMFONY_REQUIRE: ${{ matrix.symfony }}.*
165-
run: make install -e SYLIUS_VERSION=${{ matrix.sylius }} SYMFONY_VERSION=${{ matrix.symfony }}
170+
run: make install -e SYLIUS_VERSION=${{ matrix.sylius }} SYMFONY_VERSION=${{ matrix.symfony }} PHP_VERSION=${{ matrix.php }}
166171

167172
- name: Output PHP version for Symfony CLI
168173
working-directory: ./tests/Application

Makefile

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
.DEFAULT_GOAL := help
22
SHELL=/bin/bash
33
COMPOSER_ROOT=composer
4+
PLUGIN_NAME=payplug/sylius-payplug-plugin
5+
SYLIUS_VERSION=1.11.0
6+
SYMFONY_VERSION=5.4
7+
PHP_VERSION=8.0
48
TEST_DIRECTORY=tests/Application
9+
YARN=cd tests/Application && yarn
510
CONSOLE=cd tests/Application && php bin/console -e test
611
COMPOSER=cd tests/Application && composer
7-
YARN=cd tests/Application && yarn
8-
9-
SYLIUS_VERSION=1.10.0
10-
SYMFONY_VERSION=5.2
11-
PLUGIN_NAME=payplug/sylius-payplug-plugin
1212

1313
###
1414
### DEVELOPMENT
1515
### ¯¯¯¯¯¯¯¯¯¯¯
1616

17-
install: sylius ## Install Plugin on Sylius [SyliusVersion=1.9] [SymfonyVersion=5.2]
17+
install: sylius ## Install Plugin on Sylius [SyliusVersion=1.11] [SymfonyVersion=5.4] [PHP_VERSION=8.0]
1818
.PHONY: install
1919

2020
reset: ## Remove dependencies
@@ -32,20 +32,21 @@ sylius: sylius-standard update-dependencies install-plugin install-sylius
3232
.PHONY: sylius
3333

3434
sylius-standard:
35-
SYMFONY_REQUIRE=${SYMFONY_VERSION}.* ${COMPOSER_ROOT} create-project sylius/sylius-standard ${TEST_DIRECTORY} "~${SYLIUS_VERSION}"
35+
${COMPOSER_ROOT} create-project sylius/sylius-standard ${TEST_DIRECTORY} "~${SYLIUS_VERSION}" --no-install --no-scripts
36+
${COMPOSER} require sylius/sylius:"~${SYLIUS_VERSION}"
3637

3738
update-dependencies:
3839
${COMPOSER} config extra.symfony.require "^${SYMFONY_VERSION}"
3940
${COMPOSER} require --dev donatj/mock-webserver:^2.1 --no-scripts --no-update
4041
# FIX since https://github.com/Sylius/Sylius/pull/13215 is not merged
4142
${COMPOSER} require doctrine/dbal:"^2.6" doctrine/orm:"^2.9" --no-scripts --no-update
42-
ifeq ($(SYMFONY_VERSION), 4.4)
43-
${COMPOSER} require sylius/admin-api-bundle --no-scripts --no-update
43+
ifeq ($(shell [[ $(SYMFONY_VERSION) == 4.4 && $(PHP_VERSION) == 7.4 ]] && echo true ),true)
44+
${COMPOSER} require sylius/admin-api-bundle:1.10 --no-scripts --no-update
4445
endif
4546
ifeq ($(SYLIUS_VERSION), 1.8.0)
4647
${COMPOSER} update --no-progress --no-scripts --prefer-dist -n
4748
endif
48-
${COMPOSER} require symfony/asset --no-scripts --no-update
49+
${COMPOSER} require symfony/asset:^${SYMFONY_VERSION} --no-scripts --no-update
4950
${COMPOSER} update --no-progress -n
5051

5152
install-plugin:
@@ -60,18 +61,27 @@ install-plugin:
6061
sed -i "4a \ \ \ \ form_themes: ['form/form_gateway_config_row.html.twig']" ${TEST_DIRECTORY}/config/packages/twig.yaml
6162
mkdir -p ${TEST_DIRECTORY}/templates/form/
6263
cp -R src/Resources/views/form/* ${TEST_DIRECTORY}/templates/form/
64+
65+
# As of sylius/refund-plugin 1.2 the folder does not exist anymore
66+
ifneq ($(PHP_VERSION), 8)
6367
mkdir -p ${TEST_DIRECTORY}/templates/bundles/SyliusAdminBundle/
6468
cp -R src/Resources/views/SyliusAdminBundle/* ${TEST_DIRECTORY}/templates/bundles/SyliusAdminBundle/
65-
6669
# For Refund Plugin
6770
cp -R ${TEST_DIRECTORY}/vendor/sylius/refund-plugin/src/Resources/views/SyliusAdminBundle/* ${TEST_DIRECTORY}/templates/bundles/SyliusAdminBundle/
71+
endif
6872

6973
install-sylius:
7074
${CONSOLE} sylius:install -n -s default
7175
${YARN} install
7276
${YARN} build
77+
ifeq ($(shell expr $(value) \<= 5.3), 1)
7378
${CONSOLE} translation:update en PayPlugSyliusPayPlugPlugin --dump-messages
7479
${CONSOLE} translation:update fr PayPlugSyliusPayPlugPlugin --dump-messages
80+
else ifeq ($(shell expr $(value) \>= 5.4), 1)
81+
${CONSOLE} translation:extract en PayPlugSyliusPayPlugPlugin --dump-messages
82+
${CONSOLE} translation:extract fr PayPlugSyliusPayPlugPlugin --dump-messages
83+
endif
84+
7585
${CONSOLE} cache:clear
7686

7787
phpunit-configure:

README.md

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -171,15 +171,23 @@ If you plan override them also, you should retrieve them in your application.
171171

172172
Copy Sylius templates overridden in plugin to your templates directory (e.g templates/bundles/)
173173

174-
```shell
175-
mkdir -p templates/bundles/SyliusAdminBundle/
176-
mkdir -p templates/bundles/SyliusShopBundle/
177-
mkdir -p templates/bundles/SyliusUiBundle/
178-
cp -R vendor/payplug/sylius-payplug-plugin/src/Resources/views/SyliusAdminBundle/* templates/bundles/SyliusAdminBundle/
179-
cp -R vendor/payplug/sylius-payplug-plugin/src/Resources/views/SyliusShopBundle/* templates/bundles/SyliusShopBundle/
180-
cp -R vendor/payplug/sylius-payplug-plugin/src/Resources/views/SyliusUiBundle/* templates/bundles/SyliusUiBundle/
181-
```
174+
```shell
175+
mkdir -p templates/bundles/SyliusAdminBundle/
176+
mkdir -p templates/bundles/SyliusShopBundle/
177+
mkdir -p templates/bundles/SyliusUiBundle/
178+
cp -R vendor/payplug/sylius-payplug-plugin/src/Resources/views/SyliusAdminBundle/* templates/bundles/SyliusAdminBundle/
179+
cp -R vendor/payplug/sylius-payplug-plugin/src/Resources/views/SyliusShopBundle/* templates/bundles/SyliusShopBundle/
180+
cp -R vendor/payplug/sylius-payplug-plugin/src/Resources/views/SyliusUiBundle/* templates/bundles/SyliusUiBundle/
181+
```
182182

183+
You also need to edit your twig config to add your path to avoid our configuration to be prepended :
184+
```yaml
185+
twig:
186+
paths:
187+
'%kernel.project_dir%/templates/bundles/SyliusAdminBundle': SyliusAdmin
188+
'%kernel.project_dir%/templates/bundles/SyliusShopBundle': SyliusShop
189+
'%kernel.project_dir%/templates/bundles/SyliusUiBundle': SyliusUi
190+
```
183191
## Development
184192

185193
See [How to contribute](CONTRIBUTING.md).

composer.json

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
"giggsey/libphonenumber-for-php": "^8.12",
1010
"payplug/payplug-php": "^3.1",
1111
"sylius/refund-plugin": "^1.0.0",
12-
"sylius/sylius": "^1.9.0 || ^1.10.0",
13-
"symfony/asset": "^4.3|^5.0",
14-
"symfony/lock": "^4.3|^5.0",
15-
"symfony/validator": "^4.3|^5.0"
12+
"sylius/sylius": "^1.9.0 || ^1.10.0 || ^1.11.0",
13+
"symfony/asset": "^4.4|^5.0",
14+
"symfony/lock": "^4.4|^5.0",
15+
"symfony/validator": "^4.4|^5.0"
1616
},
1717
"require-dev": {
1818
"behat/behat": "^3.7",
@@ -57,7 +57,13 @@
5757
}
5858
},
5959
"config": {
60-
"sort-packages": true
60+
"sort-packages": true,
61+
"allow-plugins": {
62+
"phpstan/extension-installer": true,
63+
"dealerdirect/phpcodesniffer-composer-installer": true,
64+
"symfony/flex": true,
65+
"symfony/thanks": true
66+
}
6167
},
6268
"scripts": {
6369
"ecs": "ecs check -c rulesets/ecs.php --ansi --clear-cache .",

src/Action/NotifyAction.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ public function __construct(
4444

4545
public function execute($request): void
4646
{
47+
// Put notification asleep to prevent double processing while user is redirected manually
48+
sleep(10);
4749
$details = ArrayObject::ensureArrayObject($request->getModel());
4850

4951
$input = file_get_contents('php://input');

src/DependencyInjection/PayPlugSyliusPayPlugExtension.php

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,21 @@ public function prepend(ContainerBuilder $container): void
3232
}
3333

3434
$viewsPath = dirname(__DIR__) . '/Resources/views/';
35-
// This add our override in twig paths with correct namespace. No need for final user to copy it
35+
// This add our override in twig paths with correct namespace if there are not already overridden. No need for final user to copy it
3636
$paths = [
3737
$viewsPath . 'SyliusShopBundle' => 'SyliusShop',
3838
$viewsPath . 'SyliusAdminBundle' => 'SyliusAdmin',
3939
$viewsPath . 'SyliusUiBundle' => 'SyliusUi',
4040
];
4141

42+
$twigConfig = $container->getExtensionConfig('twig');
43+
44+
foreach ($paths as $key => $path) {
45+
if ($this->isPathAlreadyInConfiguration($path, $twigConfig)) {
46+
unset($paths[$key]);
47+
}
48+
}
49+
4250
$container->prependExtensionConfig('twig', [
4351
'paths' => $paths,
4452
'form_themes' => [
@@ -50,6 +58,27 @@ public function prepend(ContainerBuilder $container): void
5058
$this->prependDoctrineMigrations($container);
5159
}
5260

61+
/**
62+
* Verify if a given namespace is alreay extented
63+
*
64+
* @param string $namespace The namespace to verify
65+
* @param array $configurations The given configurations
66+
*
67+
* @return bool
68+
*/
69+
protected function isPathAlreadyInConfiguration(string $namespace, array $configurations): bool
70+
{
71+
foreach ($configurations as $configuration) {
72+
foreach ($configuration as $parameter => $values) {
73+
if ('paths' === $parameter && in_array($namespace, $values, true)) {
74+
return true;
75+
}
76+
}
77+
}
78+
79+
return false;
80+
}
81+
5382
protected function getMigrationsNamespace(): string
5483
{
5584
return 'PayPlug\SyliusPayPlugPlugin\Migrations';

src/Handler/PaymentNotificationHandler.php

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace PayPlug\SyliusPayPlugPlugin\Handler;
66

77
use DateTimeImmutable;
8+
use Doctrine\ORM\EntityManagerInterface;
89
use Payplug\Resource\IVerifiableAPIResource;
910
use Payplug\Resource\Payment;
1011
use Payplug\Resource\PaymentAuthorization;
@@ -19,6 +20,7 @@
1920
use Sylius\Component\Resource\Factory\FactoryInterface;
2021
use Sylius\Component\Resource\Repository\RepositoryInterface;
2122
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
23+
use Symfony\Component\Lock\LockFactory;
2224

2325
class PaymentNotificationHandler
2426
{
@@ -37,18 +39,26 @@ class PaymentNotificationHandler
3739
/** @var \Sylius\Component\Core\Repository\CustomerRepositoryInterface */
3840
private $customerRepository;
3941

42+
private EntityManagerInterface $entityManager;
43+
44+
private LockFactory $lockFactory;
45+
4046
public function __construct(
4147
LoggerInterface $logger,
4248
RepositoryInterface $payplugCardRepository,
4349
FactoryInterface $payplugCardFactory,
4450
CustomerRepositoryInterface $customerRepository,
45-
FlashBagInterface $flashBag
51+
FlashBagInterface $flashBag,
52+
EntityManagerInterface $entityManager,
53+
LockFactory $lockFactory
4654
) {
4755
$this->logger = $logger;
4856
$this->payplugCardRepository = $payplugCardRepository;
4957
$this->payplugCardFactory = $payplugCardFactory;
5058
$this->flashBag = $flashBag;
5159
$this->customerRepository = $customerRepository;
60+
$this->entityManager = $entityManager;
61+
$this->lockFactory = $lockFactory;
5262
}
5363

5464
public function treat(Generic $request, IVerifiableAPIResource $paymentResource, \ArrayObject $details): void
@@ -57,18 +67,33 @@ public function treat(Generic $request, IVerifiableAPIResource $paymentResource,
5767
return;
5868
}
5969

70+
$lock = $this->lockFactory->createLock('payment_'.$paymentResource->id);
71+
$lock->acquire(true);
72+
73+
$this->entityManager->refresh($request->getFirstModel());
74+
75+
if (PayPlugApiClientInterface::STATUS_CREATED === $request->getFirstModel()->getDetails()) {
76+
$lock->release();
77+
78+
return;
79+
}
80+
6081
if ($paymentResource->is_paid) {
6182
$details['status'] = PayPlugApiClientInterface::STATUS_CAPTURED;
6283
$details['created_at'] = $paymentResource->created_at;
6384

6485
$this->saveCard($request->getFirstModel(), $paymentResource);
6586

87+
$lock->release();
88+
6689
return;
6790
}
6891

6992
if ($this->isResourceIsAuthorized($paymentResource)) {
7093
$details['status'] = PayPlugApiClientInterface::STATUS_AUTHORIZED;
7194

95+
$lock->release();
96+
7297
return;
7398
}
7499

@@ -80,6 +105,8 @@ public function treat(Generic $request, IVerifiableAPIResource $paymentResource,
80105
'message' => $paymentResource->failure->message ?? '',
81106
];
82107

108+
$lock->release();
109+
83110
return;
84111
}
85112

@@ -94,6 +121,7 @@ public function treat(Generic $request, IVerifiableAPIResource $paymentResource,
94121
}
95122

96123
$details['status'] = PayPlugApiClientInterface::FAILED;
124+
$lock->release();
97125
}
98126

99127
private function saveCard(PaymentInterface $payment, IVerifiableAPIResource $paymentResource): void

src/PayPlugSyliusPayPlugPlugin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
final class PayPlugSyliusPayPlugPlugin extends Bundle
1111
{
12-
public const VERSION = '1.4.0';
12+
public const VERSION = '1.5.0';
1313

1414
use SyliusPluginTrait;
1515
}

0 commit comments

Comments
 (0)