iATSPayments / com.iatspayments.civicrm

CiviCRM Extension supporting iATS Payments services
Other
14 stars 38 forks source link

Email Recurring Contribution failure reports to this Email address? #378

Open yurg opened 2 years ago

yurg commented 2 years ago

I've been told no emails have been received to email address configured via "Email Recurring Contribution failure reports to this Email address" ad there are failed recurring contributions found via Contributions search, we can see all kind of REJECT responses. Cron is running and all jobs having "iATS" title are enabled. There is nothing in CiviCRM logs regarding the matter. Is there something else to configure? How do we debug? Thanks.

adixon commented 2 years ago

Interesting, here's the line that sends that email:

https://github.com/iATSPayments/com.iatspayments.civicrm/blob/f9783a6466c9c8adc05cf7f9ee454fca6a44cb6e/api/v3/Job/Iatsrecurringcontributions.php#L316

Note that the 'email recurring contribution failure' only kicks in on the subsequent contributions of a recurring sequence, not the first one. i.e. it's for a successfully set up recurring sequence that fails after the initial one has gone through, so that an administrator can do follow up with new cc information for example.

If you have "all kinds of reject responses", it sounds like you have a bigger issue.

yurg commented 2 years ago

Thank you for notes; what I'm saying is this does not work, no emails being sent, not sure why was this closed.

adixon commented 2 years ago

I can reopen if you can confirm that you understand when those emails are supposed to go out and that they are not going out (i.e. not just that you didn't receive them). I'll also need some more clues like which versions of CiviCRM and the extension you are using, and your hosting setup, and that you've confirmed that you can send transactional emails normally.

yurg commented 2 years ago

@adixon Hi, I think it is time to re-open this one. Let us start from answers to your questions, please see below:

yurg commented 2 years ago

@adixon Just to be sure: please see below, would this number of failures enough to get at least one failure report by email? image

yurg commented 2 years ago

OK so, continuing here, hope this issue will not be deleted. I've been able to fix emails in /api/v3/Job/Iatsrecurringcontributions.php, around line 319

This do not work:

    // $mailparams = array(
    //   'from' => $fromName . ' <' . $fromEmail . '> ',
    //   'to' => 'System Administrator <' . $email_failure_report . '>',
    //   'subject' => ts('iATS Recurring Payment job failure report: ' . date('c')),
    //   'text' => $failure_report_text,
    //   'returnPath' => $fromEmail,
    // );
    // print_r($mailparams);

This works: at least failure recurring payment emails are being sent to admin

$mailparams = [
      'groupName' => 'iATS Email Sender',
      'from' => $fromEmail,
      'toName' => ts('Admin'),
      'toEmail' => $email_failure_report,
      'subject' => ts('iATS Recurring Payment job failure report')  . date('c') ,
      'text' => 'Master Yoda says: Recurring payment errors looks it like. <br />' 
      . $failure_report_text . implode("<br />", $output) 
      . implode("<br />", $mailparams)
      ];
KarinG commented 2 years ago

@yurg - Email notification for recurring contribution failures applies to recurring contributions generated by the API job - not to the initiating contribution. A contribution is not recurring until at least one successful transaction has taken place.

KarinG commented 2 years ago

Unable to process transaction is not a REJ code - so it’s not a failure as in Card reported lost or stolen eg.

KarinG commented 2 years ago

It actually sounds like perhaps it can’t find the tokens in your database.

adixon commented 2 years ago

@yurg thanks for this. Looks like the syntax for sending transactional emails from CiviCRM has changed and I wasn't paying attention. I would have assumed that we would have seen errors in the log in a case like this, but given that your edits have fixed the issue, I'll try some tests of my own and turn it into a patch.

Thanks again, leaving this issue open ...

yurg commented 2 years ago

@adixon @KarinG Thank you for your help. I can confirm $mailparams code changes work, see below print_r($output) I've got by email. A few more questions if I may ( and please let me know if any of them "deserves" its own issue to be opened):

  1. It is not possible to enter multiple email addresses in "email" field for alerts: any reason behind this? What do you say if we allow multiple recipients? Would you accept PR request, should I make corresponded code changes.

  2. There are quite a lot of REJECT: 55 responses: according to this it means ACH REJECT CODES: 55 System Error. @KarinG any chance you know what this is about? I wonder which "system" produces the error: would it be CiviCRM or iATS?

  3. I'm going to add "Send receipt with human-readable error text to a contributor" functionality to /api/v3/Job/Iatsrecurringcontributions.php , where "unlucky" contributors get the same receipt "successful" contributors do, the only difference would be the receipt text with human-readable error message. Since the receipt would contain the same "self-service" tokens/URLs, contributors will be able to edit payment details, etc. Do you think this this functionality would be useful for more than one ( mine) project? I'd seek ways/hooks to implement this as a custom project-specific code in order to keep the code at future iATS updates.

  4. I'd like to add Contact ID and Display Name to the report, we are too lazy to search by contribution ID :-) What would be the best way to do this?

Thank you for your help.


Failed to process recurring contribution id 26: Incorrect CVV2 or expiry date. Failed to process recurring contribution id 28: Charge card expired. Failed to process recurring contribution id 56: REJECT: 55 Failed to process recurring contribution id 77: REJECT: 55 Failed to process recurring contribution id 85: REJECT: 55 Failed to process recurring contribution id 86: REJECT: 55 Failed to process recurring contribution id 89: REJECT: 55 Failed to process recurring contribution id 92: Incorrect CVV2 or expiry date. Failed to process recurring contribution id 116: REJECT: 55 Failed to process recurring contribution id 118: REJECT: 55 Failed to process recurring contribution id 120: Restricted card status, usually on corporate cards restricted to specific sales. Failed to process recurring contribution id 122: REJECT: 55 Failed to process recurring contribution id 128: REJECT: 55

adixon commented 2 years ago

These are great questions, nice to see that you're using this extension. Here are a few quick answers for now:

  1. PR welcomed

  2. There are quite a lot of REJECT: 55 responses: according to this it means ACH REJECT CODES: 55 System Error. @KarinG any chance you know what this is about? I wonder which "system" produces the error: would it be CiviCRM or iATS?

Those are iATS codes. We have a function "reasonMessage" that tries to do some translation, but I haven't looked at it in a long while and I can see it doesn't translate "55":

https://github.com/iATSPayments/com.iatspayments.civicrm/blob/1a41b7eea8d340ee3a7b17a1e8eeba12a006d229/CRM/Iats/iATSServiceRequest.php#L605

  1. PR welcomed for this as well, no need for a separate project.

  2. If you're referring to the emailed failure report, that's all pretty primitive code within the recurring payment job, here:

https://github.com/iATSPayments/com.iatspayments.civicrm/blob/1a41b7eea8d340ee3a7b17a1e8eeba12a006d229/CRM/Iats/Transaction.php#L228

PRs welcomed!

yurg commented 2 years ago

@adixon Thank you for your notes, good to hear proposed changes are useful.

re: #3 "REJECT:55 " - please see grab below, according to what they say it means "System Error" and it is not quite clear for me how to "translate" this in actionable message for contributors. Say, " Incorrect CVV2 or expiry date." message is clear and, combined with self-service links in receipt, it simplifies user experience interaction with the system, while sending "System Error" (or REJECT:55 on this matter) would be confusing at least.

Footer notes here https://content.iatspayments.com/developers-ach-reject-codes contain "the reject reason is dynamically received from the bank." sentence. Does it mean we can't or won't get more detailed response from iATS? Is it bank-specific error code and we need to collect each bank response to extend "reasonMessage" function? Or would it be iATS-specific: in that case we may need a bit more details.

@adixon: may I ask you to ask them for advice, please? Afraid it's not possible for me to use partners@iatspayments.com since I'm not a "partner". Thanks.

image

yurg commented 2 years ago

@adixon More to "reasonMessage" function

The content looks dated indeed (PR welcomed? ;-) ) and according to the latest iATS documentation response messages differ depending on bank location: https://content.iatspayments.com/developers-credit-card-reject-codes-north-america https://content.iatspayments.com/developers-credit-card-reject-codes-uk-europe

I've compared USA vs UK/EU reject reasons, the only significant difference would be in REJ: 6 : USA "Please have cardholder call the number on the back of the card." vs. UK/EU "Transaction not supported by institution."

For UK/EU responses starting from REJ:60 and down it could be some general "Payment gateway error: please try later" or something like that.

There is no mentions of possible bank location detection feature here: https://github.com/iATSPayments/com.iatspayments.civicrm/blob/1a41b7eea8d340ee3a7b17a1e8eeba12a006d229/CRM/Iats/iATSServiceRequest.php#L603 I wonder if it makes sense to dig more into this though: while we have donors across the globe, they will be happy with simple responses like "this bloody thing isn't working at the moment, please send us a cheque".