我有以下html:
<form id="payment-form" method="post" submit="/checkout">
<input type="submit" value="Pay $10">
<input type="hidden" name="payment_method_nonce" value="0fgg1679-75e2-43e0-bc1f-94faee177877">
<iframe src="https://assets.braintreegateway.com/dropin/2.28.0/inline-frame.html#3a713953-3106-4fd5-8714-b0ada1723284" frameborder="0" allowtransparency="true" scrolling="no" name="braintree-dropin-frame" width="100%" height="68" id="braintree-dropin-frame" style="transition: height 210ms cubic-bezier(0.39, 0.575, 0.565, 1); border: 0px; z-index: 9999; height: 70px;"></iframe>
</form>
html最初只是input type=submit
和payment-form
,但我的javascript具有以下代码,可将元素转换为上面所示的内容:
braintree.setup(BT_CLIENT_TOKEN, "dropin", {
container: "payment-form"
});
BT_CLIENT_TOKEN在服务器端成功实例化到客户端。 当我打开网站时,我可以登录沙箱并看到以下内容:
但是,当我点击“付费”时,表单不会通过nodejs服务器端的app.post("/checkout")
提交,而是通过默认路由app.post("/")
提交。此外,请求的正文总是空的req.body: {}
(并且据我所知,不应该至少带来nounce)。
有没有人知道发生了什么?非常感谢你。
答案 0 :(得分:1)
完全披露:我在Braintree工作。如果您有任何其他问题,请随时联系support。
我有几点建议。首先,请务必在action
中定义<form>
属性。
<form id="payment-form" method="post" action="/checkout">
其次,要在 a <form>
内嵌套的Braintree Drop-in requires a container元素。这个容器元素应该在braintree.setup()
内定位。
<强> HTML 强>
<form id="payment-form" method="post" action="/checkout">
<div id="dropin-container"></div>
</form>
<强>的JavaScript 强>
braintree.setup('BT_CLIENT_TOKEN', 'dropin', {
container: 'dropin-container'
});
关于req.body: {}
,如果没有更全面地查看代码,就很难深入挖掘,而且我更愿意在没有上下文的情况下避免猜测。如果上述建议无法解决问题,也许您可以编辑问题并提供更多代码段,以帮助社区更密切地检查这一点。