MolliePaymentDeriver.php in Mollie Payment 8.2
File
src/Plugin/Payment/Method/MolliePaymentDeriver.php
View source
<?php
namespace Drupal\mollie_payment\Plugin\Payment\Method;
use Drupal\Component\Plugin\Derivative\DeriverBase;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
use Drupal\payment\Plugin\Payment\MethodConfiguration\PaymentMethodConfigurationManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class MolliePaymentDeriver extends DeriverBase implements ContainerDeriverInterface {
protected $paymentMethodConfigurationManager;
protected $paymentMethodConfigurationStorage;
public function __construct(EntityStorageInterface $payment_method_configuration_storage, PaymentMethodConfigurationManagerInterface $payment_method_configuration_manager) {
$this->paymentMethodConfigurationStorage = $payment_method_configuration_storage;
$this->paymentMethodConfigurationManager = $payment_method_configuration_manager;
}
public static function create(ContainerInterface $container, $base_plugin_id) {
$entity_manager = $container
->get('entity.manager');
return new static($entity_manager
->getStorage('payment_method_configuration'), $container
->get('plugin.manager.payment.method_configuration'));
}
public function getDerivativeDefinitions($base_plugin_definition) {
$payment_methods = $this->paymentMethodConfigurationStorage
->loadMultiple();
foreach ($payment_methods as $payment_method) {
if ($payment_method
->getPluginId() == 'mollie_payment') {
$configuration_plugin = $this->paymentMethodConfigurationManager
->createInstance($payment_method
->getPluginId(), $payment_method
->getPluginConfiguration());
$this->derivatives[$payment_method
->id()] = [
'id' => $base_plugin_definition['id'] . ':' . $payment_method
->id(),
'active' => $payment_method
->status(),
'label' => $configuration_plugin
->getBrandLabel() ? $configuration_plugin
->getBrandLabel() : $payment_method
->label(),
'profile' => $configuration_plugin
->getProfile() ? $configuration_plugin
->getProfile() : '',
'message_text' => $configuration_plugin
->getMessageText(),
'message_text_format' => $configuration_plugin
->getMessageTextFormat(),
'execute_status_id' => $configuration_plugin
->getExecuteStatusId(),
'capture' => $configuration_plugin
->getCapture(),
'capture_status_id' => $configuration_plugin
->getCaptureStatusId(),
'refund' => $configuration_plugin
->getRefund(),
'refund_status_id' => $configuration_plugin
->getRefundStatusId(),
] + $base_plugin_definition;
}
}
return $this->derivatives;
}
}