Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I'm working on the Commerce Realex payment gateway module which can accept both credit cards and debit cards. Debit cards don't require a "security code" (aka CVV) field so I'd like the ability to generate the form field but not have it required. The attached patch allows me to specify this - in much the same way as you currently have for the 'issue number' field.
Comment | File | Size | Author |
---|---|---|---|
#7 | commerce-skip-cvv-validation-if-empty-1810110-7.patch | 809 bytes | jsacksick |
| |||
#4 | 1810110-4-optional_security_code.patch | 1.12 KB | Albert Volkman |
#1 | 1810110-1-optional_security_code.patch | 1.14 KB | stella |
commerce_optional_cvv_code_field.patch | 746 bytes | stella | |
Comments
Comment #1
stella CreditAttribution: stella commentedPatch re-roll to stop the error "You have entered an invalid card security code." appearing too.
Comment #2
rszrama CreditAttribution: rszrama commentedWouldn't this reverse the current default behavior so sites that currently expect it to be required could suddenly see it appearing as not required?
Comment #3
stella CreditAttribution: stella commentedI guess it would depend on each payment gateway definition. If the payment gateway doesn't set it then it's not required. I just implemented it the same way as the issue number. Then in the commerce_realex payment gateway I do a requirement check based on the card type selected.
Maybe there's a better approach, but there needs to be some way to have the CVV field be optional as not all card types require it (e.g. Laser debit card).
Comment #4
Albert Volkman CreditAttribution: Albert Volkman commentedThis patch builds on the previous patch by introducing a new option "no_code". We can add this piece without breaking existing functionality, and then allow payment types implement this as an option (like the patch from #1948540: Make Security code optional).
Comment #5
rszrama CreditAttribution: rszrama commentedI'd like to see the validation in #4 be a little smarter. commerce_payment_validate_credit_card_security_code() isn't the place to add an exception for an empty code; the function assumes it's being passed a CVV to validate, not an empty string. Better would be to not invoke the function to begin with if we know the CVV isn't required and is an empty string.
Comment #6
nickonom CreditAttribution: nickonom commentedCan't believe this was last updated 3 years ago and nobody else posted here. I am also interested in this feature.
Comment #7
jsacksick CreditAttribution: jsacksick at Centarro commentedMaking the actual field not required could easily be achieved by implementing a hook_form_alter().
However, once you do that, the validation will fail because of the isset() check in commerce_payment_credit_card_validate(), I suggest we replace it by a !empty() check, this way, the CVV would only be validated if filled...
Comment #9
rszrama CreditAttribution: rszrama at Centarro commentedSorry this is so long overdue. Committed the patch in #7.