PaymentReceiveForm.php in Commerce Core 8.2
File
modules/payment/src/PluginForm/PaymentReceiveForm.php
View source
<?php
namespace Drupal\commerce_payment\PluginForm;
use Drupal\commerce_price\Price;
use Drupal\Core\Form\FormStateInterface;
class PaymentReceiveForm extends PaymentGatewayFormBase {
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$payment = $this->entity;
$form['#success_message'] = $this
->t('Payment received.');
$form['amount'] = [
'#type' => 'commerce_price',
'#title' => $this
->t('Amount'),
'#default_value' => $payment
->getAmount()
->toArray(),
'#required' => TRUE,
];
return $form;
}
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
$values = $form_state
->getValue($form['#parents']);
$amount = Price::fromArray($values['amount']);
$payment = $this->entity;
$payment_gateway_plugin = $this->plugin;
$payment_gateway_plugin
->receivePayment($payment, $amount);
}
}