Zen Cart Logo
Forums / General Questions / How to post order to admin/database upon clicking 'Confirm'?

How to post order to admin/database upon clicking 'Confirm'?

Locked

Views: 1,244

Results 1 to 6 of 6
This thread is locked. New replies are disabled.
7 Sep 2010, 5:37 PM
#1
milkyway avatar

milkyway

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!!

7 Sep 2010, 5:39 PM
#2
milkyway avatar

milkyway

Inactive

Join Date:
Aug 2006
Location:
Singapore
Posts:
167
Plugin Contributions:
1

Re: How to post order to admin/database upon clicking 'Confirm'?

And I know some garbage codes still in the coding above... not yet cleaned them up :P

7 Sep 2010, 5:59 PM
#3
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: How to post order to admin/database upon clicking 'Confirm'?

milkyway:

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.I suggest that you don't do it that way. Bad idea, since you're basically telling the customer that you've accepted their order, even if they don't pay you.> milkyway:

However, for the life of me, I can't figure out how to post success order to database upon clicking 'confirm' button
That's because it's not designed to work that way in any of the modules.

Instead, you have your gateway return the customer back to the store's main_page=checkout_process page, which will save the order and send the email after verifying that the payment has been completed.
It's not a "callback". It's not a "notification". It's merely a "return".

This would require that you put your POST code into the before_process() function, instead of the pre_confirmation_check() function.

7 Sep 2010, 6:17 PM
#4
milkyway avatar

milkyway

Inactive

Join Date:
Aug 2006
Location:
Singapore
Posts:
167
Plugin Contributions:
1

Re: How to post order to admin/database upon clicking 'Confirm'?

DrByte, thank you for your reply and I agree with you as returning them to checkout_process page will be much better.

But I'm an idiot :P, how zencart knows which order is completed if no session and no order id sent back from payment site?

By the way, this payment gateway allow HTML code at their payment page, does it help if we ask customer to click the link back to store which redirect them to checkout process page?

Many thanks again!

8 Sep 2010, 2:28 PM
#5
milkyway avatar

milkyway

Inactive

Join Date:
Aug 2006
Location:
Singapore
Posts:
167
Plugin Contributions:
1

Re: How to post order to admin/database upon clicking 'Confirm'?

DrByte,

I didn't put anything in function before_process() and just ask customer to click link which redirecting to checkout_process page after payment, and the order posted successfully to admin/database.

It seems working good so far.

Thanks!

8 Sep 2010, 2:30 PM
#6
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: How to post order to admin/database upon clicking 'Confirm'?

I recommend that you do extensive testing to try to make it accept the order even if payment fails ... because some hacker is gonna try that on you and you'll be sorry if you don't accommodate proper checking for fraud attempts.