Skip to content
Snippets Groups Projects
Commit 39abab5e authored by Nishant Kumar's avatar Nishant Kumar Committed by Eirik Morland
Browse files

Issue #3352897 by Nishant, ramlev, kjankowski, dlevchik, Yuraul, esolitos,...

Issue #3352897 by Nishant, ramlev, kjankowski, dlevchik, Yuraul, esolitos, zaporylie: Make module Drupal 10 ready
parent 4502c88e
No related branches found
Tags 8.x-1.0-rc3
1 merge request!4Make Drupal10 Compatable
Pipeline #54813 passed
Showing
with 111 additions and 20 deletions
......@@ -2,6 +2,6 @@ name: Commerce Payment Extra
type: module
description: Provides expanded payment API.
package: Commerce
core_version_requirement: ^8.7.7 || ^9
core_version_requirement: ^9 || ^10
dependencies:
- commerce:commerce_payment
......@@ -5,7 +5,7 @@
"homepage": "http://drupal.org/project/commerce_payment_extra",
"license": "GPL-2.0-or-later",
"require": {
"drupal/core": "^8.7.7 || ^9",
"drupal/core": "^9 || ^10",
"drupal/commerce": "^2.19",
"drupal/advancedqueue": "^1.0@beta"
},
......
......@@ -2,7 +2,7 @@ name: Commerce Payment Extra - Synchronize orders
type: module
description: Synchronizes Payment status on Order transition.
package: Commerce
core_version_requirement: ^8.7.7 || ^9
core_version_requirement: ^9 || ^10
dependencies:
- commerce_payment_extra:commerce_payment_extra
- commerce:commerce_payment
......
<?php
/**
* @file
* Installation functions for Commerce Payment Extra Order module.
*/
/**
* Set default values for new config.
*
......
<?php
/**
* @file
* Commerce Payment Extra module.
*/
/**
* Implements hook_cron().
*/
......
......@@ -6,7 +6,7 @@ use Drupal\commerce_payment_extra_order\OrderAuthorizedManagerInterface;
use Drush\Commands\DrushCommands;
/**
* Class AuthorizedOrdersCommands.
* Drush commands for processing orders.
*
* @package Drupal\commerce_payment_extra_order
*/
......@@ -30,8 +30,9 @@ class AuthorizedOrdersCommands extends DrushCommands {
}
/**
* Place all orders that have been authorized in full but never placed. This
* can happen if user never returned to the website after completing the
* Place all orders that have been authorized in full but never placed.
*
* This can happen if user never returned to the website after completing the
* payment.
*
* @command commerce-payment-extra-order:place-authorized-orders
......
......@@ -7,9 +7,11 @@ use Drupal\commerce_payment_extra\PaymentManager;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\state_machine\Event\WorkflowTransitionEvent;
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* Provides an event subscriber for handling order cancellation transition.
*/
class CancelOrderEventSubscriber implements EventSubscriberInterface {
/**
......
......@@ -10,6 +10,9 @@ use Drupal\state_machine\Event\WorkflowTransitionEvent;
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* Provides an event subscriber for handling order completion transition.
*/
class CompleteOrderEventSubscriber implements EventSubscriberInterface {
/**
......@@ -80,7 +83,8 @@ class CompleteOrderEventSubscriber implements EventSubscriberInterface {
$amount = $balance->greaterThan($payment->getAmount()) ? $payment->getAmount() : $balance;
// Enqueue payment.
$job = Job::create('commerce_payment_extra_capture', ['payment_id' => $payment->id(), 'amount' => $amount->toArray()]);
$job = Job::create('commerce_payment_extra_capture',
['payment_id' => $payment->id(), 'amount' => $amount->toArray()]);
$queue->enqueueJob($job);
// Get updated balance.
......
......@@ -11,29 +11,42 @@ use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Lock\LockBackendInterface;
use Psr\Log\LoggerInterface;
/**
* Default implementation of the order authorized manager.
*/
class OrderAuthorizedManager implements OrderAuthorizedManagerInterface {
/**
* The entity type manager service.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* Settings.
*
* @var \Drupal\Core\Config\ImmutableConfig
*/
protected $config;
/**
* The time.
*
* @var \Drupal\Component\Datetime\TimeInterface
*/
protected $time;
/**
* The payment manager service.
*
* @var \Drupal\commerce_payment_extra\PaymentManager
*/
protected $paymentManager;
/**
* The logger.
*
* @var \Psr\Log\LoggerInterface
*/
protected $logger;
......@@ -56,12 +69,19 @@ class OrderAuthorizedManager implements OrderAuthorizedManagerInterface {
* OrderAuthorizedManager constructor.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $configFactory
* The config factory.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
* The entity type manager service.
* @param \Drupal\Component\Datetime\TimeInterface $time
* The time.
* @param \Drupal\commerce_payment_extra\PaymentManager $paymentManager
* The payment manager service.
* @param \Psr\Log\LoggerInterface $logger
* The logger.
* @param \Drupal\Core\Database\Connection $database
* The database connection.
* @param \Drupal\Core\Lock\LockBackendInterface $lock
* The lock service.
*/
public function __construct(ConfigFactoryInterface $configFactory, EntityTypeManagerInterface $entityTypeManager, TimeInterface $time, PaymentManager $paymentManager, LoggerInterface $logger, Connection $database, LockBackendInterface $lock) {
$this->config = $configFactory->get('commerce_payment_extra_order.settings');
......@@ -117,6 +137,7 @@ class OrderAuthorizedManager implements OrderAuthorizedManagerInterface {
* least one payment entity attached to it.
*
* @return int[]
* The order IDs.
*/
protected function getOrderIds() {
......@@ -133,7 +154,10 @@ class OrderAuthorizedManager implements OrderAuthorizedManagerInterface {
}
/**
* Processes and places orders.
*
* @param \Drupal\commerce_order\Entity\OrderInterface $order
* The order.
*/
protected function processOrder(OrderInterface $order) {
if ($order->getState()->getId() != 'draft') {
......@@ -180,4 +204,5 @@ class OrderAuthorizedManager implements OrderAuthorizedManagerInterface {
'@order_id' => $order->id(),
]);
}
}
......@@ -8,9 +8,10 @@ namespace Drupal\commerce_payment_extra_order;
interface OrderAuthorizedManagerInterface {
/**
* Process all orders that were authorized in full but never placed. This can
* happened for multiple reasons - one of them being that user paid with an
* app and never returned back to the website. Commerce has a code to
* Process all orders that were authorized in full but never placed.
*
* This can happen for multiple reasons - one of them being that user paid
* with an app and never returned back to the website. Commerce has a code to
* automatically place orders that were paid in full (captured) but not for
* the authorized ones which is where this method becomes helpful.
*/
......
# Configuration file for PHPStan static code checking, see https://phpstan.org .
# PHPStan is triggered on Drupal CI in commit-code-check.sh.
# @see: https://git.drupalcode.org/project/drupal/-/blob/10.0.x/core/phpstan.neon.dist
parameters:
level: 1
ignoreErrors:
# new static() is a best practice in Drupal, so we cannot fix that.
# @see https://www.drupal.org/docs/develop/development-tools/phpstan/handling-unsafe-usage-of-new-static
- "#^Unsafe usage of new static#"
......@@ -3,7 +3,7 @@
namespace Drupal\commerce_payment_extra\Event;
use Drupal\commerce_order\Entity\OrderInterface;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Contracts\EventDispatcher\Event;
/**
* Defines the event for filtering payments.
......
......@@ -2,6 +2,9 @@
namespace Drupal\commerce_payment_extra\Event;
/**
* Defines event types for filtering payments.
*/
final class PaymentExtraEvents {
/**
......
......@@ -9,10 +9,16 @@ use Drupal\commerce_payment_extra\Event\FilterVoidablePaymentsEvent;
use Drupal\commerce_payment_extra\Event\PaymentExtraEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* Provides an event subscriber for filtering payments.
*/
class FilterPaymentsSubscriber implements EventSubscriberInterface {
/**
* Filters capturable payments.
*
* @param \Drupal\commerce_payment_extra\Event\FilterCapturablePaymentsEvent $event
* The event.
*/
public function filterCapturable(FilterCapturablePaymentsEvent $event) {
$payments = [];
......@@ -30,7 +36,10 @@ class FilterPaymentsSubscriber implements EventSubscriberInterface {
}
/**
* Filters voidable payments.
*
* @param \Drupal\commerce_payment_extra\Event\FilterVoidablePaymentsEvent $event
* The event.
*/
public function filterVoidable(FilterVoidablePaymentsEvent $event) {
$payments = [];
......@@ -57,4 +66,5 @@ class FilterPaymentsSubscriber implements EventSubscriberInterface {
];
return $events;
}
}
......@@ -6,11 +6,13 @@ use Drupal\commerce_order\Entity\OrderInterface;
use Drupal\commerce_payment_extra\Event\FilterCapturablePaymentsEvent;
use Drupal\commerce_payment_extra\Event\FilterVoidablePaymentsEvent;
use Drupal\commerce_payment_extra\Event\PaymentExtraEvents;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
/**
* Manages payments.
*/
class PaymentManager {
/**
......@@ -54,13 +56,15 @@ class PaymentManager {
* Loads all Payments assigned to Order that can be Captured.
*
* @param \Drupal\commerce_order\Entity\OrderInterface $order
* The order.
*
* @return \Drupal\commerce_payment\Entity\PaymentInterface[]
* The payments.
*/
public function loadCapturablePaymentsByOrder(OrderInterface $order) {
$payments = $this->entityTypeManager->getStorage('commerce_payment')->loadMultipleByOrder($order);
$event = new FilterCapturablePaymentsEvent($payments, $order);
$this->eventDispatcher->dispatch(PaymentExtraEvents::FILTER_CAPTURABLE_PAYMENTS, $event);
$this->eventDispatcher->dispatch($event, PaymentExtraEvents::FILTER_CAPTURABLE_PAYMENTS);
return $event->getPayments();
}
......@@ -68,13 +72,15 @@ class PaymentManager {
* Loads all Payments assigned to Order that can be Voided.
*
* @param \Drupal\commerce_order\Entity\OrderInterface $order
* The order.
*
* @return \Drupal\commerce_payment\Entity\PaymentInterface[]
* The payments.
*/
public function loadVoidablePaymentsByOrder(OrderInterface $order) {
$payments = $this->entityTypeManager->getStorage('commerce_payment')->loadMultipleByOrder($order);
$event = new FilterVoidablePaymentsEvent($payments, $order);
$this->eventDispatcher->dispatch(PaymentExtraEvents::FILTER_VOIDABLE_PAYMENTS, $event);
$this->eventDispatcher->dispatch($event, PaymentExtraEvents::FILTER_VOIDABLE_PAYMENTS);
return $event->getPayments();
}
......
......@@ -28,11 +28,15 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
class CapturePayment extends JobTypeBase implements ContainerFactoryPluginInterface {
/**
* The entity type manager service.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* The logger.
*
* @var \Psr\Log\LoggerInterface
*/
protected $logger;
......@@ -41,10 +45,15 @@ class CapturePayment extends JobTypeBase implements ContainerFactoryPluginInterf
* CapturePayment constructor.
*
* @param array $configuration
* @param $plugin_id
* @param $plugin_definition
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
* The entity type manager service.
* @param \Psr\Log\LoggerInterface $logger
* The logger.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entityTypeManager, LoggerInterface $logger) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
......@@ -98,4 +107,5 @@ class CapturePayment extends JobTypeBase implements ContainerFactoryPluginInterf
return JobResult::failure($this->t('Unknown error: @message', ['@message' => $e->getMessage()]));
}
}
}
......@@ -8,7 +8,6 @@ use Drupal\advancedqueue\Plugin\AdvancedQueue\JobType\JobTypeBase;
use Drupal\commerce_payment\Exception\HardDeclineException;
use Drupal\commerce_payment\Exception\PaymentGatewayException;
use Drupal\commerce_payment\Plugin\Commerce\PaymentGateway\SupportsVoidsInterface;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Psr\Log\LoggerInterface;
......@@ -27,11 +26,15 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
class VoidPayment extends JobTypeBase implements ContainerFactoryPluginInterface {
/**
* The entity type manager service.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* The logger.
*
* @var \Psr\Log\LoggerInterface
*/
protected $logger;
......@@ -40,10 +43,15 @@ class VoidPayment extends JobTypeBase implements ContainerFactoryPluginInterface
* VoidPayment constructor.
*
* @param array $configuration
* @param $plugin_id
* @param $plugin_definition
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
* The entity type manager service.
* @param \Psr\Log\LoggerInterface $logger
* The logger.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entityTypeManager, LoggerInterface $logger) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment