PaymentExecutionPaymentMethodManager.php in Payment 8.2
File
src/Plugin/Payment/Method/PaymentExecutionPaymentMethodManager.php
View source
<?php
namespace Drupal\payment\Plugin\Payment\Method;
use Drupal\Component\Plugin\Discovery\DiscoveryInterface;
use Drupal\Component\Plugin\Exception\PluginNotFoundException;
use Drupal\Core\Session\AccountInterface;
use Drupal\payment\Entity\PaymentInterface;
use Drupal\payment\Plugin\Payment\PaymentAwarePluginManagerDecorator;
class PaymentExecutionPaymentMethodManager extends PaymentAwarePluginManagerDecorator implements PaymentMethodManagerInterface {
protected $account;
protected $decoratedPaymentMethodManager;
public function __construct(PaymentInterface $payment, AccountInterface $account, PaymentMethodManagerInterface $payment_method_manager, DiscoveryInterface $discovery = NULL) {
parent::__construct($payment, $payment_method_manager, $discovery);
$this->account = $account;
$this->decoratedPaymentMethodManager = $payment_method_manager;
}
protected function processDecoratedDefinitions(array $decorated_definitions) {
$processed_definitions = [];
foreach ($decorated_definitions as $plugin_id => $decorated_definition) {
$payment_method = $this
->createInstance($plugin_id);
if ($payment_method
->executePaymentAccess($this->account)
->isAllowed()) {
$processed_definitions[$plugin_id] = $decorated_definition;
}
}
return $processed_definitions;
}
public function getOperationsProvider($plugin_id) {
if ($this
->hasDefinition($plugin_id)) {
return $this->decoratedPaymentMethodManager
->getOperationsProvider($plugin_id);
}
else {
throw new PluginNotFoundException($plugin_id);
}
}
}