javascript - 2CheckOut - TwoCheckoutException:错误请求 - 参数错误
问题描述
所以基本上我正在尝试在我的网站中实现 2checkout 并且我已经完成了文档中的所有操作,但是我收到了这个错误:TwoCheckoutException: Bad request - parameter error
。我尝试使用私钥/公钥和 id 检查和玩游戏,但是当我更改它们时,它会显示“授权错误”,所以我确信它们没问题。我阅读了有关地址和所有内容的信息,我已经更改了它们,但仍然无法正常工作。
这是我的完整代码:
@{
ViewData["Title"] = "Test";
}
<script type="text/javascript" src="https://www.2checkout.com/checkout/api/2co.min.js"></script>
<h2>Test</h2>
<form id="myCCForm" action="/Home/SubmitCard" method="post">
<input name="token" type="hidden" value="" />
<div>
<label>
<span>Card Number</span>
<input id="ccNo" type="text" value="" autocomplete="off" required />
</label>
</div>
<div>
<label>
<span>Expiration Date (MM/YYYY)</span>
<input id="expMonth" type="text" size="2" required />
</label>
<span> / </span>
<input id="expYear" type="text" size="4" required />
</div>
<div>
<label>
<span>CVC</span>
<input id="cvv" type="text" value="" autocomplete="off" required />
</label>
</div>
<input type="submit" value="Submit Payment" />
</form>
<script type="text/javascript">
// Called when token created successfully.
var successCallback = function (data) {
var myForm = document.getElementById('myCCForm');
// Set the token as the value for the token input
myForm.token.value = data.response.token.token;
// IMPORTANT: Here we call `submit()` on the form element directly instead of using jQuery to prevent and infinite token request loop.
myForm.submit();
};
// Called when token creation fails.
var errorCallback = function (data) {
if (data.errorCode === 200) {
alert("Error 200");
// This error code indicates that the ajax call failed. We recommend that you retry the token request.
} else {
alert(data.errorMsg);
}
};
var tokenRequest = function () {
// Setup token request arguments
var args = {
sellerId: "901417674",
publishableKey: "309FC596-8380-4B6F-B269-3E157A5A5D0B",
ccNo: $("#ccNo").val(),
cvv: $("#cvv").val(),
expMonth: $("#expMonth").val(),
expYear: $("#expYear").val()
};
// Make the token request
TCO.requestToken(successCallback, errorCallback, args);
};
$(function () {
// Pull in the public encryption key for our environment
TCO.loadPubKey('sandbox');
$("#myCCForm").submit(function (e) {
// Call our token request function
tokenRequest();
// Prevent form from submitting
return false;
});
});
</script>
这是服务器端代码:
public IActionResult SubmitCard()
{
TwoCheckout.TwoCheckoutConfig.SellerID = "901417674";
TwoCheckout.TwoCheckoutConfig.PrivateKey = "4E704021-B233-435F-A904-47B2620B9E66";
TwoCheckout.TwoCheckoutConfig.Sandbox = true;
try
{
TwoCheckout.AuthBillingAddress Billing = new TwoCheckout.AuthBillingAddress();
Billing.addrLine1 = "123 Main Street";
Billing.city = "Townsville";
Billing.zipCode = "43206";
Billing.state = "Ohio ";
Billing.country = "USA";
Billing.name = "Joe Flagster";
Billing.email = "Ex@a.com";
Billing.phoneNumber = "065";
TwoCheckout.ChargeAuthorizeServiceOptions Customer = new TwoCheckout.ChargeAuthorizeServiceOptions();
Customer.total = 1;
Customer.currency = "USD";
Customer.merchantOrderId = "12";
Customer.billingAddr = Billing;
Customer.token = Request.Form["token"];
TwoCheckout.ChargeService Charge = new TwoCheckout.ChargeService();
var result = Charge.Authorize(Customer);
return View("Success", result);
}
catch(TwoCheckout.TwoCheckoutException ex)
{
return View("Error", ex.ToString());
}
}
这是我沙箱中的所有信息:
解决方案
您可能需要从“站点管理” -> “站点设置”更新沙盒的站点设置,然后打开“演示设置”并再次检查
愿它帮助你
推荐阅读
- node.js - 如何从另一个云功能更新一个云功能?
- typescript - 嵌套对象类型的 TypeScript keyof
- docker - GKE Autopilot Ingress 部署后 5-15 分钟返回 502 错误
- types - Python 3 中不同格式的返回类型
- python - 最好使用语法或正则表达式解析表格
- django - 视图 HomePage.views.signin 未返回 HttpResponse 对象。它返回 None 而不是
- regex - webpack-cli SyntaxError: 无效的正则表达式: /(\p{大写字母}+|\p{小写字母}|\d)(\p{大写字母}+)/:
- java - Spring Boot POST 请求验证
- python - 错误:Google Colab(>7GB)中的“找不到中央目录的开始;zipfile 损坏”
- java - 属性“mainMergedManifest”不存在