public function PaymentMethodAddForm::submitConfigurationForm in Commerce Core 8.2
Form submission handler.
Parameters
array $form: An associative array containing the structure of the plugin form as built by static::buildConfigurationForm().
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form. Calling code should pass on a subform state created through \Drupal\Core\Form\SubformState::createForSubform().
Overrides PaymentMethodFormBase::submitConfigurationForm
File
- modules/
payment/ src/ PluginForm/ PaymentMethodAddForm.php, line 65
Class
Namespace
Drupal\commerce_payment\PluginFormCode
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
parent::submitConfigurationForm($form, $form_state);
/** @var \Drupal\commerce_payment\Entity\PaymentMethodInterface $payment_method */
$payment_method = $this->entity;
if ($payment_method
->bundle() == 'credit_card') {
$this
->submitCreditCardForm($form['payment_details'], $form_state);
}
elseif ($payment_method
->bundle() == 'paypal') {
$this
->submitPayPalForm($form['payment_details'], $form_state);
}
$values = $form_state
->getValue($form['#parents']);
/** @var \Drupal\commerce_payment\Plugin\Commerce\PaymentGateway\SupportsStoredPaymentMethodsInterface $payment_gateway_plugin */
$payment_gateway_plugin = $this->plugin;
// The payment method form is customer facing. For security reasons
// the returned errors need to be more generic.
try {
$payment_gateway_plugin
->createPaymentMethod($payment_method, $values['payment_details']);
} catch (DeclineException $e) {
$this->logger
->warning($e
->getMessage());
throw new DeclineException(t('We encountered an error processing your payment method. Please verify your details and try again.'));
} catch (PaymentGatewayException $e) {
$this->logger
->error($e
->getMessage());
throw new PaymentGatewayException(t('We encountered an unexpected error processing your payment method. Please try again later.'));
}
}