Inactive
- Join Date:
- Aug 2006
- Location:
- Singapore
- Posts:
- 167
- Plugin Contributions:
- 1
How to post order to admin/database upon clicking 'Confirm'?
Dear Zenners!
I'm building a simple payment module for a client, like an offline cc processing, but at external site, we sent some hidden fields info to the payment gateway such as order amount etc, this part is done and no problem.
But this payment gateway doesn't have return notification (callback) to the store, so we have to post order as success to database/admin and emailing customer upon click 'Confirm' button on Checkout Confirmation page before leaving the store.
However, for the life of me, I can't figure out how to post success order to database upon clicking 'confirm' button, I'm not expert in coding and maybe I'm too old for this :D
Please help me if you know how to do that, below is the coding I made:
<?php
class cardcharge {
var $code, $title, $description, $enabled;
function cardcharge()
{
global $db, $order;
$this->code = 'cardcharge';
$this->title = MODULE_PAYMENT_CARDCHARGE_TEXT_TITLE;
$this->description = MODULE_PAYMENT_CARDCHARGE_TEXT_DESCRIPTION;
$this->sort_order = MODULE_PAYMENT_CARDCHARGE_SORT_ORDER;
$this->enabled = ((MODULE_PAYMENT_CARDCHARGE_STATUS == 'True') ? true : false);
$this->form_action_url = "https://www.somesite.com/ccConnect.aspx";
if ((int)MODULE_PAYMENT_CARDCHARGE_ORDER_STATUS_ID > 0)
{
$this->order_status = MODULE_PAYMENT_CARDCHARGE_ORDER_STATUS_ID;
}
if (is_object($order)) $this->update_status();
}
function update_status() {
global $order, $db;
if ( ($this->enabled == true) && ((int)MODULE_PAYMENT_CARDCHARGE_ZONE > 0) ) {
$check_flag = false;
$check = $db->Execute("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_PAYMENT_CARDCHARGE_ZONE . "' and zone_country_id = '" . $order->billing['country']['id'] . "' order by zone_id");
while (!$check->EOF)
{
if ($check->fields['zone_id'] < 1)
{
$check_flag = true;
break;
}
elseif ($check->fields['zone_id'] == $order->billing['zone_id'])
{
$check_flag = true;
break;
}
$check->MoveNext();
}
if ($check_flag == false) {
$this->enabled = false;
}
}
}
function javascript_validation() {
return false;
}
function selection() {
global $order;
return array('id' => $this->code,
'module' => 'Cardcharge Secure Card Processor <br> <span style="padding:25px;"> <img src=images/logo_Cardcharge.gif border=0 alt=Cardcharge Online Payment title=Cardcharge Online Payment Gateway height=39 width=107></span>'
);
}
function pre_confirmation_check() {
return false;
}
function confirmation() {
return false;
}
function process_button() {
global $_POST, $db, $languages_id, $shipping_cost, $total_cost, $shipping_selected, $shipping_method, $currencies, $currency, $db, $order, $order_status, $last_modified, $order_id;
$prod = $order->product;
while ( list($key,$val) = each($order->products) ) {
$pname.= $val[name]." x ".$val[qty]."\n";
}
$zenId = zen_session_name() . '=' . zen_session_id();
$cartId = zen_session_id();
$curr_obj = $order->info;
$currency = $curr_obj[currency];
$scSubmitButtonLabel = MODULE_PAYMENT_CARDCHARGE_TEXT_SUBMIT_LABEL;
$scCardHeaderText = MODULE_PAYMENT_CARDCHARGE_TEXT_CARD_HEADER;
$scCardFooterText = MODULE_PAYMENT_CARDCHARGE_TEXT_CARD_FOOTER;
$scConfirmText = MODULE_PAYMENT_CARDCHARGE_TEXT_CONFIRM_TEXT;
$scConfirmInfo = MODULE_PAYMENT_CARDCHARGE_TEXT_CONFIRM_INFO;
$OrderAmt = number_format($order->info['total'] * $currencies->get_value($currency), $currencies->get_decimal_places($currency), '.', '') ;
$oid_sql = "select Max(orders_id) as oid from ".TABLE_ORDERS." ";
$oid = $db->Execute($oid_sql);
$oid = $oid->fields['oid']+1;
$db->Execute("UPDATE " . TABLE_ORDERS . " SET orders_status = '" . $order_status . "', last_modified = '" . $last_modified . "' WHERE orders_id = '" . (int)$order_id . "'");
$accid = MODULE_PAYMENT_CARDCHARGE_ID;
$process_button_string =
zen_draw_hidden_field('scAMOUNT', $OrderAmt).
zen_draw_hidden_field('ACCOUNTID', $accid).
zen_draw_hidden_field('scSubmitButtonLabel', $scSubmitButtonLabel).
zen_draw_hidden_field('scCardHeaderText', $scCardHeaderText).
zen_draw_hidden_field('scCardFooterText', $scCardFooterText).
zen_draw_hidden_field('scConfirmText', $scConfirmText).
zen_draw_hidden_field('scConfirmInfo', $scConfirmInfo);
return $process_button_string ;
}
function before_process() {
return false;
}
function after_process() {
return false;
}
function get_error() {
global $_GET;
$error = array('title'=>'CardCharge Error',
'error'=>'Error Detail');
//return false;
}
function check() {
global $db;
if (!isset($this->_check)) {
$check_query = $db->Execute("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_PAYMENT_CARDCHARGE_STATUS'");
$this->_check = $check_query->RecordCount();
}
return $this->_check;
}
function install() {
global $db;
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values
('Enable Cardcharge Module', 'MODULE_PAYMENT_CARDCHARGE_STATUS', 'True', 'Do you want to accept Cardcharge payments?', '6', '1', 'zen_cfg_select_option(array(\'True\', \'False\'), ', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values
('Cardcharge Account ID', 'MODULE_PAYMENT_CARDCHARGE_ID', '', 'Your Cardcharge Merchant ID', '6', '2', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values
('Sort order of display.', 'MODULE_PAYMENT_CARDCHARGE_SORT_ORDER', '0', 'Sort order of display. Lowest is displayed first.', '6', '0', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, use_function, date_added) values
('Set Order Status', 'MODULE_PAYMENT_CARDCHARGE_ORDER_STATUS_ID', '0', 'Set the status of orders made with this payment module to this value', '6', '0', 'zen_cfg_pull_down_order_statuses(', 'zen_get_order_status_name', now())");
}
function remove() {
global $db;
$db->Execute("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
}
////////////////////////////////////////////////////
// Create our Key - > Value Arrays
////////////////////////////////////////////////////
function keys() {
return array(
'MODULE_PAYMENT_CARDCHARGE_STATUS'
,'MODULE_PAYMENT_CARDCHARGE_ID'
,'MODULE_PAYMENT_CARDCHARGE_SORT_ORDER'
,'MODULE_PAYMENT_CARDCHARGE_ORDER_STATUS_ID'
);
}
}
?>
many thanks!!