【发布时间】:2020-10-23 19:16:08
【问题描述】:
我是在我们的 Angular 和 asp.net 核心网站上集成 razorpay 支付网关的初学者。将数据发布到网关 url 时出现 500 错误。请检查我的代码并倾诉您的答案。我正在搜索它近2天。
public async Task<IActionResult> CreateOrder([FromBody] TicketSales Sales)
{
System.Net.ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
string razorkey = "key";
string secret = "secret";
RazorpayClient client = new RazorpayClient(razorkey, secret);
Dictionary<string, object> options = new Dictionary<string, object>();
options.Add("amount", Sales.subTotal.Replace(".", "")); // amount in the smallest currency unit
options.Add("receipt", "Receipt_567");
options.Add("currency", "INR");
options.Add("payment_capture", "0");
Order order = client.Order.Create(options);
using (var httpClient = new HttpClient())
{
httpClient.BaseAddress = new Uri("https://api.razorpay.com/v1/checkout/embedded");
var content = new FormUrlEncodedContent(new[]
{
new KeyValuePair<string, string>("key",razorkey),
new KeyValuePair<string, string>("Amount", Sales.subTotal),
new KeyValuePair<string, string>("currency", "INR"),
new KeyValuePair<string, string>("name",Sales.bName),
new KeyValuePair<string, string>("description","Test Transaction"),
new KeyValuePair<string, string>("imag", ""),
new KeyValuePair<string, string>("order_id",Convert.ToString(order["id"])),
new KeyValuePair<string, string>("callback_url","localhost:4200//signin"),
});
var result = await httpClient.PostAsync("https://api.razorpay.com/v1/checkout/embedded", content);
if (result.IsSuccessStatusCode)
{
}
}
return Json(new { orderId = order["id"].ToString(),result });
}
【问题讨论】:
标签: asp.net-core-webapi payment-gateway razorpay