Skip to content

Commit

Permalink
Attempt to handle offsite return URL for webform correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
mattwire committed Nov 2, 2018
1 parent b27c827 commit 08e2604
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 25 deletions.
4 changes: 3 additions & 1 deletion CRM/Core/Payment/OmnipayMultiProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,7 @@ protected function redirectOrExit($outcome, $response = NULL) {
$redirectUrl = $this->getStoredUrl('fail');
if (empty($redirectUrl)) {
$redirectUrl = $this->getReturnFailUrl(CRM_Utils_Request::retrieve('qfKey', 'String'));

}
if ($redirectUrl && method_exists($response, 'error')) {
$response->error($redirectUrl, $userMsg);
Expand All @@ -820,8 +821,9 @@ protected function redirectOrExit($outcome, $response = NULL) {
case 'success':
$userMsg = NULL;
$redirectUrl = $this->getStoredUrl('success');
Civi::log()->debug('redirectURLstored: ' . $redirectUrl);
if (empty($redirectUrl)) {
$redirectUrl = $this->getReturnSuccessUrl(CRM_Utils_Request::retrieve('qfKey', 'String'));
$redirectUrl = $this->getReturnSuccessUrl();
}
if ($redirectUrl && method_exists($response, 'confirm')) {
$output = $response->confirm($redirectUrl, $userMsg);
Expand Down
86 changes: 62 additions & 24 deletions CRM/Core/Payment/PaymentExtended.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,42 +107,64 @@ public function __construct($mode, &$paymentProcessor) {
* @param string $qfKey
*
* @return string
* @throws \CRM_Core_Exception
*/
protected function getReturnSuccessUrl($qfKey) {
protected function getReturnSuccessUrl($qfKey = NULL) {
if (isset($this->successUrl)) {
return $this->successUrl;
$returnURL = $this->successUrl;
}
return CRM_Utils_System::url($this->getBaseReturnUrl(), array(
'_qf_ThankYou_display' => 1,
'qfKey' => $qfKey,
),
TRUE, NULL, FALSE, TRUE
);
else {
$wfNode = CRM_Utils_Request::retrieve('wfNode', 'String');
$sid = CRM_Utils_Request::retrieve('sid', 'Integer');
$qfKey = CRM_Utils_Request::retrieve('qfKey', 'String');

if ($wfNode) {
// Drupal webform
$returnURL = CRM_Utils_System::url("{$wfNode}/done", ['sid' => $sid], TRUE, NULL, FALSE, TRUE);
}
else {
// Contribution / event
$returnURL = CRM_Utils_System::url($this->getBaseReturnUrl(), [
'_qf_ThankYou_display' => 1,
'qfKey' => $qfKey
], TRUE, NULL, FALSE, TRUE);
}
}

Civi::log()->debug('getReturnSuccessUrl: ' . $returnURL);
return $returnURL;
}

/**
* @param $key
* @param null $participantID
* @param null $eventID
* @param string $key
* @param int $participantID
* @param int $eventID
*
* @return string
* @throws \CRM_Core_Exception
*/
protected function getReturnFailUrl($key, $participantID = NULL, $eventID = NULL) {
if (isset($this->cancelUrl)) {
return $this->cancelUrl;
}
$test = $this->_is_test ? '&action=preview' : '';
if ($this->_component == "event") {
return CRM_Utils_System::url('civicrm/event/register',
"reset=1&cc=fail&participantId={$participantID}&id={$eventID}{$test}&qfKey={$key}",
TRUE, NULL, FALSE, TRUE
);
$returnURL = $this->cancelUrl;
}
else {
return CRM_Utils_System::url('civicrm/contribute/transact',
"_qf_Main_display=1&cancel=1&qfKey={$key}{$test}",
TRUE, NULL, FALSE, TRUE
);
$wfNode = CRM_Utils_Request::retrieve('wfNode', 'String');
$qfKey = CRM_Utils_Request::retrieve('qfKey', 'String');
$url = ($this->_component == 'event') ? 'civicrm/event/register' : 'civicrm/contribute/transact';
$cancel = ($this->_component == 'event') ? '_qf_Register_display' : '_qf_Main_display';

// Default cancel
$returnURL = CRM_Utils_System::url($url, [
$cancel => 1,
'cancel' => 1,
'qfKey' => $qfKey
], TRUE, NULL, FALSE, TRUE);
if ($wfNode) {
$returnURL = CRM_Utils_System::url("{$wfNode}", NULL, TRUE, NULL, FALSE, TRUE);
}
}
Civi::log()->debug('getReturnFailUrl: ' . $returnURL);
return $returnURL;
}

/**
Expand All @@ -160,13 +182,29 @@ protected function getReturnFailUrl($key, $participantID = NULL, $eventID = NULL
* URL to notify outcome of transaction.
*/
protected function getNotifyUrl($allowLocalHost = FALSE) {
// For redirect offsite payment processors we need either the qfKey or 'q' (for webform)
// to rebuild the redirect URL
// These are then passed back via getReturnSuccess/FailURL to the payment processor so we can redirect to the right ending page
$wfNode = CRM_Utils_Array::value('q', $_GET);
$qfKey = CRM_Utils_Request::retrieve('qfKey', 'String');
$query = NULL;
if ($qfKey) {
// If we have a qfKey we are not a webform
$query['qfKey'] = $qfKey;
}
elseif ($wfNode) {
// Otherwise assume we are.
$query['wfNode'] = $wfNode;
}

$url = CRM_Utils_System::url(
'civicrm/payment/ipn/' . $this->formatted_transaction_id . '/' . $this->_paymentProcessor['id'],
array('qfKey' => CRM_Utils_Request::retrieve('qfKey', 'String')),
$query,
TRUE,
NULL,
FALSE
);
Civi::log()->debug('getNotifyUrl: ' . $url);
return $allowLocalHost ? $url : ((stristr($url, '.')) ? $url : '');
}

Expand Down

0 comments on commit 08e2604

Please sign in to comment.