Re: Hi Andy, We must have lost

Posts: 17
Joined: 03/27/2008

hi mate, yeah dunno what happened there. ill be on in about half on hour. i have been working on the code and this is what i got so far: why doesnt it step into the

function uc_nochex_complete

when it reaches the confirmation page. i Must be missing something.

<?php
// $Id$

/**
* @file
* Integrates noxchex.com's redirected payment service.
*
* Development sponsored by .
*/

/*******************************************************************************
* Hook Functions (Drupal)
******************************************************************************/

/**
* Implementation of hook_menu().
*/
function uc_nochex_menu($may_cache) {
  if ($may_cache) {
    $items[] = array(
      'path' => 'content/order-complete',
      'title' => t('Order complete'),
      'callback' => 'uc_nochex_complete',
      'access' => user_access('access content'),
      'type' => MENU_CALLBACK,
    );
  }

  return $items;
}

/**
* Implementation of hook_form_alter().
*/
function uc_nochex_form_alter($form_id, &$form) {
  if ($form_id == 'uc_cart_checkout_review_form' && ($order_id = intval($_SESSION['cart_order'])) > 0) {
    $order = uc_order_load($order_id);

    if ($order->payment_method == 'nochex') {
      unset($form['submit']);
      $form['#prefix'] = '<table style="display: inline; padding-top: 1em;"><tr><td>';
      $form['#suffix'] = '</td><td>'. drupal_get_form('uc_nochex_form', $order) .'</td></tr></table>';
    }
  }
}


/*******************************************************************************
* Callback Functions, Forms, and Tables
******************************************************************************/

/**
* Callback for Nochex payment method settings.
*/

function uc_payment_method_nochex($op, &$arg1) {
  switch ($op) {
  
    case 'settings':

      $form['uc_nochex_test'] = array(
        '#type' => 'checkbox',
        '#title' => t('Enable test mode, allowing you to process fake orders for testing purposes.'),
        '#default_value' => variable_get('uc_nochex_test', FALSE),
      );
      $form['uc_nochex_hidebilling'] = array(
        '#type' => 'checkbox',
        '#title' => t('Hide Billing address on payment page, so customers cant edit it.'),
        '#default_value' => variable_get('uc_nochex_hidebilling', FALSE),
      );
      $form['uc_nochex_sid'] = array(
        '#type' => 'textfield',
        '#title' => t('Nochex email address'),
        '#description' => t('Your Nochex account email.'),
        '#default_value' => variable_get('uc_nochex_sid', ''),
        '#size' => 16,
      );
      $form['uc_nochex_method_title'] = array(
        '#type' => 'textfield',
        '#title' => t('Payment method title'),
        '#default_value' => variable_get('uc_nochex_method_title', t('Credit Card:')),
      );
      $form['uc_nochex_checkout_button'] = array(
        '#type' => 'textfield',
        '#title' => t('Order review submit button text'),
        '#description' => t('Provide Nochex specific text for the submit button on the order review page.'),
        '#default_value' => variable_get('uc_nochex_checkout_button', t('Submit Order')),
      );
      return $form;
 
}
}

// Form to build the submission to Nochex.com.
function uc_nochex_form($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(
    'merchant_id' => variable_get('uc_nochex_sid', ''),
    'logo' => "http://www.headboxed.com/themes/greenNblack/img/header_bg.png",
    'amount' => uc_currency_format($order->order_total, FALSE, FALSE, '.'),
    'order_id' => $order->order_id,
    'success_url' => "http://www.headboxed.com/content/order-complete/",
    'cancel_url' => "http://www.headboxed.com/content/order-complete/",
    'billing_fullname' =>  substr($order->billing_first_name .' '. $order->billing_last_name, 0, 128),
    'billing_address' => substr($order->billing_street1. ' '. $order->billing_street2. ' '. $order->billing_city. ' '. $order->billing_zone.' '. $country[0]['country_iso_code_2'], 0, 256),
    'billing_postcode' => substr($order->billing_postal_code, 0, 16),
    'customer_phone_number' => substr($order->billing_phone, 0, 16),
    'callback_url' => url('http://www.headboxed.com/content/order-complete/'. uc_cart_get_id(), NULL, NULL, TRUE),
    'email_address' => substr($order->primary_email, 0, 64),
    'hide_billing_details' => variable_get('uc_nochex_hidebilling', TRUE) ? 'true' : 'false',
   
    'test_transaction' => variable_get('uc_nochex_test', TRUE) ? '100' : '',
    'test_success_url' => url('http://www.headboxed.com/content/order-complete/', NULL, NULL, TRUE)

  );

  $i = 0;
  foreach ($order->products as $product) {
    $i++;
    $data['c_prod_'. $i] = $product->model .','. $product->qty;
    $data['c_name_'. $i] = $product->title;
    $data['c_description_'. $i] = $desc;
    $data['c_price_'. $i] = uc_currency_format($product->price, FALSE, FALSE, '.');
  }

  $form['#action'] = 'https://secure.nochex.com';

  foreach ($data as $name => $value) {
    $form[$name] = array('#type' => 'hidden', '#value' => $value);
  }

  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => variable_get('uc_nochex_checkout_button', t('Submit Order')),
  );

  return $form;
}



function uc_nochex_complete($cart_id = 0) {
 
  $order = uc_order_load($_POST['order_id']);

  // change order status to payment revieved
  uc_order_update_status($order, 'payment_received');

  // Empty the cart.
  uc_cart_empty($cart_id);

  exit();
}

nochex integration By: montana (6 replies) Thu, 03/27/2008 - 18:49