Currently, it is not possible to customize the display title of a payment instance, neither through code nor the UI.

I think this would greatly improve the UX of payment methods, as it gives site builders much more control over how those payment methods are displayed.

Additional features like configurable description/images and so on would be cool as well, but much more work, this is almost trivial.

I'm not sure what the commit policy for Commerce 7.x-1.x is, this should be backwards compatible unless there is a payment method out there that defines a display_title setting that is used for something else. It does introduce two new strings, though.

Alternatively, I could also provide a patch that only contains the check, so payment methods could add this setting on their own.

Comments

berdir’s picture

Status: Active » Needs review
StatusFileSize
new1.95 KB

Here is the patch.

berdir’s picture

Per discussion with Ryan, I'll change it to a textarea and run it through filter_xss_admin() to support HTML, like displaying credit card images or something like that.

berdir’s picture

StatusFileSize
new84.8 KB
new14.75 KB
new2.18 KB

Ok, here is a re-roll that does that.

- Changed textarea
- Uses format_xss_admin()
- Added both a rendered default display title below and the raw html to the description. I'm not sure what to do with that (keep either of them or both), because the problem is that while simple display titles work with with just the part in the description, it gets very ugly with e.g. Paypal WPS. See attached screenshots.

bessone’s picture

Which patch will be committed?

bessone’s picture

I noticed that in the display order in the administration i do not see the custom name, but only the original name, any advice?

In the commerce_payment_order view i see:

Display the payment method using the following title

  • The full administrative title of the payment method
  • A short version of the title safe to display to all
  • The title displayed on the checkout form (may include HTML)

but also with the last option, i can't see the custom title in this admin view.

elgandoz’s picture

I have the same problem with the administration view, it's not possible to show the custom title in the payment page, you just see the original title.

berdir’s picture

Re-roll of the previous patch.

Yes, the view needs to be updated as well.

rbrownell’s picture

Has this been committed yet?

EDIT: Given how the patch applied correctly to the current dev version I am going to say it probably wasn't. What needs to be done to get this committed? Currently I am working on testing it if that helps at all.

-R

rszrama’s picture

It would need to be translatable.

rbrownell’s picture

Status: Needs review » Needs work

This Patch 7 does not modify the title for PayPal WPS. It looks like that if the module does not already overwrite the title this method works. It seems logical that the PayPal module should follow the method here to modify the title and simply have any fancy graphics and text built into the rule so that can be overridden as opposed to the current hard coded, very difficult to change without patching the module, method.

Would you recommend a different Patch 3 over Patch 7?

EDIT: Patch 7 works when the following is commented out of the Commerce PayPal WPS Module.

/**
 * Implements hook_form_FORM_ID_alter().
*/
function commerce_paypal_wps_form_commerce_checkout_form_alter(&$form, &$form_state) {
  // If this checkout form contains the payment method radios...
  if (!empty($form['commerce_payment']['payment_method']['#options'])) {
    // Loop over its options array looking for a PayPal WPS option.
    foreach ($form['commerce_payment']['payment_method']['#options'] as $key => &$value) {
      list($method_id, $rule_name) = explode('|', $key);

      // If we find PayPal WPS...
      if ($method_id == 'paypal_wps') {
        // Prepare the replacement radio button text with icons.
        $icons = commerce_paypal_icons();
        $value = t('!logo PayPal - pay securely without sharing your financial information', array('!logo' => $icons['paypal']));
        $value .= '<div class="commerce-paypal-icons"><span class="label">' . t('Includes:') . '</span>' . implode(' ', $icons) . '</div>';

        // Add the CSS.
        $form['commerce_payment']['payment_method']['#attached']['css'][] = drupal_get_path('module', 'commerce_paypal_wps') . '/theme/commerce_paypal_wps.theme.css';

        break;
      }
    }
  }
}

-R

rbrownell’s picture

This may not be relevant here but when I was looking for how to customize the display of the payment types I kept coming to this page... For information on how to do with with template.php in your theme read #2062337: Remove Logos.

bigEwok’s picture

Issue summary: View changes

Hi, i applied this patch but i have a problem in /commerce/orders.
I created 2 rules with the same method of paiement. It works in the checkout, the user may choose one of these 2 rules.
But in /commerce/orders i can't display the custom title, only the title of the method of paiement.
So i can't differentiate the choice of the user, that is the problem.
If somebody knows, thanks.

zmove’s picture

Status: Needs work » Needs review

+1 to this. The #7 patch should be commited ASAP (even if not perfect, it's better than nothing (that's what we have today)).

heathdutton’s picture

+1 for #7.

joelpittet’s picture

Status: Needs review » Needs work

Wrapping the result in t() on the way out would work but variables going into t() is a no-no generally. Is there another approach to making that work or is that the only way?

Setting to CNW from #9

nico.knaepen’s picture

The only way to work around the t() issue with variables is to foresee a variable per active language.

nico.knaepen’s picture

I've created a new module where you are able to alter the display title's of the source language and foresee a translation for other languages. https://www.drupal.org/project/commerce_payment_alter

andren’s picture

Thanks Nico #18 Worked like a Charm!

daletrexel’s picture

I have also made use of Commerce Payment Alter (thanks Nico!), however, in my trials, PayPal WPS continues to override any attempt to change the title, even with the module in use. The module is working for me as described for Commerce Square and Commerce Custom Offline Payment.

It would be nice to not need an extra module to be able to customize (and internationalize) payment option titles, and it would be especially nice to not allow payment methods to hard-code their own titles and styling, like PayPal WPS seems intent on doing.

sourabhjain’s picture

Rerolled the patch against latest 7.x-1.x branch.