public override List <Payment> GetPayments(Address_V01 shippingAddress) { var paymentList = new List <Payment>(); CheckForPaymentGatewayResponse(); var choice = GetCurrentPaymentOptionOverride(); switch (choice) { case PaymentOptionChoiceOverride.WireTransfer: // Pay by Phone { paymentList.Add(CreateDummyPayment(shippingAddress)); (paymentList.First()).TransactionType = "DB"; break; } case PaymentOptionChoiceOverride.PaymentGateway: // eBanking { paymentList.Add(CreateDummyPayment(shippingAddress)); (paymentList.First()).TransactionType = "10"; break; } case PaymentOptionChoiceOverride.Bill99: // 99 bill { paymentList.Add(CreateDummyPayment(shippingAddress)); (paymentList.First()).TransactionType = "12"; Session.Remove(PaymentGatewayInvoker.PaymentInformation); Session.Add(PaymentGatewayInvoker.PaymentInformation, paymentList.First()); break; } case PaymentOptionChoiceOverride.CreditCard: // CNP { var paymentInfo = GetCurrentPaymentInformation(_locale, _distributorId); // Check mobile controls first if (!string.IsNullOrEmpty(txtCardNumberMob.Text) && ddlBankdsMob.SelectedItem != null && !string.IsNullOrEmpty(txtExpMonthMob.Text) && !string.IsNullOrEmpty(txtExpYearMob.Text) && !string.IsNullOrEmpty(txtCVVMob.Text)) { decimal amount = 0; int cardMobileId = 0; int.TryParse(txtCardIdMob.Text, out cardMobileId); if (decimal.TryParse(txtAmountMob.Text, out amount) && cardMobileId > 0) { var info = (paymentInfo != null && paymentInfo.Count > 0) ? paymentInfo[0] : new PaymentInformation(); info.CardHolder = new Name_V01(); var payment = new CreditPayment_V01(); info.Amount = amount; payment.Card = new CreditCard(); payment.AuthorizationMethod = AuthorizationMethodType.Online; payment.Card.IssuerAssociation = IssuerAssociationType.None; payment.Amount = amount; payment.Address = shippingAddress; info.CardNumber = payment.Card.AccountNumber = CryptographicProvider.Encrypt(txtCardNumberMob.Text.Trim()); payment.Card.CVV = CryptographicProvider.Encrypt(txtCVVMob.Text.Trim()); payment.AuthorizationCode = string.Empty; info.Expiration = payment.Card.Expiration = getExpDate(txtExpMonthMob.Text, txtExpYearMob.Text); info.AuthorizationFailures = 0; if (isExpires(info.Expiration)) { //info.AuthorizationFailures = 3; imgDeclinedMob.ImageUrl = GetStatusImageUrl(info.ID); imgDeclinedMob.ToolTip = GetStatusImageToolTip(info.ID); imgDeclinedMob.Visible = true; lblErrorMessages.Text = PlatformResources.GetGlobalResourceString("ErrorMessage", "CardExpiredForSavedCard"); } payment.Card.NameOnCard = string.Empty; payment.AuthorizationMerchantAccount = ddlBankdsMob.SelectedItem != null ? ddlBankdsMob.SelectedValue : string.Empty; payment.Currency = HLConfigManager.Configurations.CheckoutConfiguration.Currency.Trim(); payment.Address = (null != info.BillingAddress) ? info.BillingAddress : shippingAddress; payment.PaymentOptions = new PaymentOptions_V01 { NumberOfInstallments = 1 }; info.Options = payment.PaymentOptions; payment.TransactionType = "CC"; paymentList.Add(payment); Session.Remove(PaymentGatewayInvoker.PaymentInformation); Session.Add(PaymentGatewayInvoker.PaymentInformation, payment); SetCurrentPaymentInformation(paymentInfo, _locale, _distributorId); } break; } foreach (GridViewRow row in gridViewCardInfo.Rows) { var txtCVV = row.FindControl("txtCVV") as TextBox; var txtAmount = row.FindControl("txtAmount") as TextBox; var txtCardNumber = row.FindControl("txtCardNumber") as TextBox; var txtExpMonth = row.FindControl("txtExpMonth") as TextBox; var txtExpYear = row.FindControl("txtExpYear") as TextBox; var id = row.FindControl("cardID") as TextBox; var currentOptions = row.FindControl("lnkPaymentOptions") as LinkButton; var banks = row.FindControl("ddlCards") as DropDownList; // list of banks int cardID = int.Parse(id.Text); decimal cardAmount; if (decimal.TryParse(txtAmount.Text, out cardAmount) && cardID > 0) { var info = (paymentInfo != null && paymentInfo.Count > 0) ? paymentInfo[0] : new PaymentInformation(); info.CardHolder = new Name_V01(); var payment = new CreditPayment_V01(); info.Amount = cardAmount; payment.Card = new CreditCard(); payment.AuthorizationMethod = AuthorizationMethodType.Online; payment.Card.IssuerAssociation = IssuerAssociationType.None; payment.Amount = cardAmount; payment.Address = shippingAddress; info.CardNumber = payment.Card.AccountNumber = CryptographicProvider.Encrypt(txtCardNumber.Text.Trim()); payment.Card.CVV = CryptographicProvider.Encrypt(txtCVV.Text.Trim()); payment.AuthorizationCode = string.Empty; info.Expiration = payment.Card.Expiration = getExpDate(txtExpMonth.Text, txtExpYear.Text); info.AuthorizationFailures = 0; if (isExpires(info.Expiration)) { //info.AuthorizationFailures = 3; var img = row.FindControl("imgDeclined") as Image; if (null != img) { img.ImageUrl = GetStatusImageUrl(info.ID); img.ToolTip = GetStatusImageToolTip(info.ID); img.Visible = true; } lblErrorMessages.Text = PlatformResources.GetGlobalResourceString("ErrorMessage", "CardExpiredForSavedCard"); } payment.Card.NameOnCard = string.Empty; payment.AuthorizationMerchantAccount = banks.SelectedItem != null ? banks.SelectedValue : string.Empty; payment.Currency = HLConfigManager.Configurations.CheckoutConfiguration.Currency.Trim(); payment.Address = (null != info.BillingAddress) ? info.BillingAddress : shippingAddress; payment.PaymentOptions = new PaymentOptions_V01 { NumberOfInstallments = 1 }; info.Options = payment.PaymentOptions; payment.TransactionType = "CC"; SetPaymentOptions(info, row); payment.ReferenceID = currentOptions.Text; paymentList.Add(payment); Session.Remove(PaymentGatewayInvoker.PaymentInformation); Session.Add(PaymentGatewayInvoker.PaymentInformation, payment); SetCurrentPaymentInformation(paymentInfo, _locale, _distributorId); } } break; } case PaymentOptionChoiceOverride.QuickPay: // Quick Pay { var payment = new CreditPayment_V01(); payment.TransactionType = "QP"; payment.Currency = HLConfigManager.Configurations.CheckoutConfiguration.Currency.Trim(); payment.AuthorizationMerchantAccount = BankList_QuickPay.SelectedValue; var card = new QuickPayPayment(); if (IsNewQuickPayRegistration()) { var membershipUser = (MembershipUser <DistributorProfileModel>)Membership.GetUser(); var name = string.Empty; if (membershipUser != null) { name = membershipUser.Value.DistributorName(); } if (!string.IsNullOrEmpty(CardCVV_QuickPay.Text)) { card.CVV = CryptographicProvider.Encrypt(CardCVV_QuickPay.Text); } card.AccountNumber = CryptographicProvider.Encrypt(CardNumber_QuickPay.Text.Trim()); card.CardHolderId = IdentityNumber_QuickPay.Text; card.CardHolderType = "0"; //CNID card.NameOnCard = name; card.MobilePhoneNumber = PhoneNumber_QuickPay.Text; int expiredMonth = 0; int expiredYear = 0; DateTime tmpDate = DateTime.Now; if (int.TryParse(CardExpiredDate_Month_QuickPay.Text, out expiredMonth) && int.TryParse("20" + CardExpiredDate_Year_QuickPay.Text, out expiredYear) && DateTime.TryParseExact("01/" + CardExpiredDate_Month_QuickPay.Text + "/20" + CardExpiredDate_Year_QuickPay.Text, "dd/MM/yyyy", null, System.Globalization.DateTimeStyles.None, out tmpDate)) { card.Expiration = new DateTime(expiredYear, expiredMonth, 1); } } else { card.AccountNumber = CryptographicProvider.Encrypt(CardNumberLabel_QuickPay.Text.Trim()); card.StorablePAN = card.AccountNumber; card.CardHolderId = IdentityNumberLabel_QuickPay.Text; card.CardHolderType = "0"; //CNID card.MobilePhoneNumber = PhoneNumberLabel_QuickPay.Text; } card.IssuingBankID = BankList_QuickPay.SelectedValue; card.IsDebitCard = IsQuickPayDebitCard(); card.BindCard = BindCard_QuickPay.Checked; payment.Card = card; payment.Amount = GetTotals().AmountDue; paymentList.Add(payment); Session.Remove(PaymentGatewayInvoker.PaymentInformation); Session.Add(PaymentGatewayInvoker.PaymentInformation, payment); break; } } string currentKey = PaymentsConfiguration.GetCurrentPaymentSessionKey(_locale, _distributorId); Session[currentKey] = paymentList; return(paymentList); }
public static bool PostCNPForMobile(MyHLShoppingCart shoppingcart, CreditPayment_V01 payment, string disId, string name, decimal amoun, string orderNumber, string distributorId, string phone) { if (shoppingcart == null || payment == null) { return(false); } ConfigHelper configHelper = new ConfigHelper("CN_99BillPaymentGateway"); var tr3Url = configHelper.GetConfigEntry("paymentGatewayReturnUrlApproved"); var merchantId = configHelper.GetConfigEntry("CNPTerminalId"); var terminalId = configHelper.GetConfigEntry("terminalId"); try { var amount = amoun <= 0 ? "0.00" : amoun.ToString("0.00"); var tins = DistributorOrderingProfileProvider.GetTinList(disId, true); var tin = tins.Find(t => t.ID == "CNID"); 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>", phone); sbXml.AppendFormat("<tr3Url>{0}</tr3Url>", tr3Url.Trim()); sbXml.AppendFormat("<bankId>{0}</bankId>", payment.AuthorizationMerchantAccount); sbXml.AppendFormat("</TxnMsgContent></MasMessage>"); var encyptedCardNum = CryptographicProvider.Encrypt(payment.Card.AccountNumber); var encryptedCvv = CryptographicProvider.Encrypt(payment.Card.CVV); var decyptedCardNum = CryptographicProvider.Decrypt(encyptedCardNum); var decryptedCvv = CryptographicProvider.Decrypt(encryptedCvv); var logData = sbXml.ToString() .Replace(payment.Card.AccountNumber, encyptedCardNum) .Replace(payment.Card.CVV, encryptedCvv); LogMessageWithInfo(PaymentGatewayLogEntryType.Request, orderNumber, orderNumber, orderNumber, PaymentGatewayRecordStatusType.Unknown, logData); 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, payment.Card.AccountNumber) }; 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; 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, "CN_99BillPaymentGatewayInvoker", PaymentGatewayRecordStatusType.Declined, msgReturn + errorMessage); return(false); } } else { var authorizationCodeback = ""; 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(approved); } LogMessageWithInfo(PaymentGatewayLogEntryType.Response, orderNumber, string.Empty, "CN_99BillPaymentGateway", PaymentGatewayRecordStatusType.Declined, msgReturn); return(approved); } } 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; LogMessageWithInfo(PaymentGatewayLogEntryType.Response, orderNumber, distributorId, "CN_99BillPaymentGatewayInvoker", PaymentGatewayRecordStatusType.Approved, msgReturn); //sessionInfo.OrderStatus = SubmitOrderStatus.Unknown; } payment.Card.IssuingBankID = refNumberback; payment.AuthorizationMerchantAccount = externalRefNumberback; return(approved); } else { var resp = string.Format( "Response failure. Unable to connect to 99Bill. OrderNumber: {0} ; response: {1}; status: {2}", orderNumber, response.Response, response.Status); //LoggerHelper.Error(resp); LogMessageWithInfo(PaymentGatewayLogEntryType.Response, orderNumber, distributorId, "CN_99BillPaymentGatewayInvoker", PaymentGatewayRecordStatusType.Declined, resp); return(false); } } else { var resp = "Response null, Unable to connect to 99Bill. OrderNumber:" + orderNumber; //LoggerHelper.Error(resp); LogMessageWithInfo(PaymentGatewayLogEntryType.Response, orderNumber, distributorId, "CN_99BillPaymentGatewayInvoker", PaymentGatewayRecordStatusType.Declined, resp); return(false); } } else { var resp = "PostCNP - " + lockfailed.TrimStart(',') + " locking fails. OrderNumber:" + orderNumber; LogMessageWithInfo(PaymentGatewayLogEntryType.Response, orderNumber, distributorId, "CN_99BillPaymentGatewayInvoker", PaymentGatewayRecordStatusType.Declined, resp); return(false); } } catch (Exception ex) { var resp = string.Format("PostCNP Error. OrderNumber: {0}. ex : {1} ", orderNumber, ex.Message); LoggerHelper.Error(resp); LogMessage(PaymentGatewayLogEntryType.Response, orderNumber, distributorId, "CN_99BillPaymentGatewayInvoker", PaymentGatewayRecordStatusType.Declined, resp); return(false); } }