Exemple #1
0
        public virtual void GetPaymentInfo(SerializedOrderHolder holder)
        {
            var payment      = holder.BTOrder.Payments[0];
            var orderPayment = (holder.Order as Order_V01).Payments[0] as CreditPayment_V01;

            if (!string.IsNullOrEmpty(CardNumber))
            {
                payment.AccountNumber = CardNumber;
            }
            else
            {
                payment.AccountNumber = PaymentInfoProvider.GetDummyCreditCardNumber(IssuerAssociationType.Visa);
            }

            payment.PaymentCode = HLConfigManager.CurrentPlatformConfigs[holder.Locale].PaymentsConfiguration.PaymentGatewayPayCode;
            if (string.IsNullOrEmpty(payment.PaymentCode))
            {
                payment.PaymentCode = CreditCard.CardTypeToHPSCardType(CardType);
            }
            orderPayment.Card.IssuerAssociation = CreditCard.GetCardType(payment.PaymentCode);

            if (!string.IsNullOrEmpty(AuthorizationCode))
            {
                payment.AuthNumber = AuthorizationCode;
            }
            orderPayment.AuthorizationCode = payment.AuthNumber;

            if (!string.IsNullOrEmpty(TransactionCode))
            {
                payment.TransactionCode = TransactionCode;
            }
            orderPayment.TransactionID = payment.TransactionCode;

            //They don't always return the full cardnumber, so if less than 15, use the base method which has a fixer in it
            if (payment.AccountNumber.Length < 15)
            {
                payment.AccountNumber = new string('*', 16 - payment.AccountNumber.Length) + payment.AccountNumber;
            }
            orderPayment.Card.AccountNumber = payment.AccountNumber;
        }
 public string GetDummyCreditCardNumber(IssuerAssociationType cardBrand)
 {
     return(PaymentInfoProvider.GetDummyCreditCardNumber(cardBrand));
 }
Exemple #3
0
        private void PostCNP(MyHLShoppingCart shoppingcart, CreditPayment_V01 payment, SessionInfo sessionInfo, string disId, string name)
        {
            if (shoppingcart == null || payment == null)
            {
                return;
            }

            var tr3Url     = _configHelper.GetConfigEntry("paymentGatewayReturnUrlApproved");
            var merchantId = _configHelper.GetConfigEntry("CNPTerminalId");
            var terminalId = _configHelper.GetConfigEntry("terminalId");

            try
            {
                var phoneNumber = DistributorOrderingProfileProvider.GetPhoneNumberForCN(disId).Trim();
                var amount      = _orderAmount <= 0 ? "0.00" : _orderAmount.ToString("0.00");
                var tins        = DistributorOrderingProfileProvider.GetTinList(disId, true);
                var tin         = tins.Find(t => t.ID == "CNID");
                //var phoneNum = string.Empty;
                if (string.IsNullOrEmpty(phoneNumber) && shoppingcart.DeliveryInfo != null &&
                    shoppingcart.DeliveryInfo.Address != null)
                {
                    phoneNumber = shoppingcart.DeliveryInfo.Address.Phone;
                }

                var sbXml = new StringBuilder();
                sbXml.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><MasMessage xmlns=\"http://www.99bill.com/mas_cnp_merchant_interface\">");
                sbXml.Append("<version>1.0</version><TxnMsgContent><txnType>PUR</txnType><interactiveStatus>TR1</interactiveStatus>");
                sbXml.AppendFormat("<cardNo>{0}</cardNo>", payment.Card.AccountNumber);
                sbXml.AppendFormat("<expiredDate>{0}</expiredDate>", payment.Card.Expiration.ToString("MM") + payment.Card.Expiration.ToString("yy"));
                sbXml.AppendFormat("<cvv2>{0}</cvv2>", payment.Card.CVV);
                sbXml.AppendFormat("<amount>{0}</amount>", amount);
                sbXml.AppendFormat("<merchantId>{0}</merchantId>", merchantId.Trim());
                sbXml.AppendFormat("<terminalId>{0}</terminalId>", terminalId.Trim());
                sbXml.AppendFormat("<cardHolderName>{0}</cardHolderName>", name);
                sbXml.AppendFormat("<cardHolderId>{0}</cardHolderId>", tin == null ? string.Empty : tin.IDType.Key.Trim());
                sbXml.Append("<idType>0</idType>");
                sbXml.AppendFormat("<entryTime>{0}</entryTime>", DateTime.Now.ToString("yyyyMMddHHmmss"));
                sbXml.AppendFormat("<externalRefNumber>{0}</externalRefNumber>", _orderNumber);
                sbXml.AppendFormat("<extMap><extDate><key>phone</key><value>{0}</value></extDate></extMap>", phoneNumber);
                sbXml.AppendFormat("<tr3Url>{0}</tr3Url>", tr3Url.Trim());
                sbXml.AppendFormat("<bankId>{0}</bankId>", payment.AuthorizationMerchantAccount);
                sbXml.AppendFormat("</TxnMsgContent></MasMessage>");

                var decyptedCardNum = CryptographicProvider.Decrypt(payment.Card.AccountNumber);
                var decyptedCVV     = CryptographicProvider.Decrypt(payment.Card.CVV);

                var securedOrderData = sbXml.ToString().Replace(payment.Card.AccountNumber, PaymentInfoProvider.GetDummyCreditCardNumber(IssuerAssociationType.Visa));

                if (!string.IsNullOrEmpty(decyptedCVV))
                {
                    securedOrderData = securedOrderData.Replace(payment.Card.CVV, "123");
                }

                LogMessageWithInfo(PaymentGatewayLogEntryType.Request, _orderNumber, _distributorId, _gatewayName,
                                   PaymentGatewayRecordStatusType.Unknown, securedOrderData);

                bool   isLockedeach = true;
                bool   isLocked     = true;
                string lockfailed   = string.Empty;
                if (shoppingcart.pcLearningPointOffSet > 0M && !(shoppingcart.OrderCategory == ServiceProvider.CatalogSvc.OrderCategoryType.ETO))
                {
                    isLockedeach = OrderProvider.LockPCLearningPoint(_distributorId, _orderNumber,
                                                                     new OrderMonth(shoppingcart.CountryCode).OrderMonthShortString,
                                                                     Convert.ToInt32(Math.Truncate(shoppingcart.pcLearningPointOffSet)),
                                                                     HLConfigManager.Platform);
                    if (!isLockedeach)
                    {
                        lockfailed = "PC Learning Point";
                        isLocked   = false;
                    }
                }
                else if (shoppingcart.pcLearningPointOffSet > 0M)
                {
                    isLockedeach = OrderProvider.LockETOLearningPoint(
                        shoppingcart.CartItems.Select(s => s.SKU),
                        _distributorId,
                        _orderNumber,
                        new OrderMonth(shoppingcart.CountryCode).OrderMonthShortString,
                        Convert.ToInt32(Math.Truncate(shoppingcart.pcLearningPointOffSet)),
                        HLConfigManager.Platform);

                    if (!isLockedeach)
                    {
                        lockfailed = "ETO Learning Point";
                        isLocked   = false;
                    }
                }
                if (shoppingcart.HastakenSrPromotion)
                {
                    isLockedeach = ChinaPromotionProvider.LockSRPromotion(shoppingcart, _orderNumber);
                    if (!isLockedeach)
                    {
                        lockfailed = lockfailed + ", SR Promotion";
                        isLocked   = false;
                    }
                }
                if (shoppingcart.HastakenSrPromotionGrowing)
                {
                    isLockedeach = ChinaPromotionProvider.LockSRQGrowingPromotion(shoppingcart, _orderNumber);
                    if (!isLockedeach)
                    {
                        lockfailed = lockfailed + ", SR Query Growing";
                        isLocked   = false;
                    }
                }
                if (shoppingcart.HastakenSrPromotionExcelnt)
                {
                    isLockedeach = ChinaPromotionProvider.LockSRQExcellentPromotion(shoppingcart, _orderNumber);
                    if (!isLockedeach)
                    {
                        lockfailed = lockfailed + ", SR Query Excellent";
                        isLocked   = false;
                    }
                }
                if (shoppingcart.HastakenBadgePromotion)
                {
                    isLockedeach = ChinaPromotionProvider.LockBadgePromotion(shoppingcart, _orderNumber);
                    if (!isLockedeach)
                    {
                        lockfailed = lockfailed + ", Badge promo";
                        isLocked   = false;
                    }
                }
                if (shoppingcart.HastakenNewSrpromotion)
                {
                    isLockedeach = ChinaPromotionProvider.LockNewSRPromotion(shoppingcart, _orderNumber);
                    if (!isLockedeach)
                    {
                        lockfailed = lockfailed + ", NewSrPromotion";
                        isLocked   = false;
                    }
                }

                if (shoppingcart.HasBrochurePromotion)
                {
                    isLockedeach = ChinaPromotionProvider.LockBrochurePromotion(shoppingcart, _orderNumber);
                    if (!isLockedeach)
                    {
                        lockfailed = lockfailed + ", Brochure Promotion";
                        isLocked   = false;
                    }
                }
                if (isLocked)
                {
                    var proxy   = ServiceClientProvider.GetChinaOrderServiceProxy();
                    var request = new ServiceProvider.OrderChinaSvc.GetCNPPaymentServiceRequest_V01()
                    {
                        Data = sbXml.ToString().Replace(payment.Card.AccountNumber, decyptedCardNum).Replace(payment.Card.CVV, decyptedCVV)
                    };
                    var response = proxy.GetCnpPaymentServiceDetail(new ServiceProvider.OrderChinaSvc.GetCnpPaymentServiceDetailRequest(request)).GetCnpPaymentServiceDetailResult as ServiceProvider.OrderChinaSvc.GetCNPPaymentServiceResponse_V01;

                    if (null != response)
                    {
                        if (response.Status == ServiceProvider.OrderChinaSvc.ServiceResponseStatusType.Success && response.Response.Length > 0)
                        {
                            var msgReturn = response.Response;
                            if (msgReturn.IndexOf("xmlns=\"http://www.99bill.com/mas_cnp_merchant_interface\"") > 1)
                            {
                                msgReturn = msgReturn.Replace(" xmlns=\"http://www.99bill.com/mas_cnp_merchant_interface\"", "");
                            }
                            var xmlDoc        = new XmlDocument();
                            var encodedString = Encoding.UTF8.GetBytes(msgReturn);
                            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");
                            var    externalRefNumberback = string.Empty;
                            var    refNumberback         = string.Empty;
                            var    gatewayAmount         = string.Empty;
                            var    approved     = false;
                            string responseCode = "";
                            if (list != null && list.Count == 0)
                            {
                                var selectSingleNode = xmlDoc.SelectSingleNode("MasMessage/ErrorMsgContent/errorMessage");
                                if (selectSingleNode != null)
                                {
                                    var errorMessage = selectSingleNode.InnerText;
                                    LogMessageWithInfo(PaymentGatewayLogEntryType.Response, _orderNumber, _distributorId, _gatewayName, PaymentGatewayRecordStatusType.Declined, msgReturn + errorMessage);
                                }
                            }
                            else
                            {
                                var authorizationCodeback = "";
                                var selectSingleNode      = xmlDoc.SelectSingleNode("MasMessage/TxnMsgContent/responseCode");
                                if (selectSingleNode != null)
                                {
                                    responseCode = selectSingleNode.InnerText;
                                    approved     = responseCode == "00";
                                }

                                var singleNode = xmlDoc.SelectSingleNode("MasMessage/TxnMsgContent/externalRefNumber");
                                externalRefNumberback = singleNode != null ? singleNode.InnerText : string.Empty;
                                var refNumber = xmlDoc.SelectSingleNode("MasMessage/TxnMsgContent/refNumber");
                                refNumberback = refNumber != null ? refNumber.InnerText : string.Empty;
                                var authorizationCode = xmlDoc.SelectSingleNode("MasMessage/TxnMsgContent/authorizationCode");
                                authorizationCodeback = authorizationCode != null
                                                            ? authorizationCode.InnerText
                                                            : string.Empty;
                                var retAmount = xmlDoc.SelectSingleNode("MasMessage/TxnMsgContent/amount");
                                gatewayAmount = retAmount != null ? retAmount.InnerText : string.Empty;

                                if (approved)
                                {
                                    LogMessageWithInfo(PaymentGatewayLogEntryType.Response, _orderNumber, _distributorId, _gatewayName, PaymentGatewayRecordStatusType.Approved, msgReturn);
                                }
                                else
                                {
                                    var strCNPUnknown             = Settings.GetRequiredAppSetting("CNPResponseCodeForUnknown", "C0,68");
                                    var cnpResponseCodeForUnknown = new List <string>(strCNPUnknown.Split(new char[] { ',' }));
                                    if (cnpResponseCodeForUnknown.Contains(responseCode.ToUpper()))
                                    {
                                        LogMessageWithInfo(PaymentGatewayLogEntryType.Response, _orderNumber, _distributorId, _gatewayName, PaymentGatewayRecordStatusType.Unknown, msgReturn);
                                    }
                                    else
                                    {
                                        LogMessageWithInfo(PaymentGatewayLogEntryType.Response, _orderNumber, _distributorId, _gatewayName, PaymentGatewayRecordStatusType.Declined, msgReturn);
                                    }
                                }

                                sessionInfo.OrderStatus = SubmitOrderStatus.Unknown;
                            }
                            payment.Card.IssuingBankID           = refNumberback;
                            payment.AuthorizationMerchantAccount = externalRefNumberback;
                            var signMsgVal = string.Format("{0},{1},{2},{3},{4},{5}", _orderNumber, approved ? "1" : "0", DateTime.Now.ToString(DateTimeFormat), refNumberback, externalRefNumberback, gatewayAmount);
                            var verStr     = Encrypt(signMsgVal, EncryptionKey);
                            var url        = string.Format("{0}?VerStr={1}", _configHelper.GetConfigEntry("paymentGatewayReturnUrlApproved"), verStr);

                            HttpContext.Current.Response.Redirect(url, false);
                            HttpContext.Current.ApplicationInstance.CompleteRequest();
                        }
                        else
                        {
                            var resp =
                                string.Format("CNP - PostCNP response fails. OrderNumber: {0} ; response: {1}; status: {2}",
                                              _orderNumber, response.Response, response.Status);
                            //LoggerHelper.Error(resp);
                            LogMessageWithInfo(PaymentGatewayLogEntryType.Response, _orderNumber, _distributorId, _gatewayName, PaymentGatewayRecordStatusType.Declined, resp);
                        }
                    }
                    else
                    {
                        var resp = "CNP - PostCNP response fails. OrderNumber:" + _orderNumber;
                        //LoggerHelper.Error(resp);
                        LogMessageWithInfo(PaymentGatewayLogEntryType.Response, _orderNumber, _distributorId, _gatewayName, PaymentGatewayRecordStatusType.Declined, resp);
                    }
                }
                else
                {
                    var resp = "CNP - " + lockfailed.TrimStart(',') + " locking fails. OrderNumber:" + _orderNumber;
                    LogMessageWithInfo(PaymentGatewayLogEntryType.Response, _orderNumber, _distributorId, _gatewayName, PaymentGatewayRecordStatusType.Declined, resp);
                }
            }
            catch (Exception ex)
            {
                var resp = string.Format("CNP - PostCNP exception. OrderNumber: {0}. ex : {1} ", _orderNumber, ex.Message);
                LoggerHelper.Error(resp);
                LogMessage(PaymentGatewayLogEntryType.Response, _orderNumber, _distributorId, _gatewayName, PaymentGatewayRecordStatusType.Declined, resp);
            }
        }