Commit b097cb7b authored by mattwire's avatar mattwire

Improvements to get/setTokenParameter

parent 0cfba0a2
......@@ -497,12 +497,14 @@ trait CRM_Core_Payment_MJWTrait {
*
* @param string $parameterName
* @param array $params
* @param bool $required
*
* @return array
* @throws \CRM_Core_Exception
*/
protected function getTokenParameter($parameterName, $params) {
protected function getTokenParameter($parameterName, $params, $required = TRUE) {
// Get the passed in parameter
$parameterValue = NULL;
if(!empty(CRM_Utils_Array::value($parameterName, $params))) {
$parameterValue = CRM_Utils_Array::value($parameterName, $params);
}
......@@ -514,11 +516,10 @@ trait CRM_Core_Payment_MJWTrait {
elseif(CRM_Utils_Request::retrieve($parameterName, 'String')) {
$parameterValue = CRM_Utils_Request::retrieve($parameterName, 'String');
}
if (empty($parameterValue)) {
Civi::log()->debug("{$parameterName}paymentIntentID not found. \$params: " . print_r($params, TRUE));
if (empty($parameterValue) && $required) {
Civi::log()->debug("{$parameterName} not found. \$params: " . print_r($params, TRUE));
CRM_Core_Error::statusBounce(E::ts('Unable to complete payment! Missing %1.', [1 => $parameterName]));
}
$params[$parameterName] = $parameterValue;
return $params;
}
......@@ -533,13 +534,12 @@ trait CRM_Core_Payment_MJWTrait {
* @throws \CRM_Core_Exception
*/
public static function setTokenParameter($parameterName, &$form) {
// Retrieve the paymentIntentID that was posted along with the form and add it to the form params
// Retrieve the parameterValue that was posted along with the form and add it to the form params
// This allows multi-page checkout to work (eg. register->confirm->thankyou)
$params = $form->get('params');
if (!$params) {
// @fixme Hack for contributionpages - see https://github.com/civicrm/civicrm-core/pull/15252
$params = $form->getVar('_params');
$hackForContributionPages = TRUE;
}
if (isset($params['amount'])) {
// Contribution pages have params directly in the main array
......@@ -552,14 +552,12 @@ trait CRM_Core_Payment_MJWTrait {
else {
return;
}
$paymentIntentID = CRM_Utils_Request::retrieveValue($parameterName, 'String');
if ($paymentIntentID) {
$paymentParams[$parameterName] = $paymentIntentID;
$parameterValue = CRM_Utils_Request::retrieveValue($parameterName, 'String');
if ($parameterValue) {
$paymentParams[$parameterName] = $parameterValue;
$form->set('params', $params);
if (isset($hackForContributionPages)) {
// @fixme Hack for contributionpages - see https://github.com/civicrm/civicrm-core/pull/15252
CRM_Core_Session::singleton()->set($parameterName, $paymentIntentID);
}
// @fixme Hack for contributionpages - see https://github.com/civicrm/civicrm-core/pull/15252
CRM_Core_Session::singleton()->set($parameterName, $parameterValue);
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment