I wanted to modify the names and descriptions of my payment gateways on the checkout form. I wasn't happy with the way they were being displayed.
I figured out a way to do this, but it wasn't obvious or easy to do.
With that said, I'll be posting the method here, so others can find it. I would also perhaps recommend easier access to do this via the API.
function MYMODULE_commerce_payment_method_info_alter(&$payment_methods) {
//dpm($payment_methods);
$i = 0;
foreach($payment_methods as $method_id => $payment_method) {
$i++;
$instance_id = $method_id . '|' . "commerce_payment_" . $method_id;
$pmi = commerce_payment_method_instance_load($instance_id);
//dpm($pmi);
$payment_methods[$method_id]['display_title'] = "Payment Method # $i";
}
Here's a sample module which you can view and modify to get you started:
http://drupal.org/sandbox/j0rd/1253092
I believe the function commerce_payment_method_instance_load($instance_id); arguments need to get improved to take two arguments instead of taking a concatenated argument via a PIPE. Or simply just one argument if possible, since they appear to be based off each other.
If there are better ways to get this done, please make them known.
Functions/Hooks used in this are: hook_commerce_payment_method_info_alter() AND commerce_payment_method_instance_load()
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | load_settings_in_payment_method_rule-1260674-9.patch | 497 bytes | j0rd |
| #6 | 1260674-payment-methods-alter.patch | 1.74 KB | damien tournoud |
Comments
Comment #1
j0rd commentedUpdated the misleading title.
Comment #2
j0rd commented#1258386: hook_commerce_payment_method_info() now requires 'active' field. marked as duplicate
Comment #3
j0rd commentedI'm also getting this error
from commerce/modules/payment/commerce_payment.module
So I'm wrapping this code with an empty() statement for now as a work around
Comment #4
damien tournoud commentedYou just cannot load a payment instance from
hook_commerce_payment_method_info_alter()that's incorrect and invalid.The simplest way to do what you want to do would be for us to implement a
hook_commerce_payment_methods_alter().Comment #5
damien tournoud commentedComment #6
damien tournoud commentedPatch for review.
Comment #7
j0rd commentedSeems to be working in the right direction.
Problem is now, I can't reach the defaulted display_title or title values.
Does this alter perhaps need to be moved down a little?
EDIT:
Confirmed, I can't change display_title variable of the payment methods from this new hook. So it's not useful for me. I'd need to do it by hacking the payment module or using HOOK_commerce_payment_method_info_alter().
Any other suggestions?
Comment #8
j0rd commentedYa, I really need to be able to access the configuration in hook_commerce_payment_method_info_alter(), as this is the information that's used for display.
I can do it in form_alter(), but I have a problem with being able to identifying the payment methods are they're key'd in that weird pipe format.
The ideal way would be to pass in the payment configuration into hook_commerce_payment_method_info_alter() so the developers have all the information they'll need to modify it accordingly to their particular needs. Having the order in there would be nice too. Not sure if this is feasible, but with out it, we're pretty much forced to use the default payment gateways display information with out major hackery.
I might have a patch.
Comment #9
j0rd commentedThe problem is you keep calling commerce_payment_method_load() which doesn't have the changes made via hook_commerce_payment_methods_alter() and it overrides them. You seem to only be trusting the data which comes via commerce_payment_method_load(). In order to make this work, the code needs a re-factor.
I would do this myself, but I have a feeling anything I do may have un-intended consequences.
With that said, I have a proposed solution. You need to trust the data $order->payment_methods. We also need to load the payment_method information which is loaded via the rule in there as well. Then you'll need to prune out the potentially bad (or disabled) payment modules. Although, you may just be being over diligent in the code. I'm not sure.
If you wanted to go this route, I've added a patch. After this patch, if you always use the information in $order->payment_methods in the function commerce_payment_pane_checkout_form(), we should be good as far as I'm concerned.
---
Caveat: If you use this patch data in commerce_payment_method_load() can't really be trusted, as it's not modified. Ideally commerce_payment_method_load() would return the proper modified data.
Let me know if you need additional elaboration.
Comment #10
introfini commentedsubscribe...
Comment #11
j0rd commentedUpdated my module to work with -dev.
Here's the code:
http://drupal.org/project/commerce_payment_icons
Comment #12
rszrama commentedj0rd, that's brilliant. In your opinion, is it ok for us to move some of those icons into the modules themselves?
Comment #13
j0rd commentedI do think my example provides a much better user experience as it's much more clear to the end user what processor is used for what.

In my opinion, the best method for UX would be for each processor to define these elements. For those who create processors, it should be required that they define these elements.
The site builder, then needs to be able to override all of these. Ideally this could be done via a UX, but if not a proper hook could be provided to do it in code. Thus the site builder has full control of what the best method is to display and describe each processor they have enabled on their site.
Like for example, I'm not a huge fan of displaying "Paypal WPS" and would much rather have it just say "Paypal". Currently there no easy way to change this.
Currently there's no appropriate hook to do so and it becomes fairly hacky as my module demonstrates.
I'd also like the old Security Code description popup which Ubercart had. Currently I believe some users won't understand what to put in there.
Comment #14
rszrama commentedYeah, the PayPal thing definitely needs to be fixed. I think there's already an issue for that in its tracker. Perhaps if we provide the base set of icons in the Payment module itself it will make it easier for the payment methods to display them inline with their display titles on the checkout form.
Comment #15
summit commentedHi, http://drupal.org/project/commerce_payment_icons is not working, what I see on project page.
Any solution for the payment icons already please?
Thanks a lot in advance for your reply!
Greetings,
Martijn
Comment #16
berdirI can confirm that the hook doesn't really help to solve the problem of configurable display titles, because these come from the payment methods.
I've written an alternative patch that implements this functionality directly in commerce_payment, instead of adding a hook. Please review #1806540: Allow to customize the display title of a payment instance through the rule.