You are here

function uc_2checkout_form in Ubercart 7.3

Same name and namespace in other branches
  1. 5 payment/uc_2checkout/uc_2checkout.module \uc_2checkout_form()
  2. 6.2 payment/uc_2checkout/uc_2checkout.module \uc_2checkout_form()

Form to build the submission to 2Checkout.com.

1 string reference to 'uc_2checkout_form'
uc_2checkout_uc_payment_method in payment/uc_2checkout/uc_2checkout.module
Implements hook_uc_payment_method().

File

payment/uc_2checkout/uc_2checkout.module, line 192
Integrates 2Checkout.com's redirected payment service.

Code

function uc_2checkout_form($form, &$form_state, $order) {
  $country = uc_get_country_data(array(
    'country_id' => $order->billing_country,
  ));
  if ($country === FALSE) {
    $country = array(
      0 => array(
        'country_iso_code_3' => 'USA',
      ),
    );
  }
  $data = array(
    'sid' => variable_get('uc_2checkout_sid', ''),
    'mode' => '2CO',
    'card_holder_name' => drupal_substr($order->billing_first_name . ' ' . $order->billing_last_name, 0, 128),
    'street_address' => drupal_substr($order->billing_street1, 0, 64),
    'street_address2' => drupal_substr($order->billing_street2, 0, 64),
    'city' => drupal_substr($order->billing_city, 0, 64),
    'state' => uc_get_zone_code($order->billing_zone),
    'zip' => drupal_substr($order->billing_postal_code, 0, 16),
    'country' => $country[0]['country_iso_code_3'],
    'email' => drupal_substr($order->primary_email, 0, 64),
    'phone' => drupal_substr($order->billing_phone, 0, 16),
    'purchase_step' => 'payment-method',
    'demo' => variable_get('uc_2checkout_demo', TRUE) ? 'Y' : 'N',
    'lang' => variable_get('uc_2checkout_language', 'en'),
    'merchant_order_id' => $order->order_id,
    'pay_method' => 'CC',
    'x_receipt_link_url' => url('cart/2checkout/complete/' . uc_cart_get_id(), array(
      'absolute' => TRUE,
    )),
    'total' => uc_currency_format($order->order_total, FALSE, FALSE, '.'),
    'cart_order_id' => $order->order_id,
  );
  if ($currency_code = variable_get('uc_2checkout_currency_code', '')) {
    $data['currency_code'] = $currency_code;
  }
  $i = 0;
  foreach ($order->products as $product) {
    $i++;
    $data['li_' . $i . '_name'] = $product->title;
    $data['li_' . $i . '_price'] = uc_currency_format($product->price, FALSE, FALSE, '.');
  }
  if (variable_get('uc_2checkout_checkout_type', 'dynamic') == 'direct') {
    $form['#suffix'] = '<script src="https://www.2checkout.com/static/checkout/javascript/direct.min.js"></script>';
  }
  $form['#action'] = variable_get('uc_2checkout_server_url', 'https://www.2checkout.com/checkout/purchase');
  foreach ($data as $name => $value) {
    $form[$name] = array(
      '#type' => 'hidden',
      '#value' => $value,
    );
  }
  $form['actions'] = array(
    '#type' => 'actions',
  );
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Submit order'),
  );
  return $form;
}