Example #1
0
        public async Task RevertTransaction(CustomerOrder order)
        {
            if (order == null)
            {
                throw new ArgumentNullException(nameof(order));
            }

            var settings = _settingsManager.Get(order.StoreId);

            if (!settings.IsActive || !settings.ReverseECommerceTransaction)
            {
                return;
            }

            using (var tracker = new SimpleTracker(settings.TrackingId, settings.TrackingDomain ?? string.Empty, CreateEnvironment()))
            {
                var list = new List <Task <TrackingResult> >();

                var task = tracker.TrackAsync(ECommerceConverter.OrderToTransaction(order, true));
                list.Add(task);

                foreach (var lineItem in order.Items)
                {
                    var lineItemTask = tracker.TrackAsync(ECommerceConverter.LineItemToTransactionItem(order, lineItem, true));
                    list.Add(lineItemTask);
                }

                await Task.WhenAll(list.ToArray());
            }
        }
Example #2
0
        public void OrderToRevertTransaction()
        {
            var customerOrder = GetOrder();

            var result = ECommerceConverter.OrderToTransaction(customerOrder, true);

            Assert.Equal(customerOrder.Number, result.TransactionId);
            Assert.Equal(customerOrder.CustomerId, result.ClientId);
            Assert.Equal(customerOrder.Currency, result.CurrencyCode);
            Assert.Equal(-1 * customerOrder.Total, result.TransactionRevenue);
            Assert.Equal(-1 * customerOrder.ShippingTotal, result.TransactionShipping);
            Assert.Equal(-1 * customerOrder.TaxTotal, result.TransactionTax);
            Assert.Equal(customerOrder.CustomerId, result.UserId);
        }