Ejemplo n.º 1
0
        public static PaymentGatewayResponse GetOrderStatus(string orderNumber)
        {
            var _distributorId = HttpContext.Current.User.Identity.Name;
            var currentSession = SessionInfo.GetSessionInfo(_distributorId, HLConfigManager.Configurations.Locale);

            if (currentSession.OrderQueryStatus99BillInprocess)
            {
                return(null);
            }
            //LogMessage(PaymentGatewayLogEntryType.Request,
            //              orderNumber,
            //              string.Empty,
            //              "CN_99BillPaymentGateway",
            //              PaymentGatewayRecordStatusType.Unknown, "GatewayOrderQueryRequest for OrderNumber: " + orderNumber);
            var requestString       = "GatewayOrderQueryRequest for OrderNumber: " + orderNumber;
            var orderStatusResponse = China.OrderProvider.Get99BillOrderStatus(orderNumber);

            if (orderStatusResponse == null)
            {
                return(null);
            }
            if (orderStatusResponse.IsCreditCardOrder && !string.IsNullOrEmpty(orderStatusResponse.CreditCardResponse))
            {
                return(CNPQueryResponse(orderStatusResponse.CreditCardResponse, orderNumber));
            }
            if (orderStatusResponse.IsWechatOrder)
            {
                PaymentGatewayResponse response = new CN_99BillPaymentGatewayResponse();
                response.OrderNumber         = orderNumber;
                response.CanSubmitIfApproved = true;
                response.ReloadShoppingCart  = true;
                if (!string.IsNullOrEmpty(orderStatusResponse.WechatResponse) &&
                    orderStatusResponse.WechatResponse == "SUCCESS")
                {
                    response.IsApproved = true;
                }
                else
                {
                    response.IsApproved = false;
                }
                return(response);
            }


            if (orderStatusResponse.GatewayResponse == null)
            {
                return(null);
            }
            if (orderStatusResponse.GatewayResponse.OrderDetail != null &&
                orderStatusResponse.GatewayResponse.OrderDetail.Any())
            {
                if (orderStatusResponse.GatewayResponse.OrderDetail.FirstOrDefault().PayResult != "10")
                {
                    LogMessageWithInfo(
                        PaymentGatewayLogEntryType.Response,
                        orderNumber,
                        string.Empty,
                        orderStatusResponse.GetType().Name.Replace("Response", string.Empty),
                        PaymentGatewayRecordStatusType.Declined, requestString + ToXml(orderStatusResponse.GatewayResponse)
                        );
                    return(null);
                }
                currentSession.OrderQueryStatus99BillInprocess = true;
                LogMessageWithInfo(PaymentGatewayLogEntryType.Response,
                                   orderNumber,
                                   string.Empty,
                                   orderStatusResponse.GetType().Name.Replace("Response", string.Empty),
                                   PaymentGatewayRecordStatusType.Approved, requestString + ToXml(orderStatusResponse.GatewayResponse)
                                   );
                PaymentGatewayResponse response = new CN_99BillPaymentGatewayResponse();

                response.IsApproved          = true;
                response.OrderNumber         = orderNumber;
                response.CanSubmitIfApproved = true;
                response.ReloadShoppingCart  = true;
                response.SpecialResponse     = string.Format("{0},{1}",
                                                             orderStatusResponse.GatewayResponse.OrderDetail.FirstOrDefault()
                                                             .DealId,
                                                             orderStatusResponse.GatewayResponse.OrderDetail.FirstOrDefault()
                                                             .DealId);
                return(response);
            }
            var strDecline             = Settings.GetRequiredAppSetting("EbankingResponseCodeForDecline", "31003,31005,31006");
            var responseCodeForDecline = new List <string>(strDecline.Split(new char[] { ',' }));

            if (responseCodeForDecline.Contains(orderStatusResponse.GatewayResponse.ErrorCode))
            {
                currentSession.OrderQueryStatus99BillInprocess = false;
                LogMessageWithInfo(
                    PaymentGatewayLogEntryType.Response,
                    orderNumber,
                    string.Empty,
                    orderStatusResponse.GetType().Name.Replace("Response", string.Empty),
                    PaymentGatewayRecordStatusType.Declined, requestString + ToXml(orderStatusResponse.GatewayResponse)
                    );
            }
            return(null);
        }
Ejemplo n.º 2
0
        private static CN_99BillPaymentGatewayResponse CNPQueryResponse(string response, string orderNumber)
        {
            if (response.IndexOf("xmlns=\"http://www.99bill.com/mas_cnp_merchant_interface\"") > 1)
            {
                response = response.Replace(" xmlns=\"http://www.99bill.com/mas_cnp_merchant_interface\"", "");
            }
            var xmlDoc        = new XmlDocument();
            var encodedString = Encoding.UTF8.GetBytes(response);
            var ms            = new MemoryStream(encodedString);

            ms.Flush();
            ms.Position = 0;
            // Build the XmlDocument from the MemorySteam of UTF-8 encoded bytes
            xmlDoc.Load(ms);
            var list = xmlDoc.SelectNodes("//TxnMsgContent");

            if (list != null && list.Count == 0)
            {
                var selectSingleNode = xmlDoc.SelectSingleNode("MasMessage/ErrorMsgContent/errorMessage");
                if (selectSingleNode != null)
                {
                    LogMessageWithInfo(PaymentGatewayLogEntryType.Response, orderNumber, string.Empty, "CN_99BillPaymentGateway",
                                       PaymentGatewayRecordStatusType.Declined, response + selectSingleNode.InnerText);
                }
            }
            else
            {
                var approved         = false;
                var selectSingleNode = xmlDoc.SelectSingleNode("MasMessage/TxnMsgContent/responseCode");
                if (selectSingleNode != null)
                {
                    var responseCode = selectSingleNode.InnerText;
                    approved = responseCode == "00";
                    if (!approved)
                    {
                        var strCNPUnknown             = Settings.GetRequiredAppSetting("CNPResponseCodeForUnknown", "C0,68");
                        var cnpResponseCodeForUnknown = new List <string>(strCNPUnknown.Split(new char[] { ',' }));
                        if (cnpResponseCodeForUnknown.Contains(responseCode.ToUpper()))
                        {
                            return(null);
                        }
                        LogMessageWithInfo(PaymentGatewayLogEntryType.Response, orderNumber, string.Empty,
                                           "CN_99BillPaymentGateway",
                                           PaymentGatewayRecordStatusType.Declined, response + selectSingleNode.InnerText);
                        return(null);
                    }
                }
                if (!approved)
                {
                    return(null);
                }
                var distributorId  = HttpContext.Current.User.Identity.Name;
                var currentSession = SessionInfo.GetSessionInfo(distributorId, HLConfigManager.Configurations.Locale);
                currentSession.OrderQueryStatus99BillInprocess = true;
                var singleNode            = xmlDoc.SelectSingleNode("MasMessage/TxnMsgContent/externalRefNumber");
                var externalRefNumberback = singleNode != null ? singleNode.InnerText : string.Empty;
                var refNumber             = xmlDoc.SelectSingleNode("MasMessage/TxnMsgContent/refNumber");
                var refNumberback         = refNumber != null ? refNumber.InnerText : string.Empty;
                LogMessageWithInfo(PaymentGatewayLogEntryType.Response, orderNumber, string.Empty, "CN_99BillPaymentGateway",
                                   PaymentGatewayRecordStatusType.Approved, response);

                var paymentGatewayResponse = new CN_99BillPaymentGatewayResponse
                {
                    IsApproved          = true,
                    OrderNumber         = orderNumber,
                    CanSubmitIfApproved = true,
                    ReloadShoppingCart  = true,
                    SpecialResponse     = string.Format("{0},{1}", externalRefNumberback, refNumberback)
                };
                return(paymentGatewayResponse);
            }
            return(null);
        }