InvalidArgumentException : Invalid credit card type "" dans Drupal\commerce_payment\CreditCard::getType() (ligne 31 de commerce/modules/payment/src/CreditCard.php).

version Commerce: 2.2 / Drupal : 8.4.0

Comments

mh.marouan created an issue. See original summary.

mh.marouan’s picture

Issue summary: View changes
bojanz’s picture

This is a bug in your payment gateway module.

Go to admin/config/development/logging and set error reporting to "All messages, with backtrace information", then reproduce the error again, it should give us more information.

mh.marouan’s picture

I find this error :
Trying to get property of non-object dans Drupal\commerce_payment\Plugin\Commerce\PaymentMethodType\CreditCard->buildLabel() commerce/modules/payment/src/Plugin/Commerce/PaymentMethodType/CreditCard.php ligne 24

bojanz’s picture

Status: Active » Postponed (maintainer needs more info)

And on which page does this error occur? How can we reproduce it?

Some piece of code created an empty payment method, and the code trying to display it can't handle empty values (in CreditCard::buildLabel()). But from your info I was unable to determine more.

bojanz’s picture

Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)
jptillman’s picture

Version: 8.x-2.2 » 8.x-2.13
Status: Closed (cannot reproduce) » Active

I'm experiencing this same error while trying to create a custom payment gateway. Here's my stack trace. Any suggestions on where to go next?

The website encountered an unexpected error. Please try again later.</br></br><em class="placeholder">InvalidArgumentException</em>: Invalid credit card type &quot;&quot; in <em class="placeholder">Drupal\commerce_payment\CreditCard::getType()</em> (line <em class="placeholder">31</em> of <em class="placeholder">modules/contrib/commerce/modules/payment/src/CreditCard.php</em>). <pre class="backtrace">Drupal\commerce_payment\Plugin\Commerce\PaymentMethodType\CreditCard-&gt;buildLabel(Object) (Line: 75)
Drupal\commerce_payment\Entity\PaymentMethod-&gt;label() (Line: 112)
template_preprocess_commerce_payment_method(Array, &#039;commerce_payment_method&#039;, Array) (Line: 287)
Drupal\Core\Theme\ThemeManager-&gt;render(&#039;commerce_payment_method&#039;, Array) (Line: 437)
Drupal\Core\Render\Renderer-&gt;doRender(Array) (Line: 450)
Drupal\Core\Render\Renderer-&gt;doRender(Array) (Line: 450)
Drupal\Core\Render\Renderer-&gt;doRender(Array, ) (Line: 195)
Drupal\Core\Render\Renderer-&gt;render(Array) (Line: 501)
Drupal\Core\Template\TwigExtension-&gt;escapeFilter(Object, Array, &#039;html&#039;, NULL, 1) (Line: 55)
__TwigTemplate_3b7fb15633c44efb2f378211df295da17e1678a75cc7edb9fc8638a32eab24e7-&gt;doDisplay(Array, Array) (Line: 455)
Twig\Template-&gt;displayWithErrorHandling(Array, Array) (Line: 422)
Twig\Template-&gt;display(Array) (Line: 434)
Twig\Template-&gt;render(Array) (Line: 64)
twig_render_template(&#039;modules/contrib/commerce/modules/checkout/templates/commerce-checkout-pane.html.twig&#039;, Array) (Line: 384)
Drupal\Core\Theme\ThemeManager-&gt;render(&#039;commerce_checkout_pane&#039;, Array) (Line: 437)
Drupal\Core\Render\Renderer-&gt;doRender(Array) (Line: 450)
Drupal\Core\Render\Renderer-&gt;doRender(Array, ) (Line: 195)
Drupal\Core\Render\Renderer-&gt;render(Array) (Line: 501)
Drupal\Core\Template\TwigExtension-&gt;escapeFilter(Object, Array, &#039;html&#039;, NULL, 1) (Line: 59)
__TwigTemplate_12934608ab22cbdf18c2ad38f7d281a3e75711c85f5050ccd74887e9e038cd01-&gt;doDisplay(Array, Array) (Line: 455)
Twig\Template-&gt;displayWithErrorHandling(Array, Array) (Line: 422)
Twig\Template-&gt;display(Array) (Line: 434)
Twig\Template-&gt;render(Array) (Line: 64)
twig_render_template(&#039;modules/contrib/commerce/modules/checkout/templates/commerce-checkout-form--with-sidebar.html.twig&#039;, Array) (Line: 384)
Drupal\Core\Theme\ThemeManager-&gt;render(&#039;commerce_checkout_form&#039;, Array) (Line: 437)
Drupal\Core\Render\Renderer-&gt;doRender(Array, ) (Line: 195)
Drupal\Core\Render\Renderer-&gt;render(Array, ) (Line: 226)
Drupal\Core\Render\MainContent\HtmlRenderer-&gt;Drupal\Core\Render\MainContent\{closure}() (Line: 582)
Drupal\Core\Render\Renderer-&gt;executeInRenderContext(Object, Object) (Line: 227)
Drupal\Core\Render\MainContent\HtmlRenderer-&gt;prepare(Array, Object, Object) (Line: 117)
Drupal\Core\Render\MainContent\HtmlRenderer-&gt;renderResponse(Array, Object, Object) (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber-&gt;onViewRenderArray(Object, &#039;kernel.view&#039;, Object)
call_user_func(Array, Object, &#039;kernel.view&#039;, Object) (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher-&gt;dispatch(&#039;kernel.view&#039;, Object) (Line: 156)
Symfony\Component\HttpKernel\HttpKernel-&gt;handleRaw(Object, 1) (Line: 68)
Symfony\Component\HttpKernel\HttpKernel-&gt;handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session-&gt;handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle-&gt;handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache-&gt;pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache-&gt;handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware-&gt;handle(Object, 1, 1) (Line: 52)
Drupal\Core\StackMiddleware\NegotiationMiddleware-&gt;handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel-&gt;handle(Object, 1, 1) (Line: 693)
Drupal\Core\DrupalKernel-&gt;handle(Object) (Line: 19)
</pre>

jptillman’s picture

Following up on this, I discovered that my commerce_payment_method table had a record in it that had been created during a prior test order submission and there was no corresponding record in the commerce_payment_method__card_type table. Deleting that record and clearing cache caused the error to go away.

I suspect it may have happened because my gateway module did not properly implement the createPaymentMethod() method yet and some bad data got inserted. I will post more here if I manage to figure this all out.

Kartagis’s picture

Hello and sorry for hijacking this issue.

I've been having the same problem and my error is

The website encountered an unexpected error. Please try again later.InvalidArgumentException: Invalid credit card type "" in Drupal\commerce_payment\CreditCard::getType() (line 31 of modules/contrib/commerce/modules/payment/src/CreditCard.php). 
Drupal\iyzipay\Plugin\Commerce\PaymentMethodType\FullCreditCard->buildLabel(Object) (Line: 75)
Drupal\commerce_payment\Entity\PaymentMethod->label() (Line: 85)
Drupal\commerce_payment\PaymentOptionsBuilder->buildOptions(Object, Array) (Line: 172)
Drupal\commerce_payment\Plugin\Commerce\CheckoutPane\PaymentInformation->buildPaneForm(Array, Object, Array) (Line: 558)
Drupal\commerce_checkout\Plugin\Commerce\CheckoutFlow\CheckoutFlowWithPanesBase->buildForm(Array, Object, 'order_information')
call_user_func_array(Array, Array) (Line: 519)
Drupal\Core\Form\FormBuilder->retrieveForm('commerce_checkout_flow_multistep_default', Object) (Line: 276)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 217)
Drupal\Core\Form\FormBuilder->getForm(Object, 'order_information') (Line: 94)
Drupal\commerce_checkout\Controller\CheckoutController->formPage(Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 582)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 151)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 68)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 52)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 693)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

I am using Drupal 8.7.7 and Commerce 2.13. The URL after getting the error is checkout/1/order_information, if that helps.

Regards,

deixadilson’s picture

When I went to the orders page of the site I got white screen with "unexpected error" message. Went to reports page and the error was: "InvalidArgumentException: Invalid credit card type "elo" in function Drupal\commerce_payment\CreditCard::getType() (line 31 of file /modules/contrib/commerce/modules/payment/src/CreditCard.php)."
Looks like a custommer paid with a 'elo' credit card and broke the site.

I went to modules/contrib/commerce/modules/payment/src/CreditCard.php file and added the keys bellow to the $definitions array in the function Drupal\commerce_payment\CreditCard::getType()

'elo' => [
  'id' => 'elo',
  'label' => new TranslatableMarkup('elo'),
  'number_prefixes' => [
    '636368','438935','504175','451416','509048','509067','509049',
    '509069','509050','509074','509068','509040','509045','509051',
    '509046','509066','509047','509042','509052','509043','509064',
    '509040','36297','5067','4576','4011',
  ],
  'number_lengths' => [16],
],
'hipercard' => [
  'id' => 'hipercard',
  'label' => new TranslatableMarkup('Hipercard'),
  'number_prefixes' => ['38','60'],
  'number_lengths' => [13, 16, 19],
]

And the problem was solved untill someone pays with a totally different card type. =P

Nathaniel’s picture

It might be nice to have a way to alter that list or default to simply "Card" if the type is null or not found. I ran into some issues with this migrating uc_recurring and had to query the gateway for the card type during the migration since it was not being stored in the D7 database.

jsacksick’s picture

Category: Bug report » Support request
Status: Active » Closed (won't fix)

As explained by Bojan, this seems to be caused by broken custom|contrib code, (For example the stacktrace from comment #9 seems to indicate that the izipay module is not mapping the credit card type properly.

Basically, it's the payment gateway plugin responsability to map a remote credit card type name to a credit card type known/accepted/supported by Drupal commerce.