Problem/Motivation

Right now we are using

<?php
// Assuming the explode is working card_type is at index 51.
        $card_type = $validation_direct_response[51];
?>

To get the credit card type and some people have flag that sometimes they get errors like 'Unsupported credit card type "XXXX1111"'

Proposed resolution

To avoid this error and the 51 hard coding let do a client side credit card type detection. Drupal commerce has #2790551: Implement a JS library for the credit card form which needs review. But the js code var detectType = function (number) in that issue is scoped in the way that it make it hard to reuse this function in an external file.

The ideal would be to refactor the js function so that detectType is reusable then write a patch here which use the refactored detectType. Another solution would be to write a temporary js snippet like the one at https://stackoverflow.com/questions/5911236/identify-card-type-from-card... then remove it when the commerce core one committed.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

nikathone created an issue. See original summary.

chrisrockwell’s picture

Dropping this here...I'm only just now testing this out but I am getting this error. My response has the card type at index 52, not 51

zengenuity’s picture

I came across the same issue as @chrisrockwell. It was inconsistent. I didn't get the error every time, but sometimes the card type is definitely in index 52. Attached is a workaround patch. It's not a good solution at all, but it prevents the form error and lets you complete checkout successfully.

mglaman’s picture

Status: Active » Needs review
mglaman’s picture

So here is our real problem. Here's an example response string

1,1,1,This transaction has been approved.,000000,Y,2000000000,none,Test transaction for 
ValidateCustomerPaymentProfile.,0.00,CC,auth_only,none,John,Doe,,123 Main St.,Bellevue,WA,98004,USA,000-000-0000,,email@example.com,,,,,,,,,0.00,0.00,0.00,FALSE,none,E42C2F81807AA1B581DEA12EB6727604,P,2,,,,,,,,,,,XXXX1111,Visa,,,,,,,,,,,,,,,,,

We explode that string by commas. If any of the data has a , value it will throw off our keys. This could be due to a name or street address with a comma in it. Or name. That would explain why it is bumped up by one key.

I just realized the 7.x module has

  // Make the response an array and trim off the encapsulating characters.
  $response = explode('|', $result);

  for ($i = 0; $i < count($response); $i++) {
    $response[$i] = substr($response[$i], 1, strlen($response[$i]) - 2);
  }

which creates the array structure I assumed and copied.

Our code makes the right key assumption. #3 is a quickfix for when a value has a comma and skews the results.

mglaman’s picture

Hrm. Per https://github.com/AuthorizeNet/sdk-php/blob/master/lib/AuthorizeNetAIM....

It does the same thing $this->_response_array = explode($delimiter, $response);

Then there is:

            $this->account_number       = $this->_response_array[50];
            $this->card_type            = $this->_response_array[51];
            $this->split_tender_id      = $this->_response_array[52];

We need sanitized validationDirectResponse and validationDirectResponseList responses to test this.

mglaman’s picture

Status: Needs review » Needs work
nikathone’s picture

Status: Needs work » Needs review
FileSize
9 KB

Here is patch adding a js to detect credit card type.

mglaman’s picture

Issue tags: +Needs manual testing
mglaman’s picture

nikathone’s picture

Re-rolled the patch based on the fix in #2968123: Validation direct response can be broken by delimiter in customer data. Wasn't sure if should update the tests added on that issue that why I am uploading two patches where the one without any changes in Drupal\Tests\commerce_authnet\Kernel\AcceptJsCreatePaymentMethodTest.php should fail and the one should pass the tests since I added an empty credit card type string('credit_card_type' => '',) to force the server side credit card type detection.

nikathone’s picture

+++ b/src/Plugin/Commerce/PaymentGateway/AcceptJs.php
@@ -584,22 +584,27 @@ class AcceptJs extends OnsiteBase implements SupportsRefundsInterface {
+    if (!($card_type = $payment_details['credit_card_type'])) {

Maybe I should have used !empty() and leave the tests alone. Will wait and what other reviewer think.

Status: Needs review » Needs work

The last submitted patch, 11: will-fail-test-2932486-11.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

nikathone’s picture

Status: Needs work » Needs review

Didn't know how to name the one which will fail test so that drupal bot doesn't change the issue status. So putting the issue back on review for manual manual testing.

The last submitted patch, 3: commerce_authnet-card-type-error-2932486-3.patch, failed testing. View results

The last submitted patch, 8: 2932486-8.patch, failed testing. View results

heddn’s picture

Status: Needs review » Needs work

Needs a re-roll.

heddn’s picture

Status: Needs review » Needs work

The last submitted patch, 18: 2932486-18.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.