Drupal Commerce: Getting payment gateway configuration programatically
In Drupal Commerce RC3, there's no easy way to get this done, but I managed to figure it out.
UPDATE: I finished a basic sample module, which others might find useful. Go download Commerce Payment Icons.
I'm not a huge fan of how Drupal Commerce displays the payment options to the end user during checkout. I feel it's poor UX and hard to understand.
I wanted to change it to look more like Ubercart, which I feel is easier for the end user to understand.
Let's take a look at these panes in Ubercart vs. Drupal Commerce
Drupal Commerce Payment Pane

Ubercart Payment Pane

I personally much prefer the Ubercart pane with the icons. I think the users will understand this more, than the bare form with Drupal Commerce. With that said, you'll need to hook into Drupal Commerce Paypal payment module to get this to happen. Since we'll only want to display the images for credit cards which are enabled, we'll need to get at the Payment modules configuration to be used in hook_commerce_payment_method_info_alter(). Unfortunately, this isn't as easy as one would guess because of how payment gateways are configured via the rules UI in Drupal Commerce. I managed to find the appropriate snippet to get you started on this though.
<?php
function pe_commerce_commerce_payment_method_info_alter(&$payment_methods) {
dpm($payment_methods);
foreach($payment_methods as $payment_method) {
$instance_id = $payment_method['method_id'] . '|' . "commerce_payment_" . $payment_method['method_id'];
$pm = commerce_payment_method_instance_load($instance_id);
dpm($pm);
}
}
?>Seems easy enough, but it took me a couple hours to figure out. So hopefully I'll save you some time when you find this via Google :)
Comments
Thank you so much