Пример #1
0
        public IActionResult Success()
        {
            var   orderId          = _webHelper.QueryString <string>("x_reference");
            var   oxipayStatus     = _webHelper.QueryString <string>("x_result");
            var   oxipayOrderId    = _webHelper.QueryString <string>("x_gateway_reference");
            var   newPaymentStatus = OxipayHelper.GetPaymentStatus(oxipayStatus, null);
            Order order            = null;

            if (Guid.TryParse(orderId, out Guid orderGuid))
            {
                order = _orderService.GetOrderByGuid(orderGuid);
            }
            if (order != null)
            {
                order.OrderNotes.Add(new OrderNote
                {
                    Note = "Oxipay order ID: " + oxipayOrderId,
                    DisplayToCustomer = false,
                    CreatedOnUtc      = DateTime.UtcNow
                });
                _orderService.UpdateOrder(order);
            }
            switch (newPaymentStatus)
            {
            case PaymentStatus.Pending:
            {}
            break;

            case PaymentStatus.Paid:
            {
                //valid
                if (_orderProcessingService.CanMarkOrderAsPaid(order))
                {
                    _orderProcessingService.MarkOrderAsPaid(order);
                }
                break;
            }

            case PaymentStatus.Voided:
            {
                if (_orderProcessingService.CanVoidOffline(order))
                {
                    _orderProcessingService.VoidOffline(order);
                }
            }
            break;

            default:
                break;
            }
            if (order == null)
            {
                return(RedirectToAction("Index", "Home", new { area = string.Empty }));
            }

            return(RedirectToRoute("CheckoutCompleted", new { orderId = order.Id }));
        }
Пример #2
0
        public IActionResult Callback()
        {
            byte[] parameters;
            using (var stream = new MemoryStream())
            {
                this.Request.Body.CopyTo(stream);
                parameters = stream.ToArray();
            }
            var strRequest = Encoding.ASCII.GetString(parameters);

            var processor = _paymentService.LoadPaymentMethodBySystemName("Payments.Oxipay") as OxipayPaymentProcessor;

            if (processor == null ||
                !_paymentService.IsPaymentMethodActive(processor) || !processor.PluginDescriptor.Installed)
            {
                throw new NopException("Oxipay module cannot be loaded");
            }

            if (processor.OxipayCallback(strRequest, out Dictionary <string, string> values))
            {
                values.TryGetValue("x_result", out string x_result);
                values.TryGetValue("x_gateway_reference", out string x_gateway_reference);
                values.TryGetValue("x_account_id", out string x_account_id);
                values.TryGetValue("x_reference", out string x_reference);
                values.TryGetValue("x_amount", out string x_amount);

                var   newPaymentStatus = OxipayHelper.GetPaymentStatus(x_result, null);
                Order order            = null;

                if (Guid.TryParse(x_reference, out Guid orderGuid))
                {
                    order = _orderService.GetOrderByGuid(orderGuid);
                }
                switch (newPaymentStatus)
                {
                case PaymentStatus.Pending:
                {}
                break;

                case PaymentStatus.Paid:
                {
                    if (order != null)
                    {
                        order.OrderNotes.Add(new OrderNote
                            {
                                Note = x_gateway_reference,
                                DisplayToCustomer = false,
                                CreatedOnUtc      = DateTime.UtcNow
                            });
                        _orderService.UpdateOrder(order);
                    }
                    break;
                }

                case PaymentStatus.Voided:
                { }
                break;

                default:
                    break;
                }
            }
            //nothing should be rendered to visitor
            return(Content(""));
        }