我是Braintree的新手。我在沙盒环境中集成了DropIn UI。提交表单后,“ payment_method_nonce”返回空值,这使交易失败。 DropIn UI在特定的div中正确显示,并且为确保一切正常,我为PaymentMethodNonce添加了一个占位符,该占位符为“ fake-valid-nonce”,这使交易有效。我对为何Braintree服务器没有发回Nonce值感到困惑。
我对token.php进行Ajax调用以获取客户端令牌,该令牌使DropIn UI能够正确呈现。
下面的Ajax调用:
<script>
$.ajax({
url: "/braintree/token.php",
type: "get",
dataType: "json",
success: function (data) {
braintree.setup(data, 'dropin', {container: 'dropin-container'});
);
</script>
这是token.php,它生成客户端令牌:
require ("braintree.php"); $clientToken = $gateway->clientToken()->generate(); echo json_encode($clientToken);
当我检查HTML时,BrainTree显示一个“服务器错误消息” div,并显示“处理您的请求时出错。请重试。”有关此问题的其他帖子都提到,可以设置和提交HTML表单的方式可能导致此问题。
这是我的表格:
<div class="container">
<div class="row flex-nowrap">
<div class="alpha-container col-12">
<div class="content-container">
<form id="infoForm" method="post" action="/congrats.php">
<div class="tab">
<h2>Pick a Time</h2>
<div>
<!-- Google Schedule API goes here -->
</div>
<div>
<h4>Distance:</h4>
<p></p>
<br>
<h4>Duration:</h4>
<p></p>
<h4>Estimate:</h4>
<p></p>
</div>
</div>
<div class="tab">
<h2>Contact Information</h2>
<div class="contact-form">
<div class="contact-block">
<label for="fullname"></label>
<input type="text" name="Data[fullname]" class="contact" placeholder="Full Name">
</div>
<div class="contact-block">
<label for="email"></label>
<input type="email" name="Data[email]" class="contact" placeholder="Email Address">
</div>
<div class="contact-block">
<label for="phonenumber"></label>
<input type="number" name="Data[phonenumber]" class="contact" placeholder="Phone Number">
</div>
</div>
</div>
<div class="tab">
<h2>Payment Information</h2>
<div class="payment-form">
<label for="firstName"></label>
<input type="text" placeholder="First Name" name="Data[first_name]">
<label for="lastName"></label>
<input type="text" placeholder="Last Name" name="Data[last_name]">
<div id="dropin-container"></div>
</div>
</div>
<!-- Next/Previous Buttons -->
<div style="overflow:auto;">
<div style="float:right;">
<button type="button" id="prevBtn" onclick="nextPrev(-1)">Previous</button>
<button type="button" id="nextBtn" onclick="nextPrev(1)">Next</button>
</div>
</div>
<!--Progress Bar -->
<div style="text-align:center;margin-top:40px;">
<span class="step"></span>
<span class="step"></span>
<span class="step"></span>
</div>
</form>
</div>
</div>
</div>
</div>
该表单使用Javascript隐藏表单的步骤,然后添加一个Submit按钮,然后到达最后一步。 “ congrats.php”是我要处理交易的地方。我在标头中同时包含了jQuery和Braintree JS。
编辑:通过编辑HTML表单找到了我的解决方案。上面的表单使用javascript在表单的最后一步添加了一个提交按钮。我的新表单现在只有一个带有type = submit的按钮标签,并且正在创建“ payment_method_nonce”。无论出于何种原因,Braintree服务器在提交后都没有收到我的付款信息。