Example #1
0
        // Xử lý kết quả từ server VTC POST về trang đón tại server Merchant
        private void ExcuteResultNotifyFromVTCPay()
        {
            // Tiến hành thực hiện update trạng thái cho giao dịch và post tới server merchant.
            string data = Request.Form.Get("data") ?? "";
            string sign = Request.Form.Get("signature") ?? "";

            merchantSign = Security.SHA256encrypt(data + "|" + Security_Key);
            isVerify     = (merchantSign == sign);

            if (isVerify)
            {
                // Chữ ký OK, phân tích kết quả của VTC trả về để xử lý tiếp tại hệ thống của Merchant
                // data = amount|message|payment_type|reference_number| status|trans_ref_no|website_id
                if (string.IsNullOrEmpty(data) || data.Split('|').Length != 7)
                {
                    NLogLogger.LogInfo("Du lieu khong hop le. Can check lai:" + data);
                }
                else
                {
                    string[] arrParamReturn   = data.Split('|');
                    string   amount           = arrParamReturn[0];
                    string   message          = arrParamReturn[1];
                    string   payment_type     = arrParamReturn[2]; // Hinh thuc thanh toan cua khach hang tai cong VTC Pay (VCB, Visa, Master, vi VTC Pay ...)
                    string   reference_number = arrParamReturn[3]; // Ma cua Merchant luc gui don hang
                    string   status           = arrParamReturn[4]; // Trang thai don hang
                    string   trans_ref_no     = arrParamReturn[5]; // Ma tham chieu trên hệ thống VTC
                    string   website_id       = arrParamReturn[6]; //
                }
            }
            else
            {
                // Sai chữ ký --> Chưa xác định được tính đúng đắn của dữ liệu trả về từ VTC. Cần phối hợp với VTC để check nguyên nhân sai chữ ký
            }

            NLogLogger.LogInfo("Ket qua POST. data: " + data
                               + Environment.NewLine + "signature: " + sign
                               + Environment.NewLine + "Vefify: " + isVerify);
        }
Example #2
0
        // Xu ly ket qua VTC tra ve Merchant tren url
        private void ExcuteResultRedirectUrl()
        {
            NLogLogger.LogInfo("Ket qua GET:" + HttpContext.Current.Request.Url.AbsoluteUri);

            if (Request.QueryString["reference_number"] == null || Request.QueryString["amount"] == null || Request.QueryString["website_id"] == null)
            {
                return;
            }

            // Lay cac tham so tra ve tren url
            double amount           = Convert.ToDouble(Request.QueryString["amount"]);
            string message          = Request.QueryString["message"];
            string payment_type     = Request.QueryString["payment_type"];
            string reference_number = Request.QueryString["reference_number"];
            int    status           = Convert.ToInt32(Request.QueryString["status"]);
            string trans_ref_no     = Request.QueryString["trans_ref_no"];
            int    website_id       = Convert.ToInt32(Request.QueryString["website_id"]);
            string signature        = Server.HtmlDecode(Request.QueryString["signature"].ToString().Replace(" ", "+"));

            object[] arrParamReturn = new object[] { amount, message, payment_type, reference_number, status, trans_ref_no, website_id };
            string   textSign       = string.Join("|", arrParamReturn) + "|" + Security_Key;

            merchantSign = Security.SHA256encrypt(textSign);
            isVerify     = (merchantSign == signature);

            if (isVerify)
            {
                lblVerify.Text = "Chu ky hop le";
                lblReport.Text = GetStatusMessage(status);
            }
            else
            {
                NLogLogger.LogInfo("HTTP GET.Sai chu ky. Text:" + textSign
                                   + Environment.NewLine + "Sign:" + merchantSign);
                lblVerify.Text = "Chu ky sai";
            }
        }
Example #3
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            try
            {
                string Security_Key = ConfigurationManager.AppSettings["SecretKey"];

                string website_id       = txtWebsiteID.Text.Trim();
                string amount           = txtTotalAmount.Text.Trim();
                string currency         = ddlCurrency.SelectedValue;
                string receiver_account = txtReceiveAccount.Text.Trim();
                string reference_number = txtOrderID.Text.Trim();

                string transaction_type     = txtTransactionType.Text;
                string language             = ddlLanguage.SelectedValue;
                string url_return           = txtUrlReturn.Text;
                string payment_type         = txtPaymentType.Text;
                string bill_to_email        = txtEmail.Text;
                string bill_to_phone        = txtPhone.Text;
                string bill_to_address      = txtAddressLine1.Text;
                string bill_to_address_city = txtCity.Text;
                string bill_to_surname      = txtSurName.Text;
                string bill_to_forename     = txtForeName.Text;


                Dictionary <string, object> paramQueryList = new Dictionary <string, object>()
                {
                    { "website_id", website_id },
                    { "amount", amount },
                    { "currency", currency },
                    { "receiver_account", receiver_account },
                    { "reference_number", reference_number },
                    { "transaction_type", transaction_type },
                    { "language", language },
                    { "url_return", url_return },
                    { "payment_type", payment_type },
                    { "bill_to_email", bill_to_email },
                    { "bill_to_phone", bill_to_phone },
                    { "bill_to_address", bill_to_address },
                    { "bill_to_address_city", bill_to_address_city },
                    { "bill_to_surname", bill_to_surname },
                    { "bill_to_forename", bill_to_forename }
                };

                string plaintext = string.Empty;
                string listparam = string.Empty;

                String[] sortedKeys = paramQueryList.Keys.ToArray();
                Array.Sort(sortedKeys);

                foreach (String key in sortedKeys)
                {
                    plaintext += string.Format("{0}{1}", plaintext.Length > 0 ? "|" : string.Empty, paramQueryList[key]);
                    if (new string[] { "url_return", "bill_to_surname", "bill_to_forename", "bill_to_address", "bill_to_address_city" }.Contains(key))
                    {
                        listparam += string.Format("{0}={1}&", key, Server.UrlEncode(paramQueryList[key].ToString()));
                    }
                    else
                    {
                        listparam += string.Format("{0}={1}&", key, paramQueryList[key].ToString());
                    }
                }

                string textSign  = string.Format("{0}|{1}", plaintext, Security_Key);
                string signature = Security.SHA256encrypt(textSign);

                NLogLogger.LogInfo("Textsign:" + textSign
                                   + Environment.NewLine + "signature:" + signature);

                listparam = string.Format("{0}signature={1}", listparam, signature);
                string urlRedirect = string.Format("{0}?{1}", ddlEnvinroment.SelectedValue, listparam);

                NLogLogger.LogInfo("urlFull: " + urlRedirect);

                Response.Redirect(urlRedirect, false);
            }
            catch (Exception ex)
            {
                Label1.Text = ex.ToString();
                NLogLogger.Info(ex.ToString());
            }
        }