예제 #1
0
        public void ToSvDiscounts()
        {
            var orderDiscount = new OrderLineItemDiscount
            {
                AmountMoney = new Money(3, "USD"),
                Scope       = SquareDiscountScope.Order,
                Name        = "Some order discount"
            };
            var itemDiscount = new OrderLineItemDiscount
            {
                AppliedMoney = new Money(4, "GBP"),
                Scope        = SquareDiscountScope.LineItem,
                Name         = "Some item discount"
            };
            var discounts = new List <OrderLineItemDiscount>
            {
                orderDiscount,
                itemDiscount
            };

            var result = discounts.ToSvDiscounts();

            var resultOrderDiscount = result.First();
            var resultItemDiscount  = result.Skip(1).First();

            resultOrderDiscount.Amount.Value.Should().Be(orderDiscount.AmountMoney.ToNMoney());
            resultOrderDiscount.Code.Should().Be(orderDiscount.Name);
            resultItemDiscount.Amount.Value.Should().Be(itemDiscount.AppliedMoney.ToNMoney());
            resultItemDiscount.Code.Should().Be(itemDiscount.Name);
        }
예제 #2
0
        public void ToSvDiscounts_Types()
        {
            var fixedAmountDiscount = new OrderLineItemDiscount
            {
                Type = "FIXED_AMOUNT"
            };
            var percentageDiscount = new OrderLineItemDiscount
            {
                Type = "FIXED_PERCENTAGE"
            };
            var unknownDiscount = new OrderLineItemDiscount
            {
                Type = "MARY_HAD_A_LITTLE_LAMB"
            };
            var discounts = new List <OrderLineItemDiscount>
            {
                fixedAmountDiscount,
                percentageDiscount,
                unknownDiscount
            };

            var result = discounts.ToSvDiscounts().ToArray();

            result[0].Type.Should().Be(SquareDiscountTypeEnum.FixedAmount);
            result[1].Type.Should().Be(SquareDiscountTypeEnum.Percentage);
            result[2].Type.Should().Be(SquareDiscountTypeEnum.Undefined);
        }
예제 #3
0
        private IObservable <Subtransaction> CreateSubtransactionFromDiscount(OrderLineItemDiscount orderLineItemDiscount)
        {
            Product product;

            if (orderLineItemDiscount.Name.Contains("macaron", StringComparison.OrdinalIgnoreCase))
            {
                product = new Product("BUN-DCM", "BUN-DCM", "Box of Macarons Discount", "Buy 6 macarons for \"£12.00\"", -0.01m);
            }
            else if (orderLineItemDiscount.Name.Contains("pocky", StringComparison.OrdinalIgnoreCase))
            {
                product = new Product("BUN-DCP", "BUN-DCP", "Box of Pocky Discount", "Discount on buying multiple packs of Pocky.", -0.01m);
            }
            else
            {
                product = new Product("TLM-D", "TLM-D", "Other discounts", "Discounts that aren't tracked.", -0.01m);
            }

            var quantity       = orderLineItemDiscount.AppliedMoney.Amount ?? 0;
            var amount         = decimal.Divide(quantity, 100);
            var subtransaction = new Subtransaction(product, (int)quantity, -amount);

            return(Observable.Return(subtransaction));
        }