Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev/core#521: PCP Send notification after successful contribution payment #19096

Conversation

nishant-bhorodia
Copy link
Contributor

@nishant-bhorodia nishant-bhorodia commented Dec 3, 2020

Overview

Owner notification email sending before payment. When you are the owner of a fundraising page, you are supposed to receive a notification email after a successful donation has been made to your fundraising page. However when you are using a payment processor that navigates you out from civicrm to its own payment page (like sagepay, or paypal standard) the owner notification is sent before the payment has been made.
Core issue: https://lab.civicrm.org/dev/core/-/issues/521

Before

PCP Owner received notification for contribution before the payment was done.

After

PCP Owner receives notification only after successful contribution payment is done.

Technical Details

CRM_Contribute_Form_Contribution_Confirm::pcpNotifyOwner function will be called at two places now.

  1. in protected static function processPCP($pcp, $contribution) for backend pcp contributions.
  2. in public static function completeOrder for contributions made by using PCP page.

@civibot
Copy link

civibot bot commented Dec 3, 2020

(Standard links)

@civibot civibot bot added the master label Dec 3, 2020
@yashodha
Copy link
Contributor

yashodha commented Dec 4, 2020

@nishant-bhorodia

Are the failing tests related?

@@ -4340,6 +4340,16 @@ public static function completeOrder($input, $ids, $contribution, $isPostPayment
$contribution->contribution_status_id = $contributionParams['contribution_status_id'];

CRM_Core_Error::debug_log_message('Contribution record updated successfully');
$contributionSoft = civicrm_api3('ContributionSoft', 'get', [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the v4 api for ContributionSoft is about to be merged let's use that

#19083

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @eileenmcnaughton
I will update the code to use api4 then :)

$contributionSoft = (object) $contributionSoft['values'][0];
//Send notification to owner for PCP
if ($contributionSoft->pcp_id) {
CRM_Contribute_Form_Contribution_Confirm::pcpNotifyOwner($contribution, $contributionSoft);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is only called from one place in the code so we can easily change it to receive an array rather than cast to an object

@eileenmcnaughton
Copy link
Contributor

Test fails are enotices as $contributionSoft['values'][0] may not be set - but I think it is better to switch to apiv4 here anyway as we are trying to use apiv4 on new code

@eileenmcnaughton
Copy link
Contributor

Also - I should say - I think this is the right thing in terms of moving the code to a more appropriate location. I am trying to find out if there is any test cover in #19113

@nishant-bhorodia
Copy link
Contributor Author

nishant-bhorodia commented Dec 4, 2020

Hey @yashodha @eileenmcnaughton
Thanks for reviewing, I think in terms of changes, we want to do the following:

  1. Use API4 for contributioSoft
  2. Add a check to see if the value exists
  3. Change signature for pcpNotifyOwner function to use array instead of object

Please let me know if we need any other changes?
Thanks!!

eileenmcnaughton added a commit to eileenmcnaughton/civicrm-core that referenced this pull request Dec 4, 2020
I wound up adding PcpBlock v4 api to write the test

In support of
civicrm#19096
eileenmcnaughton added a commit to eileenmcnaughton/civicrm-core that referenced this pull request Dec 4, 2020
I wound up adding PcpBlock v4 api to write the test

In support of
civicrm#19096
@eileenmcnaughton
Copy link
Contributor

@nishant-bhorodia that sounds right - might need to pull #19083 in or wait for it to be merged first

I added a test here #19117

@nishant-bhorodia
Copy link
Contributor Author

Many Thanks @eileenmcnaughton :)

@eileenmcnaughton
Copy link
Contributor

the soft credit api is merged now

eileenmcnaughton added a commit to eileenmcnaughton/civicrm-core that referenced this pull request Dec 5, 2020
I wound up adding PcpBlock v4 api to write the test

In support of
civicrm#19096
eileenmcnaughton added a commit to eileenmcnaughton/civicrm-core that referenced this pull request Dec 5, 2020
I wound up adding PcpBlock v4 api to write the test

In support of
civicrm#19096
@nishant-bhorodia nishant-bhorodia force-pushed the Issue#521-send-owner-notification-after-successful-payment branch 5 times, most recently from fbba50e to d185010 Compare December 15, 2020 12:09
@nishant-bhorodia
Copy link
Contributor Author

Thanks @eileenmcnaughton 😄
Updated the code to use civicrm api 4 instead.
thanks!

@eileenmcnaughton
Copy link
Contributor

thanks @nishant-bhorodia - still test fails :-(

@nishant-bhorodia
Copy link
Contributor Author

oh :( checking!

eileenmcnaughton added a commit to eileenmcnaughton/civicrm-core that referenced this pull request Dec 23, 2020
This is a partial of civicrm#19096 which requires contributionSoft to be an array & just simplifies that commit (which
is still failing tests
@nishant-bhorodia nishant-bhorodia force-pushed the Issue#521-send-owner-notification-after-successful-payment branch from 923d84b to ab5f980 Compare December 28, 2020 10:37
@mattwire mattwire changed the title Issue#521: Send notification after successful contribution payment dev/core#521: Send notification after successful contribution payment Dec 28, 2020
@nishant-bhorodia nishant-bhorodia force-pushed the Issue#521-send-owner-notification-after-successful-payment branch 2 times, most recently from da706e9 to ea8190f Compare December 30, 2020 10:27
@eileenmcnaughton
Copy link
Contributor

@nishant-bhorodia ideally completeOrder should be hit in both flows. The problem I see in create is that an unrelated edit could trigger it too

@nishant-bhorodia nishant-bhorodia force-pushed the Issue#521-send-owner-notification-after-successful-payment branch 2 times, most recently from b6038fc to 731c3be Compare March 24, 2021 10:45
@nishant-bhorodia
Copy link
Contributor Author

Hello @eileenmcnaughton
Hope you are well.
Sorry for delay in getting back to this, got side tracked!!
I have made few changes to this please can you have a look when you get a chance?
thanks!!

@nishant-bhorodia
Copy link
Contributor Author

gentle reminder @eileenmcnaughton :)
Many thanks!!

@eileenmcnaughton
Copy link
Contributor

test this please

//Send notification to owner for PCP
if ($contributionSoft->pcp_id && empty($pcpId)) {
// Send notification to owner for PCP.
if ($contributionSoft->pcp_id && empty($pcpId) && empty($contribution->contribution_page_id)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nishant-bhorodia I feel like this might be the wrong extra criteria to add. Does it work if instead we change the contribution status? (if it's still pending we should not send)

Copy link
Contributor Author

@nishant-bhorodia nishant-bhorodia Apr 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @eileenmcnaughton
thanks for reviewing!

I have added another condition to check if the status is completed.
The two conditions I added does the following:

  1. Check if the contribution is made without contribution page i.e., from the admin area.
  2. Check if the status is completed.

Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @eileenmcnaughton ,
Hope you are well!!
Please can I ask if the change looks fine?
thanks!!

@nishant-bhorodia nishant-bhorodia force-pushed the Issue#521-send-owner-notification-after-successful-payment branch from 731c3be to d5bd28f Compare April 7, 2021 12:29
@eileenmcnaughton
Copy link
Contributor

There is a test failure

CRM_Core_Payment_AuthorizeNetIPNTest::testIPNPaymentMembershipRecurSuccessNoLeakage
Undefined variable: contribution

/home/jenkins/bknix-dfl/build/core-19096-8dde/web/sites/all/modules/civicrm/CRM/Contribute/BAO/Contribution.php:4290
/home/jenkins/bknix-dfl/build/core-19096-8dde/web/sites/all/modules/civicrm/CRM/Core/Payment/AuthorizeNetIPN.php:177
/home/jenkins/bknix-dfl/build/core-19096-

@ahed-compucorp ahed-compucorp force-pushed the Issue#521-send-owner-notification-after-successful-payment branch from d5bd28f to 09e3798 Compare June 1, 2021 09:05
@ahed-compucorp ahed-compucorp force-pushed the Issue#521-send-owner-notification-after-successful-payment branch from 09e3798 to 9fb8ac2 Compare June 1, 2021 09:06
@ahed-compucorp
Copy link
Contributor

ahed-compucorp commented Jun 1, 2021

Updated the PR to pass the failing tests which includes :

  • The result of calling civicrm_api4 is an instance of ArrayObject which evaluates to true when it is casted to a boolean or false when it is used with empty() construct . Instead I checked against the first element $result->first() which returns null for when the civicrm_api4 returns no items.
  • The first parameter for pcpNotifyOwner($contribution, $contributionSoft) must be contribution object.
     $transaction->commit();
     \Civi::log()->info("Contribution {$contributionParams['id']} updated successfully");
-    $contributionSoft = civicrm_api4('ContributionSoft', 'get', [
+    $result = civicrm_api4('ContributionSoft', 'get', [
...
+    $contributionSoft = $result->first();

-    if (!empty($contributionSoft)) {
+    if ($contributionSoft && $contributionSoft['pcp_id']) {
       //Send notification to owner for PCP
-      if ($contributionSoft->column('pcp_id')) {
-        CRM_Contribute_Form_Contribution_Confirm::pcpNotifyOwner($contribution, $contributionSoft[0]);
-      }
+      $contributionDetails = $contributionResult['values'][$contributionResult['id']];
+      $contribution = new CRM_Contribute_BAO_Contribution();
+      $contribution->copyValues($contributionDetails);
+      CRM_Contribute_Form_Contribution_Confirm::pcpNotifyOwner($contribution, $contributionSoft);
     }

@mattwire mattwire changed the title dev/core#521: Send notification after successful contribution payment dev/core#521: PCP Send notification after successful contribution payment Jun 1, 2021
eileenmcnaughton added a commit to eileenmcnaughton/civicrm-core that referenced this pull request Jun 7, 2021
This is cleanup towards civicrm#19096 in that
it gets the function out of the form layer and also makes it so it does
not require a BAO. This does add one extra db lookup in some cases but I think
it's pretty low volume and will mean this is not required

https://github.com/civicrm/civicrm-core/pull/19096/files#diff-4c9d0b1abe07057a4eea2b47bc627eecb95face8ed8d86c1c005312a52cca811R4271-R4273
eileenmcnaughton added a commit to eileenmcnaughton/civicrm-core that referenced this pull request Jun 7, 2021
This is cleanup towards civicrm#19096 in that
it gets the function out of the form layer and also makes it so it does
not require a BAO. This does add one extra db lookup in some cases but I think
it's pretty low volume and will mean this is not required

https://github.com/civicrm/civicrm-core/pull/19096/files#diff-4c9d0b1abe07057a4eea2b47bc627eecb95face8ed8d86c1c005312a52cca811R4271-R4273
eileenmcnaughton added a commit to eileenmcnaughton/civicrm-core that referenced this pull request Jun 7, 2021
This is cleanup towards civicrm#19096 in that
it gets the function out of the form layer and also makes it so it does
not require a BAO. This does add one extra db lookup in some cases but I think
it's pretty low volume and will mean this is not required

https://github.com/civicrm/civicrm-core/pull/19096/files#diff-4c9d0b1abe07057a4eea2b47bc627eecb95face8ed8d86c1c005312a52cca811R4271-R4273
eileenmcnaughton added a commit to eileenmcnaughton/civicrm-core that referenced this pull request Jun 7, 2021
This is a reviewer's cut of civicrm#19096
the only substantive difference is the check around the contribution_status_id
in this line https://github.com/civicrm/civicrm-core/pull/19096/files#diff-9f33a2073e9f844dbb842e0737b7df4bce13db31eabe13b9bdd10e1035dbf6d3R612
has had the empty(->contribution_page_id) bit removed - I can
't think why that would be added in & I think it was discussed out but not removed
eileenmcnaughton added a commit to eileenmcnaughton/civicrm-core that referenced this pull request Jun 7, 2021
This is cleanup towards civicrm#19096 in that
it gets the function out of the form layer and also makes it so it does
not require a BAO. This does add one extra db lookup in some cases but I think
it's pretty low volume and will mean this is not required

https://github.com/civicrm/civicrm-core/pull/19096/files#diff-4c9d0b1abe07057a4eea2b47bc627eecb95face8ed8d86c1c005312a52cca811R4271-R4273
eileenmcnaughton added a commit to eileenmcnaughton/civicrm-core that referenced this pull request Jun 7, 2021
This is a reviewer's cut of civicrm#19096
the only substantive difference is the check around the contribution_status_id
in this line https://github.com/civicrm/civicrm-core/pull/19096/files#diff-9f33a2073e9f844dbb842e0737b7df4bce13db31eabe13b9bdd10e1035dbf6d3R612
has had the empty(->contribution_page_id) bit removed - I can
't think why that would be added in & I think it was discussed out but not removed
eileenmcnaughton added a commit to eileenmcnaughton/civicrm-core that referenced this pull request Jul 4, 2021
This is cleanup towards civicrm#19096 in that
it gets the function out of the form layer and also makes it so it does
not require a BAO. This does add one extra db lookup in some cases but I think
it's pretty low volume and will mean this is not required

https://github.com/civicrm/civicrm-core/pull/19096/files#diff-4c9d0b1abe07057a4eea2b47bc627eecb95face8ed8d86c1c005312a52cca811R4271-R4273
eileenmcnaughton added a commit to eileenmcnaughton/civicrm-core that referenced this pull request Jul 4, 2021
This is a reviewer's cut of civicrm#19096
the only substantive difference is the check around the contribution_status_id
in this line https://github.com/civicrm/civicrm-core/pull/19096/files#diff-9f33a2073e9f844dbb842e0737b7df4bce13db31eabe13b9bdd10e1035dbf6d3R612
has had the empty(->contribution_page_id) bit removed - I can
't think why that would be added in & I think it was discussed out but not removed
@demeritcowboy
Copy link
Contributor

@nishant-bhorodia @ahed-compucorp This now has file conflicts.

@eileenmcnaughton
Copy link
Contributor

I'm pretty sure this has been otherwise fixed

@ahed-compucorp
Copy link
Contributor

Yes, you have created pull request #20523 and merged it.

@eileenmcnaughton
Copy link
Contributor

yay

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants