PaymentForm.php in Payment 8.2
File
modules/payment_form/src/Plugin/Payment/Type/PaymentForm.php
View source
<?php
namespace Drupal\payment_form\Plugin\Payment\Type;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Entity\EntityFieldManagerInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Core\StringTranslation\TranslationInterface;
use Drupal\Core\Url;
use Drupal\payment\EventDispatcherInterface;
use Drupal\payment\Plugin\Payment\Type\PaymentTypeBase;
use Drupal\payment\Response\Response;
use Symfony\Component\DependencyInjection\ContainerInterface;
class PaymentForm extends PaymentTypeBase implements ContainerFactoryPluginInterface {
protected $entityFieldManager;
public function __construct(array $configuration, $plugin_id, array $plugin_definition, EventDispatcherInterface $event_dispatcher, EntityFieldManagerInterface $entity_field_manager, TranslationInterface $string_translation) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $event_dispatcher);
$this->entityFieldManager = $entity_field_manager;
$this->stringTranslation = $string_translation;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('payment.event_dispatcher'), $container
->get('entity_field.manager'), $container
->get('string_translation'));
}
public function defaultConfiguration() {
return [
'bundle' => NULL,
'destination_url' => NULL,
'entity_type_id' => NULL,
'field_name' => NULL,
] + parent::defaultConfiguration();
}
protected function doGetResumeContextResponse() {
return new Response(Url::fromUri($this
->getDestinationUrl()));
}
public function resumeContextAccess(AccountInterface $account) {
return AccessResult::allowed();
}
public function getPaymentDescription() {
$field_definitions = $this->entityFieldManager
->getFieldDefinitions($this
->getEntityTypeId(), $this
->getBundle());
return isset($field_definitions[$this
->getFieldName()]) ? $field_definitions[$this
->getFieldName()]
->getLabel() : new TranslatableMarkup('Unavailable');
}
public function setEntityTypeId($entity_type_id) {
$this->configuration['entity_type_id'] = $entity_type_id;
return $this;
}
public function getEntityTypeId() {
return $this->configuration['entity_type_id'];
}
public function setBundle($bundle) {
$this->configuration['bundle'] = $bundle;
return $this;
}
public function getBundle() {
return $this->configuration['bundle'];
}
public function setFieldName($field_name) {
$this->configuration['field_name'] = $field_name;
return $this;
}
public function getFieldName() {
return $this->configuration['field_name'];
}
public function setDestinationUrl($url) {
$this->configuration['destination_url'] = $url;
return $this;
}
public function getDestinationUrl() {
return $this->configuration['destination_url'];
}
}