CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Drupal webforms doesn't allow sending emails if used with some IPN processors
Pages: [1]

Author Topic: Drupal webforms doesn't allow sending emails if used with some IPN processors  (Read 916 times)

capo

  • I post occasionally
  • **
  • Posts: 108
  • Karma: 5
Drupal webforms doesn't allow sending emails if used with some IPN processors
October 14, 2016, 09:19:32 am
Hello,

The Drupal CiviCRM webforms module allows, among other things, to use the standard Drupal webforms capabilities for sending emails after a webform has been submited. But if you use it along with a IPN processor, such as the Redsys one (is the one I'm testing with, particularly), the emails are not sent.

This was one of my latest goal for the Edale sprint, but, as is about to finish, I've decided to write a forum post describing what I've already debugged and asking for ideas on how to address it.

When it works: The pay later use case

If you define a contribution page in CiviCRM and configure it to allow paying later, you'll be able to use this page as a base for a Drupal webform and it will allow you to entirely use the standard Drupal webforms emails tab. Meaning you'll be able to use it for sending Thank you emails or notifications to the site admin when a form is sent.

It that case, the execution logic goes (simplified), goes as follow:
  • File: webform/webform.module, Method: webform_client_form_submit, Line: 3249
  • File: webform/webform.module, Method: webform_client_form_submit, Line: 3344, Calls: webform_submission_send_mail
Where there's a call to webform_submission_send_mail that takes care of sending the email, in case it was configured to do so.

When we use a IPN like Redsys

The case I'm working with, is similar to the one before but considering the use of an IPN payment processor. In particular, I'm trying to see if it works with the Redsys one. In that case, the execution I've been following, goes like that:
  • File: webform/webform.module, Method: webform_client_form_submit, Line: 3249
  • File: webform/webform.module, Method: webform_client_form_submit, Line: 3310, Calls: webform_submission_insert
  • File: webform/includes/webform.submissions.inc, Method: webform_submission_insert, Line: 141
  • File: webform/includes/webform.submissions.inc, Method: webform_submission_insert, Line: 173, Calls: module_invoke_all#webform_submission_insert
  • File: webform_civicrm/webform_civicrm.module, Method: webform_civicrm_webform_submission_insert, Line: 212
  • File: webform_civicrm/webform_civicrm.module, Method: webform_civicrm_webform_submission_insert, Line: 215, Calls: postSave
  • File: webform_civicrm/includes/wf_crm_webform_postprocess.inc, Method: postSave, Line: 213
  • File: webform_civicrm/includes/wf_crm_webform_postprocess.inc, Method: postSave, Line: 239, Calls: submitIPNPayment
  • File: webform_civicrm/includes/wf_crm_webform_postprocess.inc, Method: submitIPNPayment, Line: 1695
  • File: webform_civicrm/includes/wf_crm_webform_postprocess.inc, Method: submitIPNPayment, Line: 1733, Calls: doTransferCheckout
  • File: CRM/Core/Payment/Redsys.php, Method: doTransferCheckout, Line: 112
  • File: CRM/Core/Payment/Redsys.php, Method: doTransferCheckout, Line: 206, Calls: civiExit
This latest civiExit implies that the logic of the pair lines above is being ignored after the pointed lines, being specially relevant in this case that the lines of the webform_client_form_submit method after 3310 are not going to be executed. Considering that the line sending the email is 3344, the observed behaviour is actually the expected: the email isn't being sent.

Any idea on how to solve it?

Thanks!

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: Drupal webforms doesn't allow sending emails if used with some IPN processors
October 14, 2016, 09:44:58 am
This might fix it: https://github.com/colemanw/webform_civicrm/pull/45
Try asking your question on the new CiviCRM help site.

capo

  • I post occasionally
  • **
  • Posts: 108
  • Karma: 5
Re: Drupal webforms doesn't allow sending emails if used with some IPN processors
October 14, 2016, 09:58:05 am
I've just tested it in the same environment I was working and apparently fixes it. Thanks! :-)

capo

  • I post occasionally
  • **
  • Posts: 108
  • Karma: 5
Re: Drupal webforms doesn't allow sending emails if used with some IPN processors
October 18, 2016, 02:22:25 am
Ups! We've just found a use case that still needs attention. Wrong IPN payments, or contributors who cancel the transaction during the IPN processing, would receive the email with the patch as it is.

capo

  • I post occasionally
  • **
  • Posts: 108
  • Karma: 5
Re: Drupal webforms doesn't allow sending emails if used with some IPN processors
October 18, 2016, 02:33:56 am
Would it be possible to do the call in the completeTransaction method of the CRM_Core_Payment_BaseIPN class?

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: Drupal webforms doesn't allow sending emails if used with some IPN processors
October 18, 2016, 05:35:07 am
If there is a hook there we can call it. If not we should add one.
Will you give that a try?
Try asking your question on the new CiviCRM help site.

capo

  • I post occasionally
  • **
  • Posts: 108
  • Karma: 5
Re: Drupal webforms doesn't allow sending emails if used with some IPN processors
October 19, 2016, 02:52:36 am
I've just defined a completeTransaction hook: https://github.com/elcapo/civicrm-core/commit/71d68cec554de42bac271e06389165f77095d3d1

Does it look correct? To test it, I've created an extension implementing it:

Code: [Select]
function myextension_civicrm_completeTransaction(&$input, &$ids, &$objects, &$transaction, $recur) {
  // I'm gathering all of this information...
  $contribution = CRM_Utils_Array::value('contribution', $objects);
  $participant = CRM_Utils_Array::value('participant', $objects);
  $memberships = CRM_Utils_Array::value('membership', $objects);
  $recurContrib = CRM_Utils_Array::value('contributionRecur', $objects);
  $event = CRM_Utils_Array::value('event', $objects);

  // and then ignoring it!
}

It's apparently working but I guess there are at least two things to be done before sending a PR:

  • Add a test to ensure the hook is being called.
  • Add a wiki page to document the new hook.

About the first thing, is there any example on how to test a hook is being called?

capo

  • I post occasionally
  • **
  • Posts: 108
  • Karma: 5
Re: Drupal webforms doesn't allow sending emails if used with some IPN processors
October 19, 2016, 05:32:11 am
Coleman, hi again,

@xurizaemon suggested using the pre and/or post hooks, instead of creating a new one. I've been trying to see if that would be possible but I still don't know how could I know, from within one of this hooks, if the transaction actually comes from a Drupal webform and if it comes from an IPN payment processor. If there are ways to know about it from the webform module (maybe querying the Drupal webform tables?), I guess it would be the best way. Is that possible?

adixon

  • I post frequently
  • ***
  • Posts: 314
  • Karma: 19
    • Blackfly Solutions
Re: Drupal webforms doesn't allow sending emails if used with some IPN processors
October 19, 2016, 07:31:56 am
I've used pre-post hooks for intercepting payments in the past, and they haven't been a very good solution. A complete transaction hook sounds like a nice addition. My issue with the pre/post hook was basically that there were so many cases to consider and handle, across multiple versions - e.g. the initial contribution is now normally created as pending and then completed, but didn't used to be.

On the other hand, for your specific case - you might consider using rules and civicrm entity? You're already using Drupal for webform, so might as well double down on the dependencies [couldn't resist the alliteration]. Of course, I didn't read your posting very carefully, so that might not work either.

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: Drupal webforms doesn't allow sending emails if used with some IPN processors
October 19, 2016, 06:12:25 pm
Eileen suggests adding the to the api instead of that rather unwieldy function with the big fixme in the comments.
Try asking your question on the new CiviCRM help site.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Drupal webforms doesn't allow sending emails if used with some IPN processors

This forum was archived on 2017-11-26.