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.
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 ?
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).
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 =:)
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! :smile:
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);
$returnurl= zen_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
Re: allocated order number
Quote:
Originally Posted by
ajmn
...
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...
Re: allocated order number
Quote:
Originally Posted by
lhungil
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!
Re: allocated order number
Quote:
Originally Posted by
ajmn
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!
Re: allocated order number
sorry I'm still scratching my head on this one
please can someone outline the processing flow within zen-cart from after the 3rd party sends me back to the store
everything i'm reading points to getting to
PHP Code:
function before_process() {
// RESPONSE ACTION DEFINED
}
but nothing is seemingly being processed there, even if i only have a simple redirect to an intercept page (to check I got there!)
after returning to the store I am consistently given a 404 Page Not Found
where should I be handling the responses?
and what should my urls be if not
PHP Code:
$posturl = zen_href_link(FILENAME_CHECKOUT_PROCESS);
$returnurl= zen_href_link(FILENAME_CHECKOUT_PROCESS);
Here's the integration guidance i'm working with:
Quote:
Transaction Responses are posted back to the script in the post url:
• 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)
The order_number is appended to the returnurl (as ono).
the GET method allows you to identify the returning cardholder, and typically perform a database lookup on
your own server to ascertain what transaction status result was delivered to the Post URL for that particular
cardholder.
as i read it, the post url is sending the transaction responses to the store to be processed behind the scenes, so where should i place my code checking for A or D (saving to the DB etc)?
i'm figuring once i have dealt with the post responses and
the customer returns to the store, i'm coding a $db look up to check if their transaction was successful or not and redirect then accordingly,
where do i do this? i was thinking it handled with
PHP Code:
$payment_modules->after_process();
...
but, without getting the responses dealt with i haven't got to that bit yet!!
I’m just not spotting what i’m missing!
Re: allocated order number
Put your transaction verification logic into before_process()
Re: allocated order number
Just as I thought... and have been trying... and still failing to see it acted upon!
I've managed to write and run some code that will effectively bypass the deadzone, i.e. write the response data and the order details, to the DB in a custom testing table, and then land the customer on the correct final page (either back on checkout_payment or checkout_success), however, i'm still not able to route it through the before_process or after_process.
I know, it’s obvious, the final stages of the sale is not being handled correctly!
i'm even able to use the DB via the zen-cart syntax because i'm still having to operate outside the zen-processs...
the order does not appear in the my account history pages even if i write to the correct DB tables
~ I don't want to rewrite the whole of the checkout section!
i know haven’t fully figured the correct flow,
i’ve looked at dozens of other payment mods and they ALL do things slightly differently so there’s no clear example
other than the occasional bit of syntax that looks the same, but then it’s been placed in a different places, so they are not easily comparable,
i don’t think i’ve found one that has the same/or similar structure that i need.
I feel I'm almost there but still so far away... I might try a few other variations including rearranging the actual location of the code, (writing a custom header etc).
Any way, I need the store live ASAP, so in the meantime i'm going to break from this and use another standard payment method....
when finished though (with the what now seems the trivial) and the store is live.... 'I will be back', as someone once said....
hopefully not still using a car to break through the walls but using the door as it should be used! I’ll let you know what happens.
Re: allocated order number
Care to post a zip of the affected files?
Re: allocated order number
Success !!
Phew, was that a hurdle or what!!
Just need to tidy up ~ removing all the commented duff lines, checking the file structure is efficient etc.,
it still needs thorough testing,
but looking forward to presenting it to y'all
Re: allocated order number
Hi ajmn,
I am looking at doing a similar thing for a new website I am currently building.
I have always found the sequential order no system problematic specially for sites that receive few orders, or like the one I am currently working on.
It does not instill any customer confidence in a site when you are the first one to place an order and get order no 00001 or so. Again if I wanted to buy another product a few months later and my new order number may be 00024.
As a customer I would seriously question the validity of the site.
So an automatically generated O/N such as yyyymmddhhmmss would be a great option, as it immediately identyfies the exact date etc. the order was placed.
The only bug I see would be if your sever would be in a different timezone than your shop, and you decide to include a timezone offset some time in the future.
Do you have a working version yet?
Kind regards,
Goshawk
Re: allocated order number
yyyymmddhhmmss would easily become tzyyyymmddhhmmss instead.
>Do you have a working version yet?
yes,
I've been taking a brief break and was hoping to get onto it again very soon ~ tidying up rewrite etc with a fresh set of eyes.