Results 1 to 6 of 6
  1. #1
    Join Date
    Aug 2006
    Location
    Singapore
    Posts
    167
    Plugin Contributions
    1

    Default 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

    Please help me if you know how to do that, below is the coding I made:

    PHP Code:

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

  2. #2
    Join Date
    Aug 2006
    Location
    Singapore
    Posts
    167
    Plugin Contributions
    1

    Default 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

  3. #3
    Join Date
    Jan 2004
    Posts
    66,443
    Plugin Contributions
    279

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

    Quote Originally Posted by milkyway View Post
    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.
    Quote Originally Posted by milkyway View Post
    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.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  4. #4
    Join Date
    Aug 2006
    Location
    Singapore
    Posts
    167
    Plugin Contributions
    1

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

  5. #5
    Join Date
    Aug 2006
    Location
    Singapore
    Posts
    167
    Plugin Contributions
    1

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

  6. #6
    Join Date
    Jan 2004
    Posts
    66,443
    Plugin Contributions
    279

    Default 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.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

 

 

Similar Threads

  1. ERROR: your cart is empty messsage upon paypal checkout/confirm order?
    By wondergirl in forum Built-in Shipping and Payment Modules
    Replies: 5
    Last Post: 21 Dec 2010, 04:38 AM
  2. Replies: 3
    Last Post: 20 Dec 2010, 04:57 AM
  3. Replies: 4
    Last Post: 7 Dec 2010, 11:40 PM
  4. Blanks page loads after clicking Confirm Order
    By slapface in forum Addon Payment Modules
    Replies: 11
    Last Post: 27 Nov 2010, 08:33 PM
  5. Problems after clicking 'Confirm Order'
    By superprg in forum General Questions
    Replies: 1
    Last Post: 28 Aug 2007, 09:22 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg