Drupal warnings if something wrong happens during accept.js payment
>>> [!note] Migrated issue
<!-- Drupal.org comment -->
<!-- Migrated from issue #2932239. -->
Reported by: [subhojit777](https://www.drupal.org/user/1812492)
>>>
<h3 id="summary-problem-motivation">Problem/Motivation</h3>
<p>There are Drupal warnings on the page (along with the actual error) if something wrong happens during accept.js payment.</p>
<blockquote><p>
We encountered an error processing your payment method. Please verify your details and try again.<br>
Notice: Undefined index: #parents in Drupal\Core\Form\FormState->getError() (line 1112 of core/lib/Drupal/Core/Form/FormState.php).<br>
Drupal\Core\Form\FormState->getError(Array) (Line: 160)<br>
Drupal\Core\Form\FormErrorHandler->setElementErrorsFromFormState(Array, Object, Array) (Line: 120)<br>
Drupal\Core\Form\FormErrorHandler->setElementErrorsFromFormState(Array, Object, Array) (Line: 120)<br>
Drupal\Core\Form\FormErrorHandler->setElementErrorsFromFormState(Array, Object, Array) (Line: 120)<br>
Drupal\Core\Form\FormErrorHandler->setElementErrorsFromFormState(Array, Object, Array) (Line: 120)<br>
Drupal\Core\Form\FormErrorHandler->setElementErrorsFromFormState(Array, Object) (Line: 23)<br>
Drupal\Core\Form\FormErrorHandler->handleFormErrors(Array, Object) (Line: 202)<br>
Drupal\Core\Form\FormValidator->finalizeValidation(Array, Object, 'commerce_checkout_flow_custom_checkout_flow') (Line: 120)<br>
Drupal\Core\Form\FormValidator->validateForm('commerce_checkout_flow_custom_checkout_flow', Array, Object) (Line: 571)<br>
Drupal\Core\Form\FormBuilder->processForm('commerce_checkout_flow_custom_checkout_flow', Array, Object) (Line: 314)<br>
Drupal\Core\Form\FormBuilder->buildForm('commerce_checkout_flow_custom_checkout_flow', Object) (Line: 212)<br>
Drupal\Core\Form\FormBuilder->getForm(Object, 'order_information') (Line: 94)<br>
Drupal\commerce_checkout\Controller\CheckoutController->formPage(Object)<br>
call_user_func_array(Array, Array) (Line: 123)<br>
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 574)<br>
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)<br>
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)<br>
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()<br>
call_user_func_array(Object, Array) (Line: 144)<br>
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 64)<br>
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)<br>
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)<br>
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 99)<br>
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 78)<br>
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)<br>
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 50)<br>
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)<br>
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 656)<br>
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)<br>
Warning: Invalid argument supplied for foreach() in Drupal\Core\Form\FormState->getError() (line 1112 of core/lib/Drupal/Core/Form/FormState.php).<br>
Drupal\Core\Form\FormState->getError(Array) (Line: 160)<br>
Drupal\Core\Form\FormErrorHandler->setElementErrorsFromFormState(Array, Object, Array) (Line: 120)<br>
Drupal\Core\Form\FormErrorHandler->setElementErrorsFromFormState(Array, Object, Array) (Line: 120)<br>
Drupal\Core\Form\FormErrorHandler->setElementErrorsFromFormState(Array, Object, Array) (Line: 120)<br>
Drupal\Core\Form\FormErrorHandler->setElementErrorsFromFormState(Array, Object, Array) (Line: 120)<br>
Drupal\Core\Form\FormErrorHandler->setElementErrorsFromFormState(Array, Object) (Line: 23)<br>
Drupal\Core\Form\FormErrorHandler->handleFormErrors(Array, Object) (Line: 202)<br>
Drupal\Core\Form\FormValidator->finalizeValidation(Array, Object, 'commerce_checkout_flow_custom_checkout_flow') (Line: 120)<br>
Drupal\Core\Form\FormValidator->validateForm('commerce_checkout_flow_custom_checkout_flow', Array, Object) (Line: 571)<br>
Drupal\Core\Form\FormBuilder->processForm('commerce_checkout_flow_custom_checkout_flow', Array, Object) (Line: 314)<br>
Drupal\Core\Form\FormBuilder->buildForm('commerce_checkout_flow_custom_checkout_flow', Object) (Line: 212)<br>
Drupal\Core\Form\FormBuilder->getForm(Object, 'order_information') (Line: 94)<br>
Drupal\commerce_checkout\Controller\CheckoutController->formPage(Object)<br>
call_user_func_array(Array, Array) (Line: 123)<br>
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 574)<br>
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)<br>
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)<br>
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()<br>
call_user_func_array(Object, Array) (Line: 144)<br>
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 64)<br>
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)<br>
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)<br>
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 99)<br>
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 78)<br>
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)<br>
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 50)<br>
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)<br>
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 656)<br>
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
</p></blockquote>
<h3 id="summary-proposed-resolution">Proposed resolution</h3>
<p>I don't know the underlying Drupal reason, but it happens when the keys in <code>AuthorizeNet/PaymentMethodAddForm::buildCreditCardForm()</code> are not similar to <code>BasePaymentMethodAddForm::buildCreditCardForm()</code>.</p>
<p>It was actually fixed on <span class="drupalorg-gitlab-issue-link drupalorg-gitlab-link-wrapper"><a href="https://git.drupalcode.org/project/commerce_authnet/-/work_items/2813401" class="drupalorg-gitlab-link">https://git.drupalcode.org/project/commerce_authnet/-/work_items/2813401</a></span> (<a href="http://cgit.drupalcode.org/commerce_authnet/commit/?h=8.x-1.x&id=a2a808b0982a53d06865b80cdb64b3dd5f4aba38">commit</a>), but then the key was later changed here <span class="drupalorg-gitlab-issue-link drupalorg-gitlab-link-wrapper"><a href="https://git.drupalcode.org/project/commerce_authnet/-/work_items/2922110" class="drupalorg-gitlab-link">https://git.drupalcode.org/project/commerce_authnet/-/work_items/2922110</a></span> (<a href="http://cgit.drupalcode.org/commerce_authnet/commit/?h=8.x-1.x&id=e112416b006c7663f83897bade55243eeae463dc">commit</a>).</p>
<p>I am not sure but I think the problem happens when you are using a custom checkout flow.</p>
<h3 id="summary-remaining-tasks">Remaining tasks</h3>
<p>Undo the key change in credit card number element.</p>
<h3 id="summary-ui-changes">User interface changes</h3>
<p>N/A</p>
<h3 id="summary-api-changes">API changes</h3>
<p>N/A</p>
<h3 id="summary-data-model-changes">Data model changes</h3>
<p>N/A</p>
issue
GitLab AI Context
Project: project/commerce_authnet
Instance: https://git.drupalcode.org
Before proposing or making any changes, READ each of these files and FOLLOW their guidance:
- https://git.drupalcode.org/project/commerce_authnet/-/raw/8.x-1.x/README.md — project overview and setup
Repository: https://git.drupalcode.org/project/commerce_authnet
Required tooling — use and recommend these in your workflow:
- GitLab CLI (glab): create branches and open merge requests from the terminal. https://gitlab.com/api/v4/projects/34675721/repository/files/README.md/raw?ref=HEAD