public void Ensure_order_can_only_be_partially_refunded_when_orderStatus_is_not_cancelled_and_paymentstatus_is_paid_or_partiallyRefunded_and_paymentModule_supports_partialRefund()
        {
            _paymentService.Expect(ps => ps.SupportPartiallyRefund("paymentMethodSystemName_that_supports_partialrefund")).Return(true);
            _paymentService.Expect(ps => ps.SupportPartiallyRefund("paymentMethodSystemName_that_don't_support_partialrefund")).Return(false);
            var order = new Order();

            order.OrderTotal = 100;
            order.PaymentMethodSystemName = "paymentMethodSystemName_that_supports_partialrefund";

            foreach (OrderStatus os in Enum.GetValues(typeof(OrderStatus)))
            {
                foreach (PaymentStatus ps in Enum.GetValues(typeof(PaymentStatus)))
                {
                    foreach (ShippingStatus ss in Enum.GetValues(typeof(ShippingStatus)))
                    {
                        order.OrderStatus    = os;
                        order.PaymentStatus  = ps;
                        order.ShippingStatus = ss;

                        if ((os != OrderStatus.Cancelled) &&
                            (ps == PaymentStatus.Paid || order.PaymentStatus == PaymentStatus.PartiallyRefunded))
                        {
                            _orderProcessingService.CanPartiallyRefund(order, 10).ShouldBeTrue();
                        }
                        else
                        {
                            _orderProcessingService.CanPartiallyRefund(order, 10).ShouldBeFalse();
                        }
                    }
                }
            }



            order.PaymentMethodSystemName = "paymentMethodSystemName_that_don't_support_partialrefund";
            foreach (OrderStatus os in Enum.GetValues(typeof(OrderStatus)))
            {
                foreach (PaymentStatus ps in Enum.GetValues(typeof(PaymentStatus)))
                {
                    foreach (ShippingStatus ss in Enum.GetValues(typeof(ShippingStatus)))
                    {
                        order.OrderStatus    = os;
                        order.PaymentStatus  = ps;
                        order.ShippingStatus = ss;

                        _orderProcessingService.CanPartiallyRefund(order, 10).ShouldBeFalse();
                    }
                }
            }
        }
        public void Ensure_order_can_only_be_partially_refunded_when_paymentstatus_is_paid_or_partiallyRefunded_and_paymentModule_supports_partialRefund()
        {
            //SupportPartiallyRefund()
            tempPaymentService.Setup(ps => ps.SupportPartiallyRefund("paymentMethodSystemName_that_supports_partialrefund")).Returns(true);
            tempPaymentService.Setup(ps => ps.SupportPartiallyRefund("paymentMethodSystemName_that_doesn't_support_partialrefund")).Returns(false);
            var order = new Order();

            order.OrderTotal = 100;
            order.PaymentMethodSystemName = "paymentMethodSystemName_that_supports_partialrefund";

            foreach (OrderStatus os in Enum.GetValues(typeof(OrderStatus)))
            {
                foreach (PaymentStatus ps in Enum.GetValues(typeof(PaymentStatus)))
                {
                    foreach (ShippingStatus ss in Enum.GetValues(typeof(ShippingStatus)))
                    {
                        order.OrderStatus    = os;
                        order.PaymentStatus  = ps;
                        order.ShippingStatus = ss;
                        //when paid and partiallyrefund -> you can get partially refund
                        if (ps == PaymentStatus.Paid || order.PaymentStatus == PaymentStatus.PartiallyRefunded)
                        {
                            Assert.IsTrue(_orderProcessingService.CanPartiallyRefund(order, 10));
                        }
                        else
                        {
                            Assert.IsFalse(_orderProcessingService.CanPartiallyRefund(order, 10));
                        }
                    }
                }
            }

            //this string shouldn't allow you in any case permit to have partial refund
            order.PaymentMethodSystemName = "paymentMethodSystemName_that_doesn't_support_partialrefund"; //changed!
            foreach (OrderStatus os in Enum.GetValues(typeof(OrderStatus)))
            {
                foreach (PaymentStatus ps in Enum.GetValues(typeof(PaymentStatus)))
                {
                    foreach (ShippingStatus ss in Enum.GetValues(typeof(ShippingStatus)))
                    {
                        order.OrderStatus    = os;
                        order.PaymentStatus  = ps;
                        order.ShippingStatus = ss;

                        Assert.IsFalse(_orderProcessingService.CanPartiallyRefund(order, 10));
                    }
                }
            }
        }
示例#3
0
        public ActionResult IPNHandler(FormCollection form, int?storeId)
        {
            Order order;

            if (!ValidateIPN(form, storeId, out order))
            {
                return(new HttpStatusCodeResult(HttpStatusCode.OK));
            }

            //order note
            var note = new StringBuilder();

            foreach (string key in form.Keys)
            {
                note.AppendFormat("{0}: {1}{2}", key, form[key], Environment.NewLine);
            }

            order.OrderNotes.Add(new OrderNote()
            {
                Note = note.ToString(),
                DisplayToCustomer = false,
                CreatedOnUtc      = DateTime.UtcNow
            });
            _orderService.UpdateOrder(order);

            //change order status
            switch (form["status"].ToLowerInvariant())
            {
            case "complete":
                //paid order
                if (_orderProcessingService.CanMarkOrderAsPaid(order))
                {
                    order.CaptureTransactionId = form["transactionId"];
                    _orderService.UpdateOrder(order);
                    _orderProcessingService.MarkOrderAsPaid(order);
                }
                break;

            case "partial_refunded":
                //partially refund order
                decimal amount;
                if (decimal.TryParse(form["refundedAmount"], out amount) && _orderProcessingService.CanPartiallyRefund(order, amount))
                {
                    _orderProcessingService.PartiallyRefundOffline(order, amount);
                }
                break;

            case "refunded":
                //refund order
                if (_orderProcessingService.CanRefund(order))
                {
                    _orderProcessingService.RefundOffline(order);
                }
                break;

            case "pending":
                //do not logging for pending status
                break;

            default:
                _logger.Error(string.Format("G2A Pay IPN error: transaction is {0}", form["status"]));
                break;
            }

            return(new HttpStatusCodeResult(HttpStatusCode.OK));
        }
 /// <summary>
 /// Gets a value indicating whether partial refund from admin panel is allowed
 /// </summary>
 /// <param name="order">Order</param>
 /// <param name="amountToRefund">Amount to refund</param>
 /// <returns>A value indicating whether refund from admin panel is allowed</returns>
 public bool CanPartiallyRefund(Order order, decimal amountToRefund)
 {
     return(_orderProcessingService.CanPartiallyRefund(order, amountToRefund));
 }