Created
October 23, 2014 19:31
-
-
Save albertvolkman/961944382378d115e4d7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Load available payment methods for an order. | |
* | |
* @param string $order_uuid | |
* The order's UUID. | |
* | |
* @return array | |
* The available payment methods. | |
*/ | |
public function getUserPaymentMethods($order_uuid) | |
{ | |
static $options = array(); | |
if (empty($options)) { | |
// Bootstrap store. | |
$this->drupalWithUser->bootstrapStore(); | |
// Load the order. | |
$order = reset(entity_uuid_load('commerce_order', array($order_uuid))); | |
rules_invoke_all('commerce_payment_methods', $order); | |
drupal_alter('commerce_payment_methods', $order); | |
// Sort the payment methods array by the enabling Rules' weight values. | |
uasort($order->payment_methods, 'drupal_sort_weight'); | |
// Generate an array of payment method options for the checkout form. | |
$options = array(); | |
foreach ($order->payment_methods as $instance_id => $method_info) { | |
// Ensure we've received a valid payment method that can be used on the | |
// checkout form. | |
if ($payment_method = commerce_payment_method_load($method_info['method_id'])) { | |
if (!empty($payment_method['checkout'])) { | |
$options[$instance_id] = $payment_method['display_title']; | |
} | |
} | |
} | |
} | |
return $options; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment