You are here

public function PaymentMethodAddForm::submitConfigurationForm in Commerce Purchase Order 8

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

src/PluginForm/PurchaseOrder/PaymentMethodAddForm.php, line 40

Class

PaymentMethodAddForm
PaymentMethodAddForm for Purchase Order.

Namespace

Drupal\commerce_purchase_order\PluginForm\PurchaseOrder

Code

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;
  $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.
  // The Purchase Order Gateway will handle processing the form values.
  try {
    $payment_gateway_plugin
      ->createPaymentMethod($payment_method, $values['payment_details']);
  } catch (DeclineException $e) {
    \Drupal::logger('commerce_payment')
      ->warning($e
      ->getMessage());
    throw new DeclineException('We encountered an error processing your payment method. Please verify your details and try again.');
  } catch (PaymentGatewayException $e) {
    \Drupal::logger('commerce_payment')
      ->error($e
      ->getMessage());
    throw new PaymentGatewayException('We encountered an unexpected error processing your payment method. Please try again later.');
  }
}