class OnsitePaymentAddForm in Commerce Core 8.2
Hierarchy
- class \Drupal\Core\Plugin\PluginFormBase implements PluginAwareInterface, PluginFormInterface
- class \Drupal\commerce_payment\PluginForm\PaymentGatewayFormBase implements PaymentGatewayFormInterface uses DependencySerializationTrait, StringTranslationTrait
- class \Drupal\commerce_payment\PluginForm\OnsitePaymentAddForm
- class \Drupal\commerce_payment\PluginForm\PaymentGatewayFormBase implements PaymentGatewayFormInterface uses DependencySerializationTrait, StringTranslationTrait
Expanded class hierarchy of OnsitePaymentAddForm
File
- modules/
payment/ src/ PluginForm/ OnsitePaymentAddForm.php, line 8
Namespace
Drupal\commerce_payment\PluginFormView source
class OnsitePaymentAddForm extends PaymentGatewayFormBase {
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
/** @var \Drupal\commerce_payment\Entity\PaymentInterface $payment */
$payment = $this->entity;
$order = $payment
->getOrder();
if (!$order) {
throw new \InvalidArgumentException('Payment entity with no order reference given to PaymentAddForm.');
}
// The payment amount should not exceed the remaining order balance.
$balance = $order
->getBalance();
$amount = $balance
->isPositive() ? $balance : $balance
->multiply(0);
$form['amount'] = [
'#type' => 'commerce_price',
'#title' => $this
->t('Amount'),
'#default_value' => $amount
->toArray(),
'#required' => TRUE,
];
$form['transaction_type'] = [
'#type' => 'radios',
'#title' => $this
->t('Transaction type'),
'#title_display' => 'invisible',
'#options' => [
'authorize' => $this
->t('Authorize only'),
'capture' => $this
->t('Authorize and capture'),
],
'#default_value' => 'capture',
'#access' => $this->plugin instanceof SupportsAuthorizationsInterface,
];
return $form;
}
/**
* {@inheritdoc}
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
$values = $form_state
->getValue($form['#parents']);
$capture = $values['transaction_type'] == 'capture';
/** @var \Drupal\commerce_payment\Entity\PaymentInterface $payment */
$payment = $this->entity;
$payment->amount = $values['amount'];
/** @var \Drupal\commerce_payment\Plugin\Commerce\PaymentGateway\OnsitePaymentGatewayInterface $payment_gateway_plugin */
$payment_gateway_plugin = $this->plugin;
$payment_gateway_plugin
->createPayment($payment, $capture);
}
}
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 | |
OnsitePaymentAddForm:: |
public | function |
Form constructor. Overrides PluginFormInterface:: |
|
OnsitePaymentAddForm:: |
public | function |
Form submission handler. Overrides PluginFormInterface:: |
|
PaymentGatewayFormBase:: |
protected | property | The form entity. | |
PaymentGatewayFormBase:: |
public | function |
Gets the form entity. Overrides PaymentGatewayFormInterface:: |
|
PaymentGatewayFormBase:: |
public | function |
Gets the form element to which errors should be assigned. Overrides PaymentGatewayFormInterface:: |
1 |
PaymentGatewayFormBase:: |
public | function |
Sets the form entity. Overrides PaymentGatewayFormInterface:: |
|
PluginFormBase:: |
protected | property | The plugin this form is for. | 3 |
PluginFormBase:: |
public | function |
Sets the plugin for this object. Overrides PluginAwareInterface:: |
1 |
PluginFormBase:: |
public | function |
Form validation handler. Overrides PluginFormInterface:: |
2 |
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. |