class Manual in Commerce Core 8.2
Provides the Manual payment gateway.
Plugin annotation
@CommercePaymentGateway(
id = "manual",
label = "Manual",
display_label = "Manual",
modes = {
"n/a" = @Translation("N/A"),
},
forms = {
"add-payment" = "Drupal\commerce_payment\PluginForm\ManualPaymentAddForm",
"receive-payment" = "Drupal\commerce_payment\PluginForm\PaymentReceiveForm",
},
payment_type = "payment_manual",
requires_billing_information = FALSE,
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\commerce_payment\Plugin\Commerce\PaymentGateway\PaymentGatewayBase implements PaymentGatewayInterface, ContainerFactoryPluginInterface uses PluginWithFormsTrait
- class \Drupal\commerce_payment\Plugin\Commerce\PaymentGateway\Manual implements ManualPaymentGatewayInterface
- class \Drupal\commerce_payment\Plugin\Commerce\PaymentGateway\PaymentGatewayBase implements PaymentGatewayInterface, ContainerFactoryPluginInterface uses PluginWithFormsTrait
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of Manual
6 string references to 'Manual'
- commerce_payment.workflows.yml in modules/
payment/ commerce_payment.workflows.yml - modules/payment/commerce_payment.workflows.yml
- EntityPrintOrderRendererTest::testRender in modules/
order/ tests/ src/ Kernel/ EntityPrintOrderRendererTest.php - Tests the rendered build output.
- OrderReceiptTest::setUp in modules/
order/ tests/ src/ Kernel/ OrderReceiptTest.php - PaymentCheckoutTest::setUp in modules/
payment/ tests/ src/ FunctionalJavascript/ PaymentCheckoutTest.php - PaymentGatewayFormTest::testPaymentGatewayCreation in modules/
payment/ tests/ src/ FunctionalJavascript/ PaymentGatewayFormTest.php - Tests using the payment gateway add form.
File
- modules/
payment/ src/ Plugin/ Commerce/ PaymentGateway/ Manual.php, line 34
Namespace
Drupal\commerce_payment\Plugin\Commerce\PaymentGatewayView source
class Manual extends PaymentGatewayBase implements ManualPaymentGatewayInterface {
/**
* The token service.
*
* @var \Drupal\Core\Utility\Token
*/
protected $token;
/**
* Constructs a new Manual object.
*
* @param array $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\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\commerce_payment\PaymentTypeManager $payment_type_manager
* The payment type manager.
* @param \Drupal\commerce_payment\PaymentMethodTypeManager $payment_method_type_manager
* The payment method type manager.
* @param \Drupal\Component\Datetime\TimeInterface $time
* The time.
* @param \Drupal\commerce_price\MinorUnitsConverterInterface $minor_units_converter
* The minor units converter.
* @param \Drupal\Core\Utility\Token $token
* The token service.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, PaymentTypeManager $payment_type_manager, PaymentMethodTypeManager $payment_method_type_manager, TimeInterface $time, MinorUnitsConverterInterface $minor_units_converter, Token $token) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $entity_type_manager, $payment_type_manager, $payment_method_type_manager, $time, $minor_units_converter);
$this->token = $token;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('entity_type.manager'), $container
->get('plugin.manager.commerce_payment_type'), $container
->get('plugin.manager.commerce_payment_method_type'), $container
->get('datetime.time'), $container
->get('commerce_price.minor_units_converter'), $container
->get('token'));
}
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return [
'instructions' => [
'value' => '',
'format' => 'plain_text',
],
] + parent::defaultConfiguration();
}
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form = parent::buildConfigurationForm($form, $form_state);
$form['instructions'] = [
'#type' => 'text_format',
'#title' => $this
->t('Payment instructions'),
'#description' => $this
->t('Shown the end of checkout, after the customer has placed their order.'),
'#default_value' => $this->configuration['instructions']['value'],
'#format' => $this->configuration['instructions']['format'],
'#element_validate' => [
'token_element_validate',
],
'#token_types' => [
'commerce_order',
'commerce_payment',
],
];
$form['token_help'] = [
'#theme' => 'token_tree_link',
'#token_types' => [
'commerce_order',
'commerce_payment',
],
];
return $form;
}
/**
* {@inheritdoc}
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
parent::submitConfigurationForm($form, $form_state);
if (!$form_state
->getErrors()) {
$values = $form_state
->getValue($form['#parents']);
$this->configuration['instructions'] = $values['instructions'];
}
}
/**
* {@inheritdoc}
*/
public function buildPaymentInstructions(PaymentInterface $payment) {
$instructions = [];
if (!empty($this->configuration['instructions']['value'])) {
$instructions_text = $this->token
->replace($this->configuration['instructions']['value'], [
'commerce_order' => $payment
->getOrder(),
'commerce_payment' => $payment,
]);
$instructions = [
'#type' => 'processed_text',
'#text' => $instructions_text,
'#format' => $this->configuration['instructions']['format'],
];
}
return $instructions;
}
/**
* {@inheritdoc}
*/
public function buildPaymentOperations(PaymentInterface $payment) {
$payment_state = $payment
->getState()
->getId();
$operations = [];
$operations['receive'] = [
'title' => $this
->t('Receive'),
'page_title' => $this
->t('Receive payment'),
'plugin_form' => 'receive-payment',
'access' => $payment_state == 'pending',
];
$operations['void'] = [
'title' => $this
->t('Void'),
'page_title' => $this
->t('Void payment'),
'plugin_form' => 'void-payment',
'access' => $payment_state == 'pending',
];
$operations['refund'] = [
'title' => $this
->t('Refund'),
'page_title' => $this
->t('Refund payment'),
'plugin_form' => 'refund-payment',
'access' => in_array($payment_state, [
'completed',
'partially_refunded',
]),
];
return $operations;
}
/**
* {@inheritdoc}
*/
public function createPayment(PaymentInterface $payment, $received = FALSE) {
$this
->assertPaymentState($payment, [
'new',
]);
$payment->state = $received ? 'completed' : 'pending';
$payment
->save();
}
/**
* {@inheritdoc}
*/
public function receivePayment(PaymentInterface $payment, Price $amount = NULL) {
$this
->assertPaymentState($payment, [
'pending',
]);
// If not specified, use the entire amount.
$amount = $amount ?: $payment
->getAmount();
$payment->state = 'completed';
$payment
->setAmount($amount);
$payment
->save();
}
/**
* {@inheritdoc}
*/
public function voidPayment(PaymentInterface $payment) {
$this
->assertPaymentState($payment, [
'pending',
]);
$payment->state = 'voided';
$payment
->save();
}
/**
* {@inheritdoc}
*/
public function refundPayment(PaymentInterface $payment, Price $amount = NULL) {
$this
->assertPaymentState($payment, [
'completed',
'partially_refunded',
]);
// If not specified, refund the entire amount.
$amount = $amount ?: $payment
->getAmount();
$this
->assertRefundAmount($payment, $amount);
$old_refunded_amount = $payment
->getRefundedAmount();
$new_refunded_amount = $old_refunded_amount
->add($amount);
if ($new_refunded_amount
->lessThan($payment
->getAmount())) {
$payment->state = 'partially_refunded';
}
else {
$payment->state = 'refunded';
}
$payment
->setRefundedAmount($new_refunded_amount);
$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. | |
Manual:: |
protected | property | The token service. | |
Manual:: |
public | function |
Form constructor. Overrides PaymentGatewayBase:: |
|
Manual:: |
public | function |
Builds the payment instructions. Overrides HasPaymentInstructionsInterface:: |
|
Manual:: |
public | function |
Builds the available operations for the given payment. Overrides PaymentGatewayBase:: |
|
Manual:: |
public static | function |
Creates an instance of the plugin. Overrides PaymentGatewayBase:: |
|
Manual:: |
public | function |
Creates a payment. Overrides ManualPaymentGatewayInterface:: |
|
Manual:: |
public | function |
Gets default configuration for this plugin. Overrides PaymentGatewayBase:: |
|
Manual:: |
public | function |
Receives the given payment. Overrides ManualPaymentGatewayInterface:: |
|
Manual:: |
public | function |
Refunds the given payment. Overrides SupportsRefundsInterface:: |
|
Manual:: |
public | function |
Form submission handler. Overrides PaymentGatewayBase:: |
|
Manual:: |
public | function |
Voids the given payment. Overrides SupportsVoidsInterface:: |
|
Manual:: |
public | function |
Constructs a new Manual object. Overrides PaymentGatewayBase:: |
|
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PaymentGatewayBase:: |
protected | property | The ID of the parent config entity. | |
PaymentGatewayBase:: |
protected | property | The entity type manager. | |
PaymentGatewayBase:: |
protected | property | The minor units converter. | |
PaymentGatewayBase:: |
protected | property | The parent config entity. | |
PaymentGatewayBase:: |
protected | property | The payment method types handled by the gateway. | |
PaymentGatewayBase:: |
protected | property | The payment type used by the gateway. | |
PaymentGatewayBase:: |
protected | property | The time. | |
PaymentGatewayBase:: |
protected | function | Asserts that the payment method is neither empty nor expired. | |
PaymentGatewayBase:: |
protected | function | Asserts that the payment state matches one of the allowed states. | |
PaymentGatewayBase:: |
protected | function | Asserts that the refund amount is valid. | |
PaymentGatewayBase:: |
public | function |
Builds a label for the given AVS response code and card type. Overrides PaymentGatewayInterface:: |
2 |
PaymentGatewayBase:: |
public | function |
Calculates dependencies for the configured plugin. Overrides DependentPluginInterface:: |
|
PaymentGatewayBase:: |
public | function | ||
PaymentGatewayBase:: |
public | function | ||
PaymentGatewayBase:: |
public | function | ||
PaymentGatewayBase:: |
public | function |
Gets whether the payment gateway collects billing information. Overrides PaymentGatewayInterface:: |
|
PaymentGatewayBase:: |
public | function |
Gets this plugin's configuration. Overrides ConfigurableInterface:: |
|
PaymentGatewayBase:: |
public | function |
Gets the credit card types handled by the gateway. Overrides PaymentGatewayInterface:: |
|
PaymentGatewayBase:: |
protected | function | Gets the default payment gateway forms. | 1 |
PaymentGatewayBase:: |
public | function |
Gets the default payment method type. Overrides PaymentGatewayInterface:: |
|
PaymentGatewayBase:: |
public | function |
Gets the payment gateway display label. Overrides PaymentGatewayInterface:: |
|
PaymentGatewayBase:: |
public | function |
Gets the JS library ID. Overrides PaymentGatewayInterface:: |
|
PaymentGatewayBase:: |
public | function |
Gets the payment gateway label. Overrides PaymentGatewayInterface:: |
|
PaymentGatewayBase:: |
public | function |
Gets the mode in which the payment gateway is operating. Overrides PaymentGatewayInterface:: |
|
PaymentGatewayBase:: |
public | function |
Gets the payment method types handled by the payment gateway. Overrides PaymentGatewayInterface:: |
|
PaymentGatewayBase:: |
public | function |
Gets the payment type used by the payment gateway. Overrides PaymentGatewayInterface:: |
|
PaymentGatewayBase:: |
protected | function | Gets the remote customer ID for the given user. | |
PaymentGatewayBase:: |
public | function |
Gets the supported modes. Overrides PaymentGatewayInterface:: |
|
PaymentGatewayBase:: |
public | function |
Sets the configuration for this plugin instance. Overrides ConfigurableInterface:: |
|
PaymentGatewayBase:: |
protected | function | Sets the remote customer ID for the given user. | |
PaymentGatewayBase:: |
public | function |
Converts the given amount to its minor units. Overrides PaymentGatewayInterface:: |
|
PaymentGatewayBase:: |
public | function |
Form validation handler. Overrides PluginFormInterface:: |
|
PaymentGatewayBase:: |
public | function |
Overrides DependencySerializationTrait:: |
|
PaymentGatewayBase:: |
public | function |
Overrides DependencySerializationTrait:: |
|
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. | |
PluginWithFormsTrait:: |
public | function | ||
PluginWithFormsTrait:: |
public | function | ||
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. |