public void Ensure_order_can_only_be_refunded_when_paymentstatus_is_paid_and_paymentModule_supports_refund() { //method SupportRefund() is expected to return true or false - it depends on string tempPaymentService.Setup(ps => ps.SupportRefund("paymentMethodSystemName_that_supports_refund")).Returns(true); tempPaymentService.Setup(ps => ps.SupportRefund("paymentMethodSystemName_that_doesn't_support_refund")).Returns(false); var order = new Order(); order.OrderTotal = 1; order.PaymentMethodSystemName = "paymentMethodSystemName_that_supports_refund"; 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 product is paid - you can take cost refund if (ps == PaymentStatus.Paid) { Assert.IsTrue(_orderProcessingService.CanRefund(order)); } else { Assert.IsFalse(_orderProcessingService.CanRefund(order)); } } } } order.PaymentMethodSystemName = "paymentMethodSystemName_that_doesn't_support_refund"; 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; //but you can't take refund, when it is not supported Assert.IsFalse(_orderProcessingService.CanRefund(order)); } } } }
public void Ensure_order_can_only_be_refunded_when_orderStatus_is_not_cancelled_and_paymentstatus_is_paid_and_paymentModule_supports_refund() { _paymentService.Expect(ps => ps.SupportRefund("paymentMethodSystemName_that_supports_refund")).Return(true); _paymentService.Expect(ps => ps.SupportRefund("paymentMethodSystemName_that_don't_support_refund")).Return(false); var order = new Order(); order.OrderTotal = 1; order.PaymentMethodSystemName = "paymentMethodSystemName_that_supports_refund"; 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)) { _orderProcessingService.CanRefund(order).ShouldBeTrue(); } else { _orderProcessingService.CanRefund(order).ShouldBeFalse(); } } } } order.PaymentMethodSystemName = "paymentMethodSystemName_that_don't_support_refund"; 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.CanRefund(order).ShouldBeFalse(); } } } }
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 refund from admin panel is allowed /// </summary> /// <param name="order">Order</param> /// <returns>A value indicating whether refund from admin panel is allowed</returns> public bool CanRefund(Order order) { return(_orderProcessingService.CanRefund(order)); }