November Happy Hour will be moved to Thursday December 5th.

Cart ordergroup Id differs from Purchase Order ID

Vote:
 

Hi team,

We find that the orderId obtained from the cart differs from the orderId when the cart is saved as purchase order.

We have obtained the OrderId from cart as follows :

OrderGroupId = cart.OrderLink.OrderGroupId.


We need to send the order id to the credit card transaction before the cart is converted into purchase order.
Now we find the orderId of purchase order and orderId from cart to be differnt.

Can you please let us know what we are missing or is there any other way to obtain the OrderId before it is converted into purchase order.

Thanks in advance,

Nikhil

#261179
Aug 27, 2021 5:45
Vote:
 

Cart and order are separate and you are right, cart id is not order id. There is no way to retain the order, except if you convert to the order before sending the information to the payment gateway

another way is to generate an unique id (guid perhaps?) and use that as the "order number", which you will set to your order once it's created. 

#261183
Aug 27, 2021 10:55
Vote:
 

Hi Nikhil,

When you convert a cart to a Purchase Order, the purchase order entity is a new row in the database so the OrderGroupId will not be maintained.

Consider the following approach:

  • Creating an Entity Framework  repository to store order numbers in a table. These order numbers can be based on the original Order Group Id and maybe appending a code. You will probably find that your payment provider will need orders number to be unqiue for each payment request. Failed payments will result in multiple attempts for shopping cart. As the order group id will not change, it's often neccessary to append extra digits to ensure each payment attempt sends a unique order number. The need for this will be dependant on your payment provider of choice.
  • Inject a custom implementation of IOrderNumberGenerator to so that the "GenerateOrderNumber" method queries this table. This assumes the order number is already generate. Something like this
  •         public string GenerateOrderNumber(IOrderGroup orderGroup)
            {
                var orderGroupId =  orderGroup.OrderLink.OrderGroupId;
    
                var orderTrackingNumber = _purchaseOrderTrackingReferenceRepository.GetByOrderGroupId(orderGroupId);
    
                return FormatOrderTrackingNumber(orderTrackingNumber);
            }
  • Generate the Shopping Cart based Order Number in the appropriate place depending on your implementation. Payment method maybe?
  • var orderNumber = _purchaseOrderTrackingReferenceRepository.CreateOrderNumberByOrderGroupId(form.OrderGroupId)
     
  • When creating the order, before the purchase order is created, get the Order Number using your IOrderNumberGenerator  
  • Set this value as the Order Number on the purchase order
  •                 // Load current order number
                    string orderNumber = _webOrderNumberProvider.GenerateOrderNumber(cart);
  •                     // Set order / tracking number
                        ((PurchaseOrder)purchaseOrder).TrackingNumber = orderNumber;

There are different ways of meeting this requirement. The best way would depend on your website implementation. I hope this example helps.

Thanks

#261184
Edited, Aug 27, 2021 11:53
Vote:
 

We had the similar requirement for our payment provider using Chase Paymentech. We used OrderGroup.OrderLink.OrderGroupId during authorization and saved it into payment.TransactionId after the successful authorization. During capture we retrieved the transactionId and used that to interact with payment provider. Every time you are going to refer back to the exact transaction, you can use that payment.TransactionId to interact with the payment provider, be it Capture, Credit or Void transaction.

cardPayment.TransactionID = string.Format("{0}", OrderGroup.OrderLink.OrderGroupId);

To retrieve

string orderId = payment.TransactionID;

~ Sujit

#263675
Edited, Sep 23, 2021 20:22
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.