Skip to content

Commit

Permalink
Fix configuration documentation (#57)
Browse files Browse the repository at this point in the history
* Fix configuration documentation

* Make notices prettier

* Update configuration.md

* Bump sylius/refund-plugin version

* Bump sylius/refund-plugin version

* Fix psalm errors

* Post readme fixes

* Post readme fixes

* Remove unnecessary service definition

* Specify monolog directories

* Update configuration.md with new screenshots

* Update configuration.md
  • Loading branch information
jakub-groncki authored Jun 6, 2022
1 parent e9f81a7 commit cdb5053
Show file tree
Hide file tree
Showing 17 changed files with 135 additions and 55 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"adyen/php-api-library": "^11.0",
"composer/package-versions-deprecated": "^1.11",
"nyholm/psr7": "^1.4",
"sylius-labs/doctrine-migrations-extra-bundle": "^0.1.4",
"sylius/refund-plugin": "~1.0.0 || ^1.1",
"sylius/resource-bundle": "^1.8",
"sylius/sylius": "^1.10.0 || ^1.11.0",
Expand Down
Binary file modified doc/adyen-allowed-origins.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/adyen-api-key.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed doc/adyen-api-keys.png
Binary file not shown.
Binary file added doc/adyen-client-key.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/adyen-webhook-authentication.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/adyen-webhook-hmac.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
44 changes: 26 additions & 18 deletions doc/configuration.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,35 @@
## Configuration

> :warning: **Notice**
>
> When it comes to configuration of Sylius itself: some countries need to contain the *state* or *province* field to properly handle some of the offered payment methods. These can be configured under Configuration > Countries in the Sylius admin panel.
> :warning: **Notice**
>
> Mind that refunds **from** Adyen do not work. You must refund order items directly from the Sylius admin panel.
> :warning: **Notice**
>
> The plugin resolves the available payment methods based on the base currency of your shop. This means that when USD is the base currency and the user switches over to EUR and, say, Klarna is constrained to EUR, the payment method will not be visible to the customer.
1. Obtain an [Adyen](https://adyen.com) account. If you want to test the gateway, [register a test account](https://www.adyen.com/signup/).

2. Head to API Credentials page:
2. Head over to the API Credentials page:

![API Credentials](adyen-api-credentials.png)

3. Choose an existing merchant account or create new.
3. Choose an existing merchant account or create a new one.

4. Generate an API key + client key:

![API + client key](adyen-api-keys.png)
4. Generate an API key + client key (remember to copy them immediately, they're displayed only once):

![Origin](adyen-api-key.png)
![Origin](adyen-client-key.png)

5. Add an origin; type your shop URL and save (keep in mind that you should have already copied the API key, it's displayed only once):
5. Add an origin; type your shop URL and save it:

![Origin](adyen-allowed-origins.png)

6. Create a new Adyen payment method. Type a merchant account, API and client key obtained in step 4. Also, create a username and password to be used for notifications credentials and choose correct environment, either `live` or `test`. Don't save yet.
6. Create a new Adyen payment method. Fill in the merchant account, API and client keys obtained in step 4. Also, create a username and password to be used for webhook credentials and choose the correct environment, either `live` or `test`. Don't save yet.

![Adyen payment method](payment-method-form.png)

Expand All @@ -25,25 +38,20 @@
![Webhook](adyen-webhooks.png)
![Standard webhook](adyen-webhook-type.png)

8. Type username password typed in step 6:
8. Type the username and password obtained in step 6:

![Credentials](adyen-webhook-authentication.png)

9. Expand `Additional settings section` and generate HMAC key:
9. Expand the `Additional settings section` and generate an HMAC key:

![HMAC](adyen-webhook-hmac.png)

10. Back to the Sylius payment method configuration and paste previously generated HMAC key.
10. Go back to the Sylius payment method configuration and paste the previously generated HMAC key.

11. Save payment method.
11. Save the payment method.

12. Once saved, additional box is being displayed. Copy the URL and paste in Adyen panel:
12. Once saved, an additional box will be displayed. Copy the URL and paste it in the Adyen panel:

![Adyen notifications endpoint](notifications-endpoint.png)

13. Now you're ready to save and test the webhook notification. If everything goes green, you're done and ready to go.


> :warning: **Notice**
>
> When it comes to configuration of Sylius itself: some countries need to contain a "state" or "province" field to properly handle some of the offered payment methods. These can be configured under Configuration > Countries in the Sylius admin panel.
13. Now you're ready to save and test the webhooks. If everything goes green, you're done and ready to go.
62 changes: 35 additions & 27 deletions doc/installation.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
## Installation

1. Require with composer
1. Complete [refund plug-in](https://github.com/Sylius/RefundPlugin) installation steps

2. Require with composer

```bash
composer require bitbag/sylius-adyen-plugin --no-script
composer require bitbag/sylius-adyen-plugin --no-scripts
```
2. When using Symfony flex the proper bundle class is registered in your bundles.php file. Otherwise, add it to your `config/bundles.php` file:
3. When using Symfony flex the proper bundle class will be automatically registered in your bundles.php file. Otherwise, add it to your `config/bundles.php` file:

```php
return [
...
// ...
BitBag\SyliusAdyenPlugin\BitBagSyliusAdyenPlugin::class => ['all' => true],
];
```

3. Import required config in your `config/packages/_sylius.yaml` file:
4. Import required config in your `config/packages/_sylius.yaml` file:

```yaml
# config/packages/_sylius.yaml
Expand All @@ -24,7 +26,7 @@ imports:
- { resource: "@BitBagSyliusAdyenPlugin/Resources/config/config.yaml" }
```
4. Import the routing in your `config/routes.yaml` file:
5. Import the routing in your `config/routes.yaml` file:

```yaml
# config/routes.yaml
Expand All @@ -33,7 +35,19 @@ bitbag_sylius_adyen_plugin:
resource: "@BitBagSyliusAdyenPlugin/Resources/config/routing.yaml"
```

5. Add Adyen payment method as supported refund gateway in `config/packages/_sylius.yaml`
6. Add logging to your environment in config/packages/{dev, prod, staging}/monolog.yaml

```yaml
monolog:
channels: [adyen]
handlers: # Add alongside other handlers you might have
doctrine:
type: service
channels: [adyen]
id: bitbag.sylius_adyen_plugin.logging.monolog.doctrine_handler
```

7. Add Adyen payment method as a supported refund gateway in `config/packages/_sylius.yaml`

```yaml
# config/packages/_sylius.yaml
Expand All @@ -42,9 +56,9 @@ bitbag_sylius_adyen_plugin:
sylius_refund.supported_gateways:
- offline
- adyen
```
```

6. Copy Sylius templates overridden by plug-in to your templates directory (`templates/bundles/`):
8. Copy Sylius templates overridden by plug-in to your templates directory (`templates/bundles/`):

```
mkdir -p templates/bundles/SyliusAdminBundle/
Expand All @@ -54,33 +68,27 @@ cp -R vendor/bitbag/sylius-adyen-plugin/tests/Application/templates/bundles/Syli
cp -R vendor/bitbag/sylius-adyen-plugin/tests/Application/templates/bundles/SyliusShopBundle/* templates/bundles/SyliusShopBundle/
```

7. Complete [refund plug-in](https://github.com/Sylius/RefundPlugin) install steps (e.g. templates and so on)
9. Execute migrations

```
bin/console doctrine:migrations:migrate
```
8. Install assets
10. Install assets
```
bin/console assets:install
```
**Note:** If you are running it on production, add the `-e prod` flag to this command.
9. Synchronize the database
11. Clear cache
```
bin/console doctrine:migrations:migrate
bin/console cache:clear
```
10. [Obtain Adyen credentials and configure payment method](configuration.md)
**Note:** If you are running it on production, add the `-e prod` flag to this command.
11. Add logging to your environment in {dev, prod, staging}/monolog.yaml
12. [Obtain Adyen credentials and configure the payment method](configuration.md)
```yaml
monolog:
channels: [adyen]
handlers: # Add alongside other handlers you might have
doctrine:
type: service
channels: [adyen]
id: bitbag.sylius_adyen_plugin.logging.monolog.doctrine_handler
```
If you want to access the log page, go to /adyen/log.
13. If you want to access the log page, visit /adyen/log.
10 changes: 8 additions & 2 deletions src/Controller/Shop/ProcessNotificationsAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,23 @@ public function __invoke(string $code, Request $request): Response
{
foreach ($this->notificationResolver->resolve($code, $request) as $notificationItem) {
if (!$notificationItem->success) {
$this->logger->info(\sprintf(
$this->logger->error(\sprintf(
'Payment with pspReference [%s] did not return success',
$notificationItem->pspReference ?? ''
));
} else {
$this->logger->debug(\sprintf(
'Payment with pspReference [%s] finished with event code [%s]',
$notificationItem->pspReference ?? '',
$notificationItem->eventCode ?? ''
));
}

try {
$command = $this->notificationCommandResolver->resolve($code, $notificationItem);
$this->dispatcher->dispatch($command);
} catch (NoCommandResolvedException $ex) {
$this->logger->error($ex->getMessage());
$this->logger->error('Tried to dispatch an unknown command');
}
}

Expand Down
18 changes: 17 additions & 1 deletion src/DependencyInjection/BitBagSyliusAdyenExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,30 @@
use Symfony\Component\Config\Definition\ConfigurationInterface;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\HttpKernel\DependencyInjection\ConfigurableExtension;

final class BitBagSyliusAdyenExtension extends ConfigurableExtension
final class BitBagSyliusAdyenExtension extends ConfigurableExtension implements PrependExtensionInterface
{
public const TRANSPORT_FACTORY_ID = 'bitbag.sylius_adyen_plugin.client.adyen_transport_factory';
public const SUPPORTED_PAYMENT_METHODS_LIST = 'bitbag.sylius_adyen_plugin.supported_payment_methods';

public function prepend(ContainerBuilder $container): void
{
$container->prependExtensionConfig('doctrine_migrations', [
'migrations_paths' => [
'BitBag\SyliusAdyenPlugin\Migrations' => __DIR__ . '/../Migrations',
],
]);

$container->prependExtensionConfig('sylius_labs_doctrine_migrations_extra', [
'migrations' => [
'BitBag\SyliusAdyenPlugin\Migrations' => ['Sylius\Bundle\CoreBundle\Migrations'],
],
]);
}

public function loadInternal(array $config, ContainerBuilder $container): void
{
$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,14 @@ private function isAuthenticated(Request $request, array $configuration): bool
\hash_equals($request->getUser() ?? '', $authUser)
&& \hash_equals($request->getPassword() ?? '', $authPassword)
) {
$this->logger->info('Webhook authentication successful');

return true;
}

$this->logger->error('Webhook authentication failed. Check the provided credentials');
$this->logger->error(\sprintf(
'Webhook authentication failed. Check the provided credentials: [%s] [%s]',
$request->getUser() ?? '',
$request->getPassword() ?? ''
));

return false;
}
Expand Down
39 changes: 39 additions & 0 deletions src/Migrations/Version20220426141106.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

namespace BitBag\SyliusAdyenPlugin\Migrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20220426141106 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE TABLE bitbag_adyen_log (id INT AUTO_INCREMENT NOT NULL, level INT NOT NULL, error_code INT NOT NULL, message VARCHAR(1000) NOT NULL, date_time DATETIME NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE bitbag_adyen_reference (id INT AUTO_INCREMENT NOT NULL, refund_payment_id INT DEFAULT NULL, payment_id INT DEFAULT NULL, psp_reference VARCHAR(64) NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME DEFAULT NULL, UNIQUE INDEX UNIQ_7FD033A818C3BB89 (psp_reference), UNIQUE INDEX UNIQ_7FD033A8E739D017 (refund_payment_id), INDEX IDX_7FD033A84C3A3BB (payment_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE bitbag_adyen_token (id INT AUTO_INCREMENT NOT NULL, customer_id INT DEFAULT NULL, payment_method_id INT DEFAULT NULL, identifier VARCHAR(64) NOT NULL, UNIQUE INDEX UNIQ_681C2E9A772E836A (identifier), INDEX IDX_681C2E9A9395C3F3 (customer_id), INDEX IDX_681C2E9A5AA1164F (payment_method_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('ALTER TABLE bitbag_adyen_reference ADD CONSTRAINT FK_7FD033A8E739D017 FOREIGN KEY (refund_payment_id) REFERENCES sylius_refund_refund_payment (id)');
$this->addSql('ALTER TABLE bitbag_adyen_reference ADD CONSTRAINT FK_7FD033A84C3A3BB FOREIGN KEY (payment_id) REFERENCES sylius_payment (id)');
$this->addSql('ALTER TABLE bitbag_adyen_token ADD CONSTRAINT FK_681C2E9A9395C3F3 FOREIGN KEY (customer_id) REFERENCES sylius_customer (id)');
$this->addSql('ALTER TABLE bitbag_adyen_token ADD CONSTRAINT FK_681C2E9A5AA1164F FOREIGN KEY (payment_method_id) REFERENCES sylius_payment_method (id)');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('DROP TABLE bitbag_adyen_log');
$this->addSql('DROP TABLE bitbag_adyen_reference');
$this->addSql('DROP TABLE bitbag_adyen_token');
}
}
2 changes: 1 addition & 1 deletion src/Resources/config/routing.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
bitbag_adyen_localized:
bitbag_adyen_shop:
resource: "@BitBagSyliusAdyenPlugin/Resources/config/routing/shop_routing.yml"
bitbag_adyen_admin:
prefix: /admin
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/config/sylius/blocks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ sylius_ui:
blocks:
adyen_description:
priority: 11
template: '@BitBagSyliusAdyenPlugin/Admin/_description.html.twig'
template: '@BitBagSyliusAdyenPlugin/Admin/_description.html.twig'
2 changes: 0 additions & 2 deletions src/Resources/public/js/dropin.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@
_successfulFetchCallback(dropin, data);
})
.catch(error => {
alert(configuration.translations['bitbag_sylius_adyen_plugin.runtime.payment_failed_try_again']);
_toggleLoader(false);
})
;
Expand Down Expand Up @@ -146,7 +145,6 @@
submitHandler(state, dropin, configuration.path.paymentDetails)
},
onError: (error, component) => {
alert(typeof error['errorText'] !== "undefined" ? error.errorText : 'Unknown error occurred');
}
});
};
Expand Down
2 changes: 2 additions & 0 deletions tests/Application/config/packages/doctrine_migrations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ doctrine_migrations:
storage:
table_storage:
table_name: sylius_migrations
migrations_paths:
'BitBag\SyliusAdyenPlugin\Migrations': '%kernel.project_dir%/../../src/Migrations'

0 comments on commit cdb5053

Please sign in to comment.