SitePoint Sponsor

User Tag List

Results 1 to 14 of 14
  1. #1
    SitePoint Zealot LucidSurf's Avatar
    Join Date
    Mar 2005
    Location
    Sydney, Australia
    Posts
    115
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Generating random, unique invoice number

    Hi guys,

    I have developed an ecommerce system and would like to give people a nice, tidy reference number when they have signed up.

    At the moment the reference number is created using a combination of today's date and then a string representing their domain name - but I don't think this is very user friendly or tidy!
    PHP Code:
    $ref = echo date("Ymd") . stripslashes($website); 
    This produces something like: 20070613www.lucidsurf.com

    I was thinking, maybe it would be better to convert their domain name into numbers (serialise it?) so that the reference is all numeric - but am not sure of the best approach.

    Any suggestions would be much appreciated.

  2. #2
    SitePoint Enthusiast c.norris's Avatar
    Join Date
    Jun 2007
    Location
    Butler, PA
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Maybe you can use the time instead of date and thea actual invoice number, such as if its your first order it will be 12021 (using 24 hrs time) that looks good I think.

  3. #3
    Worship the Krome kromey's Avatar
    Join Date
    Sep 2006
    Location
    Fairbanks, AK
    Posts
    1,621
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've also favored YYYYMMDDHHMMSS# for this kind of application, where # is a counter (just in case you're issuing more than one per second; add more digits if you're doing more than 10 per second). For example, the first 3 invoices issued at this very moment would be
    200706131631490
    200706131631491
    200706131631492

    You could easily break this up to make it easier on your users:
    20070613-163149-0
    Or even:
    2007-0613-163149-0
    PHP questions? RTFM
    MySQL questions? RTFM

  4. #4
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Why not give them their actual order number from your ecommerce system's database? Why do you want to create some second artificial identifier?

  5. #5
    SitePoint Enthusiast c.norris's Avatar
    Join Date
    Jun 2007
    Location
    Butler, PA
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I guess so that a customer doesn't think that the website is new.

    What , I am order number #1???

  6. #6
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by c.norris View Post
    I guess so that a customer doesn't think that the website is new.

    What , I am order number #1???
    Then start numbering at 1000

  7. #7
    SitePoint Enthusiast c.norris's Avatar
    Join Date
    Jun 2007
    Location
    Butler, PA
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Lol, I wouldn't be afraid to start with 1. Email : ~Congradulations, you are our first order.

  8. #8
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by c.norris View Post
    Lol, I wouldn't be afraid to start with 1. Email : ~Congradulations, you are our first order.
    I started one of my ecommerce sites at 1 in 2004. It's now in the 30,000's. Those first customers didn't mind at all

  9. #9
    Worship the Krome kromey's Avatar
    Join Date
    Sep 2006
    Location
    Fairbanks, AK
    Posts
    1,621
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I like starting with 1234. It's just a fun little number
    PHP questions? RTFM
    MySQL questions? RTFM

  10. #10
    SitePoint Zealot LucidSurf's Avatar
    Join Date
    Mar 2005
    Location
    Sydney, Australia
    Posts
    115
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks everyone.

    Hi Dan, I actually have to generate the reference number before submitting the transaction to my payment gateway. The system I have only enters orders into the database if they are successfully processed, so I really need to create a transaction id at the start of the process.

    I guess I could query the database and get the last successful transaction id and then + 1 to it before submitting to the payment gateway.

    Although, I'm thinking that for a quick solution Kromey's idea would work pretty well.

  11. #11
    SitePoint Enthusiast c.norris's Avatar
    Join Date
    Jun 2007
    Location
    Butler, PA
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I wouldn't mind being the first order, here is a scenario. Lets say they mess up big time and their order is hmmn, tehre doing date and time so 2106130607 the customer is going to say, I wonder if anyone else of the 2,106,130,607 people they serviced has had this same problem :-X

  12. #12
    SitePoint Enthusiast c.norris's Avatar
    Join Date
    Jun 2007
    Location
    Butler, PA
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    order_number++;

  13. #13
    Worship the Krome kromey's Avatar
    Join Date
    Sep 2006
    Location
    Fairbanks, AK
    Posts
    1,621
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by LucidSurf View Post
    I guess I could query the database and get the last successful transaction id and then + 1 to it before submitting to the payment gateway.
    Careful about that - you could conceivably end up submitting the same transaction ID twice if two people place orders simultaneously.

    I would add to the database, setting a flag to say "not yet processed", then use the database-generated ID as their transaction ID (maybe after adding, say, 1234 to it ).
    PHP questions? RTFM
    MySQL questions? RTFM

  14. #14
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by LucidSurf View Post
    Hi Dan, I actually have to generate the reference number before submitting the transaction to my payment gateway. The system I have only enters orders into the database if they are successfully processed, so I really need to create a transaction id at the start of the process.
    Why do you need to give someone a reference number before they've finished checking out and paying?

    Quote Originally Posted by kromey View Post
    I would add to the database, setting a flag to say "not yet processed", then use the database-generated ID as their transaction ID (maybe after adding, say, 1234 to it ).
    When a customer on one of my sites finishes shopping, has gone through the first half of checkout, and reaches the payment stage, that's when I convert their cart into an order entry in the database. I have payment information associated with an order (is it paid? what method? reference info? when?) and not having that information means the order isn't paid for.

    It's necessary to record orders in the database before payment if you intend to accept PayPal. You might get away with not doing so with other 3rd party processors if they guarantee returning the user to your site after paying, but with PayPal, payment might actually occur way out in the future -- 2 weeks sometimes for an eCheck payment -- so you definitely have to record the order first and update its payment status later.


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
  •