我正在尝试在我的ASP.NET MVC项目中实现PAYTM付款集成方法。我在网站上应用了paytm付款集成,但得到的结果是
Result after payment code run error showing
我有一个控制器:
public class PaytmController : Controller
{
// GET: Paytm
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult CreatePayment(RequestData requestData)
{
String merchantKey = Key.merchantKey;
Dictionary<string, string> parameters = new Dictionary<string, string>();
parameters.Add("MID", Key.merchantId);
parameters.Add("CHANNEL_ID", "WEB");
parameters.Add("INDUSTRY_TYPE_ID", "Retail");
parameters.Add("WEBSITE", "WEBSTAGING");
parameters.Add("EMAIL", requestData.email);
parameters.Add("MOBILE_NO", requestData.mobileNumber);
parameters.Add("CUST_ID", "1");
parameters.Add("ORDER_ID", "ORDER8");
parameters.Add("TXN_AMOUNT", requestData.amount);
parameters.Add("CALLBACK_URL", "http://localhost:60308/Paytm/paytmResponse"); //This parameter is not mandatory. Use this to pass the callback url dynamically.
string checksum = paytm.CheckSum.generateCheckSum(merchantKey, parameters);
string paytmURL = "https://securegw-stage.paytm.in/theia/processTransaction?orderid=" + parameters.FirstOrDefault(x => x.Key == "ORDER_ID").Value;
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>";
ViewBag.htmlData = outputHTML;
return View("PaymentPage");
}
[HttpPost]
public ActionResult paytmResponse(PaytmResponse response)
{
return View("paytmResponse" , response);
}
}
索引视图如下:
@model MyHoroscope.ViewModels.RequestData
@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<div align="center">
@using (Html.BeginForm("CreatePayment", "Paytm", FormMethod.Post))
{
<table>
<tr>
<td>
Mobile Number :
</td>
<td>
<input type="text" name="mobileNumber" value="" />
</td>
</tr>
<tr>
<td>
Email :
</td>
<td>
<input type="text" name="email" value="" />
</td>
</tr>
<tr>
<td>
Amount :
</td>
<td>
<input type="text" name="amount" value="" />
</td>
</tr>
</table>
<pre>
<input type="submit" value="Save" />
</pre>
}
</div>
和PaymentPage
视图如下:
@{
Layout = null;
}
@Html.Raw(ViewBag.htmlData)
我还创建了一个paymentResponse
视图:
@model MyHoroscope.ViewModels.PaytmResponse
@{
ViewBag.Title = "paytmResponse";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>paytmResponse</h2>
<div align="center">
<table border="1" width="50%">
<tr>
<td>@Html.DisplayNameFor(m => m.MID)</td>
<td>@Html.DisplayFor(m => m.MID)</td>
</tr>
<tr>
<td>@Html.DisplayNameFor(m => m.ORDER_ID)</td>
<td>@Html.DisplayFor(m => m.ORDER_ID)</td>
</tr>
<tr>
<td>@Html.DisplayNameFor(m => m.TXN_AMOUNT)</td>
<td>@Html.DisplayFor(m => m.TXN_AMOUNT)</td>
</tr>
<tr>
<td>@Html.DisplayNameFor(m => m.CURRENCY)</td>
<td>@Html.DisplayFor(m => m.CURRENCY)</td>
</tr>
<tr>
<td>@Html.DisplayNameFor(m => m.TXNID)</td>
<td>@Html.DisplayFor(m => m.TXNID)</td>
</tr>
<tr>
<td>@Html.DisplayNameFor(m => m.BANKTXNID)</td>
<td>@Html.DisplayFor(m => m.BANKTXNID)</td>
</tr>
<tr>
<td>@Html.DisplayNameFor(m => m.STATUS)</td>
<td>@Html.DisplayFor(m => m.STATUS)</td>
</tr>
<tr>
<td>@Html.DisplayNameFor(m => m.RESPCODE)</td>
<td>@Html.DisplayFor(m => m.RESPCODE)</td>
</tr>
<tr>
<td>@Html.DisplayNameFor(m => m.RESPMSG)</td>
<td>@Html.DisplayFor(m => m.RESPMSG)</td>
</tr>
<tr>
<td>@Html.DisplayNameFor(m => m.TXNDATE)</td>
<td>@Html.DisplayFor(m => m.TXNDATE)</td>
</tr>
<tr>
<td>@Html.DisplayNameFor(m => m.GATEWAYNAME)</td>
<td>@Html.DisplayFor(m => m.GATEWAYNAME)</td>
</tr>
<tr>
<td>@Html.DisplayNameFor(m => m.BANKNAME)</td>
<td>@Html.DisplayFor(m => m.BANKNAME)</td>
</tr>
<tr>
<td>@Html.DisplayNameFor(m => m.PAYMENTMODE)</td>
<td>@Html.DisplayFor(m => m.PAYMENTMODE)</td>
</tr>
<tr>
<td>@Html.DisplayNameFor(m => m.CHECKSUMHASH)</td>
<td>@Html.DisplayFor(m => m.CHECKSUMHASH)</td>
</tr>
</table>
</div>
为什么我的代码不起作用?