Hi, im having some trouble making a nochex payment module for ubercart and was wondering if anyone can help? Heres the php code for it. so far it will take the user to the checkout but once they have paid i need to to go to a confirmation page and edit the order status on my website.
Any help would be great
Thanks
Andy
Any help would be great
Thanks
Andy
PHP:
<?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' => 'cart/nochex/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>';
}
}
}
/*******************************************************************************
* Hook Functions (Ubercart)
******************************************************************************/
/**
* Implementation of hook_payment_method().
*/
function uc_nochex_payment_method() {
$path = base_path() . drupal_get_path('module', 'uc_nochex');
$title = variable_get('uc_nochex_method_title', t('Credit Card'));
$title .= '<br /><img src="'. $path .'/merchant-services.jpg" style="position: relative; left: 2.5em;">';
$methods[] = array(
'id' => 'nochex',
'name' => t('Nochex'),
'title' => $title,
'review' => variable_get('uc_nochex_check', FALSE) ? t('Credit card/eCheck') : t('Credit card'),
'desc' => t('Redirect to Nochex to pay by credit card or eCheck.'),
'callback' => 'uc_payment_method_nochex',
'weight' => 3,
'checkout' => TRUE,
'no_gateway' => TRUE,
);
return $methods;
}
/*******************************************************************************
* Callback Functions, Forms, and Tables
******************************************************************************/
/**
* Callback for Nochex payment method settings.
*/
function uc_payment_method_nochex($op, &$arg1) {
switch ($op) {
case 'cart-details':
if (variable_get('uc_nochex_check', FALSE)) {
if ($_SESSION['pay_method'] == 'CK') {
$sel[2] = ' selected="selected"';
}
else {
$sel[1] = ' selected="selected"';
}
unset($_SESSION['pay_method']);
$details = '<div class="form-item"><b>'. t('Select your payment type:')
.'</b> <select name="pay_method" class="form-select" id="edit-pay-method">'
.'<option value="CC"'. $sel[1] .'>'. t('Credit card') .'</option>'
.'<option value="CK"'. $sel[2] .'>'. t('Online check') .'</option></select></div>';
}
return $details;
case 'cart-process':
$_SESSION['pay_method'] = $_POST['pay_method'];
return;
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/cart/nochex/complete/",
'cancel_url' => "http://www.headboxed.com/cart/nochex/cancel/",
'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/cart/nochex/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/cart/nochex/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) {
watchdog('Nochex', t('Receiving new order notification for order !order_id.', array('!order_id' => check_plain($_POST['order_id']))));
$order = uc_order_load($_POST['order_id']);
if ($order === FALSE || uc_order_status_data($order->order_status, 'state') != 'in_checkout') {
print t('An error has occurred during payment. Please contact us to ensure your order has submitted.');
exit();
}
$order->billing_street1 = $_POST['billing_street1'];
$order->billing_street2 = $_POST['billing_street2'];
$order->city = $_POST['billing_city'];
$order->billing_postal_code = $_POST['billing_postal_code'];
$order->billing_phone = $_POST['billing_phone'];
$country_id = db_result(db_query("SELECT country_id FROM {uc_countries} WHERE country_name LIKE '%s'", $_POST['country']));
if (!empty($zone_id)) {
$order->billing_country = $country_id;
}
$comment = t('Paid by !type, nochex.com order #!order.', array('!order' => check_plain($_POST['order_id'])));
uc_payment_enter($order->order_id, 'nochex', $_POST['amount'], 0, NULL, $comment);
// Empty that cart...
uc_cart_empty($cart_id);
$output .= uc_cart_complete_sale($order);
// Add a comment to let sales team know this came in through the site.
uc_order_comment_save($order->order_id, 0, t('Order created through website.'), 'admin');
print $output;
exit();
}