Commit fc549598 authored by mattwire's avatar mattwire

Release 0.4

parent 1cf64d74
......@@ -178,6 +178,8 @@ trait CRM_Core_Payment_MJWTrait {
public function getDefaultCurrencyForForm($form) {
// For contribution pages it is in $form->_values
$currency = CRM_Utils_Array::value('currency', $form->_values);
// If we AJAX load and have more than one processor (eg. stripe, pay later) we can end up with the wrong
// currency set in $form->_values. So we use $form->getVar('currency') to get the right one!
if (!$currency && is_a($form, 'CRM_Financial_Form_Payment')) {
$currency = $form->getVar('currency');
}
......@@ -489,4 +491,75 @@ trait CRM_Core_Payment_MJWTrait {
return $params;
}
/**
* Get a "token" parameter that was inserted via javascript on the payment form (eg. paymentIntentID).
*
* @param string $parameterName
* @param array $params
*
* @return array
* @throws \CRM_Core_Exception
*/
protected function getTokenParameter($parameterName, $params) {
// Get the passed in parameter
if(!empty(CRM_Utils_Array::value($parameterName, $params))) {
$parameterValue = CRM_Utils_Array::value($parameterName, $params);
}
elseif (CRM_Core_Session::singleton()->get($parameterName)) {
// @fixme Hack for contributionpages - see https://github.com/civicrm/civicrm-core/pull/15252
$parameterValue = CRM_Core_Session::singleton()->get($parameterName);
CRM_Core_Session::singleton()->set($parameterName, NULL);
}
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));
CRM_Core_Error::statusBounce(E::ts('Unable to complete payment! Missing %1.', [1 => $parameterName]));
}
$params[$parameterName] = $parameterValue;
return $params;
}
/**
* Given a submitted form, retrieve a parameter that was added via (an input element added by) javascript.
* Save the parameter in the params array for the form so it's accessible at the end of a multi-page form.
*
* @param string $parameterName
* @param \CRM_Core_Form $form
*
* @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
// 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
$paymentParams = &$params;
}
elseif (isset($params[0]['amount'])) {
// Event registration pages have params in a sub-array
$paymentParams = &$params[0];
}
else {
return;
}
$paymentIntentID = CRM_Utils_Request::retrieveValue($parameterName, 'String');
if ($paymentIntentID) {
$paymentParams[$parameterName] = $paymentIntentID;
$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);
}
}
}
}
## Release 0.4
* Fix issue with non-default currency on form when you can choose from more than one payment processor on the form.
* Add `getTokenParameter()`/`setTokenParameter()` functions to MJWTrait which should be used when setting parameters
via javascript (eg. Stripe `paymentIntentID`) which are required when the payment is actually processed (via `doPayment()`).
## Release 0.3
* Major refactor of MJWIPNTrait.
......
......@@ -13,8 +13,8 @@
<url desc="Support">https://www.mjwconsult.co.uk</url>
<url desc="Licensing">http://www.gnu.org/licenses/agpl-3.0.html</url>
</urls>
<releaseDate>2019-09-13</releaseDate>
<version>0.3</version>
<releaseDate>2019-09-16</releaseDate>
<version>0.4</version>
<develStage>stable</develStage>
<compatibility>
<ver>5.13</ver>
......
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