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

[REF] Refactor adding payment processor radio section onto register a… #16595

Merged

Conversation

seamuslee001
Copy link
Contributor

…nd contribution main forms

Overview

Following the merge of https://github.com/civicrm/civicrm-core/pull/15940/files and picking up a comment in a DM from ages ago from @eileenmcnaughton i think we should try and refactor this a little

Before

Multiple places adding in the radio select option for Payment Processors

After

Single function

ping @mattwire

@civibot
Copy link

civibot bot commented Feb 19, 2020

(Standard links)

@civibot civibot bot added the master label Feb 19, 2020
@eileenmcnaughton
Copy link
Contributor

@seamuslee001 I think the shared trait is a better place (avoids static functions too)

@seamuslee001 seamuslee001 force-pushed the refactor_payment_processor_radio branch from 8502892 to 612ffb3 Compare February 19, 2020 21:23
@eileenmcnaughton
Copy link
Contributor

@seamuslee001 the trait I referred to is CRM_Financial_Form_FrontEndPaymentFormTrait

@seamuslee001
Copy link
Contributor Author

@eileenmcnaughton at present on the event form is using the trait i think not contribution page

@seamuslee001
Copy link
Contributor Author

actually take that back wrong

@eileenmcnaughton
Copy link
Contributor

lol

@seamuslee001 seamuslee001 force-pushed the refactor_payment_processor_radio branch from 612ffb3 to cd22c58 Compare February 19, 2020 21:31
@seamuslee001
Copy link
Contributor Author

ok its on the trait now @eileenmcnaughton

@eileenmcnaughton
Copy link
Contributor

@seamuslee001 I worked through the same extraction & came up with a slightly different function

  • the main difference is not passing the output of getProcessors as there is no cost to speak of in getting that from the form variables. Other than that the function name felt misleading, the abbreviated parameters can be made into meaningful ones
  /**
   * Add the payment processor fields to the form.
   *
   *  Adds in either a set of radio buttons or hidden fields to contain the payment processors on a front end form
   */
  protected function addPaymentProcessorFieldsToForm() {
    $paymentProcessors = $this->getProcessors();
    $optAttributes = [];
    foreach (array_keys($paymentProcessors) as $key) {
      if ($key > 0) {
        $optAttributes[$key]['class'] = 'payment_processor_' . strtolower($this->_paymentProcessors[$key]['payment_processor_type']);
      }
      else {
        $optAttributes[$key]['class'] = 'payment_processor_paylater';
      }
    }
    if (count($paymentProcessors) > 1) {
      $this->addRadio('payment_processor_id', ts('Payment Method'), $paymentProcessors,
        NULL, ' ', FALSE, $optAttributes
      );
    }
    elseif (count($paymentProcessors) === 1) {
      $this->addElement('hidden', 'payment_processor_id', reset($paymentProcessors));
    }
  }

@seamuslee001
Copy link
Contributor Author

@eileenmcnaughton just on the function name, I wanted to be clearer about the fact that it is the front end, on the back office fields it is a select field rather than radio button so as this function is only dealing with the front end adding of payment processors i wanted to be more explicit on that

backoffice-payment-processor

@eileenmcnaughton
Copy link
Contributor

Doesn't the fact it's on the FrontEndPaymentFormTrait make that obsolete?

@seamuslee001
Copy link
Contributor Author

I guess so

@seamuslee001 seamuslee001 force-pushed the refactor_payment_processor_radio branch from cd22c58 to e959496 Compare February 20, 2020 01:52
@seamuslee001
Copy link
Contributor Author

have updated it now @eileenmcnaughton

…nd contribution main forms

Move Contribute form specific handling back to its own form

Move shared function to the trait
@seamuslee001 seamuslee001 force-pushed the refactor_payment_processor_radio branch from e959496 to 1421b01 Compare February 20, 2020 20:32
@seamuslee001
Copy link
Contributor Author

@eileenmcnaughton is this good now?

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.

4 participants