Right now the 7.x-3.x version of the Recurly.js module doesn't display any useful information when a credit card is declined. On the subscribe form you'll get a PHP error in most cases, and at best you'll get the message "Unable to create subscription." with no additional details. On the billing info update form you'll likely trigger an exception.
We should add better exception handling for Recurly_ValidationError exceptions, and display the message we get from the gateway to the user. These errors are generally user correctable things like invalid address, wrong CC number, etc. By not showing them to the user we're likely going to end up driving people away who don't know why their transaction is declined and are un-willing to contact you to ask for more information.
Comment | File | Size | Author |
---|---|---|---|
#13 | Screen Shot 2017-04-10 at 2.17.16 PM.png | 17.95 KB | adamzimmermann |
#13 | display_error_message-2854667-13.patch | 3.33 KB | adamzimmermann |
#10 | interdiff-7-10.txt | 930 bytes | markdorison |
#10 | display_error_message-2854667-10.patch | 2.98 KB | markdorison |
#7 | display_error_message-2854667-7.patch | 2.98 KB | markdorison |
Comments
Comment #2
eojthebraveThis patch adds exception handling for credit card form validation errors. Generally speaking this is handling errors related to the issuing bank or gateway declining the card or a transaction.
You can test the various error codes using the test CC numbers with the Recurly test gateway - https://docs.recurly.com/docs/test
In
recurlyjs_subscribe_form_submit()
I removed the line$recurly_account->create();
that fell outside the try/catch block. This was causing a Recurly_ValidationError exception to be thrown if a card is declined, and the request to be aborted because we're not handling the exception. The call is also not necessary since just below we call$subscription->create()
which will also save the account info.It also adds exception handling for Recurly_ValidationError to both the subscription form and billing info update form. I chose to not log these errors using watchdog after displaying them because the declined transaction, and all it's details, are already logged in Recurly. Though, we could add it to watchdog as well if that's a good idea?
Comment #3
adamzimmermann CreditAttribution: adamzimmermann at Chromatic commentedI installed this patch and tried several invalid card numbers, commented out some token code, and all the errors were handled. I can also confirm that accounts are still created, even with
$recurly_account->create();
removed.Comment #5
markdorisonComment #6
markdorisonComment #7
markdorisonComment #8
adamzimmermann CreditAttribution: adamzimmermann at Chromatic commentedI didn't test this yet, but I did notice one thing.
\Drupal::logger('recurlyjs')
should be called by injecting this service, as opposed to using the\Drupal
class.Comment #9
markdorison@adamzimmermann Good catch; I cleaned up the instance present in this diff. We should create an independent ticket to resolve this elsewhere throughout the module.
Comment #10
markdorisonBad patch; correction attached.
Comment #11
markdorisonComment #12
adamzimmermann CreditAttribution: adamzimmermann at Chromatic commentedComment #13
adamzimmermann CreditAttribution: adamzimmermann at Chromatic commentedI re-rolled this patch to fix a conflict, and also removed
$recurly_account->create();
to match the D7 changes. Without this removed, the form still throws errors, and removing it seems to be safe based upon the discussion above. I can confirm that I see an error when I use4000-0000-0000-0002
as a card number.So this is tested, but I'll let someone else mark it RTBC, as I don't like to mark my own patches as reviewed without someone else confirming they work as intended.
Comment #14
adamzimmermann CreditAttribution: adamzimmermann at Chromatic commentedComment #16
markdorison