MarketPress custom gateway requires 12-digit order id, ALL DIGITS - what to do?

Subj. pretty much says it all. My payment processor won't eat order id's with characters in them, so what approach would you recommend here, Aaron? time()? :slight_smile:

  • digitsoft

    Obviously Aaron is the man for this, but thought I'd chime in since I already worked on it.

    Add this function to the main marketpress.php file:
    function generate_random_number($length) {
    $random = '';
    for ($i = 0; $i < $length; $i++) {
    $random .= chr(rand(ord('0'), ord('9')));
    return $random;

    Then call it like: generate_random_number(12);

    Replace this line (2903) in the main marketpress.php file:
    $order_id = substr(sha1(uniqid('')), rand(1, 24), 12);
    $order_id = generate_random_number(12);

  • lkraav

    Patching marketpress core is not a realistic option. Maintenance of x+1 instance upgrades later, possibly indefinitely, is not something I'm looking forward to. I'd expect some sort of a new hook in core that lets me define my own order id strategy.

    And now that I'm grepping through marketpress, I'm seeing:

    2907 $order_id = apply_filters( 'mp_order_id', $order_id ); //Very important to make sure order numbers are unique and not sequential if filtering

    So mr digitsoft, nice effort but why are you hacking core like that again..? This filter is there since 1.2.2.

    Anyway, I'm pretty sure this topic is resolved. :slight_smile:

    Although my question to Aaron now is, what's wrong with having sequential order id's?

  • aecnu

    Greetings lkraav,

    Just a quick note that the support staff are to resolve any and all tickets we can in any legal manner that we can whether or not it comes from WPMU Dev, WordPress Repository, or hacking core code period.

    Just because the member did not like the answer does not make the suggested repair any less valid, especially if it works.

    Many of the hacks both staff and members come up often become permanent within the plugins core code, especially fixes.

    @Rob rock on! Thank you for your solution and helping other members whether they appreciate it or not.

    Cheers, Joe

  • lkraav

    Not sure I understand the sensitivity here. I apologize if I didn't come across as someone with a simple "one programmer to another" question. Of course I appreciate all replies, it gets thoughts moving to where they need to. It was digitsoft's snippet that got me through grepping through Marketpress and finding the correct hook.

    But It doesn't make my reply any less valid. It's impossible for me to tell up front whether "patching core" is a familiar term for someone or not. You posted code, so I assume you're at least half-programmer. If the term is not familiar, then I still can't exactly feel guilty about pointing out that doing it is not a particularly good approach when a much more solid approach has existed for a long period of time. Many people are going to be reading and following the half-broken suggestion in this thread for a long time, if noone says anything.

  • AlwynW

    You don't want anyone to be able to guess them or they can see other peoples basic order details.

    That's a very weird thing to say. You can easily solve that by checking if the user is logged in and if this order id belongs to the user in question.
    IMHO there should be an option in the settings to choose which kind of order id you want.

    Also I don't see why you wouldn't hack the marketpress core, I've been doing nothing else because there's just so many things missing in MP. Or things you can't change with filters, templates or hooks.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.