CRM-9996 Refactor / tidy Contribution receipt mail

    Details

    • Type: Improvement
    • Status: Done/Fixed
    • Priority: Minor
    • Resolution: Fixed/Completed
    • Affects Version/s: 4.2.0
    • Fix Version/s: 4.4.0
    • Component/s: None
    • Labels:
      None

      Description

      GOAL - don't have other objects call BaseIPN to send emails (e.g. send pdf emails)

      Two main functionalities being called within BaseIPN from outside

      1) Load Related Objects
      2) Construct email - by applying tokens to tpl. - should return html to calling function so it can email or pdf or otherwise render

      Also
      3) related requirement for process contribution with related objects (e.g. participant) to be available to API &
      4) API should be able to construct email (need to debate w X how that would look in terms of params)

      Relevant existing functions (generally all do some of the two functionalities listed

      CRM_Core_Payment_BaseIPN::- validate (calls load objects not important in itself)
      CRM_Core_Payment_BaseIPN::loadObjects
      CRM_Core_Payment_BaseIPN::completeTransaction
      CRM_Core_Payment_BaseIPN::pending
      CRM_Core_Payment_BaseIPN::failed
      CRM_Core_Payment_BaseIPN::cancelled
      CRM_Core_Payment_BaseIPN::updatecontributionStatus
      CRM_Contribute_BAO_Contribution_Utils::ProcessAPIContribution (called by paypal & google for BaseIPN like stuff)
      CRM_Contribute_BAO_Contribution_Utils::FormatAPIParams (probably should be function on Paypal class)
      CRM_Contribute_Form_Contribution::updateRelatedComponent
      CRM_Contribute_Form_Contribution_Confirm::processContribution
      CRM_Contribute_BAO_ContributionPage::sendmail
      CRM_Contribute_BAO_Contribution::add
      CRM_Contribute_BAO_Contribution::create
      CRM_Contribute_BAO_Contribution::getConmponentFields
      CRM_Contribute_BAO_Contribution::transitionComponents
      CRM_Contribute_Import_Parser_Contribution::processpledgepayments

      Places in the code where BaseIPN is called
      CRM_Event_Form_Task_Batch::updatePendingOnlineContribution
      CRM_Contribute_Form_Task_Status::postProcess
      CRM_Contribute_Form_Task_PDF::postProcess
      CRM_Contribute_BAO_ContributionRecur::cancelrecurcontribution
      CRM_Contribute_BAO_Contribution::transitionComponents - YES really - the core contribution BAO object calls the payment processor Instant payment Notification class - Tail, Dog anyone?

      So, I think that CRM_Contribute_BAO_Contribution should have these functions

      loadRelatedObjects -
      – initially code from CRM_Core_Payment_BaseIPN::loadObjects but stash an array of BAO objects in an array called objects or related objects which is a property of

      – composeHtmlMessage
      takes a messageId OR message_text & swaps out tokens based on contribution object & related Objects. If no message passed in defaults to component relevant receipt email (e.g. if membership exists it uses online membership email).

      – sendEmail - wrapper for composeHtmlMessage that sends result

      – renderPdf - wrapper for composeHtmlMessage that sends pdf

      – processRelatedObjects (called by create)

      These should also apply to membership etc & we need to define api actions

      Step 1 - write test for load objects on BaseIPN
      Step 2 move guts of load objects to Contribute & call it from BaseIPN
      Step 3 Write test calling BaseIPN :send mail & returning Html
      Step 4 move guts of BaseIPN compose to Contribute & call from BaseIPN
      Step 5 Create pdf & email as wrapper functions, change receipt Task to call them

        Attachments

          Activity

          [CRM-9996] Refactor / tidy Contribution receipt mail
          Eileen McNaughton added a comment -
          Eileen McNaughton added a comment -

          This is started in 4.2 but will continue in 4.3

          David Greenberg added a comment -

          Tracking down notices in CRM_Contribute_BAO_Contribution::loadRelatedObjects() - the $contribution object referenced on line 1895 is never defined (hence the notices below). This seems like a copy/paste error - and makes me a bit concerned about other changes under this issue. Evidently this type of mistake is not showing up in the unit tests ??? I'm also puzzled as to why this line isn't triggering an error in my logfile since contributionType->id is never defined:

          if (!$contributionType->find(TRUE))

          ==== notices ====
          Notice: Undefined variable: contribution in CRM_Contribute_BAO_Contribution->loadRelatedObjects() (line 1895 of /Users/dgg/svn/crm_v4.2/CRM/Contribute/BAO/Contribution.php).
          Notice: Trying to get property of non-object in CRM_Contribute_BAO_Contribution->loadRelatedObjects() (line 1895 of /Users/dgg/svn/crm_v4.2/CRM/Contribute/BAO/Contribution.php).

          Eileen McNaughton added a comment -

          Changing to 4.2 for review of Dave's comment to take place now.

          Would be good if unit tests showed E-Notice - but Actually -I can't see the IPN related tests on the server? Maybe I'm a bit blind

          http://tests.dev.civicrm.org/trunk/results-CRM/

          Eileen McNaughton added a comment -

          Hmm - I realise that I moved on from this to deal with something else & thought I'd left it more stable than I did. I have committed some fixes for the items identified & some extra tests but will do a bit more over the next few days.

          Eileen McNaughton added a comment -

          Have added a bunch more test & I see someone else went through to - will add more tests & tidy code in 4.3

          Eileen McNaughton added a comment -

          api for contribute sendconfirmation now available

            People

            • Assignee:
              Eileen McNaughton
              Reporter:
              Eileen McNaughton

              Dates

              • Created:
                Updated:
                Resolved: