Skip to content

Commit

Permalink
Merge pull request #17543 from eileenmcnaughton/dummy
Browse files Browse the repository at this point in the history
[Ref] Readability extraction in Dummy class
  • Loading branch information
seamuslee001 authored Jun 8, 2020
2 parents f0d2bc7 + 5562e2e commit cbcf1e0
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions CRM/Core/Payment/Dummy.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,22 +94,9 @@ public function doDirectPayment(&$params) {
$result['trxn_id'] = array_shift($this->_doDirectPaymentResult['trxn_id']);
return $result;
}
if ($this->_mode === 'test') {
$query = "SELECT MAX(trxn_id) FROM civicrm_contribution WHERE trxn_id LIKE 'test\\_%'";
$p = [];
$trxn_id = (string) CRM_Core_DAO::singleValueQuery($query, $p);
$trxn_id = str_replace('test_', '', $trxn_id);
$trxn_id = (int) $trxn_id + 1;
$params['trxn_id'] = 'test_' . $trxn_id . '_' . uniqid();
}
else {
$query = "SELECT MAX(trxn_id) FROM civicrm_contribution WHERE trxn_id LIKE 'live_%'";
$p = [];
$trxn_id = (string) CRM_Core_DAO::singleValueQuery($query, $p);
$trxn_id = str_replace('live_', '', $trxn_id);
$trxn_id = (int) $trxn_id + 1;
$params['trxn_id'] = 'live_' . $trxn_id . '_' . uniqid();
}

$params['trxn_id'] = $this->getTrxnID();;

$params['gross_amount'] = $propertyBag->getAmount();
// Add a fee_amount so we can make sure fees are handled properly in underlying classes.
$params['fee_amount'] = 1.50;
Expand Down Expand Up @@ -219,4 +206,21 @@ public function doCancelRecurring(PropertyBag $propertyBag) {
return ['message' => ts('Recurring contribution cancelled')];
}

/**
* Get a value for the transaction ID.
*
* Value is made up of the max existing value + a random string.
*
* Note the random string is likely a historical workaround.
*
* @return string
*/
protected function getTrxnID() {
$string = $this->_mode;
$trxn_id = CRM_Core_DAO::singleValueQuery("SELECT MAX(trxn_id) FROM civicrm_contribution WHERE trxn_id LIKE '{$string}_%'");
$trxn_id = str_replace($string, '', $trxn_id);
$trxn_id = (int) $trxn_id + 1;
return $string . '_' . $trxn_id . '_' . uniqid();
}

}

0 comments on commit cbcf1e0

Please sign in to comment.