【问题标题】:Braintree: Generate Client Token in ASP.NET MVC 4.5Braintree:在 ASP.NET MVC 4.5 中生成客户端令牌
【发布时间】:2016-04-26 22:39:05
【问题描述】:

我在集成 Braintree 以及理解事务如何发生的概念方面遇到了一些问题。

这是我目前对 Braintree 的理解:

Server 生成 ClientToken -> 集成到 html/js -> 用户接收支付表单并将数据发送到 Braintree -> Nonce 发送到 Server -> Server 发送 Transaction 到 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 示例没有显示令牌生成阶段时。

谢谢!

【问题讨论】:

  • 你检查过你的newEdit是否为空吗?
  • 我很愚蠢,我太专注了,以为我对这个概念的理解有问题,以至于我完全忘记了仔细检查内部类是否正在实例化。
  • 您可以将您的发现作为解决方案发布。在 Stack Overflow 上完全没问题。 :)

标签: c# asp.net asp.net-mvc braintree


【解决方案1】:

正如评论中所说,我太专注于 Braintree,以至于我犯了一个非常初学者的错误。这很好地提醒您,您只需退后一步并从新的角度看待错误即可找到答案。 :)

【讨论】:

    猜你喜欢
    • 2018-04-27
    • 1970-01-01
    • 2019-01-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-26
    • 2016-07-18
    • 1970-01-01
    相关资源
    最近更新 更多