public static string GetPaymentUrlIfNeeded(Order order) { if (order == null || order.OrderId <= 0) { return(string.Empty); } if (order.PaymentMethod == ProductConfiguration.OnePAYNoiDiaPaymentMethodId || order.PaymentMethod == ProductConfiguration.OnePAYQuocTePaymentMethodId) // Onepay { //https://mtf.onepay.vn/developer/?page=modul_noidia //https://mtf.onepay.vn/developer/?page=modul_quocte // Thông số tài khoản cổng thanh toán: string urlPayment = string.Empty; string hashcode = string.Empty; string merchantId = string.Empty; string accesscode = string.Empty; string returnUrl = string.Empty; string queryDRUser = string.Empty; string queryDRPassword = string.Empty; if (GetOnePayParameter(order.PaymentMethod, out urlPayment, out hashcode, out merchantId, out accesscode, out returnUrl, out queryDRUser, out queryDRPassword)) { // Khoi tao lop thu vien va gan gia tri cac tham so gui sang cong thanh toan VPCRequest conn = new VPCRequest(urlPayment); conn.SetSecureSecret(hashcode); // Add the Digital Order Fields for the functionality you wish to use // Core Transaction Fields if (order.PaymentMethod == ProductConfiguration.OnePAYQuocTePaymentMethodId) { conn.AddDigitalOrderField("AgainLink", "http://onepay.vn"); } 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", "2"); conn.AddDigitalOrderField("vpc_Command", "pay"); conn.AddDigitalOrderField("vpc_Merchant", merchantId); conn.AddDigitalOrderField("vpc_AccessCode", accesscode); conn.AddDigitalOrderField("vpc_MerchTxnRef", Guid.NewGuid().ToString()); conn.AddDigitalOrderField("vpc_OrderInfo", order.OrderCode.ToString()); conn.AddDigitalOrderField("vpc_Amount", Convert.ToDouble(order.OrderTotal * 100).ToString()); //*100? if (order.PaymentMethod == ProductConfiguration.OnePAYNoiDiaPaymentMethodId) { conn.AddDigitalOrderField("vpc_Currency", "VND"); } conn.AddDigitalOrderField("vpc_ReturnURL", returnUrl); // Thong tin them ve khach hang. De trong neu khong co thong tin //conn.AddDigitalOrderField("vpc_SHIP_Street01", order.BillingAddress); //conn.AddDigitalOrderField("vpc_SHIP_Provice", billingProvinceName); //conn.AddDigitalOrderField("vpc_SHIP_City", billingDistrictName); //conn.AddDigitalOrderField("vpc_SHIP_Country", "Vietnam"); conn.AddDigitalOrderField("vpc_Customer_Phone", order.BillingPhone); conn.AddDigitalOrderField("vpc_Customer_Email", order.BillingEmail); if (order.UserGuid != Guid.Empty) { conn.AddDigitalOrderField("vpc_Customer_Id", order.UserGuid.ToString()); } // Dia chi IP cua khach hang conn.AddDigitalOrderField("vpc_TicketNo", order.CreatedFromIP); // Chuyen huong trinh duyet sang cong thanh toan return(conn.Create3PartyQueryString()); } } return(string.Empty); }
public static string ProcessCallbackData(string hashcode) { string hashvalidateResult = string.Empty; // Khoi tao lop thu vien VPCRequest conn = new VPCRequest("http://onepay.vn"); conn.SetSecureSecret(hashcode); // Xu ly tham so tra ve va kiem tra chuoi du lieu ma hoa hashvalidateResult = conn.Process3PartyResponse(System.Web.HttpContext.Current.Request.QueryString); // Lay gia tri tham so tra ve tu cong thanh toan string vpc_TxnResponseCode = conn.GetResultField("vpc_TxnResponseCode", "Unknown"); string txnResponseCode = vpc_TxnResponseCode; //string merchTxnRef = conn.GetResultField("vpc_MerchTxnRef", "0"); string orderInfo = conn.GetResultField("vpc_OrderInfo", ""); Order order = null; if (orderInfo.Length > 0) { order = Order.GetOrderByCode(orderInfo); } if (order == null || order.OrderId < 0 || order.IsDeleted) { order = null; } // Sua lai ham check chuoi ma hoa du lieu if (hashvalidateResult == "CORRECTED" && txnResponseCode.Trim() == "0") // "Transaction was paid successful" { if (order != null) { order.PaymentStatus = (int)OrderPaymentMethod.Successful; if (order.OrderNote.Length == 0) { order.OrderNote = "Transaction was paid successful"; } order.Save(); } return(SiteUtils.GetZoneUrl(ConfigHelper.GetIntProperty("OnePAY.ZoneID.TransactionSuccessful", 1))); } else if (hashvalidateResult == "INVALIDATED" && txnResponseCode.Trim() == "0") // "Transaction is pending" { if (order != null) { order.PaymentStatus = (int)OrderPaymentMethod.Pending; if (order.OrderNote.Length == 0) { order.OrderNote = "Transaction is pending"; } order.Save(); } return(SiteUtils.GetZoneUrl(ConfigHelper.GetIntProperty("OnePAY.ZoneID.TransactionPending", 1))); } else // "Transaction was not paid successful" { if (order != null) { order.PaymentStatus = (int)OrderPaymentMethod.NotSuccessful; if (order.OrderNote.Length == 0) { order.OrderNote = "Transaction was not paid successful"; } order.Save(); } return(SiteUtils.GetZoneUrl(ConfigHelper.GetIntProperty("OnePAY.ZoneID.TransactionNotSuccessful", 1))); } }