Loading README.md +9 −3 Original line number Diff line number Diff line Loading @@ -31,7 +31,8 @@ Required modules * [Commerce Payment](https://www.drupal.org/project/commerce) Paybox Service specific requirements * PHP OpenSSL must be enabled on your server (see documentation for how to enable it). * PHP OpenSSL must be enabled on your server (see documentation for how to enable it). INSTALLATION Loading @@ -48,8 +49,13 @@ CONFIGURATION 2. Navigate to Commerce > Configuration > Payment > Payment Gateways 3. Add payment gateway 4. Choice Paybox Plugin and save plugin. 5. Testing Data can be found in bank documentation (French doc available only) 5. Testing Data can be found in bank documentation (French doc available only) Regarding the **Entity ID configuration** (mapping and separator), config is stored globally. It means that if you create a site with 2 or more Paybox gateways, they will have the same config for those two specific values. MAINTAINERS ----------- Loading @@ -58,4 +64,4 @@ MAINTAINERS Supporting organizations: * Choosit - https://www.drupal.org/choosit * Spiriit - https://www.drupal.org/spiriit commerce_paybox_payment.services.yml +7 −1 Original line number Diff line number Diff line services: logger.channel.commerce_paybox_payment: parent: logger.channel_base arguments: ['commerce_paybox_payment'] payment_return.access_checker: class: Drupal\commerce_paybox_payment\Access\PaymentReturnAccessCheck arguments: ['@request_stack', '@entity_type.manager'] arguments: ['@request_stack', '@entity_type.manager', '@commerce_paybox_payment.pbx_cmd_ref_helper'] tags: - { name: access_check, applies_to: _payment_return_access_check } commerce_paybox_payment.pbx_cmd_ref_helper: class: Drupal\commerce_paybox_payment\Services\PbxCmdRefHelper arguments: ['@config.factory'] config/install/commerce_paybox_payment.settings.yml 0 → 100644 +2 −0 Original line number Diff line number Diff line entity_id_mapping: payment_id entity_id_separator: '_' config/schema/commerce_paybox_payment.schema.yml +10 −0 Original line number Diff line number Diff line Loading @@ -22,3 +22,13 @@ commerce_payment.commerce_payment_gateway.plugin.paybox: payment_diff: type: integer label: 'deferred payment' commerce_paybox_payment.settings: type: config_object label: 'Commerce Paybox Payment global settings' mapping: entity_id_mapping: type: string label: 'Entity ID mapping' entity_id_separator: type: string label: 'Entity ID separator' src/Access/PaymentReturnAccessCheck.php +31 −5 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ namespace Drupal\commerce_paybox_payment\Access; use Drupal\commerce_paybox_payment\Services\PbxCmdRefHelperInterface; use Drupal\commerce_paybox_payment\SignatureChecker; use Drupal\commerce_payment\Entity\PaymentInterface; use Drupal\Core\Access\AccessResult; Loading @@ -16,7 +17,7 @@ use Symfony\Component\HttpFoundation\RequestStack; class PaymentReturnAccessCheck implements AccessInterface { /** * Request. * The request. * * @var \Symfony\Component\HttpFoundation\Request|null */ Loading @@ -27,7 +28,21 @@ class PaymentReturnAccessCheck implements AccessInterface { * * @var \Drupal\Core\Entity\EntityStorageInterface */ private $commercePaymentStorage; private $paymentStorage; /** * Commerce Payment Gateway Storage. * * @var \Drupal\Core\Entity\EntityStorageInterface */ private $gatewayStorage; /** * Drupal\commerce_paybox_payment\Services\PbxCmdRefHelperInterface Service. * * @var \Drupal\commerce_paybox_payment\Services\PbxCmdRefHelperInterface */ private $pbxCmdRefHelper; /** * PaymentReturnAccessCheck constructor. Loading @@ -36,10 +51,20 @@ class PaymentReturnAccessCheck implements AccessInterface { * Request Stack Service. * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager * EntityTypeManager Service. * @param \Drupal\commerce_paybox_payment\Services\PbxCmdRefHelperInterface $pbxCmdRefHelper * PbxCmdRefHelperInterface Service. * * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException */ public function __construct(RequestStack $requestStack, EntityTypeManagerInterface $entityTypeManager) { public function __construct( RequestStack $requestStack, EntityTypeManagerInterface $entityTypeManager, PbxCmdRefHelperInterface $pbxCmdRefHelper) { $this->request = $requestStack->getCurrentRequest(); $this->commercePaymentStorage = $entityTypeManager->getStorage('commerce_payment'); $this->paymentStorage = $entityTypeManager->getStorage('commerce_payment'); $this->gatewayStorage = $entityTypeManager->getStorage('commerce_payment_gateway'); $this->pbxCmdRefHelper = $pbxCmdRefHelper; } /** Loading @@ -61,7 +86,8 @@ class PaymentReturnAccessCheck implements AccessInterface { return AccessResult::forbidden(); } } $payment = $this->commercePaymentStorage->load($this->request->query->get('Ref')); $paymentId = $this->pbxCmdRefHelper->extractPaymentIdFromRef($this->request); $payment = $this->paymentStorage->load($paymentId); if (!$payment instanceof PaymentInterface) { return AccessResult::forbidden(); } Loading Loading
README.md +9 −3 Original line number Diff line number Diff line Loading @@ -31,7 +31,8 @@ Required modules * [Commerce Payment](https://www.drupal.org/project/commerce) Paybox Service specific requirements * PHP OpenSSL must be enabled on your server (see documentation for how to enable it). * PHP OpenSSL must be enabled on your server (see documentation for how to enable it). INSTALLATION Loading @@ -48,8 +49,13 @@ CONFIGURATION 2. Navigate to Commerce > Configuration > Payment > Payment Gateways 3. Add payment gateway 4. Choice Paybox Plugin and save plugin. 5. Testing Data can be found in bank documentation (French doc available only) 5. Testing Data can be found in bank documentation (French doc available only) Regarding the **Entity ID configuration** (mapping and separator), config is stored globally. It means that if you create a site with 2 or more Paybox gateways, they will have the same config for those two specific values. MAINTAINERS ----------- Loading @@ -58,4 +64,4 @@ MAINTAINERS Supporting organizations: * Choosit - https://www.drupal.org/choosit * Spiriit - https://www.drupal.org/spiriit
commerce_paybox_payment.services.yml +7 −1 Original line number Diff line number Diff line services: logger.channel.commerce_paybox_payment: parent: logger.channel_base arguments: ['commerce_paybox_payment'] payment_return.access_checker: class: Drupal\commerce_paybox_payment\Access\PaymentReturnAccessCheck arguments: ['@request_stack', '@entity_type.manager'] arguments: ['@request_stack', '@entity_type.manager', '@commerce_paybox_payment.pbx_cmd_ref_helper'] tags: - { name: access_check, applies_to: _payment_return_access_check } commerce_paybox_payment.pbx_cmd_ref_helper: class: Drupal\commerce_paybox_payment\Services\PbxCmdRefHelper arguments: ['@config.factory']
config/install/commerce_paybox_payment.settings.yml 0 → 100644 +2 −0 Original line number Diff line number Diff line entity_id_mapping: payment_id entity_id_separator: '_'
config/schema/commerce_paybox_payment.schema.yml +10 −0 Original line number Diff line number Diff line Loading @@ -22,3 +22,13 @@ commerce_payment.commerce_payment_gateway.plugin.paybox: payment_diff: type: integer label: 'deferred payment' commerce_paybox_payment.settings: type: config_object label: 'Commerce Paybox Payment global settings' mapping: entity_id_mapping: type: string label: 'Entity ID mapping' entity_id_separator: type: string label: 'Entity ID separator'
src/Access/PaymentReturnAccessCheck.php +31 −5 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ namespace Drupal\commerce_paybox_payment\Access; use Drupal\commerce_paybox_payment\Services\PbxCmdRefHelperInterface; use Drupal\commerce_paybox_payment\SignatureChecker; use Drupal\commerce_payment\Entity\PaymentInterface; use Drupal\Core\Access\AccessResult; Loading @@ -16,7 +17,7 @@ use Symfony\Component\HttpFoundation\RequestStack; class PaymentReturnAccessCheck implements AccessInterface { /** * Request. * The request. * * @var \Symfony\Component\HttpFoundation\Request|null */ Loading @@ -27,7 +28,21 @@ class PaymentReturnAccessCheck implements AccessInterface { * * @var \Drupal\Core\Entity\EntityStorageInterface */ private $commercePaymentStorage; private $paymentStorage; /** * Commerce Payment Gateway Storage. * * @var \Drupal\Core\Entity\EntityStorageInterface */ private $gatewayStorage; /** * Drupal\commerce_paybox_payment\Services\PbxCmdRefHelperInterface Service. * * @var \Drupal\commerce_paybox_payment\Services\PbxCmdRefHelperInterface */ private $pbxCmdRefHelper; /** * PaymentReturnAccessCheck constructor. Loading @@ -36,10 +51,20 @@ class PaymentReturnAccessCheck implements AccessInterface { * Request Stack Service. * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager * EntityTypeManager Service. * @param \Drupal\commerce_paybox_payment\Services\PbxCmdRefHelperInterface $pbxCmdRefHelper * PbxCmdRefHelperInterface Service. * * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException */ public function __construct(RequestStack $requestStack, EntityTypeManagerInterface $entityTypeManager) { public function __construct( RequestStack $requestStack, EntityTypeManagerInterface $entityTypeManager, PbxCmdRefHelperInterface $pbxCmdRefHelper) { $this->request = $requestStack->getCurrentRequest(); $this->commercePaymentStorage = $entityTypeManager->getStorage('commerce_payment'); $this->paymentStorage = $entityTypeManager->getStorage('commerce_payment'); $this->gatewayStorage = $entityTypeManager->getStorage('commerce_payment_gateway'); $this->pbxCmdRefHelper = $pbxCmdRefHelper; } /** Loading @@ -61,7 +86,8 @@ class PaymentReturnAccessCheck implements AccessInterface { return AccessResult::forbidden(); } } $payment = $this->commercePaymentStorage->load($this->request->query->get('Ref')); $paymentId = $this->pbxCmdRefHelper->extractPaymentIdFromRef($this->request); $payment = $this->paymentStorage->load($paymentId); if (!$payment instanceof PaymentInterface) { return AccessResult::forbidden(); } Loading