123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250 |
- <?php
- /**
- * @file
- * Integrates 2Checkout.com's redirected payment service.
- */
- /**
- * Implements hook_help().
- */
- function uc_2checkout_help($path, $arg) {
- switch ($path) {
- case 'admin/store/settings/payment/method/%':
- if ($arg[5] == '2checkout') {
- return '<p>' . t('To accept PayPal payments in 2Checkout, please ensure that demo mode is disabled and your store currency is one of USD, AUD, CAD, EUR or GBP.') . '</p>';
- }
- }
- }
- /**
- * Implements hook_menu().
- */
- function uc_2checkout_menu() {
- $items = array();
- $items['cart/2checkout/complete'] = array(
- 'title' => 'Order complete',
- 'page callback' => 'uc_2checkout_complete',
- 'access callback' => TRUE,
- 'type' => MENU_CALLBACK,
- 'file' => 'uc_2checkout.pages.inc',
- );
- $items['cart/2checkout/notification'] = array(
- 'page callback' => 'uc_2checkout_process_notification',
- 'access callback' => TRUE,
- 'file' => 'uc_2checkout.pages.inc',
- );
- return $items;
- }
- /**
- * Implements hook_init().
- */
- function uc_2checkout_init() {
- global $conf;
- $conf['i18n_variables'][] = 'uc_2checkout_method_title';
- }
- /**
- * Implements hook_ucga_display().
- */
- function uc_2checkout_ucga_display() {
- // Tell UC Google Analytics to display the e-commerce JS on the custom
- // order completion page for this module.
- if (arg(0) == 'cart' && arg(1) == '2checkout' && arg(2) == 'complete') {
- return TRUE;
- }
- }
- /**
- * Implements hook_uc_payment_method().
- *
- * @see uc_payment_method_2checkout()
- */
- function uc_2checkout_uc_payment_method() {
- $path = base_path() . drupal_get_path('module', 'uc_2checkout');
- $title = variable_get('uc_2checkout_method_title', t('Credit card on a secure server:'));
- $title .= '<br />' . theme('image', array(
- 'path' => drupal_get_path('module', 'uc_2checkout') . '/2co_logo.jpg',
- 'attributes' => array('class' => array('uc-2checkout-logo')),
- ));
- $methods['2checkout'] = array(
- 'name' => t('2Checkout'),
- 'title' => $title,
- 'review' => variable_get('uc_2checkout_check', FALSE) ? t('Credit card/eCheck') : t('Credit card'),
- 'desc' => t('Redirect to 2Checkout to pay by credit card or eCheck.'),
- 'callback' => 'uc_payment_method_2checkout',
- 'redirect' => 'uc_2checkout_form',
- 'weight' => 3,
- 'checkout' => TRUE,
- 'no_gateway' => TRUE,
- );
- return $methods;
- }
- /**
- * Adds 2Checkout settings to the payment method settings form.
- *
- * @see uc_2checkout_uc_payment_method()
- */
- function uc_payment_method_2checkout($op, &$order, $form = NULL, &$form_state = NULL) {
- switch ($op) {
- case 'cart-details':
- $build = array();
- if (variable_get('uc_2checkout_check', FALSE)) {
- $build['pay_method'] = array(
- '#type' => 'select',
- '#title' => t('Select your payment type:'),
- '#default_value' => $_SESSION['pay_method'] == 'CK' ? 'CK' : 'CC',
- '#options' => array(
- 'CC' => t('Credit card'),
- 'CK' => t('Online check'),
- ),
- );
- unset($_SESSION['pay_method']);
- }
- return $build;
- case 'cart-process':
- if (isset($form_state['values']['panes']['payment']['details']['pay_method'])) {
- $_SESSION['pay_method'] = $form_state['values']['panes']['payment']['details']['pay_method'];
- }
- return;
- case 'settings':
- $form['uc_2checkout_sid'] = array(
- '#type' => 'textfield',
- '#title' => t('Vendor account number'),
- '#description' => t('Your 2Checkout vendor account number.'),
- '#default_value' => variable_get('uc_2checkout_sid', ''),
- '#size' => 16,
- );
- $form['uc_2checkout_secret_word'] = array(
- '#type' => 'textfield',
- '#title' => t('Secret word for order verification'),
- '#description' => t('The secret word entered in your 2Checkout account Look and Feel settings.'),
- '#default_value' => variable_get('uc_2checkout_secret_word', 'tango'),
- '#size' => 16,
- );
- $form['uc_2checkout_demo'] = array(
- '#type' => 'checkbox',
- '#title' => t('Enable demo mode, allowing you to process fake orders for testing purposes.'),
- '#default_value' => variable_get('uc_2checkout_demo', TRUE),
- );
- $form['uc_2checkout_language'] = array(
- '#type' => 'select',
- '#title' => t('Language preference'),
- '#description' => t('Adjust language on 2Checkout pages.'),
- '#options' => array(
- 'en' => t('English'),
- 'sp' => t('Spanish'),
- ),
- '#default_value' => variable_get('uc_2checkout_language', 'en'),
- );
- $form['uc_2checkout_currency_code'] = array(
- '#type' => 'select',
- '#title' => t('Currency for the sale'),
- '#options' => array(
- '' => t('Auto detected by 2CO'),
- 'USD', 'EUR', 'ARS', 'AUD', 'BRL', 'GBP', 'CAD', 'DKK', 'HKD', 'INR', 'ILS', 'JPY', 'LTL', 'MYR', 'MXN', 'NZD', 'NOK', 'PHP', 'RON', 'RUB', 'SGD', 'ZAR', 'SEK', 'CHF', 'TRY', 'AED',
- ),
- '#default_value' => variable_get('uc_2checkout_currency_code', ''),
- );
- $form['uc_2checkout_check'] = array(
- '#type' => 'checkbox',
- '#title' => t('Allow customers to choose to pay by credit card or online check.'),
- '#default_value' => variable_get('uc_2checkout_check', FALSE),
- );
- $form['uc_2checkout_method_title'] = array(
- '#type' => 'textfield',
- '#title' => t('Payment method title'),
- '#default_value' => variable_get('uc_2checkout_method_title', t('Credit card on a secure server:')),
- );
- $form['uc_2checkout_checkout_type'] = array(
- '#type' => 'radios',
- '#title' => t('Checkout type'),
- '#options' => array(
- 'dynamic' => t('Dynamic checkout (user is redirected to 2CO)'),
- 'direct' => t('Direct checkout (payment page opens in iframe popup)'),
- ),
- '#default_value' => variable_get('uc_2checkout_checkout_type', 'dynamic'),
- );
- $form['uc_2checkout_notification_url'] = array(
- '#type' => 'textfield',
- '#title' => t('Instant notification settings URL'),
- '#description' => t('Pass this URL to the <a href="@help_url">instant notification settings</a> parameter in your 2Checkout account. This way, any refunds or failed fraud reviews will automatically cancel the Ubercart order.', array('@help_url' => 'https://www.2checkout.com/static/va/documentation/INS/index.html')),
- '#default_value' => url('cart/2checkout/notification', array('absolute' => TRUE)),
- '#attributes' => array('readonly' => 'readonly'),
- );
- return $form;
- }
- }
- /**
- * Form to build the submission to 2Checkout.com.
- */
- 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;
- }
|