我在整合Braintree方面遇到了一些问题,并了解交易发生的概念。
以下是我目前对Braintree的理解:
服务器生成ClientToken - >集成到html / js - >用户收到付款表格并将数据发送给Braintree - > Nonce被发送到服务器 - >服务器将事务发送到Braintree
这是对的吗?
我目前正在第1步,尝试生成客户端令牌,并且我收到NullReferenceException:
public ActionResult Payment(EditContainerViewModel newEdit)
{
//generate client token
newEdit.PaymentInfo.ClientToken = PaymentConstants.Gateway.ClientToken.generate();
return View(newEdit);
}
继承人宣言:
public static class PaymentConstants
{
public static BraintreeGateway Gateway = new BraintreeGateway
{
Environment = Braintree.Environment.SANDBOX,
MerchantId = "id",
PublicKey = "publickey",
PrivateKey = "privatekey"
};
}
继承我的观点:
@model Sandbox.Models.EditContainerViewModel
<h2>Payment</h2>
<form id="checkout" method="post" action="/checkout">
<div id="payment-form"></div>
<input type="submit" value="Pay $10">
</form>
<script src="https://js.braintreegateway.com/v2/braintree.js"></script>
<script>
// We generated a client token for you so you can test out this code
// immediately. In a production-ready integration, you will need to
// generate a client token on your server (see section below).
var clientToken = "@Html.Raw(Model.PaymentInfo.ClientToken)";
braintree.setup(clientToken, "dropin", {
container: "payment-form"
});
</script>
我非常感谢有关此主题的任何见解,特别是当我发现提供的ASP.NET示例未显示令牌生成阶段时。
谢谢!
答案 0 :(得分:0)
正如评论中所说的那样,我过于专注于Braintree,因此我犯了一个非常初学者的错误。这可以提醒您,只需退后一步,从新的角度查看错误,就可以找到答案。 :)