public function PaymentMethodEditForm::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/ PaymentMethodEditForm.php, line 50
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') {
$expiration_date = $form_state
->getValue([
'payment_method',
'payment_details',
'expiration',
]);
$payment_method
->get('card_exp_month')
->setValue($expiration_date['month']);
$payment_method
->get('card_exp_year')
->setValue($expiration_date['year']);
$expires = CreditCard::calculateExpirationTimestamp($expiration_date['month'], $expiration_date['year']);
$payment_method
->setExpiresTime($expires);
}
elseif ($payment_method
->bundle() == 'paypal') {
// @todo Decide how to handle saved PayPal payment methods.
}
/** @var \Drupal\commerce_payment\Plugin\Commerce\PaymentGateway\SupportsUpdatingStoredPaymentMethodsInterface $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
->updatePaymentMethod($payment_method);
$payment_method
->save();
} 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.'));
}
}