Braintree: Generate Client Token in ASP.NET MVC 4.5
<p>I'm having some issues integrating Braintree, as well as understanding the concept of how the transaction takes place.</p>

<p>Here's how i currently understand Braintree:</p>

<p>Server Generates ClientToken -> Integrates into html/js -> User receives payment form and sends data to Braintree -> Nonce is sent to Server -> Server sends Transaction to Braintree</p>

<p>Is this correct?</p>

<p>I'm currently on step 1, trying to generate a client token, and i'm getting a NullReferenceException:</p>

<pre><code>public ActionResult Payment(EditContainerViewModel newEdit)
    {

        //generate client token
        newEdit.PaymentInfo.ClientToken = PaymentConstants.Gateway.ClientToken.generate();

        return View(newEdit);
    }
</code></pre>

<p>And heres the Gateway declaration:</p>

<pre><code> public static class PaymentConstants
{
    public static BraintreeGateway Gateway = new BraintreeGateway
    {
        Environment = Braintree.Environment.SANDBOX,
        MerchantId = "id",
        PublicKey = "publickey",
        PrivateKey = "privatekey"
    };
}
</code></pre>

<p>Heres my view:</p>

<pre><code>@model Sandbox.Models.EditContainerViewModel


&lt;h2&gt;Payment&lt;/h2&gt;

&lt;form id="checkout" method="post" action="/checkout"&gt;
    &lt;div id="payment-form"&gt;&lt;/div&gt;
    &lt;input type="submit" value="Pay $10"&gt;
&lt;/form&gt;

&lt;script src="https://js.braintreegateway.com/v2/braintree.js"&gt;&lt;/script&gt;
&lt;script&gt;
// 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"
});
&lt;/script&gt;
</code></pre>

<p>I'd really appreciate any insight on this topic, especially as i found that the provided ASP.NET examples didn't show the token generation stage. </p>

<p>Thank you!</p>