布伦特里DROPIN形式的问题 - 随机数字符串没有产生 [英] Braintree dropin form issue - nonce string not being generated
问题描述
我试图使用 DROPIN形式从布伦特里,但它会产生一个怪异的行为。
I'm trying to use the dropin form from braintree but it produces a weird behaviour.
我可以成功地放置形式,一种观点:
I can successfully place the form in a view:
<form id="createTransactionForm" method="post" action="#">
<div id="payment-form"></div>
<input type="submit" value="Test - Pay">
</form>
<script>
var braintreeToken = @Html.Raw(Json.Encode(Model.brainTreeToken));
braintree.setup(
braintreeToken,
"dropin", {
container: "payment-form"
});
...
下面是结果:
他们指出在他们的<一个href=\"https://developers.braintreepayments.com/start/hello-client/javascript/v2#send-payment-method-nonce-to-server\"相对=nofollow>文档(3段)的 braintree.js将一个隐藏的名为payment_method_nonce输入添加到您的表单
。
They state in their documentation (3rd paragraph) that braintree.js will add a hidden input named payment_method_nonce to your form
.
在我的控制器,我得到了操作方法捉形式收集和有形式收集在 payment_method_nonce
键与一个空字符串作为一个值,但没有其他的按键,没有其他表单字段都在这里捕获。我期待卡号和失效日期,如在上面的图像看到。
On my controller, I got the action method to catch the form collection and there's a payment_method_nonce
key in the form collection with an empty string as a value but no other keys, no other form fields are caught here. I was expecting the card number and the expiration date, as seen in the picture above.
使用检查,我看到布伦特里DROPIN cretes的HTML结构嵌套形式:
Using the inspector, I see that the braintree dropin cretes an HTML structure with nested forms:
我的问题是,我怎么能使用布伦特里DROPIN的形式和捕捉动作方法所有的表单输入值?
My question is, how can I use the braintree dropin form and catch all their form input values in the action method?
好了,感谢@MikeMiller,我才知道,我不需要赶CC值在控制器的方法,只是据说是从他们所产生的随机数字符串。不过,我得到一个空字符串。
OK, so thanks to @MikeMiller, I learned that I don't need to catch the CC values in the controller method, just the nonce string that's supposedly generated from them. However, I am getting an empty string.
从他的建议,我试图添加到窗体中的特定值的action属性:
From his suggestion, I tried to add to the form a specific value for the action attribute:
<form id="createTransactionForm" method="post" action="@Url.Action("MyMethod", "MyController")">
但结果是相同的,对随机数一个空字符串。
But the result is the same, an empty string for the nonce.
推荐答案
我得到了我用下面的code(Laravel5刀片)的工作。我的问题是提交表单使用jQuery - 没有一个按钮元素在表单中的随机数值犯规获得人口
I got mine working with the following code (Laravel5 blade). My issue was submitting the form with jQuery - without a button element in the form the nonce value doesnt get populated.
<form id="checkout" method="post" action="{{URL('admin/checkout')}}">
<div id="payment-form"></div>
<br>
<div class="input-group">
<div class="input-group-btn" >
<div class="btn-group">
<button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown" style="width:50px">
<span data-bind="label" id="currency">£</span> <span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu" style="min-width:50px">
<li style="width:50px"><a href="GBP">£</a></li>
<li style="width:50px"><a href="USD">$</a></li>
<li style="width:50px"><a href="EUR">€</a></li>
</ul>
</div>
</div>
<input type="text" name="amount" id="amount" class="form-control" />
<div class="input-group-btn">
<button role="submit" class="btn btn-primary btn-block" id="submit">Make Payment</button>
</div>
</div>
</form>
<script src="https://js.braintreegateway.com/v2/braintree.js"></script>
<script>
braintree.setup("@braintreeClientToken", "dropin", {
container: "payment-form",
form: 'checkout'
});
</script>
这篇关于布伦特里DROPIN形式的问题 - 随机数字符串没有产生的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!