예제 #1
0
        public async Task <AjaxResponse> GetFPXValidateStatus(string refInfo)
        {
            ValidateStatusModel result = new ValidateStatusModel();
            string posting_data        = "";

            string[]            splitInfo;
            string              path = string.Empty;
            string              url  = string.Empty;
            string              fpx_debitAuthCode = string.Empty;
            NameValueCollection qscoll;

            try
            {
                if (refInfo.Contains("|AR|"))
                {
                    splitInfo = refInfo.Replace("|AR|", "|AE|").Split('|');
                }
                else
                {
                    splitInfo = refInfo.Split('|');
                }

                if (splitInfo.Length != 20)
                {
                    result.Message = "Invalid Payment Info";
                    return(new AjaxResponse(new ErrorInfo(result.Message)));
                }

                if (splitInfo[9].ToUpper() != "AE")
                {
                    result.Message = "Invalid FPX Message Type";
                    return(new AjaxResponse(new ErrorInfo(result.Message)));
                }

                path = _appConfiguration["SUNSystem:CertificateDir"] + _appConfiguration["SUNSystem:SellerExId"] + ".key";
                url  = _appConfiguration["SUNSystem:FPXTXNSTAT"];

                string fpx_buyerAccNo      = splitInfo[0];
                string fpx_buyerBankBranch = splitInfo[1];
                string fpx_buyerBankId     = splitInfo[2];
                string fpx_buyerEmail      = splitInfo[3];
                string fpx_buyerIban       = splitInfo[4];
                string fpx_buyerId         = splitInfo[5];
                string fpx_buyerName       = splitInfo[6];
                string fpx_makerName       = splitInfo[7];
                string fpx_msgToken        = splitInfo[8];
                string fpx_msgType         = splitInfo[9];
                string fpx_productDesc     = splitInfo[10];
                string fpx_sellerBankCode  = splitInfo[11];
                string fpx_sellerExId      = splitInfo[12];
                string fpx_sellerExOrderNo = splitInfo[13];
                string fpx_sellerId        = splitInfo[14];
                string fpx_sellerOrderNo   = splitInfo[15];
                string fpx_sellerTxnTime   = splitInfo[16];
                string fpx_txnAmount       = splitInfo[17];
                string fpx_txnCurrency     = splitInfo[18];
                string fpx_version         = splitInfo[19].Contains("&") ? splitInfo[19].Split('&')[0] : splitInfo[19];
                string fpx_checkSum        = Payment.Repo.RSASign.RSASignValue(refInfo, path);

                posting_data += "fpx_msgType1=AE&fpx_msgType=AE&" + "fpx_msgToken=" + fpx_msgToken + "&" + "fpx_sellerExId=" + fpx_sellerExId + "&";
                posting_data += "fpx_sellerExOrderNo=" + fpx_sellerExOrderNo + "&" + "fpx_sellerTxnTime=" + fpx_sellerTxnTime + "&";
                posting_data += "fpx_sellerOrderNo=" + fpx_sellerOrderNo + "&" + "fpx_sellerBankCode=" + fpx_sellerBankCode + "&";
                posting_data += "fpx_txnCurrency=" + fpx_txnCurrency + "&" + "fpx_txnAmount=" + fpx_txnAmount + "&";
                posting_data += "fpx_buyerEmail=" + fpx_buyerEmail + "&" + "fpx_checkSum=" + fpx_checkSum + "&";
                posting_data += "fpx_buyerName=" + fpx_buyerName + "&" + "fpx_buyerBankId=" + fpx_buyerBankId + "&";
                posting_data += "fpx_buyerBankBranch=" + fpx_buyerBankBranch + "&" + "fpx_buyerAccNo=" + fpx_buyerAccNo + "&";
                posting_data += "fpx_buyerId=" + fpx_buyerId + "&" + "fpx_makerName=" + fpx_makerName + "&";
                posting_data += "fpx_buyerIban=" + fpx_buyerIban + "&" + "fpx_productDesc=" + fpx_productDesc + "&";
                posting_data += "fpx_version=" + fpx_version + "&" + "fpx_sellerId=" + fpx_sellerId + "&";
                posting_data += "checkSum_String=" + fpx_checkSum;

                byte[] _byteVersion = Encoding.ASCII.GetBytes(string.Concat("content=", posting_data));

                var sunSystem = new Payment.Repo.SUNSystemConnection();
                result.CheckSum = sunSystem.POSTWebRequest(url, posting_data, _byteVersion);
                if (string.IsNullOrEmpty(result.CheckSum))
                {
                    result.Message       = "No return from FPX";
                    result.DebitAuthCode = "99";
                    return(new AjaxResponse(new ErrorInfo(result.DebitAuthCode, result.Message)));
                }

                if (result.CheckSum.ToUpper().Contains("ERROR"))
                {
                    result.Message       = result.CheckSum;
                    result.DebitAuthCode = "99";
                    return(new AjaxResponse(new ErrorInfo(result.DebitAuthCode, result.Message)));
                }

                var clearView = result.CheckSum.Replace("&", "&" + System.Environment.NewLine);

                qscoll = HttpUtility.ParseQueryString(result.CheckSum);
                if (qscoll != null)
                {
                    fpx_debitAuthCode = qscoll["fpx_debitAuthCode"];
                }

                if (!string.IsNullOrEmpty(fpx_debitAuthCode))
                {
                    result.DebitAuthCode = fpx_debitAuthCode;

                    var codemasterLogic = new Core.General.Repo.CODEMASTER(_env, _connectionString);
                    var listCodemaster  = codemasterLogic.RetrieveAll(x => x.CodeType == "FPX");
                    if (listCodemaster != null && listCodemaster.Count() > 0)
                    {
                        result.Message = listCodemaster.Where(x => x.Code == result.DebitAuthCode).Select(y => y.CodeDesc).FirstOrDefault();
                    }
                }
                return(new AjaxResponse(result));
            }
            catch (Exception ex)
            {
                //result.Message = ex.Message.ToString();
                //result.DebitAuthCode = "99";
                //result.CheckSum = string.Empty;
                //Log.Error(nameof(AccountingController), ex);
                //return new AjaxResponse(result);
                throw ex;
            }
        }
예제 #2
0
        public async Task <AjaxResponse> GetFPXBankList(string fpx_msgToken)
        {
            string result       = string.Empty;
            string posting_data = string.Empty;
            string fpx_msgtype  = "BE";
            string fpx_sellerExId;
            string fpx_version = _appConfiguration["SUNSystem:FPXVersion"];
            string path;
            string fpx_checkSum               = "";
            string checkSum_String            = "";
            string bankType                   = string.Empty;
            string URLBank                    = string.Empty;
            List <FPXBankListModel> resultMap = new List <FPXBankListModel>();

            try
            {
                //B2C : fpx_msgToken = 01
                //B2B : fpx_msgToken = 02

                fpx_sellerExId = _appConfiguration["SUNSystem:SellerExId"];
                path           = _appConfiguration["SUNSystem:CertificateDir"] + fpx_sellerExId + ".key";
                URLBank        = _appConfiguration["SUNSystem:UrlBankList"];

                if (fpx_msgToken == "01")
                {
                    bankType = "BNC";
                }
                else if (fpx_msgToken == "02")
                {
                    bankType = "BNB";
                }

                fpx_checkSum    = fpx_msgToken + "|" + fpx_msgtype + "|" + fpx_sellerExId + "|" + fpx_version;
                checkSum_String = Payment.Repo.RSASign.RSASignValue(fpx_checkSum, path);
                posting_data    = "fpxmsgToken=" + fpx_msgToken +
                                  "&fpx_msgToken=" + fpx_msgToken +
                                  "&fpx_msgType=" + fpx_msgtype +
                                  "&fpx_sellerExId=" + fpx_sellerExId +
                                  "&fpx_version=" + fpx_version +
                                  "&fpx_checkSum=" + checkSum_String;

                byte[] _byteVersion = Encoding.ASCII.GetBytes(string.Concat("content=", posting_data));

                var sunSystem = new Payment.Repo.SUNSystemConnection();
                result = sunSystem.POSTWebRequest(URLBank, posting_data, _byteVersion);
                if (string.IsNullOrEmpty(result))
                {
                    return(new AjaxResponse(new ErrorInfo("FPX Response Null or Empty")));
                }

                if (result.ToUpper().Contains("ERROR"))
                {
                    return(new AjaxResponse(new ErrorInfo("Connection to FPX was Error")));
                }

                var codemasterLogic = new Core.General.Repo.CODEMASTER(_env, _connectionString);
                var listCodemaster  = codemasterLogic.RetrieveAll(x => x.CodeType == bankType);

                NameValueCollection qscoll = HttpUtility.ParseQueryString(result);
                var strbanklist            = qscoll["fpx_bankList"].Replace("%7E", "~").Replace("%2C", ", ");
                var splitstrbanklist       = strbanklist.Split(',');
                foreach (var index in splitstrbanklist)
                {
                    var splitVal   = index.Split("~");
                    var bankCode   = splitVal[0];
                    var bankName   = listCodemaster != null && listCodemaster.Count() > 0 ? listCodemaster.Where(x => x.Code == bankCode).Select(y => y.CodeDesc).FirstOrDefault() : string.Empty;
                    var bankStatus = splitVal[1];

                    if (bankStatus.ToUpper() == "B")
                    {
                        bankStatus = " (OFFLINE)";
                    }
                    else
                    {
                        bankStatus = string.Empty;
                    }

                    FPXBankListModel cont = new FPXBankListModel
                    {
                        BankCode        = bankCode,
                        BankDisplayName = !string.IsNullOrEmpty(bankName) ? bankName : bankCode + bankStatus
                    };
                    resultMap.Add(cont);
                    resultMap = resultMap.OrderBy(x => x.BankDisplayName).ToList();
                }

                return(new AjaxResponse(resultMap));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }