diff --git a/src/PluginForm/AcceptJs/PaymentMethodAddForm.php b/src/PluginForm/AcceptJs/PaymentMethodAddForm.php index b74656f..c4fa1bb 100644 --- a/src/PluginForm/AcceptJs/PaymentMethodAddForm.php +++ b/src/PluginForm/AcceptJs/PaymentMethodAddForm.php @@ -257,12 +257,16 @@ class PaymentMethodAddForm extends BasePaymentMethodAddForm { public function submitCreditCardForm(array $element, FormStateInterface $form_state) { // The payment gateway plugin will process the submitted payment details. $values = $form_state->getValues(); + $email = NULL; if (!empty($values['contact_information']['email'])) { - // Then we are dealing with anonymous user. Adding a customer email. - $payment_details = $values['payment_information']['add_payment_method']['payment_details']; - $payment_details['customer_email'] = $values['contact_information']['email']; - $form_state->setValue(['payment_information', 'add_payment_method', 'payment_details'], $payment_details); + $email = $values['contact_information']['email']; + } elseif ($order = $this->routeMatch->getParameter('commerce_order')) { + $email = $order->getEmail(); } + // Add customer email to payment details for use with anonymous users. + $payment_details = $values['payment_information']['add_payment_method']['payment_details']; + $payment_details['customer_email'] = $email; + $form_state->setValue(['payment_information', 'add_payment_method', 'payment_details'], $payment_details); } /**