ManualPaymentAddForm.php in Commerce Core 8.2
File
modules/payment/src/PluginForm/ManualPaymentAddForm.php
View source
<?php
namespace Drupal\commerce_payment\PluginForm;
use Drupal\Core\Form\FormStateInterface;
class ManualPaymentAddForm extends PaymentGatewayFormBase {
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$payment = $this->entity;
$order = $payment
->getOrder();
if (!$order) {
throw new \InvalidArgumentException('Payment entity with no order reference given to PaymentAddForm.');
}
$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['received'] = [
'#type' => 'checkbox',
'#title' => $this
->t('The specified amount was already received.'),
];
return $form;
}
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
$values = $form_state
->getValue($form['#parents']);
$payment = $this->entity;
$payment->amount = $values['amount'];
$payment_gateway_plugin = $this->plugin;
$payment_gateway_plugin
->createPayment($payment, $values['received']);
}
}