Skip to content

Commit

Permalink
Remove redundant status set, set start_date centrally
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Apr 1, 2022
1 parent 58a4205 commit e62a2be
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 15 deletions.
5 changes: 3 additions & 2 deletions CRM/Contribute/BAO/ContributionRecur.php
Original file line number Diff line number Diff line change
Expand Up @@ -949,11 +949,12 @@ public static function updateOnNewPayment($recurringContributionID, $paymentStat

$existing = civicrm_api3('ContributionRecur', 'getsingle', $params);

if ($paymentStatus == 'Completed'
if ($paymentStatus === 'Completed'
&& CRM_Contribute_PseudoConstant::contributionStatus($existing['contribution_status_id'], 'name') == 'Pending') {
$params['contribution_status_id'] = 'In Progress';
$params['start_date'] = $effectiveDate;
}
if ($paymentStatus == 'Failed') {
if ($paymentStatus === 'Failed') {
$params['failure_count'] = $existing['failure_count'];
}
$params['modified_date'] = date('Y-m-d H:i:s');
Expand Down
13 changes: 0 additions & 13 deletions CRM/Core/Payment/PayPalIPN.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,19 +133,6 @@ public function recur($input, $recur, $contribution, $first) {
echo 'Failure: Invalid parameters<p>';
return;
}
if ($first) {
$recur->start_date = $now;
}
else {
$recur->modified_date = $now;
}

// make sure the contribution status is not done
// since order of ipn's is unknown
if ($recur->contribution_status_id != $contributionStatuses['Completed']) {
$recur->contribution_status_id = $contributionStatuses['In Progress'];
}
$recur->save();

if (!$first) {
// check if this contribution transaction is already processed
Expand Down
7 changes: 7 additions & 0 deletions tests/phpunit/CRM/Core/Payment/PayPalIPNTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
+--------------------------------------------------------------------+
*/

use Civi\Api4\ContributionRecur;

/**
* Class CRM_Core_Payment_PayPalProIPNTest
* @group headless
Expand Down Expand Up @@ -123,6 +125,11 @@ public function testIPNPaymentRecurSuccess(): void {
$mut = new CiviMailUtils($this, TRUE);
$paypalIPN = new CRM_Core_Payment_PayPalIPN($this->getPaypalRecurTransaction());
$paypalIPN->main();
$recur = ContributionRecur::get()
->addWhere('contact_id', '=', $this->_contactID)
->addSelect('contribution_status_id:name')
->execute()->first();
$this->assertEquals('In Progress', $recur['contribution_status_id:name']);
$mut->checkMailLog(['https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_subscr-find'], ['civicrm/contribute/unsubscribe', 'civicrm/contribute/updatebilling']);
$mut->stop();
$contribution1 = $this->callAPISuccess('Contribution', 'getsingle', ['id' => $this->_contributionID]);
Expand Down

0 comments on commit e62a2be

Please sign in to comment.