Skip to content

Commit

Permalink
Merge pull request #20318 from eileenmcnaughton/ppp
Browse files Browse the repository at this point in the history
[REF] Add getter for contributionID
  • Loading branch information
seamuslee001 authored May 20, 2021
2 parents 8215db3 + 65f8801 commit 87ea6c9
Showing 1 changed file with 44 additions and 7 deletions.
51 changes: 44 additions & 7 deletions CRM/Core/Payment/PayPalProIPN.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ class CRM_Core_Payment_PayPalProIPN extends CRM_Core_Payment_BaseIPN {
*/
protected $contributionRecurObject;


/**
* Contribution ID.
*
* @var int
*/
protected $contributionID;

/**
* Get the recurring contribution ID, if any.
*
Expand All @@ -65,13 +73,39 @@ public function getContributionRecurID(): ?int {
return $this->contributionRecurID;
}

/**
* Get the relevant contribution ID.
*
* This is the contribution being paid or the original in the
* recurring series.
*
* @return int
*
* @throws \CRM_Core_Exception
*/
protected function getContributionID(): int {
if (!$this->contributionID && $this->getValue('b', TRUE)) {
$this->contributionID = (int) $this->getValue('b', TRUE);
}
return $this->contributionID;
}

/**
* @param int|null $contributionRecurID
*/
public function setContributionRecurID(?int $contributionRecurID): void {
$this->contributionRecurID = $contributionRecurID;
}

/**
* Set contribution ID.
*
* @param int $contributionID
*/
public function setContributionID(int $contributionID): void {
$this->contributionID = $contributionID;
}

/**
* Component.
*
Expand Down Expand Up @@ -262,7 +296,7 @@ public function recur($input, $ids, $recur, $contribution, $first) {
// Also consider accepting 'Failed' like other processors.
$input['contribution_status_id'] = $contributionStatuses['Completed'];
$input['invoice_id'] = md5(uniqid(rand(), TRUE));
$input['original_contribution_id'] = $ids['contribution'];
$input['original_contribution_id'] = $this->getContributionID();
$input['contribution_recur_id'] = $this->getContributionRecurID();

civicrm_api3('Contribution', 'repeattransaction', $input);
Expand Down Expand Up @@ -294,7 +328,7 @@ public function recur($input, $ids, $recur, $contribution, $first) {
if ($sendNotification) {
//send recurring Notification email for user
CRM_Contribute_BAO_ContributionPage::recurringNotify(
$ids['contribution'],
$this->getContributionID(),
$subscriptionPaymentStatus,
$recur
);
Expand Down Expand Up @@ -430,7 +464,7 @@ public function main() {
$input['invoice'] = self::getValue('i', TRUE);
// get the contribution and contact ids from the GET params
$ids['contact'] = self::getValue('c', TRUE);
$ids['contribution'] = self::getValue('b', TRUE);
$ids['contribution'] = $this->getContributionID();

$this->getInput($input);

Expand Down Expand Up @@ -570,8 +604,10 @@ public function getInput(&$input) {
* this may not be acceptable to all sites - e.g. if they are shipping or delivering something in return
* then the quasi security of the ids array might be required - although better to
* http://stackoverflow.com/questions/4848227/validate-that-ipn-call-is-from-paypal
* but let's assume knowledge on invoice id & schedule is enough for now esp for donations
* only contribute is handled
* but let's assume knowledge on invoice id & schedule is enough for now esp
* for donations only contribute is handled
*
* @throws \CRM_Core_Exception
*/
public function handlePaymentExpress() {
//@todo - loads of copy & paste / code duplication but as this not going into core need to try to
Expand Down Expand Up @@ -606,7 +642,8 @@ public function handlePaymentExpress() {
$ids['contributionRecur'] = $this->getContributionRecurID();
$result = civicrm_api3('contribution', 'getsingle', ['invoice_id' => $input['invoice'], 'contribution_test' => '']);

$ids['contribution'] = $result['id'];
$this->setContributionID((int) $result['id']);
$ids['contribution'] = $this->getContributionID();
//@todo hardcoding 'pending' for now
$pendingStatusId = CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Pending');
if ($result['contribution_status_id'] == $pendingStatusId) {
Expand All @@ -629,7 +666,7 @@ public function handlePaymentExpress() {
// Check if the contribution exists
// make sure contribution exists and is valid
$contribution = new CRM_Contribute_BAO_Contribution();
$contribution->id = $ids['contribution'];
$contribution->id = $this->getContributionID();
if (!$contribution->find(TRUE)) {
throw new CRM_Core_Exception('Failure: Could not find contribution record for ' . (int) $contribution->id, NULL, ['context' => "Could not find contribution record: {$contribution->id} in IPN request: " . print_r($input, TRUE)]);
}
Expand Down

0 comments on commit 87ea6c9

Please sign in to comment.