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 :
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!)GetOrders
. All have the same OrderId
valueCreatedTime
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.
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With