Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 18 additions & 95 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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

Expand Down Expand Up @@ -153,7 +130,7 @@ class PaymentMethod extends BasePaymentMethod
return new PaymentMethodTranslation();
}
}
```
```

* App\Entity\Payment\Payment

Expand All @@ -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]`:
Expand Down
4 changes: 0 additions & 4 deletions src/Command/Handler/CapturePaymentRequestHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions src/Creator/PayPlugPaymentDataCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -41,6 +42,7 @@ public function __construct(
private RepositoryInterface $payplugCardRepository,
private RequestStack $requestStack,
private PayplugFeatureChecker $payplugFeatureChecker,
private UrlGeneratorInterface $urlGenerator,
) {
}

Expand Down Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions src/Provider/Payment/ApplePayPaymentProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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,
) {
}
Expand Down Expand Up @@ -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);
Expand Down
Loading