From ef503463bc86fd4512998a81d9ad18abd9a5de47 Mon Sep 17 00:00:00 2001 From: adumont-payplug Date: Mon, 20 Apr 2026 11:30:52 +0200 Subject: [PATCH 1/2] FIX: fixing dependency injection for installation --- README.md | 113 +++++++++--------------------------------------------- 1 file changed, 18 insertions(+), 95 deletions(-) diff --git a/README.md b/README.md index cea0998c..610a38d8 100644 --- a/README.md +++ b/README.md @@ -36,54 +36,31 @@ In local environment, the plugin will not work properly because you will not be | PHP | ^8.2 | | Sylius | ^2.0 | -## Installation -### 1. Require the **payplug/sylius-payplug-plugin** : +### With Symfony Flex + +#### 1. Allow contrib recipes and require the plugin ```bash composer config extra.symfony.allow-contrib true composer require payplug/sylius-payplug-plugin ``` -### 3. Register Sylius resources - -The plugin's extension does not prepend its `resources.yaml`, so the Sylius resource services for the Card and RefundHistory entities are never created. Add them manually in `config/packages/sylius_resource.yaml`: +#### 2. Install the Flex recipe -```yaml -sylius_resource: - resources: - payplug.payplug_card: - driver: doctrine/orm - classes: - model: PayPlug\SyliusPayPlugPlugin\Entity\Card - payplug.payplug_refund_history: - driver: doctrine/orm - classes: - model: PayPlug\SyliusPayPlugPlugin\Entity\RefundHistory - repository: PayPlug\SyliusPayPlugPlugin\Repository\RefundHistoryRepository +```bash +composer recipes:install payplug/sylius-payplug-plugin --force ``` -### 4. Fix service autowiring - -The plugin uses `#[Autoconfigure]` on some actions and relies on named constructor arguments that Symfony cannot resolve automatically. Add the following to `config/services.yaml`: +This automatically registers the bundle, copies configuration files, and sets up assets (on Sylius 2.1+). -```yaml -services: - PayPlug\SyliusPayPlugPlugin\Action\CaptureAction: - arguments: - $payplugCardRepository: '@payplug.repository.payplug_card' - - PayPlug\SyliusPayPlugPlugin\Repository\RefundHistoryRepositoryInterface: - alias: payplug.repository.payplug_refund_history -``` - -### 5. Apply migrations to your database: +#### 3. Apply migrations to your database ```shell bin/console doctrine:migrations:migrate - ``` +``` -### 6. Add Payplug to refundable payment method for Sylius Refund Plugin in `config/services.yaml` +#### 4. Add Payplug to refundable payment methods for Sylius Refund Plugin in `config/services.yaml` ```yaml parameters: @@ -96,7 +73,7 @@ parameters: - payplug_american_express ``` -### 7. Add Traits for Customer and PaymentMethod entities +#### 5. Add Traits for Customer and PaymentMethod entities * App\Entity\Customer\Customer @@ -153,7 +130,7 @@ class PaymentMethod extends BasePaymentMethod return new PaymentMethodTranslation(); } } -``` +``` * App\Entity\Payment\Payment @@ -179,78 +156,24 @@ class Payment extends BasePayment { use PaymentTrait; } -``` +``` -### 8. Process translations +#### 6. Process translations ```bash php bin/console translation:extract en PayPlugSyliusPayPlugPlugin --dump-messages php bin/console translation:extract fr PayPlugSyliusPayPlugPlugin --dump-messages ``` -### 9. Clear cache: +#### 7. Clear cache - ```bash - bin/console cache:clear - ``` +```bash +bin/console cache:clear +``` 🎉 You are now ready to add Payplug Payment method. In your back-office, go to `Configuration > Payment methods`, then click on `Create` and choose "**Payplug**". -### Assets installation (only for Sylius 2.0.x) - -On sylius 2.0.x, there is no automatic load of assets. -You need to add the following lines in `assets/shop/controllers.json` to allow Sylius to use our assets: - -```json -{ - "controllers": { - "@payplug/sylius-payplug-plugin": { - "oney-popin": { - "enabled": true, - "fetch": "lazy", - "autoimport": { - "@payplug/sylius-payplug-plugin/shop/dist/oney_common/index.css": true, - "@payplug/sylius-payplug-plugin/shop/dist/oney_popin/index.css": true - } - }, - "integrated-payment": { - "enabled": true, - "fetch": "lazy", - "autoimport": { - "@payplug/sylius-payplug-plugin/shop/dist/payment/integrated.css": true - } - }, - "oney-payment": { - "enabled": true, - "fetch": "lazy" - }, - "payment-logo": { - "enabled": true, - "fetch": "lazy" - }, - "checkout-select-payment": { - "enabled": true, - "fetch": "lazy", - "autoimport": { - "@payplug/sylius-payplug-plugin/shop/dist/payment/index.css": true - } - }, - "apple-pay": { - "enabled": true, - "fetch": "lazy" - } - } - }, - "entrypoints": [] -} -``` - -> [!NOTE] -> On Sylius Standard >= 2.1, assets are automatically loaded when you install the plugin with flex. -> If you are upgrading from a 2.0.x version, read the [upgrade guide](https://github.com/Sylius/Sylius/blob/2.1/UPGRADE-2.1.md#assets) - - ## Logs If you want to follow the logs in the production environment, you need to add the configuration in `config/packages/prod/monolog.yaml`, logs should be in `var/log/prod.log` which can be searched after the phrase `[Payum]` or `[Payplug]`: From 19ae7e76126b117ea89efb3d357a100ed4beb26a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jib=C3=A9=20Barth?= Date: Tue, 28 Apr 2026 10:16:10 +0200 Subject: [PATCH 2/2] PPSYL-184 - Always add a notification url when create payment --- src/Command/Handler/CapturePaymentRequestHandler.php | 4 ---- src/Creator/PayPlugPaymentDataCreator.php | 5 +++++ src/Provider/Payment/ApplePayPaymentProvider.php | 4 ---- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/Command/Handler/CapturePaymentRequestHandler.php b/src/Command/Handler/CapturePaymentRequestHandler.php index 71bcf9dd..c6c91792 100644 --- a/src/Command/Handler/CapturePaymentRequestHandler.php +++ b/src/Command/Handler/CapturePaymentRequestHandler.php @@ -27,7 +27,6 @@ public function __construct( private PayPlugPaymentDataCreator $paymentDataCreator, #[Autowire(service: 'sylius_shop.provider.order_pay.after_pay_url')] private UrlProviderInterface $afterPayUrlProvider, - private UrlGeneratorInterface $urlGenerator, ) {} public function __invoke(CapturePaymentRequest $capturePaymentRequest): void @@ -67,9 +66,6 @@ public function __invoke(CapturePaymentRequest $capturePaymentRequest): void 'cancel_url' => $returnUrl . '?&' . http_build_query(['status' => PayPlugApiClientInterface::STATUS_CANCELED]), ]; - $notificationUrl = $this->urlGenerator->generate('sylius_payment_method_notify', ['code' => $payment->getMethod()?->getCode()], UrlGeneratorInterface::ABSOLUTE_URL); - $data['notification_url'] = $notificationUrl; - $paymentRequest->setPayload($data); try { diff --git a/src/Creator/PayPlugPaymentDataCreator.php b/src/Creator/PayPlugPaymentDataCreator.php index e9e32322..8ba4a9a7 100644 --- a/src/Creator/PayPlugPaymentDataCreator.php +++ b/src/Creator/PayPlugPaymentDataCreator.php @@ -27,6 +27,7 @@ use Sylius\Component\Core\Model\Shipment; use Sylius\Component\Resource\Repository\RepositoryInterface; use Symfony\Component\HttpFoundation\RequestStack; +use Symfony\Component\Routing\Generator\UrlGeneratorInterface; class PayPlugPaymentDataCreator { @@ -41,6 +42,7 @@ public function __construct( private RepositoryInterface $payplugCardRepository, private RequestStack $requestStack, private PayplugFeatureChecker $payplugFeatureChecker, + private UrlGeneratorInterface $urlGenerator, ) { } @@ -83,6 +85,9 @@ public function create( $paymentMethod = $payment->getMethod(); $gatewayFactoryName = $paymentMethod?->getGatewayConfig()?->getFactoryName(); + $notificationUrl = $this->urlGenerator->generate('sylius_payment_method_notify', ['code' => $payment->getMethod()?->getCode()], UrlGeneratorInterface::ABSOLUTE_URL); + $details['notification_url'] = $notificationUrl; + if ( PayPlugGatewayFactory::FACTORY_NAME === $gatewayFactoryName && $paymentMethod instanceof PaymentMethodInterface diff --git a/src/Provider/Payment/ApplePayPaymentProvider.php b/src/Provider/Payment/ApplePayPaymentProvider.php index 74f9b93c..1f195d9e 100644 --- a/src/Provider/Payment/ApplePayPaymentProvider.php +++ b/src/Provider/Payment/ApplePayPaymentProvider.php @@ -5,7 +5,6 @@ namespace PayPlug\SyliusPayPlugPlugin\Provider\Payment; use DateTimeImmutable; -use Doctrine\ORM\EntityManagerInterface; use LogicException; use Payplug\Resource\IVerifiableAPIResource; use Payplug\Resource\Payment; @@ -32,7 +31,6 @@ use Sylius\Component\Payment\PaymentTransitions; use Symfony\Component\DependencyInjection\Attribute\Autowire; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\Routing\RouterInterface; use Webmozart\Assert\Assert; class ApplePayPaymentProvider @@ -45,7 +43,6 @@ public function __construct( #[Autowire('@payplug_sylius_payplug_plugin.api_client.apple_pay')] private PayPlugApiClientInterface $applePayClient, private OrderTokenAssignerInterface $orderTokenAssigner, - private RouterInterface $router, private LoggerInterface $logger, ) { } @@ -81,7 +78,6 @@ public function provide(Request $request, OrderInterface $order): PaymentInterfa ); $paymentData = $paymentDataObject->getArrayCopy(); - $paymentData['notification_url'] = $this->router->generate('sylius_payment_method_notify', ['code' => $payment->getMethod()?->getCode()], RouterInterface::ABSOLUTE_URL); $this->logger->notice('[Payplug] ApplePay payment data', ['data' => $paymentData]); $paymentResource = $this->applePayClient->createPayment($paymentData);