2

I am integrating payment gateway(CCavenue) on my website and require to send a unique order id with each request.

Here is the sample code

<form method="post" name="" action="">

<tr>

<td><input type="hidden" name="order_id" value=""/></td> //This must be a unique Id created on your website
</tr>

<tr>
<td><input type="hidden" name="amount" value=""/></td>
</tr>


<td><INPUT TYPE="submit" value="Paynow"></td>
</form>   

Can anyone let me know how this can be achieved using database or any other way . My web host support php.

Dev kaushik
  • 29
  • 1
  • 2

8 Answers8

2

You can create a auto code using jquery

$(document).ready(function()
                    {
                        var code = "";
                        var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";

                        for( var i=0; i < 6; i++ )
                            code += possible.charAt(Math.floor(Math.random() * possible.length));
                       $("#order_id").val(code);
                    });

Using PHP::

<input type="hidden" name="order_id" value="<?php echo md5(uniqid(rand()));?>"/>

Above example will give a long string

SO you can follow the following example if you need six digit no. You can chabge the example as per your need

$six_digit_random_number = mt_rand(100000, 999999);

Since all no. between 100000 and 999999 are six digits.

ALso you can proceed in the following way

string uniqid ([ string $prefix [, bool $more_entropy ]] )

Gets a prefixed unique identifier based on the current time in microseconds.

USAGE: $id = uniqid(rand(), true);
Smruti Singh
  • 565
  • 1
  • 4
  • 14
  • See, people are so eager to give negative marks on every faulty question or erronous answers, but they feel tired to give upvote in a good question – Smruti Singh Aug 22 '14 at 09:51
1

Put microtime is unique each time for unique id:

<form method="post" name="" action="">

  <tr>
    <td><input type="hidden" name="order_id" value="<?php echo microtime(true)*10000; ?>"/></td> //This must be a unique Id created on your website
  </tr>

  <tr>
    <td><input type="hidden" name="amount" value=""/></td>
  </tr>

  <td><INPUT TYPE="submit" value="Paynow"></td>
</form>   
arghtype
  • 4,376
  • 11
  • 45
  • 60
Vikram Jain
  • 5,498
  • 1
  • 19
  • 31
  • Hi Vikram, Thanks for prompt reply. Actually when I insert this php code it gives me error "Error Code: 113 Invalid Request - Order number invalid/not present" – Dev kaushik Aug 22 '14 at 11:38
  • when u get error: means at insert/update a record at database or any other's place? – Vikram Jain Aug 22 '14 at 11:44
  • I don't have much knowledge of coding so, please correct me if I am wrong. Let me tell you the whole screnio. I got four files in integration kit from CCavenue. This include Requesthandler.php, Respondhandler.php, Crypto.php and DataFrom.html. So, we need to insert Order ID in the last file. They want me to send a unique order id with each request. I am not maintaining any database at the moment and my website is totally HTML and CSS based. – Dev kaushik Aug 22 '14 at 11:56
0
  1. Save order into DB (in DB order must have PK)
  2. Get PK (using AJAX or not) and insert it in option value

it's the best practice

viktor.svirskyy
  • 469
  • 2
  • 8
  • Thanks Viktor, if possible please let me know how to insert Primary key into option value. What will be the script for the same. I don't have any knowledge of AJAX or PHP. – Dev kaushik Aug 22 '14 at 11:43
0

You can create a table with an auto in crementing key and that Id you can pass to payment gateway.

or in other case you can generate a unique Id in PHP

check the below link for generating unique Id

Generating a unique ID in PHP

and this Id you can keep in session for handling the response from payment gateway incase you need that ID after payment.

Community
  • 1
  • 1
vijayp
  • 173
  • 10
  • Thanks Vijay, I am facing error "Invalid Request - Order number invalid/not present" when using PHP for creating unique order ID. Can you please let me know how to pass incremental key value from table into the option value. – Dev kaushik Aug 22 '14 at 11:48
  • @Devkaushik , do you need this incremental key value before form post? In that case it can be and OrderId key value, How you are creating orderId? is it an auto-incremented key value of a table, same Id you can use it – vijayp Aug 26 '14 at 07:50
0
<?php
$order_id = "ID" . (string)rand(100000, 999999);  // you can change 'ID' to anything
?>

<form method="post" name="" action="">

<tr>

<td><input type="hidden" name="order_id" value=<?php echo $order_id; ?>/></td> 
</tr>

<tr>
<td><input type="hidden" name="amount" value=""/></td>
</tr>


<td><INPUT TYPE="submit" value="Paynow"></td>
</form>   
Athul AK
  • 358
  • 4
  • 15
0

PHP has function uniquid which does exactly what you need.

Rikudou_Sennin
  • 1,357
  • 10
  • 27
0

use your original order no (auto increment id )with field order_id LIKE order_no is 87644 take id CCA87644 [ this indication is order no 87644 have payment by CCavenue ]

<input type="hidden" name="order_id" value=""/>

this id will be unique and this will be help you in order tracking in future . Other wise some other post have how to create a unique id.

unique id should be in a sequence low to high. this will be helpful in payment management and payout management

PankajR
  • 340
  • 3
  • 12
0

I always use combination of the date when the order was placed and ORDER_ID which is the primary_key field of ORDER table.

So if someone places an order for example on 10th July, 2014 and the ORDER_ID of that particular order is say "20" then the unique order_id will be "2014071020". It will be unique always not matter what the circumstances are.

Incase, if you dont have any primary_key field in your table, then you can use time() function of PHP to generate one unique id.

If you need any programming help related to this, please let me know.

Regards.