Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

eBay GetOrders : how to distinguish combined orders from original transactions

Tags:

ebay-api

My eBay integration just broke after months of working properly and I'm not sure if its a bug or not on their end.

My buyer made 2 transactions of two different items and then combined them to save shipping. All this happened in a matter of a few minutes.

This had the following result :

  • New sales record created (which incidentally doesn't show up in seller manager)
  • New OrderId created for the combined order. Contains the two transactions (as expected). This OrderId was assigned to the original 2 orders and the combined one (not expected!)
  • Three orders returned in call to GetOrders. All have the same OrderId value
  • The CreatedTime on each OrderType returned is different for each with the most recent order having the latest time (as expected).

What I'm trying to figure out is how I'm supposed to know not to ship all 3 orders. If my code hadn't been trying to put these orders into a dictionary then I wouldn't even have known there were duplicate OrderId values being returned.

I'm hoping there's a property somewhere that indicates the order record was combined into another order - but I can't find it.

Am I supposed to look at the time of the order and pick the most recent one? Or is there a way to exclude transactions that have been subsequently combined from the search results.

like image 756
Simon_Weaver Avatar asked Aug 30 '12 05:08

Simon_Weaver


1 Answers

This is my C# code to check for dupes of this nature and return only the latest order. There's a lot of assertion checking in here but it hasn't crashed yet - then again I don't know if the codepath where o.Count() != 1 has ever been hit yet.

        // raw orders coming back from eBay
        var orderArrayRaw = getTransactions.ApiResponse.OrderArray.ToArray();

        // processed list to remove dupes
        var orderArray = orderArrayRaw.ToArray().GroupBy(x => x.OrderID).Select(o =>
        {
            // single unique order
            if (o.Count() == 1)
            {
                return o.Single();
            }
            else
            {
                // get most recent
                var mostRecent = o.OrderByDescending(x => x.CreatedTime).First();

                // get all the transaction IDs in the non-most-recent
                var allTransactions = o.Except(new[] { mostRecent }).SelectMany(x => x.TransactionArray.ToArray().Select(t => t.TransactionID)).OrderBy(x => x).ToArray();

                var combinedTransactions = mostRecent.TransactionArray.ToArray().Select(x => x.TransactionID).OrderBy(x => x).ToArray();

                if (allTransactions.SequenceEqual(combinedTransactions))
                {
                    // ok!
                    return mostRecent;
                }
                else
                {
                    var dupes = orderArrayRaw.ToArray().GroupBy(x => x.OrderID).Where(x => x.Count() > 1);
                    var dupeIds = dupes.Select(x => x.Key).ToArray();

                    throw new ApplicationException("The following orders were returned more than once in the response " + string.Join(", ", dupeIds));
                }
            }


        }).ToArray();
like image 50
Simon_Weaver Avatar answered Sep 30 '22 12:09

Simon_Weaver