Skip to content

Commit

Permalink
Merge pull request #24050 from eileenmcnaughton/pledge
Browse files Browse the repository at this point in the history
dev/financial#201 Fix PaypalPro IPN to refer to correct option group
  • Loading branch information
seamuslee001 authored Jul 28, 2022
2 parents b67de01 + ba2fb5a commit a453f81
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions CRM/Core/Payment/PayPalProIPN.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,20 +267,18 @@ public function recur(array $input): void {
//set transaction type
$txnType = $this->retrieve('txn_type', 'String');
//Changes for paypal pro recurring payment
$contributionStatuses = array_flip(CRM_Contribute_BAO_Contribution::buildOptions('contribution_status_id', 'validate'));
switch ($txnType) {
case 'recurring_payment_profile_created':
if (in_array($recur->contribution_status_id, [
$contributionStatuses['Pending'],
$contributionStatuses['In Progress'],
])
if (in_array(CRM_Core_PseudoConstant::getName('CRM_Contribute_BAO_ContributionRecur', 'contribution_status_id', $recur->contribution_status_id), [
'Pending', 'In Progress',
], TRUE)
&& !empty($recur->processor_id)
) {
echo "already handled";
echo 'already handled';
return;
}
$recur->create_date = $now;
$recur->contribution_status_id = $contributionStatuses['Pending'];
$recur->contribution_status_id = CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_ContributionRecur', 'contribution_status_id', 'Pending');
$recur->processor_id = $this->retrieve('recurring_payment_id', 'String');
$recur->trxn_id = $recur->processor_id;
$subscriptionPaymentStatus = CRM_Core_Payment::RECURRING_PAYMENT_START;
Expand All @@ -290,12 +288,12 @@ public function recur(array $input): void {
case 'recurring_payment':
if (!$first) {
if ($input['paymentStatus'] !== 'Completed') {
throw new CRM_Core_Exception("Ignore all IPN payments that are not completed");
throw new CRM_Core_Exception('Ignore all IPN payments that are not completed');
}

// In future moving to create pending & then complete, but this OK for now.
// Also consider accepting 'Failed' like other processors.
$input['contribution_status_id'] = $contributionStatuses['Completed'];
$input['contribution_status_id'] = CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_ContributionRecur', 'contribution_status_id', 'Completed');
$input['invoice_id'] = md5(uniqid(rand(), TRUE));
$input['original_contribution_id'] = $this->getContributionID();
$input['contribution_recur_id'] = $this->getContributionRecurID();
Expand All @@ -305,12 +303,12 @@ public function recur(array $input): void {
}

//contribution installment is completed
if ($this->retrieve('profile_status', 'String') == 'Expired') {
if ($this->retrieve('profile_status', 'String') === 'Expired') {
if (!empty($recur->end_date)) {
echo "already handled";
echo 'already handled';
return;
}
$recur->contribution_status_id = $contributionStatuses['Completed'];
$recur->contribution_status_id = CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_ContributionRecur', 'contribution_status_id', 'Completed');
$recur->end_date = $now;
$sendNotification = TRUE;
$subscriptionPaymentStatus = CRM_Core_Payment::RECURRING_PAYMENT_END;
Expand Down

0 comments on commit a453f81

Please sign in to comment.