String nonce is not being generated

0

I'm using the braintree API and I'm able to put dropin form of them on page:

         

var braintreeToken = @Html.Raw(Json.Encode(Model.brainTreeToken));

braintree.setup(
    braintreeToken,
    "dropin", {
        container: "payment-form"
    });

...

Here's the result:

Intheirdocumentationitsaysbraintree.jswilladdahiddeninputnamedpayment_method_noncetoyourform,thatis,ahiddenfieldisaddedwiththenoncevalue.

Inmycontroller,IgetthisfieldintheFormCollectionbutitalwayscomesasanemptystring.Itdoesnotcomenull,itcomesempty.

[HttpPost]publicvoidCreateTransaction(FormCollectioncollection){stringpayment_method_nonce=collection["payment_method_nonce"];

The above string is always empty. Supposedly, it would fetch a nonce string to be able to do the transaction. How do I resolve this?

EDIT

The form I write in the view is:

<form id="createTransactionForm" method="post">
    <div id="payment-form"></div>
    <input type="submit" value="Test - Pay">
</form>

The id id="payment-form" will be populated with the braintree dropin.

Using the browser inspector you can see the HTML final result, which results in one form within another. I've wondered if this is correct, if the form I write is necessary, and yes, it is anyway.

The result:

    
asked by anonymous 04.11.2015 / 18:11

1 answer

0

To work, payment_method_nonce needs to be created as a <input> field. It can be type=hidden . In your case, the field is not being created this way.

One suggestion would be to create the empty field and fill in using some JS command:

<form id="createTransactionForm" method="post">
    <div id="payment-form"></div>
    <input type="hidden" name="payment_method_nonce" value>
    <input type="submit" value="Test - Pay">
</form>
    
05.11.2015 / 15:21