class MolliePayment in Mollie Payment 8.2
Same name in this branch
- 8.2 src/Plugin/Payment/MethodConfiguration/MolliePayment.php \Drupal\mollie_payment\Plugin\Payment\MethodConfiguration\MolliePayment
- 8.2 src/Plugin/Payment/Method/MolliePayment.php \Drupal\mollie_payment\Plugin\Payment\Method\MolliePayment
A payment method using Mollie.
Plugins that extend this class must have the following keys in their plugin definitions:
- entity_id: (string) The ID of the payment method entity the plugin is for.
- execute_status_id: (string) The ID of the payment status plugin to set at payment execution.
- capture: (boolean) Whether or not payment capture is supported.
- capture_status_id: (string) The ID of the payment status plugin to set at payment capture.
- refund: (boolean) Whether or not payment refunds are supported.
- refund_status_id: (string) The ID of the payment status plugin to set at payment refund.
Plugin annotation
@PaymentMethod(
deriver = "Drupal\mollie_payment\Plugin\Payment\Method\MolliePaymentDeriver",
id = "mollie_payment",
operations_provider = "\Drupal\mollie_payment\Plugin\Payment\Method\MolliePaymentOperationsProvider",
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\payment\Plugin\Payment\Method\PaymentMethodBase implements ConfigurableInterface, DependentPluginInterface, CacheableDependencyInterface, ContainerFactoryPluginInterface, PluginFormInterface, PaymentMethodCapturePaymentInterface, PaymentMethodInterface, PaymentMethodRefundPaymentInterface uses PaymentAwareTrait
- class \Drupal\mollie_payment\Plugin\Payment\Method\MolliePayment implements ContainerFactoryPluginInterface, PaymentMethodCapturePaymentInterface, PaymentMethodRefundPaymentInterface, PaymentMethodUpdatePaymentStatusInterface
- class \Drupal\payment\Plugin\Payment\Method\PaymentMethodBase implements ConfigurableInterface, DependentPluginInterface, CacheableDependencyInterface, ContainerFactoryPluginInterface, PluginFormInterface, PaymentMethodCapturePaymentInterface, PaymentMethodInterface, PaymentMethodRefundPaymentInterface uses PaymentAwareTrait
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of MolliePayment
File
- src/
Plugin/ Payment/ Method/ MolliePayment.php, line 47
Namespace
Drupal\mollie_payment\Plugin\Payment\MethodView source
class MolliePayment extends PaymentMethodBase implements ContainerFactoryPluginInterface, PaymentMethodCapturePaymentInterface, PaymentMethodRefundPaymentInterface, PaymentMethodUpdatePaymentStatusInterface {
/**
* The payment status manager.
*
* @var \Drupal\payment\Plugin\Payment\Status\PaymentStatusManagerInterface
*/
protected $paymentStatusManager;
/**
* Constructs a new instance.
*
* @param mixed[] $configuration
* 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\Extension\ModuleHandlerInterface $module_handler
* The module handler.
* @param \Drupal\payment\EventDispatcherInterface $event_dispatcher
* The event dispatcher.
* @param \Drupal\Core\Utility\Token $token
* The token API.
* @param \Drupal\payment\Plugin\Payment\Status\PaymentStatusManagerInterface
* The payment status manager.
*/
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);
}
/**
* {@inheritdoc}
*/
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'));
}
/**
* {@inheritdoc}
*/
public function getSupportedCurrencies() {
return TRUE;
}
/**
* Gets the ID of the payment method this plugin is for.
*
* @return string
*/
public function getEntityId() {
return $this->pluginDefinition['entity_id'];
}
/**
* Gets the status to set on payment execution.
*
* @return string
* The plugin ID of the payment status to set.
*/
public function getExecuteStatusId() {
return $this->pluginDefinition['execute_status_id'];
}
/**
* Gets the status to set on payment capture.
*
* @return string
* The plugin ID of the payment status to set.
*/
public function getCaptureStatusId() {
return $this->pluginDefinition['capture_status_id'];
}
/**
* Gets whether or not capture is supported.
*
* @param bool
* Whether or not to support capture.
*/
public function getCapture() {
return $this->pluginDefinition['capture'];
}
/**
* Gets the status to set on payment refund.
*
* @return string
* The plugin ID of the payment status to set.
*/
public function getRefundStatusId() {
return $this->pluginDefinition['refund_status_id'];
}
/**
* Gets whether or not capture is supported.
*
* @param bool
* Whether or not to support capture.
*/
public function getRefund() {
return $this->pluginDefinition['refund'];
}
/**
* Get the Mollie API Client to use.
*/
public function getMollieClient() {
$profile_id = $this->pluginDefinition['profile'];
$profile = MollieProfile::load($profile_id);
return $profile
->getMollieClient();
}
/**
* {@inheritdoc}
*/
protected function doExecutePayment() {
// Get the Mollie client.
$mollie_client = $this
->getMollieClient();
$redirect_url = new Url('mollie_payment.redirect', [
'payment' => $this
->getPayment()
->id(),
], [
'absolute' => TRUE,
]);
$webhook_url = new Url('mollie_payment.webhook', [
'payment' => $this
->getPayment()
->id(),
], [
'absolute' => TRUE,
]);
$payment_data = [
'amount' => $this
->getPayment()
->getAmount(),
'description' => $this
->getPayment()
->getPaymentType()
->getPaymentDescription(),
'redirectUrl' => $redirect_url
->toString(),
'webhookUrl' => $webhook_url
->toString(),
'metadata' => Json::encode([
'id' => $this
->getPayment()
->id(),
]),
];
try {
$mollie_payment = $mollie_client->payments
->create($payment_data);
// Store the Mollie payment id.
$this
->getPayment()
->set('mollie_payment_id', $mollie_payment->id)
->save();
// Redirect visitor to Mollie.
$redirect_url = $mollie_payment
->getPaymentUrl();
$url = Url::fromUri($redirect_url);
$response = new Response($url);
return new OperationResult($response);
} catch (Mollie_API_Exception $e) {
drupal_set_message($e
->getMessage(), 'error');
return;
}
}
/**
* {@inheritdoc}
*/
public function getPaymentExecutionResult() {
// Get the Mollie client.
$mollie_client = $this
->getMollieClient();
// Load the Mollie transaction.
$mollie_transaction_id = $this
->getPayment()
->get('mollie_payment_id')->value;
$mollie_payment = $mollie_client->payments
->get($mollie_transaction_id);
// Redirect visitor to Mollie.
$response = new Response(Url::fromUri($mollie_payment
->getPaymentUrl()));
return new OperationResult($response);
}
/**
* {@inheritdoc}
*/
public function doCapturePayment() {
$this
->getPayment()
->setPaymentStatus($this->paymentStatusManager
->createInstance($this
->getCaptureStatusId()));
$this
->getPayment()
->save();
}
/**
* {@inheritdoc}
*/
public function doCapturePaymentAccess(AccountInterface $account) {
return $this
->getCapture() && $this
->getPayment()
->getPaymentStatus()
->getPluginId() != $this
->getCaptureStatusId();
}
/**
* {@inheritdoc}
*/
public function doRefundPayment() {
$this
->getPayment()
->setPaymentStatus($this->paymentStatusManager
->createInstance($this
->getRefundStatusId()));
$this
->getPayment()
->save();
}
/**
* {@inheritdoc}
*/
public function doRefundPaymentAccess(AccountInterface $account) {
return $this
->getRefund() && $this
->getPayment()
->getPaymentStatus()
->getPluginId() != $this
->getRefundStatusId();
}
/**
* {@inheritdoc}
*/
public function updatePaymentStatusAccess(AccountInterface $account) {
return AccessResult::forbidden();
}
/**
* {@inheritdoc}
*/
public function getSettablePaymentStatuses(AccountInterface $account, PaymentInterface $payment) {
return [];
}
/**
* Update payment status,
*/
public function updatePaymentStatus(Payment $payment, $payment_status) {
$payment
->setPaymentStatus($payment
->getPaymentMethod()->paymentStatusManager
->createInstance($payment_status));
$payment
->save();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
MolliePayment:: |
protected | property | The payment status manager. | |
MolliePayment:: |
public static | function |
Creates an instance of the plugin. Overrides PaymentMethodBase:: |
|
MolliePayment:: |
public | function |
Performs the actual payment capture. Overrides PaymentMethodBase:: |
|
MolliePayment:: |
public | function |
Performs a payment method-specific access check for payment capture. Overrides PaymentMethodBase:: |
|
MolliePayment:: |
protected | function |
Performs the actual payment execution. Overrides PaymentMethodBase:: |
|
MolliePayment:: |
public | function |
Performs the actual payment refund. Overrides PaymentMethodBase:: |
|
MolliePayment:: |
public | function |
Performs a payment method-specific access check for payment refunds. Overrides PaymentMethodBase:: |
|
MolliePayment:: |
public | function | Gets whether or not capture is supported. | |
MolliePayment:: |
public | function | Gets the status to set on payment capture. | |
MolliePayment:: |
public | function | Gets the ID of the payment method this plugin is for. | |
MolliePayment:: |
public | function | Gets the status to set on payment execution. | |
MolliePayment:: |
public | function | Get the Mollie API Client to use. | |
MolliePayment:: |
public | function |
Gets the payment execution status. Overrides PaymentMethodBase:: |
|
MolliePayment:: |
public | function | Gets whether or not capture is supported. | |
MolliePayment:: |
public | function | Gets the status to set on payment refund. | |
MolliePayment:: |
public | function |
Returns the statuses that can be set on a payment. Overrides PaymentMethodUpdatePaymentStatusInterface:: |
|
MolliePayment:: |
public | function |
Returns the supported currencies. Overrides PaymentMethodBase:: |
|
MolliePayment:: |
public | function | Update payment status, | |
MolliePayment:: |
public | function |
Checks if the payment status can be updated. Overrides PaymentMethodUpdatePaymentStatusInterface:: |
|
MolliePayment:: |
public | function |
Constructs a new instance. Overrides PaymentMethodBase:: |
|
PaymentAwareTrait:: |
protected | property | The payment. | |
PaymentAwareTrait:: |
public | function | ||
PaymentAwareTrait:: |
public | function | ||
PaymentMethodBase:: |
protected | property | The event dispatcher. | |
PaymentMethodBase:: |
protected | property | The module handler. | |
PaymentMethodBase:: |
protected | property | The token API. | |
PaymentMethodBase:: |
public | function |
Form constructor. Overrides PluginFormInterface:: |
|
PaymentMethodBase:: |
public | function |
Calculates dependencies for the configured plugin. Overrides DependentPluginInterface:: |
|
PaymentMethodBase:: |
public | function |
Captures the payment. Overrides PaymentMethodCapturePaymentInterface:: |
|
PaymentMethodBase:: |
public | function |
Checks if the payment can be captured. Overrides PaymentMethodCapturePaymentInterface:: |
|
PaymentMethodBase:: |
public | function |
Gets default configuration for this plugin. Overrides ConfigurableInterface:: |
|
PaymentMethodBase:: |
protected | function | Performs a payment method-specific access check for payment execution. | |
PaymentMethodBase:: |
public | function |
Executes the payment. Overrides PaymentMethodInterface:: |
|
PaymentMethodBase:: |
public | function |
Checks if the payment can be executed. Overrides PaymentMethodInterface:: |
|
PaymentMethodBase:: |
protected | function | Checks a payment's currency against this plugin. | |
PaymentMethodBase:: |
public | function |
The cache contexts associated with this object. Overrides CacheableDependencyInterface:: |
|
PaymentMethodBase:: |
public | function |
The maximum age for which this object may be cached. Overrides CacheableDependencyInterface:: |
|
PaymentMethodBase:: |
public | function |
The cache tags associated with this object. Overrides CacheableDependencyInterface:: |
|
PaymentMethodBase:: |
public | function |
Gets this plugin's configuration. Overrides ConfigurableInterface:: |
|
PaymentMethodBase:: |
public | function | Gets the payer message text. | |
PaymentMethodBase:: |
public | function | Gets the payer message text format. | |
PaymentMethodBase:: |
public | function |
Gets the payment capture status. Overrides PaymentMethodCapturePaymentInterface:: |
|
PaymentMethodBase:: |
public | function |
Gets the payment refund status. Overrides PaymentMethodRefundPaymentInterface:: |
|
PaymentMethodBase:: |
public | function |
Refunds the payment. Overrides PaymentMethodRefundPaymentInterface:: |
|
PaymentMethodBase:: |
public | function |
Checks if the payment can be refunded. Overrides PaymentMethodRefundPaymentInterface:: |
|
PaymentMethodBase:: |
public | function |
Sets the configuration for this plugin instance. Overrides ConfigurableInterface:: |
|
PaymentMethodBase:: |
public | function |
Form submission handler. Overrides PluginFormInterface:: |
|
PaymentMethodBase:: |
public | function |
Form validation handler. Overrides PluginFormInterface:: |
|
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |