protected void Button1_Click(object sender, EventArgs e) { string SECURE_SECRET = "A3EFDFABA8653DF2342E8DAC29B51AF0"; // Khoi tao lop thu vien va gan gia tri cac tham so gui sang cong thanh toan VPCRequest conn = new VPCRequest(virtualPaymentClientURL.Text); conn.SetSecureSecret(SECURE_SECRET); // Add the Digital Order Fields for the functionality you wish to use // Core Transaction Fields conn.AddDigitalOrderField("Title", "onepay paygate"); conn.AddDigitalOrderField("vpc_Locale", "vn"); //Chon ngon ngu hien thi tren cong thanh toan (vn/en) conn.AddDigitalOrderField("vpc_Version", vpc_Version.Text); conn.AddDigitalOrderField("vpc_Command", vpc_Command.Text); conn.AddDigitalOrderField("vpc_Merchant", vpc_Merchant.Text); conn.AddDigitalOrderField("vpc_AccessCode", vpc_AccessCode.Text); conn.AddDigitalOrderField("vpc_MerchTxnRef", vpc_MerchTxnRef.Text); conn.AddDigitalOrderField("vpc_OrderInfo", vpc_OrderInfo.Text); conn.AddDigitalOrderField("vpc_Amount", vpc_Amount.Text); conn.AddDigitalOrderField("vpc_Currency", vpc_Currency.Text); conn.AddDigitalOrderField("vpc_ReturnURL", vpc_ReturnURL.Text); // Thong tin them ve khach hang. De trong neu khong co thong tin conn.AddDigitalOrderField("vpc_SHIP_Street01", "194 Tran Quang Khai"); conn.AddDigitalOrderField("vpc_SHIP_Provice", "Hanoi"); conn.AddDigitalOrderField("vpc_SHIP_City", "Hanoi"); conn.AddDigitalOrderField("vpc_SHIP_Country", "Vietnam"); conn.AddDigitalOrderField("vpc_Customer_Phone", "043966668"); conn.AddDigitalOrderField("vpc_Customer_Email", "*****@*****.**"); conn.AddDigitalOrderField("vpc_Customer_Id", "onepay_paygate"); // Dia chi IP cua khach hang conn.AddDigitalOrderField("vpc_TicketNo", vpc_TicketNo.Text); // Chuyen huong trinh duyet sang cong thanh toan String url = conn.Create3PartyQueryString(); Page.Response.Redirect(url); //Bo phan code cua modul cu //int rows = 13; //string seperator = "?"; //string[,] MyArray = //{ //{"AgainLink",virtualPaymentClientURL.Text}, //{"Title","ASP VPC 3-Party" } , //{"vpc_AccessCode",vpc_AccessCode.Text}, //{"vpc_Amount",vpc_Amount.Text}, //{"vpc_Command",vpc_Command.Text }, //{"vpc_Currency",vpc_Currency.Text} , //{"vpc_Locale",vpc_Locale.Text}, //{"vpc_MerchTxnRef",vpc_MerchTxnRef.Text}, //{"vpc_Merchant",vpc_Merchant.Text}, //{"vpc_OrderInfo",vpc_OrderInfo.Text}, //{"vpc_ReturnURL",vpc_ReturnURL.Text}, //{"vpc_TicketNo",vpc_TicketNo.Text}, //{"vpc_Version",vpc_Version.Text}, //}; //string redirectURL = virtualPaymentClientURL.Text; //for (int i = 0; i < rows; i++) //{ // //redirectURL = redirectURL + seperator + MyArray[i,0] + "=" + MyArray[i,1]; // redirectURL = redirectURL + seperator + Server.UrlEncode(MyArray[i, 0]) + "=" + Server.UrlEncode(MyArray[i, 1]); // //redirectURL = redirectURL + seperator + HttpUtility.UrlEncode(MyArray[i,0].ToString(),System.Text.Encoding.Default) + "=" + HttpUtility.UrlEncode(MyArray[i,1].ToString(),System.Text.Encoding.GetEncoding("ISO-8859-1")); // seperator = "&"; //} //string stringHashData = SECURE_SECRET; //for (int k = 0; k < rows; k++) //{ // string tmp = MyArray[k, 1].ToString(); // if (tmp.Length > 0) // { // stringHashData = stringHashData + tmp; // } //} //string doSecureHash = DoMD5(stringHashData); //redirectURL = redirectURL.Replace("_", "%5F"); //redirectURL = redirectURL + seperator + "vpc_SecureHash=" + doSecureHash; //Response.Redirect(redirectURL); }
protected void Page_Load(object sender, EventArgs e) { string SECURE_SECRET = "A3EFDFABA8653DF2342E8DAC29B51AF0"; string hashvalidateResult = ""; // Khoi tao lop thu vien VPCRequest conn = new VPCRequest("http://onepay.vn"); conn.SetSecureSecret(SECURE_SECRET); // Xu ly tham so tra ve va kiem tra chuoi du lieu ma hoa hashvalidateResult = conn.Process3PartyResponse(Page.Request.QueryString); // Lay gia tri tham so tra ve tu cong thanh toan String vpc_TxnResponseCode = conn.GetResultField("vpc_TxnResponseCode", "Unknown"); string amount = conn.GetResultField("vpc_Amount", "Unknown"); string localed = conn.GetResultField("vpc_Locale", "Unknown"); string command = conn.GetResultField("vpc_Command", "Unknown"); string version = conn.GetResultField("vpc_Version", "Unknown"); string cardBin = conn.GetResultField("vpc_Card", "Unknown"); string orderInfo = conn.GetResultField("vpc_OrderInfo", "Unknown"); string merchantID = conn.GetResultField("vpc_Merchant", "Unknown"); string authorizeID = conn.GetResultField("vpc_AuthorizeId", "Unknown"); string merchTxnRef = conn.GetResultField("vpc_MerchTxnRef", "Unknown"); string transactionNo = conn.GetResultField("vpc_TransactionNo", "Unknown"); string txnResponseCode = vpc_TxnResponseCode; string message = conn.GetResultField("vpc_Message", "Unknown"); //int loop1; // Bo cac ham ma hoa du lieu cu //NameValueCollection coll = Request.QueryString; //// Get names of all keys into a string array. //String[] arr1 = coll.AllKeys; //for (int j = 0; j < arr1.Length;j++ ) //{ // arr1[j] = Server.HtmlEncode(arr1[j]); //} //Array.Sort(arr1, arr1); //string sdataHash = ""; //for (loop1 = 0; loop1 < arr1.Length; loop1++) //{ // String[] arr2 = coll.GetValues(arr1[loop1]); // if ((arr2[0] != null) && (arr2[0].Length > 0) && (arr1[loop1]!="vpc_SecureHash")) // { // sdataHash += Server.HtmlEncode(arr2[0]); // } //} // sdataHash = SECURE_SECRET + sdataHash; // string doSecureHash = DoMD5(sdataHash).Trim(); // Sua lai ham check chuoi ma hoa du lieu if (hashvalidateResult == "CORRECTED" && txnResponseCode.Trim() == "0") { vpc_Result.Text = "Transaction was paid successful"; } else if (hashvalidateResult == "INVALIDATED" && txnResponseCode.Trim() == "0") { vpc_Result.Text = "Transaction is pending"; } else { vpc_Result.Text = "Transaction was not paid successful"; } vpc_Version.Text = version; vpc_Amount.Text = amount; this.vpc_Command.Text = command; vpc_MerchantID.Text = merchantID; vpc_MerchantRef.Text = merchTxnRef; vpc_OderInfor.Text = orderInfo; vpc_ResponseCode.Text = txnResponseCode; vpc_Command.Text = command; vpc_TransactionNo.Text = transactionNo; hashvalidate.Text = hashvalidateResult; vpc_Message.Text = message; }