asp.net-mvc - mvc中的coinpayment api
问题描述
我是初学者编程。我想通过https://www.coinpayments.net/在我的网站上获得一些硬币我 在该网站上找到了一个类库来调用 API 进行交易和一个表单标签来发布值现在我很困惑我应该使用哪个?
<form action="https://www.coinpayments.net/index.php" method="post">
<input type="hidden" name="cmd" value="_pay">
<input type="hidden" name="reset" value="1">
<input type="hidden" name="merchant" value="606a89bb575311badf510a4a8b79a45e">
<input type="hidden" name="currency" value="LTC">
<input type="hidden" name="amountf" value="10.00">
<input type="hidden" name="item_name" value="Test Item">
<input type="image" src="https://www.coinpayments.net/images/pub/buynow-grey.png" alt="Buy Now with CoinPayments.net">
有没有人体验过在 mvc 中推出投币支付?
解决方案
您可以在控制器中使用此代码
使用以下代码创建一个返回字符串的方法:
NameValueCollection data = new NameValueCollection();
data.Add("cmd", "_pay"); // the api method. you can found more method in www.coinpayments.net/apidoc
data.Add("merchant", "your merchant id "); // you can get it in your cp account
data.Add("currency", "USD");
data.Add("item_name", "the item name to buy");
data.Add("want_shipping", "0");
data.Add("quantity", "1");
data.Add("amount", amount);
data.Add("amountf", amount);
data.Add("item_number", "1");
data.Add("invoice", invoce nick);
data.Add("allow_extra", "0");
data.Add("reset", "1");
data.Add("email", "email@example"); // very importat to buyer in refund case
data.Add("custom", "email@example");
data.Add("first_name", "first name");
data.Add("last_name", "last name");
data.Add("ipn_url", "Your ipn url"); // you can get it in your cp account
data.Add("success_url", "https://myfxagents.com/bo/BackOffice/MakeDeposit.aspx?s=yes");
data.Add("cancel_url", "https://myfxagents.com/bo/BackOffice/MakeDeposit.aspx?s=no");
//Prepare the Posting form, Note this return a string
return PreparePOSTForm("https://www.coinpayments.net/index.php", data);
使用以下代码创建其他名称为PreparePOSTForm的方法:
private static String PreparePOSTForm(string url, NameValueCollection data)
{
//Set a name for the form
string formID = "PostForm";
//Build the form using the specified data to be posted.
StringBuilder strForm = new StringBuilder();
strForm.Append("<form id=\"" + formID + "\" name=\"" +
formID + "\" action=\"" + url +
"\" method=\"POST\">");
foreach (string key in data)
{
strForm.Append("<input type=\"hidden\" name=\"" + key +
"\" value=\"" + data[key] + "\">");
}
strForm.Append("</form>");
//Build the JavaScript which will do the Posting operation.
StringBuilder strScript = new StringBuilder();
strScript.Append("<script language='javascript'>");
strScript.Append("var v" + formID + " = document." +
formID + ";");
strScript.Append("v" + formID + ".submit();");
strScript.Append("</script>");
//Return the form and the script concatenated.
//(The order is important, Form then JavaScript)
return strForm.ToString() + strScript.ToString();
}
接下来以该方法运行您的应用程序。
我希望我有所帮助。
推荐阅读
- javascript - React-有条件地渲染较大的组件还是较小的子组件更好
- linux-kernel - 内核抢占和禁用中断的内嵌汇编代码是什么?
- android - 在 Docker 中为 Android 运行并行 Gitlab CI 作业
- python - 如何解决未满足的依赖项错误?
- python - 在 Python IDLE 中工作但不在 VSCode 中的代码?
- c++ - 错误:使用类模板“地图”需要模板参数 (C++)
- microsoft-graph-api - 向多租户应用添加权限后更新范围
- java - How do I separate what value is stored in a single byte (of a long)?
- python - Pandas:将日期时间 (%Y-%d-%m %H:%M) 转换为 (%Y-%m-%d %H:%M)
- java - 使用 camunda 建模器进行 base64 编码/解码时出错