Page 1 of 2 12 LastLast
Results 1 to 10 of 17
  1. #1
    Join Date
    Sep 2010
    Posts
    48
    Plugin Contributions
    1

    Default allocated order number

    please can someone tell me if the order number is allocated after the customer is returned from the payment site or before being sent to the payment site?

    i'm writing a new payment module, but just cannot find when it's allocated.
    In my case, it's needed before, i.e in the hidden fields of the final process button string.

  2. #2
    Join Date
    Jan 2004
    Posts
    66,419
    Blog Entries
    7
    Plugin Contributions
    277

    Default Re: allocated order number

    The order number is assigned after the payment module completes entirely. The order is not created until payment is completed and verified by the payment module.
    .

    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.

  3. #3
    Join Date
    Sep 2010
    Posts
    48
    Plugin Contributions
    1

    Default Re: allocated order number

    many thanks for confirming this,
    i did conclude this but did not want to presume.

    as the payment method requires an order number to be posted
    that leaves me with having to create a new dynamic order number system

    for a work around does this sound a good route?....

    I could use a numbering system based on the current time (it will involve raising the ‘2000000000’ limit)
    e.g. order made today at 22:09:32 could be order number 130610220932007 [$new_orders_id = $yy . $MM . $DD . $H . $i . $s . $u] ....includes formatting the value for $u ~ ‘00’7, ‘0’17, 217 etc

    this seems straightforward,

    i concur this approach would mean gaps in the order numbers
    and
    i don’t think the probability is ever likely to be 1 for the situation where multiple orders end up having the have exact same start time.

    ideas for a alternative / simpler method ?
    Last edited by ajmn; 10 Jun 2013 at 11:08 PM.

  4. #4
    Join Date
    Jan 2004
    Posts
    66,419
    Blog Entries
    7
    Plugin Contributions
    277

    Default Re: allocated order number

    What the other payment modules do is look for the last order number, add one, and append a random suffix or timestamp, submitting the result with the payment request, but let ZC just do whatever it normally does when actually storing the final order. This accomplishes the desired goal with basically no changes to core functionality. It also prevents accidental duplicate numbers when submitting payments, even with busy sites and race-conditions, because the random number/string differentiates, and on the rare case where there is a clash, reconciliation activities are still very simple to handle when trying to match up numbers with orders (which is rarely a challenge).
    .

    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.

  5. #5
    Join Date
    Sep 2010
    Posts
    48
    Plugin Contributions
    1

    Default Re: allocated order number

    that's the easiest way, agreed,
    it does not matter what order number is finally given to the customer,
    I just did not want there to be any unnecessary confusion, e.g. one customer takes 4mins to complete and the second customer starting 1min later taking 2mins to complete.
    my logic was suggesting their order numbers would swop when the customer is returned to the store and their order was finalised and saved to db...
    therefore possibly complicating things if down the line if a request to the payment processor to administer a refund etc.
    the payment processors might be perturbed by the original posted order number not matching the refund order number
    ~ life's too short!!
    i will give your way a go, as you say it is a much simpler approach.
    once ready, i'll test for the above scenario too and report the results

    many thanks DrByte =:)

  6. #6
    Join Date
    Sep 2010
    Posts
    48
    Plugin Contributions
    1

    Default Re: allocated order number

    BTW:
    the example above...
    $new_orders_id = $yy . $MM . $DD . $H . $i . $s . $u

    was actually replaced by

    $new_orders_id = round(microtime(true) * 10000);

    ...just in case anyone was thinking WTF!

  7. #7
    Join Date
    Sep 2010
    Posts
    48
    Plugin Contributions
    1

    Default Re: allocated order number

    hi again
    i’m running into two problems,
    probably obvious but they are both eluding me... and i seem to be going around in circles... so am back for help!!

    first one is getting the order number...
    i’ve placed the following in
    PHP Code:
    function process_button() 
    and it caused the button and everything below it (on the 3of3 checkout page) to disappear,

    PHP Code:
    $last_order_id $db->Execute("SELECT * FROM " TABLE_ORDERS " ORDER BY orders_id DESC limit 1");
    $new_order_id $last_order_id->fields['orders_id'];
    $new_order_id = ($new_order_id 1);
    $new_order_id = (string)$new_order_id '-' zen_create_random_value(6); 
    in order to get to the 3rd party i’m using an arbitrary number
    PHP Code:
    round(microtime(true) * 10000
    so i get to the 3rd party....

    the second problem i’m encountering is when returning to the store.
    using a dummy card number the payment is naturally declined,

    the transaction responses use posturl for
    • transaction_status – either A (Approved) or D (Declined)
    • transaction_value_pence – as passed and processed
    • order_number – as passed
    • date_time - Date and time of order (YYYY-MM-DD HH:MM:SS)
    these are passed (as $_POST’s)
    and returnurl
    the order_number (ono)
    this is passed as $_GET

    the URLs are set as
    PHP Code:
        $posturl =  zen_href_link(FILENAME_CHECKOUT_PROCESS);
        
    $returnurlzen_href_link(FILENAME_CHECKOUT_PROCESS); 
    and then added to and sent to the 3rd party using the
    PHP Code:
    $process_button_string
    i know the values are getting sent, and then sent back...
    ...i’ve sent the store to an intercept page where i just echo my $_POST values
    and i’ve sent their $_POST and $_GET values to another intercept page which simply echo’s them, (instead of returning to my store).

    returning to the store (without diverting to the intercept echo pages) i get
    domainname.com/storefolder/index.php?main_page=checkout_process?ono=13712341508486 (the url as seen in the browser address bar)
    and the store centre column displays a 404 page not found error

    so the obvious questions are
    why am i not able to query the order number, or more precisely,
    why does the line
    PHP Code:
    $new_order_id $last_order_id->fields['orders_id']; 
    cause the button and everything below to disappear?

    and

    am i setting the right URLs (posturl and returnurl)?
    if not where should i be returning to? (NB: i’ve tried FILENAME_CHECKOUT_PAYMENT too),
    if i’m using the correct URLs, then, where do i start defining the action to take (A or !A)? (NB: currently this is in function before_process() but it’s having no effect)
    i’ve tried using the posturl intercept page to add the code and point to FILENAME_CHECKOUT_PROCESS (also FILENAME_CHECKOUT_PAYMENT) but it still fails to process the responses

    phew, hope you managed to follow the above!
    any pointers would be very very much appreciated to get me moving onward again

  8. #8
    Join Date
    Feb 2012
    Location
    mostly harmless
    Posts
    1,809
    Plugin Contributions
    8

    Default Re: allocated order number

    Quote Originally Posted by ajmn View Post
    ...
    i’ve placed the following in
    PHP Code:
    function process_button() 
    and it caused the button and everything below it (on the 3of3 checkout page) to disappear,

    PHP Code:
    $last_order_id $db->Execute("SELECT * FROM " TABLE_ORDERS " ORDER BY orders_id DESC limit 1");
    $new_order_id $last_order_id->fields['orders_id'];
    $new_order_id = ($new_order_id 1);
    $new_order_id = (string)$new_order_id '-' zen_create_random_value(6); 
    ...
    Did you remember to declare $db as global in the function? Typically a function using $db looks something like this:
    PHP Code:
    function getLastOrderId() {
        global 
    $db;

        
    $result $db->Execute(
            
    'SELECT MAX(orders_id) AS `last_id` FROM `' TABLE_ORDERS '`';
        );
        if(!
    $result->EOF) {
            return (int) 
    $result->fields['last_id'];
        }
        else return -
    1;

    When debugging errors the Zen Cart debug logs and your web server's error log are good places to look.

    Not sure about the answers to your other questions...
    The glass is not half full. The glass is not half empty. The glass is simply too big!
    Where are the Zen Cart Debug Logs? Where are the HTTP 500 / Server Error Logs?
    Zen Cart related projects maintained by lhûngîl : Plugin / Module Tracker

  9. #9
    Join Date
    Sep 2010
    Posts
    48
    Plugin Contributions
    1

    Default Re: allocated order number

    Quote Originally Posted by lhungil View Post
    Did you remember to declare $db as global in the function?
    dang! said it was something simple!!
    good job there's no-one who's around to slap me!
    same with the logs...
    haven't had to refer to them for yonks so forgot all about them!
    the second problem will probably reveal itself now with blazing light

    time I took a coffee break I think!

    many thanks


    ...now walking away to the kettle in utter despair at one's own stupidity!

  10. #10
    Join Date
    Feb 2012
    Location
    mostly harmless
    Posts
    1,809
    Plugin Contributions
    8

    Default Re: allocated order number

    Quote Originally Posted by ajmn View Post
    dang! said it was something simple!!
    ...
    haven't had to refer to them (the logs) for yonks so forgot all about them!
    the second problem will probably reveal itself now with blazing light ...
    I think I can with confidence say "we've all been there". I cannot count the number of times I've taken a break from a task (usually by working on another task), then come back and gone "duh!". And there are always the times when a second (or third) pair of eyes does the trick!

    Good Luck with the rest of your adventure!
    Last edited by lhungil; 16 Jun 2013 at 06:27 PM.
    The glass is not half full. The glass is not half empty. The glass is simply too big!
    Where are the Zen Cart Debug Logs? Where are the HTTP 500 / Server Error Logs?
    Zen Cart related projects maintained by lhûngîl : Plugin / Module Tracker

 

 
Page 1 of 2 12 LastLast

Similar Threads

  1. How can I change the order number for order page?
    By ttmb33 in forum Customization from the Admin
    Replies: 1
    Last Post: 9 May 2010, 07:50 PM
  2. start from say order number #1215 rather than order number 1
    By vandiermen in forum Managing Customers and Orders
    Replies: 4
    Last Post: 18 Mar 2009, 02:07 PM
  3. Creates duplicate order number but no order in cart
    By songenterprises in forum Managing Customers and Orders
    Replies: 1
    Last Post: 7 Nov 2007, 06:00 AM

Bookmarks

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
Zen-Cart, Internet Selling Services, Klamath Falls, OR