Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRM-21554 Offline Credit Card Membership Renewal not showing any error message on failure #11408

Merged
merged 2 commits into from
Jan 6, 2018

Conversation

sunilpawar
Copy link
Contributor

@sunilpawar sunilpawar commented Dec 14, 2017

Offline Credit Card Membership Renewal not showing any error message on failure

Function CRM_Core_Error::getMessages() check Exception is of 'CRM_Core_Error' class while it is from class 'Civi\Payment\Exception\PaymentProcessorException'
Hence unable to show the Error message received from Payment gateway.

So added additional check for ' 'Civi\Payment\Exception\PaymentProcessorException'


@sunilpawar sunilpawar changed the title Offline Credit Card Membership Renewal show not showing any error mes… CRM-21554 Offline Credit Card Membership Renewal show not showing any error mes… Dec 14, 2017
@sunilpawar sunilpawar changed the title CRM-21554 Offline Credit Card Membership Renewal show not showing any error mes… CRM-21554 Offline Credit Card Membership Renewal not showing any error message on failure Dec 14, 2017
@eileenmcnaughton
Copy link
Contributor

@sunilpawar what is the path involved here? All the calls to CRM_Core_Error::getMessages() that I found were wrapped in a CRM_Core_Error check

    if (is_a($result, 'CRM_Core_Error')) {

I personally think this block (off Registration_Confirm) where the payment is caught & handled on the form is probably where we want the code to go (it could be more generic with a redirectOnErrorUrl in it)

  /**
   * 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();
  }

@sunilpawar
Copy link
Contributor Author

CRM_Core_Error::displaySessionError function call getMessages function.
Here are the trace of function.

/CRM/Contribute/Form/CancelSubscription.php:217: CRM_Core_Error::displaySessionError($cancelSubscription);
./CRM/Contribute/Form/Contribution/Confirm.php:1138: CRM_Core_Error::displaySessionError($recurring);
./CRM/Contribute/Form/UpdateBilling.php:247: CRM_Core_Error::displaySessionError($updateSubscription);
./CRM/Contribute/Form/UpdateSubscription.php:240: CRM_Core_Error::displaySessionError($updateSubscription);
./CRM/Core/Error.php:163: public static function displaySessionError(&$error, $separator = '
') {
./CRM/Event/Cart/Form/Cart.php:155: CRM_Core_Error::displaySessionError("Could not create or match a contact with that email address. Please contact the webmaster.");
./CRM/Event/Cart/Form/Checkout/Payment.php:624: CRM_Core_Error::displaySessionError($result);
./CRM/Event/Form/Participant.php:1249: CRM_Core_Error::displaySessionError($result);
./CRM/Member/Form/Membership.php:1429: CRM_Core_Error::displaySessionError($e);
./CRM/Member/Form/MembershipRenewal.php:472: CRM_Core_Error::displaySessionError($e);

When we call doPayment function and if receive any error we create 'CRM_Core_Error' object with error message received from payment gateway.
in doPayment (CRM/Core/Payment.php), we check return value is object and not array and if object is of 'CRM_Core_Error' then we throw Exeception

    if (is_a($result, 'CRM_Core_Error')) {
      throw new PaymentProcessorException(CRM_Core_Error::getMessages($result));
    } 

We are catching this exception in membership signup and renewal form and try to show error message to user. but CRM_Core_Error::getMessages() was only checking error of 'CRM_Core_Error'.

CRM_Core_Error::displaySessionError() get return NULL from CRM_Core_Error::getMessages().

@sunilpawar
Copy link
Contributor Author

@eileenmcnaughton

we can use
CRM_Core_Session::singleton()->setStatus($e->getMessage());
but
CRM_Core_Error::displaySessionError($e)

used at multiple places i mentioned in above comment.

@eileenmcnaughton
Copy link
Contributor

@sunilpawar does calling CRM_Core_Error::displaySessionError add any value that you can see?

When I look at those places if feels to me that it was mostly a (not entirely successful) migration strategy for switching towards the use of exceptions. I found 3 places where it occurs within a try-catch block like

    catch (\Civi\Payment\Exception\PaymentProcessorException $e) {
      CRM_Core_Error::displaySessionError($result);
      CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/event/cart_checkout', "_qf_Payment_display=1&qfKey={$this->controller->_key}", TRUE, NULL, FALSE));
    }

I think it makes more sense to just call
CRM_Core_Session::singleton()->setStatus($e->getMessage());
from those 3 places.

(I note that

./CRM/Event/Cart/Form/Cart.php:155: CRM_Core_Error::displaySessionError("Could not create or match a contact with that email address. Please contact the webmaster.");

is totally broken :-))

@sunilpawar
Copy link
Contributor Author

@eileenmcnaughton made changes your suggestion.

@eileenmcnaughton
Copy link
Contributor

looks good to me.

@eileenmcnaughton eileenmcnaughton merged commit 8ba0b06 into civicrm:master Jan 6, 2018
sluc23 pushed a commit to ixiam/civicrm-core that referenced this pull request Jan 10, 2018
CRM-21554 Offline Credit Card Membership Renewal not showing any error message on failure
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants