Generating Order ID Numbers

This may not be the right place to ask this question and I apologize if it isn’t. I am creating an app the uses Apple Pay and the Chase Paymentech SDK. One of the requirements when processing a payment is to submit an orderId value. For my own purposes I want this value to be unique.

My first thought was to create an order object in Backendless and then use the objectId value as my order number. However, this means that an object must be created before the transaction is authorized. If the payment is accepted then this is fine. If it is rejected then I could delete the newly created object. While this would work, it seems to be inefficient. Additionally, I would have some very odd orderId values.

My second thought was to add an orderId property to the Order Object. Each time an order was placed, I could search for the most recent order placed and then add one to that orders orderId. For example, if the last order was “0001” the next order would be “0002”. However, if more than one order was placed before the object was created, orderIds could be duplicated.

Is there an alternative option that would require fewer calls to Backendless and allow me to create an orderId that was a bit cleaner?

Hi Jon,

How about a simpler scheme where an order id has the following format:

date-time-<uniquenumber>

The date/time part would be rather easy to get. To get a <uniquenumber>, you could use the following Backendless API:
https://backendless.com/documentation/utilities/rest/ut_caching_rest.htm

The API provides atomic counters, meaning if there are two concurrent calls, the number will be incremented transactionally.

Hope this helps.

Regards,
Mark

Perfect. Thanks Mark. Happy 4th.