Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

When is orders_id generated for an order


tfittsy

Recommended Posts

Posted

I'm customizing the lynk systems payment module. I've got it working with AVS and CVV2, but I would like one more customization where it will pass the order number instead of the session number. Has the order_id for that order been created at the point where credit card authorization takes place? Is it possible to get the number of what it will be even before it is created? I think this would still be consistent because if the authorization is successful the order is placed immediately. Thanks for any help.

Posted
I'm customizing the lynk systems payment module. I've got it working with AVS and CVV2, but I would like one more customization where it will pass the order number instead of the session number. Has the order_id for that order been created at the point where credit card authorization takes place? Is it possible to get the number of what it will be even before it is created? I think this would still be consistent because if the authorization is successful the order is placed immediately. Thanks for any help.

 

the orderid is created by the database when inserting the order.

Treasurer MFC

Posted

You will find it in checkout_process.php - the variable is $insert_id

 

Matti

Posted
You will find it in checkout_process.php - the variable is $insert_id

 

Matti

 

Is there a simple way to get that variable into a payment module? When I set $insert_id = tep_db_insert_id(); in my payment module and use $insert_id later in the module it returns a value of 0.

Posted

The way I do it is this:

 

  tep_db_perform(TABLE_ORDERS, $sql_data_array);
 $insert_id = tep_db_insert_id();
 if (!tep_session_is_registered('order_id')) tep_session_register('order_id');
 $order_id = $insert_id;

The first two lines are existing ones in checkout_process.php. After this, you can reference $order_id wherever you want in the current session.

Posted
The way I do it is this:

 

  tep_db_perform(TABLE_ORDERS, $sql_data_array);
 $insert_id = tep_db_insert_id();
 if (!tep_session_is_registered('order_id')) tep_session_register('order_id');
 $order_id = $insert_id;

The first two lines are existing ones in checkout_process.php. After this, you can reference $order_id wherever you want in the current session.

 

I tried your code. If I don't have an array in $sql_data_array I get an error. If I fill the array it puts empty orders into the database whenever I run the code. If I hit refresh 10 times I get 10 blank orders in the db. It is in the right direction though because it is able to display what the order number would be.

Posted

I think you misunderstood. The first two lines are those already existing in checkout_process.php and they add the order to the orders table. There had darned well better be an array in $sql_data_array at that point. The last two lines I added after the first two - they save the order ID in a session variable you can reference later (even on another page if you want.)

 

I did not mean that you plunk these four lines down at some random place in the code.

Posted
I think you misunderstood. The first two lines are those already existing in checkout_process.php and they add the order to the orders table. There had darned well better be an array in $sql_data_array at that point. The last two lines I added after the first two - they save the order ID in a session variable you can reference later (even on another page if you want.)

 

I did not mean that you plunk these four lines down at some random place in the code.

 

 

Oh I see. I need a way to reference the order ID before the order is put into the database. I want to pass the order id to my credit card processor, but I'm pretty sure that the code is executed before the checkout_process code is executed. Otherwise your order would be placed even if the card gets rejected. Is there an easy way to look up what the highest order number already in the database is and have it add one?

Posted

You can't do it that way as you don't know if another order will be added in the meantime. The way you have to do it is create the orders record with dummy information, thus obtaining the insert (order) ID, process the payment, and then update the record in checkout_process.

Posted
You can't do it that way as you don't know if another order will be added in the meantime. The way you have to do it is create the orders record with dummy information, thus obtaining the insert (order) ID, process the payment, and then update the record in checkout_process.

 

I thought of the possibility of another order being added in the meantime, but the variable would be generated when they click on confirm order. If it is good then they will receive that order id immediately after their card processes. My site isn't so high traffic that I've got people placing orders within miliseconds of each other.

Posted
The software engineer in me hates race conditions. It's very easy to just insert a dummy record and then update it where it is currently inserted.

 

OK, but if I insert a dummy record and the card doesn't process correctly, isn't it very likely that it would insert another dummy record when they tried again? It doesn't really seem like race conditions to me because it is all happening with one user action.

 

They click confirm

it somehow gets the next order number

it sends that order number to the credit card processor

if the processor says it is good it adds everything to the database.

 

As of right now there is no identifying number going along with the credit card. Even on the extremely small chance that somehow a second person confirms their order close enough to the person before them that the same order number is passed to the credit card processor for both orders, that would be better than what I've got now. I would just prefer not to alter the order processing and other files if I can keep it all in the payment module if that is at all possible.

Posted
I guess so. The other thing you can do is install one of the "random order number" contribs and then the order number is unrelated to the insert ID.

 

I thought about installing a random order number generator, but we want to mark each of our sites with a start number to identify the order like 12001001, 13001001 etc. I do appreciate your help in helping me work through this. Do you have any idea how I can get the upcoming number before inserting information into the database?

Posted

Not offhand. I suppose you can do a query ordered by order_id descending limit 1 or something like that to get the highest value. Those who know MySQL better than I could probably offer an alternate suggestion. Note that counting records isn't sufficient as there could be gaps.

Posted

I think probably what you want to do is rework the checkout process so its like this

 

Create Order

Process Card

Update Order Status

 

So instead of having no order when a card fails you will have an order with status failed.

 

If you check the OSC paypal IPN mod it works this way.

 

 

With a little tinkering you can move the before_process() code to the after_process() then update the order status based on the $response when $response['TransactionStatus']!=0 order status = Failed.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...