Exemplo n.º 1
0
        protected void btnUseAnotherCard_QuickPay_Click(object sender, EventArgs e)
        {
            var phoneNumber = DistributorOrderingProfileProvider.GetPhoneNumberForCN(_distributorId).Trim();
            var tins        = DistributorOrderingProfileProvider.GetTinList(_distributorId, true);
            var tin         = tins.Find(t => t.ID == "CNID");

            var membershipUser = (MembershipUser <DistributorProfileModel>)Membership.GetUser();
            var name           = string.Empty;

            if (membershipUser != null)
            {
                name = membershipUser.Value.DistributorName();
            }

            ExistingCard.Visible   = false;
            NewCardBinding.Visible = true;

            ClearQuickPayCardInput();

            CardHolderName_QuickPay.Text = name;
            IdentityNumber_QuickPay.Text = tin == null ? string.Empty : tin.IDType.Key.Trim();
            PhoneNumber_QuickPay.Text    = phoneNumber;
        }
Exemplo n.º 2
0
        protected void OnBankList_QuickPaySelected(object sender, EventArgs e)
        {
            if (!Page.Request.Params.Get("__EVENTTARGET").EndsWith("BankList_QuickPay")) //workaround for the dynamic control loading that causing OnSelectedIndexChanged event triggered during postback.
            {
                return;
            }

            string cardType = "";

            if (BankList_QuickPay.SelectedIndex > 0)
            {
                if (IsQuickPayDebitCard())
                {
                    cardType = "0002";
                }
                else
                {
                    cardType = "0001";
                }

                var phoneNumber = DistributorOrderingProfileProvider.GetPhoneNumberForCN(_distributorId).Trim();
                var tins        = DistributorOrderingProfileProvider.GetTinList(_distributorId, true);
                var tin         = tins.Find(t => t.ID == "CNID");

                var disId          = _distributorId;
                var membershipUser = (MembershipUser <DistributorProfileModel>)Membership.GetUser();
                var name           = string.Empty;
                if (membershipUser != null)
                {
                    name = membershipUser.Value.DistributorName();
                }

                var quickPayProvider = new CN_99BillQuickPayProvider();
                var isCardAvailable  = quickPayProvider.CheckBindedCard(BankList_QuickPay.SelectedValue, cardType, phoneNumber);

                if (isCardAvailable)
                {
                    ExistingCard.Visible   = true;
                    NewCardBinding.Visible = false;

                    CardNumberLabel_QuickPay.Text     = quickPayProvider.StorablePAN;
                    CardHolderNameLabel_QuickPay.Text = name;
                    IdentityNumberLabel_QuickPay.Text = tin == null ? string.Empty : tin.IDType.Key.Trim();
                    PhoneNumberLabel_QuickPay.Text    = phoneNumber;
                }
                else
                {
                    if (!string.IsNullOrEmpty(quickPayProvider.LastErrorMessage))
                    {
                        lblErrorMessages.Text = quickPayProvider.LastErrorMessage;
                    }

                    ExistingCard.Visible   = false;
                    NewCardBinding.Visible = true;

                    ClearQuickPayCardInput();

                    CardHolderName_QuickPay.Text = name;
                    IdentityNumber_QuickPay.Text = tin == null ? string.Empty : tin.IDType.Key.Trim();
                    PhoneNumber_QuickPay.Text    = phoneNumber;
                }
            }
            else
            {
                ExistingCard.Visible   = false;
                NewCardBinding.Visible = true;

                ClearQuickPayCardInput();
            }
        }
Exemplo n.º 3
0
        public MobileResponseWrapper GetBindedCards(string disID)
        {
            var result      = new List <BindedCardswithBanklist>();
            var phoneNumber = DistributorOrderingProfileProvider.GetPhoneNumberForCN(disID).Trim();
            var cn99BillQuickPayProvider = new CN_99BillQuickPayProvider();
            var tins = DistributorOrderingProfileProvider.GetTinList(disID, true);
            var tin  = tins.Find(t => t.ID == "CNID");

            PaymentInformation bindedCard = null;

            List <PaymentInformation> bindedCards = cn99BillQuickPayProvider.LoadStorableDataQuick(phoneNumber, disID);

            var usageDebit = BankUsage.UsedByQPDebit;
            var debitCards = BankInfoProvider.GetAvailableBanks(usageDebit);

            var usageCredit = BankUsage.UsedByQPCredit;
            var creditCards = BankInfoProvider.GetAvailableBanks(usageCredit);

            //QD
            if (debitCards != null && debitCards.Count > 0)
            {
                foreach (BankInformation item in debitCards)
                {
                    if (bindedCards != null && bindedCards.Count > 0)
                    {
                        bindedCard = (from a in bindedCards where a.CardType.Trim() == "QD" && a.Alias.Trim() == item.BankCode.Trim() select a).FirstOrDefault();
                    }

                    var currentBindedCard = new BindedCardswithBanklist()
                    {
                        BankCode = item.BankCode,
                        BankName = item.BankName,
                        CardType = "QD",
                    };

                    if (bindedCard != null && bindedCard.CardHolder != null)
                    {
                        currentBindedCard.BindedCard = new BindedCardViewModel();
                        currentBindedCard.BindedCard.CardHolderName = bindedCard.CardHolder.First;
                        currentBindedCard.BindedCard.CardNumber     = bindedCard.CardNumber;
                    }

                    result.Add(currentBindedCard);
                    bindedCard = null;
                }
            }

            //QC
            if (creditCards != null && creditCards.Count > 0)
            {
                foreach (BankInformation item in creditCards)
                {
                    if (bindedCards != null && bindedCards.Count > 0)
                    {
                        bindedCard = (from a in bindedCards where a.CardType.Trim() == "QC" && a.Alias.Trim() == item.BankCode.Trim() select a).FirstOrDefault();
                    }

                    var currentBindedCard = new BindedCardswithBanklist()
                    {
                        BankCode = item.BankCode,
                        BankName = item.BankName,
                        CardType = "QC",
                    };

                    if (bindedCard != null && bindedCard.CardHolder != null)
                    {
                        currentBindedCard.BindedCard = new BindedCardViewModel();
                        currentBindedCard.BindedCard.CardHolderName = bindedCard.CardHolder.First;
                        currentBindedCard.BindedCard.CardNumber     = bindedCard.CardNumber;
                    }

                    result.Add(currentBindedCard);
                    bindedCard = null;
                }
            }

            var response = new MobileResponseWrapper
            {
                Data = new BindedCardswithBanklistResponseVewModel {
                    BankList = result, PhoneNumber = phoneNumber, CNID = tin.IDType.Key.Trim()
                },
            };

            return(response);
        }
Exemplo n.º 4
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);
            }
        }