Basic.php in Payment 8.2
File
src/Plugin/Payment/Method/Basic.php
View source
<?php
namespace Drupal\payment\Plugin\Payment\Method;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Utility\Token;
use Drupal\payment\Entity\PaymentInterface;
use Drupal\payment\EventDispatcherInterface;
use Drupal\payment\Plugin\Payment\Status\PaymentStatusManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class Basic extends PaymentMethodBase implements ContainerFactoryPluginInterface, PaymentMethodCapturePaymentInterface, PaymentMethodRefundPaymentInterface, PaymentMethodUpdatePaymentStatusInterface {
protected $paymentStatusManager;
public function __construct(array $configuration, $plugin_id, array $plugin_definition, ModuleHandlerInterface $module_handler, EventDispatcherInterface $event_dispatcher, Token $token, PaymentStatusManagerInterface $payment_status_manager) {
$configuration += $this
->defaultConfiguration();
parent::__construct($configuration, $plugin_id, $plugin_definition, $module_handler, $event_dispatcher, $token, $payment_status_manager);
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('module_handler'), $container
->get('payment.event_dispatcher'), $container
->get('token'), $container
->get('plugin.manager.payment.status'));
}
public function getSupportedCurrencies() {
return TRUE;
}
public function getEntityId() {
return $this->pluginDefinition['entity_id'];
}
public function getExecuteStatusId() {
return $this->pluginDefinition['execute_status_id'];
}
public function getCaptureStatusId() {
return $this->pluginDefinition['capture_status_id'];
}
public function getCapture() {
return $this->pluginDefinition['capture'];
}
public function getRefundStatusId() {
return $this->pluginDefinition['refund_status_id'];
}
public function getRefund() {
return $this->pluginDefinition['refund'];
}
protected function doExecutePayment() {
$this
->getPayment()
->setPaymentStatus($this->paymentStatusManager
->createInstance($this
->getExecuteStatusId()));
$this
->getPayment()
->save();
}
public function doCapturePayment() {
$this
->getPayment()
->setPaymentStatus($this->paymentStatusManager
->createInstance($this
->getCaptureStatusId()));
$this
->getPayment()
->save();
}
public function doCapturePaymentAccess(AccountInterface $account) {
return $this
->getCapture() && $this
->getPayment()
->getPaymentStatus()
->getPluginId() != $this
->getCaptureStatusId();
}
public function doRefundPayment() {
$this
->getPayment()
->setPaymentStatus($this->paymentStatusManager
->createInstance($this
->getRefundStatusId()));
$this
->getPayment()
->save();
}
public function doRefundPaymentAccess(AccountInterface $account) {
return $this
->getRefund() && $this
->getPayment()
->getPaymentStatus()
->getPluginId() != $this
->getRefundStatusId();
}
public function updatePaymentStatusAccess(AccountInterface $account) {
return AccessResult::forbidden();
}
public function getSettablePaymentStatuses(AccountInterface $account, PaymentInterface $payment) {
return [];
}
}
Classes
Name |
Description |
Basic |
A basic payment method that does not transfer money. |