Mvc4 paytm 集成 - 关闭弹出窗口 windows 并重定向到主视图
Mvc4 paytm integration - close popup windows and redirect to main view
我正在将 paytm 整合到我的网站。我有观点,即 Index
。目前它只是一个视图,其中包含一个打开弹出窗口的按钮 window。
这是我的看法。
@{
ViewBag.Title = "paytm";
}
<style>
.btn2 {
background-color: #00b9f5;
padding-bottom: 10px;
padding-top: 10px;
}
</style>
<h2>paytm</h2>
<button class="btn2" style="font-weight: 600;" onclick="popitup('http://localhost:49569/home/paytmcheckout');">Pay With Paytm</button>
<script>
function popitup(url) {
window.open(url, "_blank", "width=700,height=700,scrollbars=yes");
}
</script>
这是paytmcheckout
动作
public ActionResult paytmcheckout()
{
Dictionary<string, string> parameters = new Dictionary<string, string>();
parameters.Add("MID", "Some value");
parameters.Add("CHANNEL_ID", "some value");
parameters.Add("INDUSTRY_TYPE_ID", "some value");
parameters.Add("WEBSITE", "some value");
//parameters.Add("EMAIL", "email value");
//parameters.Add("MOBILE_NO", "mobile value");
parameters.Add("CUST_ID", "some value");
parameters.Add("ORDER_ID", "some value");
parameters.Add("TXN_AMOUNT", "some value");
parameters.Add("CALLBACK_URL", "http://localhost:49569/home/thankyou/");
//This parameter is not mandatory. Use this to pass the callback url dynamically.
string checksum = paytm.CheckSum.generateCheckSum(merchantKey, parameters);
string paytmURL = "https://pguat.paytm.com/oltp-web/processTransaction";
string outputHTML = "<html>";
outputHTML += "<head>";
outputHTML += "<title>Merchant Check Out Page</title>";
outputHTML += "</head>";
outputHTML += "<body>";
outputHTML += "<center><h1>Please do not refresh this page...</h1></center>";
outputHTML += "<form method='post' action='" + paytmURL + "' name='f1'>";
outputHTML += "<table border='1'>";
outputHTML += "<tbody>";
foreach (string key in parameters.Keys)
{
outputHTML += "<input type='hidden' name='" + key + "' value='" + parameters[key] + "'>";
}
outputHTML += "<input type='hidden' name='CHECKSUMHASH' value='" + checksum + "'>";
outputHTML += "</tbody>";
outputHTML += "</table>";
outputHTML += "<script type='text/javascript'>";
outputHTML += "document.f1.submit();";
outputHTML += "</script>";
outputHTML += "</form>";
outputHTML += "</body>";
outputHTML += "</html>";
Response.Write(outputHTML);
return new EmptyResult();
}
它简单 post 一些数据到 paytm。你可以在这里找到代码 https://github.com/Paytm-Payments/Paytm_Web_Sample_Kit_dotNet
当请求发送到 paytm 时,它会处理它并在回调 url 上发送一些响应。在我的例子中,我创建了一个动作,即 thankyou
。但我想关闭弹出窗口 windows(从 Index
视图调用)并在 Index
视图中显示响应而不是显示 thankyou
视图。当前弹出窗口 windows 未关闭并在其中显示 thankyou
视图。如何关闭弹出窗口 window 并在 Index
视图中显示结果?我不知道如何实现它。
我想实现这样的东西 - http://paywithpaytm.com/demo/
主要window
<script language="Javascript">
function popitup(url) {
newwindow=window.open(url, "_blank", "width=700,height=700,scrollbars=yes");
if (window.focus) {newwindow.focus()}
}
</script>
在子弹出窗口中
<script language="Javascript">
function redirectToFB(){
window.opener.location.href="http://bla.bla.bla";
self.close();
}
</script>
而不是使用
return new EmptyResult();
使用
return View();
在那个视图文件中你可以这样编码
<script language="Javascript">
(function(){
window.opener.location.href="http://bla.bla.bla";
self.close();
})();
</script>
有关详细信息,请参阅 here
我正在将 paytm 整合到我的网站。我有观点,即 Index
。目前它只是一个视图,其中包含一个打开弹出窗口的按钮 window。
这是我的看法。
@{
ViewBag.Title = "paytm";
}
<style>
.btn2 {
background-color: #00b9f5;
padding-bottom: 10px;
padding-top: 10px;
}
</style>
<h2>paytm</h2>
<button class="btn2" style="font-weight: 600;" onclick="popitup('http://localhost:49569/home/paytmcheckout');">Pay With Paytm</button>
<script>
function popitup(url) {
window.open(url, "_blank", "width=700,height=700,scrollbars=yes");
}
</script>
这是paytmcheckout
动作
public ActionResult paytmcheckout()
{
Dictionary<string, string> parameters = new Dictionary<string, string>();
parameters.Add("MID", "Some value");
parameters.Add("CHANNEL_ID", "some value");
parameters.Add("INDUSTRY_TYPE_ID", "some value");
parameters.Add("WEBSITE", "some value");
//parameters.Add("EMAIL", "email value");
//parameters.Add("MOBILE_NO", "mobile value");
parameters.Add("CUST_ID", "some value");
parameters.Add("ORDER_ID", "some value");
parameters.Add("TXN_AMOUNT", "some value");
parameters.Add("CALLBACK_URL", "http://localhost:49569/home/thankyou/");
//This parameter is not mandatory. Use this to pass the callback url dynamically.
string checksum = paytm.CheckSum.generateCheckSum(merchantKey, parameters);
string paytmURL = "https://pguat.paytm.com/oltp-web/processTransaction";
string outputHTML = "<html>";
outputHTML += "<head>";
outputHTML += "<title>Merchant Check Out Page</title>";
outputHTML += "</head>";
outputHTML += "<body>";
outputHTML += "<center><h1>Please do not refresh this page...</h1></center>";
outputHTML += "<form method='post' action='" + paytmURL + "' name='f1'>";
outputHTML += "<table border='1'>";
outputHTML += "<tbody>";
foreach (string key in parameters.Keys)
{
outputHTML += "<input type='hidden' name='" + key + "' value='" + parameters[key] + "'>";
}
outputHTML += "<input type='hidden' name='CHECKSUMHASH' value='" + checksum + "'>";
outputHTML += "</tbody>";
outputHTML += "</table>";
outputHTML += "<script type='text/javascript'>";
outputHTML += "document.f1.submit();";
outputHTML += "</script>";
outputHTML += "</form>";
outputHTML += "</body>";
outputHTML += "</html>";
Response.Write(outputHTML);
return new EmptyResult();
}
它简单 post 一些数据到 paytm。你可以在这里找到代码 https://github.com/Paytm-Payments/Paytm_Web_Sample_Kit_dotNet
当请求发送到 paytm 时,它会处理它并在回调 url 上发送一些响应。在我的例子中,我创建了一个动作,即 thankyou
。但我想关闭弹出窗口 windows(从 Index
视图调用)并在 Index
视图中显示响应而不是显示 thankyou
视图。当前弹出窗口 windows 未关闭并在其中显示 thankyou
视图。如何关闭弹出窗口 window 并在 Index
视图中显示结果?我不知道如何实现它。
我想实现这样的东西 - http://paywithpaytm.com/demo/
主要window
<script language="Javascript">
function popitup(url) {
newwindow=window.open(url, "_blank", "width=700,height=700,scrollbars=yes");
if (window.focus) {newwindow.focus()}
}
</script>
在子弹出窗口中
<script language="Javascript">
function redirectToFB(){
window.opener.location.href="http://bla.bla.bla";
self.close();
}
</script>
而不是使用
return new EmptyResult();
使用
return View();
在那个视图文件中你可以这样编码
<script language="Javascript">
(function(){
window.opener.location.href="http://bla.bla.bla";
self.close();
})();
</script>
有关详细信息,请参阅 here