Exemple #1
0
        public string PostProcessPayment(Order order)
        {
            if (easyPayService == null)
            {
                easyPayService = new EasyPayService(UseSandbox)
                {
                    RequestEncoding = Encoding.GetEncoding(1251)
                }
            }
            ;

            int     percentsToAddToWeighItemsPrice = int.Parse(ConfigurationManager.AppSettings["PercentsToAddToWeighItemsPrice"]);
            decimal orderTotalNoSpread             = order.OrderProductVariants.Sum(orderProductVariant => orderProductVariant.Quantity * orderProductVariant.UnitPriceExclTax);
            decimal orderTmpTotalWithSpread        = order.OrderProductVariants.Sum(orderProductVariant => PaymentService.GetTmpPriceForItem(orderProductVariant, percentsToAddToWeighItemsPrice, false));

            orderTmpTotalWithSpread = PaymentService.GetPriceWithShipping(orderTotalNoSpread, orderTmpTotalWithSpread);

            order.OrderTotalWithSpread = orderTmpTotalWithSpread;
            IoC.Resolve <OrderService>().UpdateOrder(order);

            var orderDescription = new StringBuilder();

            foreach (var pv in order.OrderProductVariants)
            {
                orderDescription.AppendFormat("- {0} x {1} = {2}{3}", pv.ProductVariant.Product.Name, pv.Quantity, PaymentService.GetTmpPriceForItem(pv, percentsToAddToWeighItemsPrice, true), Environment.NewLine);
            }
            var    orderDescriptionString      = orderDescription.Length > 1999 ? string.Format("{0}...", orderDescription.ToString().Substring(0, 1996)) : orderDescription.ToString();
            int    eazyPayInvoiceLivingTimeSec = int.Parse(ConfigurationManager.AppSettings["EazyPayInvoiceLivingTimeSec"]);
            Status status = easyPayService.EP_CreateInvoice(MerchantNumber, P, order.OrderId.ToString(), orderTmpTotalWithSpread, eazyPayInvoiceLivingTimeSec, SecurityHelper.Decrypt(order.CardNumber), "Заказ в интернет-гипермаркете До Дивана", orderDescriptionString, string.Empty);

            //var status = new Status { code = 200 };
            if (status.code != 200 && status.code != 211)
            {
                throw new EasyPayException(string.Format("Не удалось создать счет в платежной системе EasyPay. Код ошибки: {0}. Ошибка: {1}", status.code, status.message));
            }

            return("");
        }
Exemple #2
0
        public void Execute(XmlNode node)
        {
            try
            {
                var ctx            = IoC.Resolve <NopObjectContext>();
                var orderService   = IoC.Resolve <OrderService>();
                var easyPayService = new EasyPayService(EasyPayPaymentProcessor.UseSandbox);
                var pendingOrders  = ctx.Orders.Where(o => o.PaymentMethodName == EasyPayPaymentProcessor.MethodName && o.PaymentStatusId == (int)PaymentStatusEnum.Pending && o.OrderStatusId == (int)OrderStatusEnum.Pending).ToList();

                double eazyPayInvoiceLivingTimeSec = double.Parse(ConfigurationManager.AppSettings["EazyPayInvoiceLivingTimeSec"]);
                var    outdatedOrders = pendingOrders.Where(o => o.CreatedOn.AddSeconds(eazyPayInvoiceLivingTimeSec) < DateTime.UtcNow).ToList();
                foreach (Order outdatedOrder in outdatedOrders)
                {
                    try
                    {
                        orderService.CancelOrder(outdatedOrder.OrderId, false);
                    }
                    catch (Exception exc)
                    {
                        IoC.Resolve <ILogService>().InsertLog(LogTypeEnum.OrderError, "Cannot cancel order", exc);
                    }
                }


                pendingOrders = pendingOrders.Except(outdatedOrders).ToList();
                foreach (Order pendingOrder in pendingOrders)
                {
                    try
                    {
                        var status = easyPayService.EP_IsInvoicePaid(EasyPayPaymentProcessor.MerchantNumber, EasyPayPaymentProcessor.P, pendingOrder.OrderId.ToString());
                        switch (status.code)
                        {
                        case 200:
                            orderService.MarkOrderAsPaid(pendingOrder.OrderId);
                            break;

                        case 211:
                            // Not paid yet. Skip it.
                            break;

                        case 503:
                        case 506:
                        case 517:
                            orderService.CancelOrder(pendingOrder.OrderId, false);
                            break;

                        default:
                            throw new Exception(string.Format("EasyPay check invoice status. Status: {0}. Error message: {1}", status.code, status.message));
                        }
                    }
                    catch (Exception exc)
                    {
                        IoC.Resolve <ILogService>().InsertLog(LogTypeEnum.OrderError, "Cannot cancel or mark order as paid", exc);
                    }
                }
            }
            catch (Exception ex)
            {
                IoC.Resolve <ILogService>().InsertLog(LogTypeEnum.OrderError, "Error checking EasyPay invoice statuses.", ex);
            }
        }