示例#1
0
        public ActionResult InitiatePayment([Bind(Include = "vpc_Amount, vpc_MerchTxnRef, vpc_OrderInfo, vpc_ReturnURL")] string vpc_Amount, string vpc_MerchTxnRef, string vpc_OrderInfo, string vpc_ReturnURL)
        {
            try
            {
                //region parameters
                var VPC_URL        = "https://migs.mastercard.com.au/vpcpay";
                var paymentRequest = new PaymentRequest
                {
                    Amount      = vpc_Amount,
                    MerchTxnRef = vpc_MerchTxnRef,
                    OrderInfo   = vpc_OrderInfo,
                    ReturnUrl   = vpc_ReturnURL
                };

                string hashSecret = ConfigurationManager.AppSettings["MigsSecureHashSecret"];
                //endregion


                //region redirect to payment gateway
                var transactionData = paymentRequest.GetParameters().OrderBy(t => t.Key, new VPCStringComparer()).ToList();
                // Add custom data, transactionData.Add(new KeyValuePair<string, string>("Title", title));
                var redirectUrl = VPC_URL + "?" + string.Join("&", transactionData.Select(item => HttpUtility.UrlEncode(item.Key) + "=" + HttpUtility.UrlEncode(item.Value)));
                if (!string.IsNullOrEmpty(hashSecret))
                {
                    redirectUrl += "&vpc_SecureHash=" + PaymentHelperMethods.CreateMD5Signature(hashSecret + string.Join("", transactionData.Select(item => item.Value)));
                }
                return(Redirect(redirectUrl));
                //endregion
            }
            catch (Exception ex)
            {
                var message = "Exception encountered. " + ex.Message;
                return(View("Error", ex));
            }
        }
示例#2
0
    public ActionResult PaymentConfirm()
    {
        try
        {
            // SECURE_SECRET can be found in Merchant Administration/Setup page
            string hashSecrest = "FE7555C9D2C35C2552934E8DB1D73D43";
            var    secureHash  = Request.QueryString["vpc_SecureHash"];
            if (!string.IsNullOrEmpty(secureHash))
            {
                if (!string.IsNullOrEmpty(hashSecrest))
                {
                    var rawHashData = hashSecrest + string.Join("", Request.QueryString.AllKeys.Where(k => k != "vpc_SecureHash").Select(k => Request.QueryString[k]));
                    var signature   = PaymentHelperMethods.CreateMD5Signature(rawHashData);
                    if (signature != secureHash)
                    {
                        return(View("Error", new ApplicationException("Invalid request.")));
                    }
                }
            }

            var vpcResponse = new PaymentResponse(Request);
            return(View(vpcResponse));
        }
        catch (Exception ex)
        {
            var message = "(51) Exception encountered. " + ex.Message;
            return(View("Error", ex));
        }
    }
示例#3
0
    public ActionResult InitiatePayment()
    {
        try
        {
            #region parameters
            var    VPC_URL        = "https://migs.mastercard.com.au/vpcpay";
            string returnURL      = "";
            string url            = System.Web.HttpContext.Current.Request.Url.Scheme + "://" + System.Web.HttpContext.Current.Request.Url.Authority + returnURL;
            var    paymentRequest = new PaymentRequest
            {
                Amount    = "100",
                ReturnUrl = "http://localhost/demo2/payment/paymentconfirm",
                OrderInfo = "Visa Assessment",
            };
            // SECURE_SECRET can be found in Merchant Administration/Setup page
            string hashSecrest = "FE7555C9D2C35C2552934E8DB1D73D43";
            #endregion
            #region redirect to payment gateway
            var transactionData = paymentRequest.GetParameters().OrderBy(t => t.Key, new VPCStringComparer()).ToList();
            // Add custom data, transactionData.Add(new KeyValuePair<string, string>("Title", title));
            var redirectUrl = VPC_URL + "?" + string.Join("&", transactionData.Select(item => HttpUtility.UrlEncode(item.Key) + "=" + HttpUtility.UrlEncode(item.Value)));
            if (!string.IsNullOrEmpty(hashSecrest))
            {
                redirectUrl += "&vpc_SecureHash=" + PaymentHelperMethods.CreateMD5Signature(hashSecrest + string.Join("", transactionData.Select(item => item.Value)));
            }
            return(Redirect(redirectUrl));

            #endregion
        }
        catch (Exception ex)
        {
            var message = "(51) Exception encountered. " + ex.Message;
            return(View("PaymentError", ex));
        }
    }
示例#4
0
        // GET: Payment
        public ActionResult Index()
        {
            var PaymentStatus = "none";

            try
            {
                string hashSecret      = ConfigurationManager.AppSettings["MigsSecureHashSecret"];
                var    secureHash      = Request.QueryString["vpc_SecureHash"];
                var    txnResponseCode = Request.QueryString["vpc_TxnResponseCode"];
                if (!string.IsNullOrEmpty(secureHash))
                {
                    if (!string.IsNullOrEmpty(hashSecret))
                    {
                        var rawHashData = hashSecret + string.Join("", Request.QueryString.AllKeys.Where(k => k != "vpc_SecureHash").Select(k => Request.QueryString[k]));
                        var signature   = PaymentHelperMethods.CreateMD5Signature(rawHashData);
                        if (signature != secureHash || txnResponseCode != "0")
                        {
                            PaymentStatus = "invalid";
                            //return View("Error", new ApplicationException("Invalid request."));
                        }
                        else
                        {
                            PaymentStatus = "approved";
                        }
                    }
                }

                ViewBag.PaymentStatus = PaymentStatus;

                var vpcResponse = new PaymentResponse(Request);
                return(View(vpcResponse));
            }
            catch (Exception ex)
            {
                var message = "Exception encountered. " + ex.Message;
                return(View("Error", ex));
            }
        }