Skip to content
Snippets Groups Projects
Commit 3f7af329 authored by mattwire's avatar mattwire
Browse files

More robust error_url

parent 6ca938f8
No related branches found
No related tags found
No related merge requests found
......@@ -266,20 +266,21 @@ trait CRM_Core_Payment_MJWTrait {
/**
* Get the error URL to "bounce" the user back to.
* @param \Civi\Payment\PropertyBag $params
*
* @param \Civi\Payment\PropertyBag $propertyBag
*
* @return string|null
*/
public function getErrorUrl($params) {
public function generateErrorUrl($propertyBag) {
// Get proper entry URL for returning on error.
if (!$params->has('qfKey') || !$params->has('entryURL')) {
if (!$propertyBag->has('qfKey') || !$propertyBag->has('entryURL')) {
// Probably not called from a civicrm form (e.g. webform) -
// will return error object to original api caller.
$errorUrl = NULL;
}
else {
$qfKey = $params->getCustomProperty('qfKey');
$parsedUrl = parse_url($params->getCustomProperty('entryURL'));
$qfKey = $propertyBag->getCustomProperty('qfKey');
$parsedUrl = parse_url($propertyBag->getCustomProperty('entryURL'));
$urlPath = trim($parsedUrl['path'], '/');
$query = $parsedUrl['query'];
if (strpos($query, '_qf_Main_display=1') === FALSE) {
......@@ -293,6 +294,18 @@ trait CRM_Core_Payment_MJWTrait {
return $errorUrl;
}
/**
* @param \Civi\Payment\PropertyBag $propertyBag
*
* @return mixed|void|null
*/
public function getErrorUrl(\Civi\Payment\PropertyBag $propertyBag): string {
if ($propertyBag->has('error_url')) {
return $propertyBag->getCustomProperty('error_url');
}
}
/**
* Are we using a test processor?
*
......@@ -308,11 +321,12 @@ trait CRM_Core_Payment_MJWTrait {
* @param string $errorCode
* @param string $errorMessage
* @param string $bounceURL
* @param bool $log
*
* @throws \Civi\Payment\Exception\PaymentProcessorException
* (or statusbounce if URL is specified)
* (or CRM_Core_Error::statusBounce if URL is specified)
*/
private function handleError($errorCode = '', $errorMessage = '', $bounceURL = NULL, $log = TRUE) {
private function handleError(string $errorCode = '', string $errorMessage = '', string $bounceURL = '', bool $log = TRUE) {
$errorMessage = empty($errorMessage) ? 'Unknown System Error.' : $errorMessage;
$message = $errorMessage . (!empty($errorCode) ? " - {$errorCode}" : '');
......@@ -324,7 +338,7 @@ trait CRM_Core_Payment_MJWTrait {
throw new \Exception('Exception thrown to avoid statusBounce because handleErrorThrowsException is set.' . $message);
}
if ($bounceURL) {
if (!empty($bounceURL)) {
CRM_Core_Error::statusBounce($message, $bounceURL, $this->getPaymentTypeLabel());
}
throw new PaymentProcessorException($errorMessage, $errorCode);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment