Skip to content

Commit

Permalink
Merge pull request #9762 from fuzionnz/CRM-19793-payment_processor_ex…
Browse files Browse the repository at this point in the history
…ception_redirect

CRM-19793: payment processor exception redirect
  • Loading branch information
eileenmcnaughton authored Feb 1, 2017
2 parents 066122b + 22f9da8 commit ebb3cec
Showing 1 changed file with 27 additions and 9 deletions.
36 changes: 27 additions & 9 deletions CRM/Event/Form/Registration/Confirm.php
Original file line number Diff line number Diff line change
Expand Up @@ -573,14 +573,10 @@ public function postProcess() {
}

if (is_object($payment)) {
try {
$result = $payment->doPayment($value);
$value = array_merge($value, $result);
}
catch (\Civi\Payment\Exception\PaymentProcessorException $e) {
CRM_Core_Session::singleton()->setStatus($e->getMessage());
CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/event/register', "id={$this->_eventId}"));
}
// Not quite sure why we don't just user $value since it contains the data
// from result
// @todo ditch $result & retest.
list($result, $value) = $this->processPayment($payment, $value);
}
else {
CRM_Core_Error::fatal($paymentObjError);
Expand Down Expand Up @@ -824,7 +820,8 @@ public function postProcess() {
// call postprocess hook before leaving
$this->postProcessHook();
// this does not return
$payment->doPayment($primaryParticipant, 'event');

$this->processPayment($payment, $primaryParticipant);
}
else {
CRM_Core_Error::fatal($paymentObjError);
Expand Down Expand Up @@ -1306,4 +1303,25 @@ public static function testSubmit($params) {
$form->postProcess();
}

/**
* Process the payment, redirecting back to the page on error.
*
* @param $payment
* @param $value
*
* @return array
*/
private function processPayment($payment, $value) {
try {
$result = $payment->doPayment($value, 'event');
return array($result, $value);
}
catch (\Civi\Payment\Exception\PaymentProcessorException $e) {
Civi::log()->error('Payment processor exception: ' . $e->getMessage());
CRM_Core_Session::singleton()->setStatus($e->getMessage());
CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/event/register', "id={$this->_eventId}"));
}
return array();
}

}

0 comments on commit ebb3cec

Please sign in to comment.