@@ -224,7 +224,7 @@ public function single($input, $ids, $contribution, $recur = FALSE) {
224
224
return ;
225
225
}
226
226
227
- CRM_Contribute_BAO_Contribution::completeOrder ($ input , $ ids [ ' contributionRecur ' ] ?? NULL , $ contribution ->id ?? NULL );
227
+ CRM_Contribute_BAO_Contribution::completeOrder ($ input , $ this -> getContributionRecurID () , $ contribution ->id ?? NULL );
228
228
}
229
229
230
230
/**
@@ -243,7 +243,6 @@ public function main() {
243
243
$ ids ['contact ' ] = $ this ->retrieve ('contactID ' , 'Integer ' , TRUE );
244
244
$ contributionID = $ ids ['contribution ' ] = $ this ->retrieve ('contributionID ' , 'Integer ' , TRUE );
245
245
$ membershipID = $ this ->retrieve ('membershipID ' , 'Integer ' , FALSE );
246
- $ contributionRecurID = $ this ->retrieve ('contributionRecurID ' , 'Integer ' , FALSE );
247
246
248
247
$ this ->getInput ($ input );
249
248
@@ -259,13 +258,13 @@ public function main() {
259
258
$ ids ['onbehalf_dupe_alert ' ] = $ this ->retrieve ('onBehalfDupeAlert ' , 'Integer ' , FALSE );
260
259
}
261
260
262
- $ paymentProcessorID = $ this ->getPayPalPaymentProcessorID ($ input , $ contributionRecurID );
261
+ $ paymentProcessorID = $ this ->getPayPalPaymentProcessorID ($ input , $ this -> getContributionRecurID () );
263
262
264
263
Civi::log ()->debug ('PayPalIPN: Received (ContactID: ' . $ ids ['contact ' ] . '; trxn_id: ' . $ input ['trxn_id ' ] . '). ' );
265
264
266
265
// Debugging related to possible missing membership linkage
267
- if ($ contributionRecurID && $ this ->retrieve ('membershipID ' , 'Integer ' , FALSE )) {
268
- $ templateContribution = CRM_Contribute_BAO_ContributionRecur::getTemplateContribution ($ contributionRecurID );
266
+ if ($ this -> getContributionRecurID () && $ this ->retrieve ('membershipID ' , 'Integer ' , FALSE )) {
267
+ $ templateContribution = CRM_Contribute_BAO_ContributionRecur::getTemplateContribution ($ this -> getContributionRecurID () );
269
268
$ membershipPayment = civicrm_api3 ('MembershipPayment ' , 'get ' , [
270
269
'contribution_id ' => $ templateContribution ['id ' ],
271
270
'membership_id ' => $ membershipID ,
@@ -285,12 +284,12 @@ public function main() {
285
284
Civi::log ()->debug ('PayPalIPN: Will attempt to compensate ' );
286
285
$ input ['membership_id ' ] = $ this ->retrieve ('membershipID ' , 'Integer ' , FALSE );
287
286
}
288
- if ($ contributionRecurID ) {
287
+ if ($ this -> getContributionRecurID () ) {
289
288
$ recurLinks = civicrm_api3 ('ContributionRecur ' , 'get ' , [
290
289
'membership_id ' => $ membershipID ,
291
- 'contribution_recur_id ' => $ contributionRecurID ,
290
+ 'contribution_recur_id ' => $ this -> getContributionRecurID () ,
292
291
]);
293
- Civi::log ()->debug ('PayPalIPN: Membership should be linked to contribution recur record ' . $ contributionRecurID
292
+ Civi::log ()->debug ('PayPalIPN: Membership should be linked to contribution recur record ' . $ this -> getContributionRecurID ()
294
293
. ' ' . $ recurLinks ['count ' ] . 'links found '
295
294
);
296
295
}
@@ -326,13 +325,11 @@ public function main() {
326
325
327
326
$ input ['payment_processor_id ' ] = $ paymentProcessorID ;
328
327
329
- if ($ contributionRecurID ) {
328
+ if ($ this -> getContributionRecurID () ) {
330
329
$ contributionRecur = new CRM_Contribute_BAO_ContributionRecur ();
331
- $ contributionRecur ->id = $ contributionRecurID ;
330
+ $ contributionRecur ->id = $ this -> getContributionRecurID () ;
332
331
if (!$ contributionRecur ->find (TRUE )) {
333
- CRM_Core_Error::debug_log_message ("Could not find contribution recur record: {$ ids ['ContributionRecur ' ]} in IPN request: " . print_r ($ input , TRUE ));
334
- echo "Failure: Could not find contribution recur record: {$ ids ['ContributionRecur ' ]}<p> " ;
335
- return FALSE ;
332
+ throw new CRM_Core_Exception ('Could not find contribution recur record ' );
336
333
}
337
334
// check if first contribution is completed, else complete first contribution
338
335
$ first = TRUE ;
@@ -344,7 +341,7 @@ public function main() {
344
341
if ($ this ->getFirstOrLastInSeriesStatus ()) {
345
342
//send recurring Notification email for user
346
343
CRM_Contribute_BAO_ContributionPage::recurringNotify (
347
- $ ids [ ' contribution ' ] ,
344
+ $ contributionID ,
348
345
$ this ->getFirstOrLastInSeriesStatus (),
349
346
$ contributionRecur
350
347
);
@@ -379,11 +376,11 @@ public function main() {
379
376
}
380
377
$ this ->single ($ input , [
381
378
'participant ' => $ ids ['participant ' ] ?? NULL ,
382
- 'contributionRecur ' => $ contributionRecurID ,
379
+ 'contributionRecur ' => $ this -> getContributionRecurID () ,
383
380
], $ contribution );
384
381
}
385
382
catch (CRM_Core_Exception $ e ) {
386
- Civi::log ()->debug ($ e ->getMessage ());
383
+ Civi::log ()->debug ($ e ->getMessage () . ' input {input} ' , [ ' input ' => $ input ] );
387
384
echo 'Invalid or missing data ' ;
388
385
}
389
386
}
@@ -511,4 +508,16 @@ protected function getFirstOrLastInSeriesStatus(): ?string {
511
508
return NULL ;
512
509
}
513
510
511
+ /**
512
+ * Get the recurring contribution ID.
513
+ *
514
+ * @return int|null
515
+ *
516
+ * @throws \CRM_Core_Exception
517
+ */
518
+ protected function getContributionRecurID (): ?int {
519
+ $ id = $ this ->retrieve ('contributionRecurID ' , 'Integer ' , FALSE );
520
+ return $ id ? (int ) $ id : NULL ;
521
+ }
522
+
514
523
}
0 commit comments