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.
Comment | File | Size | Author |
---|---|---|---|
#18 | 2932486-18.patch | 10.6 KB | heddn |
Comments
Comment #2
chrisrockwell CreditAttribution: chrisrockwell commentedDropping 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
Comment #3
zengenuity CreditAttribution: zengenuity at DrupalTutor / Zengenuity commentedI 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.
Comment #4
mglamanComment #5
mglamanSo here is our real problem. Here's an example response string
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
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.
Comment #6
mglamanHrm. 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:
We need sanitized validationDirectResponse and validationDirectResponseList responses to test this.
Comment #7
mglamanComment #8
nikathoneHere is patch adding a js to detect credit card type.
Comment #9
mglamanComment #10
mglamanThe server side detection is going to be fixed in #2968123: Validation direct response can be broken by delimiter in customer data
Comment #11
nikathoneRe-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.Comment #12
nikathoneMaybe I should have used
!empty()
and leave the tests alone. Will wait and what other reviewer think.Comment #14
nikathoneDidn'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.
Comment #17
heddnNeeds a re-roll.
Comment #18
heddn