You are here

function theme_commerce_paypal_checkout_smart_payment_buttons in Commerce PayPal 7.2

Returns HTML for the Smart payment buttons.

Parameters

$variables: An associative array containing:

  • payment_method: The payment method instance.
  • commit: A boolean indicating whether to commit the transaction.
  • order: The order.
  • flow: The flow ("shortcut"|"mark").
2 theme calls to theme_commerce_paypal_checkout_smart_payment_buttons()
commerce_paypal_checkout_form_alter in modules/checkout/commerce_paypal_checkout.module
Implements hook_form_alter().
commerce_paypal_checkout_redirect_form in modules/checkout/commerce_paypal_checkout.module
Payment method callback: redirect form.

File

modules/checkout/commerce_paypal_checkout.module, line 774
Implements PayPal Checkout in Drupal Commerce checkout.

Code

function theme_commerce_paypal_checkout_smart_payment_buttons($variables) {
  $payment_method = $variables['payment_method'];
  $settings = $payment_method['settings'] + commerce_paypal_checkout_default_settings();
  if (empty($settings['client_id']) || empty($variables['order']) || empty($variables['flow'])) {
    return;
  }
  $order = $variables['order'];
  $order_total = field_get_items('commerce_order', $order, 'commerce_order_total', LANGUAGE_NONE);
  if (!isset($order_total[0]['currency_code'])) {
    return;
  }
  $flow = $variables['flow'];
  list(, $rule_name) = explode('|', $payment_method['instance_id']);
  $options = array(
    'external' => TRUE,
    'query' => array(
      'client-id' => $settings['client_id'],
      'commit' => $variables['commit'] ? 'true' : 'false',
      'intent' => $settings['intent'],
      'currency' => $order_total[0]['currency_code'],
    ),
  );
  if (!empty($settings['disable_funding'])) {
    $options['query']['disable-funding'] = implode(',', $settings['disable_funding']);
  }
  if (!empty($settings['disable_card'])) {
    $options['query']['disable-card'] = implode(',', $settings['disable_card']);
  }
  $path = drupal_get_path('module', 'commerce_paypal_checkout');
  $js_settings = array(
    'paypalCheckout' => array(
      'src' => url('https://www.paypal.com/sdk/js', $options),
      'createOrderUri' => url("commerce-paypal-checkout/create-order/{$order->order_id}/{$rule_name}"),
      'onApproveUri' => url("commerce-paypal-checkout/approve-order/{$order->order_id}/{$rule_name}/{$flow}"),
      'style' => $settings['style'],
    ),
  );
  drupal_add_css($path . '/css/commerce_paypal_checkout.css');
  drupal_add_js($js_settings, 'setting');
  drupal_add_js($path . '/js/commerce_paypal_checkout.js');
  $id = drupal_html_id('paypal-buttons-container');
  return '<div id="' . $id . '" class="paypal-buttons-container"></div>';
}