Skip to content

Commit

Permalink
[REF] Use getter rather than passing variable
Browse files Browse the repository at this point in the history
txnType is a required parameter for recurring & unused for single. This switches to retrieving
it as needed rather than passing it around. It removes one check for whether it is
set because the abort will exit if not
  • Loading branch information
eileenmcnaughton committed Jul 14, 2021
1 parent 0caf521 commit e02cd78
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions CRM/Core/Payment/PayPalIPN.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,7 @@ public function retrieve($name, $type, $abort = TRUE) {
* @throws \CiviCRM_API3_Exception
*/
public function recur($input, $recur, $contribution, $first) {
if (!isset($input['txnType'])) {
Civi::log()->debug('PayPalIPN: Could not find txn_type in input request');
echo "Failure: Invalid parameters<p>";
return;
}

if ($input['txnType'] === 'subscr_payment' &&
if ($this->getTrxnType() === 'subscr_payment' &&
$input['paymentStatus'] !== 'Completed'
) {
Civi::log()->debug('PayPalIPN: Ignore all IPN payments that are not completed');
Expand All @@ -94,9 +88,8 @@ public function recur($input, $recur, $contribution, $first) {
$now = date('YmdHis');

// set transaction type
$txnType = $this->getTrxnType();
$contributionStatuses = array_flip(CRM_Contribute_BAO_Contribution::buildOptions('contribution_status_id', 'validate'));
switch ($txnType) {
switch ($this->getTrxnType()) {
case 'subscr_signup':
$recur->create_date = $now;
// sometimes subscr_signup response come after the subscr_payment and set to pending mode.
Expand Down Expand Up @@ -151,7 +144,7 @@ public function recur($input, $recur, $contribution, $first) {

$recur->save();

if ($txnType !== 'subscr_payment') {
if ($this->getTrxnType() !== 'subscr_payment') {
return;
}

Expand Down Expand Up @@ -336,7 +329,6 @@ public function main() {
*/
public function getInput(&$input) {
$billingID = CRM_Core_BAO_LocationType::getBilling();
$input['txnType'] = $this->retrieve('txn_type', 'String', FALSE);
$input['paymentStatus'] = $this->retrieve('payment_status', 'String', FALSE);
$input['invoice'] = $this->retrieve('invoice', 'String', TRUE);
$input['amount'] = $this->retrieve('mc_gross', 'Money', FALSE);
Expand Down Expand Up @@ -428,8 +420,7 @@ public function getPayPalPaymentProcessorID(array $input, ?int $contributionRecu
* @throws \CRM_Core_Exception
*/
protected function getTrxnType() {
$txnType = $this->retrieve('txn_type', 'String');
return $txnType;
return $this->retrieve('txn_type', 'String');
}

/**
Expand Down

0 comments on commit e02cd78

Please sign in to comment.