Should the order_no field be the Commerce Order No?

Created on 15 June 2023, about 1 year ago
Updated 14 July 2023, 12 months ago

Have a look at this line of code:
https://git.drupalcode.org/project/commerce_moneris_checkout/-/blob/1.x/...

A number is generated with the following code:

    // Make Moneris order id unique.
    // Pulled from commerce_moneris module.
    $moneris_order_id = $payment->getOrder()->id() . '-' . $payment->uuid() . '-' . time();

And sent to Moneris as order_no.

      'order_no' => $moneris_order_id, 

This number is displayed on Moneris generated receipts that are emailed to customers. I think the user readable Commerce Order No would be more appropriate:

      'order_no' => $payment->getOrder()->getOrderNumber(), 

But where the the concept was pulled from the commerce_moneris module, I wanted to make sure what I'm suggesting doesn't go against a best practice.

Thanks!

📌 Task
Status

Fixed

Version

1.0

Component

Code

Created by

🇨🇦Canada redsky

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @redsky
  • 🇺🇸United States rszrama

    My guess is the intent here was to ensure there was a unique order number for each transaction. Sometimes when there's a conflict, a payment gateway will reject the transaction attempt. At the very least, we'll be removing the pre-created Payment entity in 📌 Do not create a Payment entity until a payment has succeeded Fixed , so we won't have the payment uuid in the order number field.

    However, if preventing duplication is indeed a requirement, perhaps we're wise to keep the timestamp suffix. We do this in the PayPal module as well. Is it not possible to search via "order number beginning with ______" in the Moneris interface? If not, we can research further to see if it's fine to have multiple transactions with the same order number.

    And I guess this is really just a concern in pre-production ... naturally, once you go live, there will be no duplication of order numbers ... so maybe it's a moot point? Or maybe we could just make it a setting in the gateway configuration itself?

  • 🇨🇦Canada redsky

    Here's a screenshot of an email produced by Moneris.

    It just seems to me the Order ID is pretty prominently displayed and a long number like 91-7dc5125d-f510-4258-bd0e-b6694d09d23b-1686219548 isn't very user friendly.

    The reference number is Moneris's unique transaction number - i.e. 660160580010200010

    Have a look here: https://developer.moneris.com:3000/livedemo/checkout/preload_req/guide/d...

    The order_no falls under the optional fields section, I wonder if that is an indication that it's less important than we think.

  • 🇺🇦Ukraine marchuk.vitaliy Rivne, UA

    marchuk.vitaliy made their first commit to this issue’s fork.

  • @marchukvitaliy opened merge request.
  • Status changed to Needs review about 1 year ago
  • 🇺🇦Ukraine marchuk.vitaliy Rivne, UA

    Yes, order_no is not required, but if we omit it, the ticket number part will be used for it.
    For example, the ticket number is 1687869483HDYGZqd81ovcDYYopoinQobQpoPYLT, so the order_no will be 1687869483HDYGZqd81ovcDYY which is not very user-friendly.
    So I switched to the pattern we usually use in cases like this "order_id-current_time", like 255-1687871631, which looks much better.
    Opened MR with the fixes.

  • Status changed to Fixed about 1 year ago
  • 🇺🇦Ukraine marchuk.vitaliy Rivne, UA

    Committed!

  • 🇨🇦Canada redsky

    "order_id-current_time" is more readable but it's not meaningful to the customer or the merchant in our case.

    Could we use the pattern "order_no-current_time"?

    This change would account for people who are using Number patterns (like us).

  • Status changed to Needs review 12 months ago
  • 🇨🇦Canada geoanders Nova Scotia 🍁
  • 🇺🇦Ukraine marchuk.vitaliy Rivne, UA

    @redsky
    Unfortunately, we do not have an order number at this time as it is generated when the order is placed (see commerce/modules/order/src/EventSubscriber/OrderNumberSubscriber.php).
    Actually, we can generate it for the Draft order, but it will look weird because the order is not placed but has an Order Number.

    What's your opinion on this?

  • 🇨🇦Canada redsky

    @marchukvitaliy,

    I see what you mean about it looking weird. If we generated the number early and the payment failed you might be “wasting” the order number.

    I feel like it might be the lesser of 2 evils to have the order_no be the most useful.

    Do you think we should make this configurable? A checkbox, something like “Generate Order No early to include in Transaction”.

    Let me know what you think.

    Thanks,
    Chris

  • 🇺🇦Ukraine marchuk.vitaliy Rivne, UA

    @redsky
    We've never gone that deep or thought too much about order_no. Usually, it's just order_id or order_id-current_time and that's it.
    A solution could be to use order_id for Prod and order_id-current_time for Sandbox so in this case for Prod we'll have user-friendly order IDs and for Sandbox we won't have duplicates. Alternatively, we may open a separate issue where we provide users with the option to alter order ID.

    @rszrama what is your opinion on this?

  • 🇨🇦Canada redsky

    I like your idea of not adding time to the order number in Prod.

    However that does not solve the issue that the number is prominently displayed to the user in an email receipt and order_no is the number meaningful to the user where as order_id is a surrogate key not known to them. I'd

    If you think we should make that user configurable I'm happy to open a new ticket. I just wanted to make sure you've seen the screenshot of the email, and how this number is intended by Moneris to be useful to the user:

  • 🇺🇸United States rszrama

    Seems like a tricky issue! If this is truly for display purposes only, I don't see a harm in eliminating the timestamp. If we get reports of errors in the future based on colliding order numbers, we can bring the appended timestamp back.

    However, the issue with order number generation is a trickier one. Depending on your circumstances, some merchants may be required to maintain sequential order numbers for all placed orders, which would be disrupted by incomplete payments.

    I'd be in favor of a payment gateway configuration that allowed the merchant to choose an appropriate strategy. We can always add additional strategies to it in the future.

    Type: Radios
    Label: Moneris Checkout order number strategy
    Options:

    • Use the order ID.
    • Use the order ID with timestamp appended.
    • Generate the order number early and use it instead of the ID.

    Help text: Note: generating order numbers will likely result in out of order or missing order numbers based on if / when the orders are placed.

  • 🇨🇦Canada redsky

    I like that solution @rszrama! +1

  • @vmarchuk opened merge request.
    • vmarchuk committed f247a0f8 on 1.x
      Issue #3367095: Should the order_no field be the Commerce Order No?
      
  • 🇺🇦Ukraine marchuk.vitaliy Rivne, UA

    @rszrama

    I added the fix per comment #15 and merged MR into the 1.x branch.
    So, can this issue be marked as fixed?

  • Status changed to Fixed 12 months ago
  • 🇨🇦Canada redsky

    Thanks for putting your heads together and coming up with this solution! I've tested the "Generate the order number early and use it instead of the ID." strategy and it works great!

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.69.0 2024