我正在尝试使Braintree的沙盒支付网关Drop-In正常运行。 (https://developers.braintreepayments.com/guides/drop-in/overview/javascript/v3)我使用以下内容作为他们发布的唯一Ruby
指南,这是一个Rails
应用程序,而不是纯粹的Ruby
(我正在使用{{1 }}):https://github.com/braintree/braintree_rails_example
至此,我已经取得了进展:用卡付款表格同时显示了卡号和有效期。没什么这样就意味着生成了Sinatra
,并生成了这种形式。我填写卡和有效期字段,然后单击请求付款方式按钮提交表格。它知道它是一张VISA卡,然后消失,显示错误,然后到空白的client_token
。
首先,我的/checkout
:
JavaScript
我的var form = document.querySelector('#payment-form');
var client_token = "<%= @client_token %>";
var button = document.querySelector('#submit-button');
braintree.dropin.create({
authorization: '<%= @client_token %>',
container: '#dropin-container'
}, function (createErr, instance) {
button.addEventListener('click', function () {
instance.requestPaymentMethod(function (requestPaymentMethodErr, payload) {
// Submit payload.nonce to your server
console.log("line 59 JS dropin.create")
console.log("payload.nonce: " + payload.nonce); // this works
document.querySelector('#nonce').value = payload.nonce;
form.submit();
$.post( '/checkout', {'paymentMethodNonce': payload.nonce} ).done(function(result) {
console.log("done!");
instance.teardown(function (teardownErr) { // Tear down the Drop-in UI
if (teardownErr) {
console.error('Could not tear down Drop-in UI!');
} else {
console.info('Drop-in UI has been torn down!');
$('#submit-button').remove(); // Remove the 'Submit payment' button
}
if (result.success) {
$('#checkout-message').html('<h1>Success</h1><p>Your Drop-in UI is working! Check your <a href="https://sandbox.braintreegateway.com/login">sandbox Control Panel</a> for your test transactions.</p><p>Refresh to try another transaction.</p>');
} else {
console.log(result);
$('#checkout-message').html('<h1>Error</h1><p>Check your console.</p>');
}
}); // teardown
}); // $.post
});
});
});
/checkout
:
route
日志显示post "/checkout" do
puts
puts
puts "Params at post /checkout 61: #{ params.inspect }"
amount = params['amount']
puts "amount: #{ amount } / #{ amount.class }" if $t
nonce_from_the_client = params['payment_method_nonce']
puts "nonce at server /checkout 65 and amount: #{ nonce_from_the_client } / #{ amount }"
sleep 3
gateway = Braintree::Gateway.new(
:environment => BT_ENVIRONMENT,
:merchant_id => BT_MERCHANT_ID,
:public_key => BT_PUBLIC_KEY,
:private_key => BT_PRIVATE_KEY)
puts
puts "gateway 74: #{ gateway.inspect }"
result = gateway.transaction.sale(
amount: amount,
payment_method_nonce: nonce_from_the_client,
options: {
submit_for_settlement: true
}
)
puts
puts "result 86: #{ result.inspect }"
if result.success? || result.transaction
puts "redirect 84"
@res = result.transaction
# redirect_to checkout_path(result.transaction.id)
else
error_messages = result.errors.map { |error| "Error: #{ error.code }: #{ error.message }" }
puts error_messages
end
puts "Transaction result: #{ result.inspect }"
# erb :braintree_checkout, :layout => false
puts "#############################################################"
end
的访问量最少为两次,而/checkout
没有任何价值。然后nonce
在这里的试用日志中没有任何价值,最终获得完整的amount
,这触发了parameters
回调函数(我不知道它会多次被击中):
done()
很快出现的是App 19342 output: Params at post /checkout 61: {"amount"=>"10", "payment_method_nonce"=>""}
App 19342 output: amount: 10 / String
App 19342 output: nonce at server /checkout 65 and amount: / 10
App 19356 output:
App 19356 output:
App 19356 output: Params at post /checkout 61: {"paymentMethodNonce"=>"55008c69-15a5-0f69-60d7-c914471dd70e"}
App 19356 output: amount: / NilClass
App 19356 output: nonce at server /checkout 65 and amount: /
App 19363 output:
App 19363 output:
App 19363 output: Params at post /checkout 61: {"amount"=>"10", "payment_method_nonce"=>"55008c69-15a5-0f69-60d7-c914471dd70e"}
App 19363 output: amount: 10 / String
App 19363 output: nonce at server /checkout 65 and amount: 55008c69-15a5-0f69-60d7-c914471dd70e / 10
消息,由于某种原因该消息会转到Error. Check your console.
URI。没什么要求系统执行此操作,因为/checkout
专用于/checkout
呼叫,而不是目的地。 AJAX
中没有任何内容,因为浏览器进入console
时它已被删除。
因此/checkout
日志是我们获得一些反馈的地方:
nginx
它出于某种原因创建了三个网关(我认为每个App 21232 output: gateway 74: #<Braintree::Gateway:0x00007ffd9493b5e0 @config=#<Braintree::Configuration:0x00007ffd9493b5b8 @custom_user_agent=nil, @endpoint=nil, @http_open_timeout=nil, @http_read_timeout=nil, @logger=nil, @merchant_id="6q2mkkkmmpvdjh66", @public_key="svpnrj7sd52n9wq8", @private_key="[FILTERED]", @environment=:sandbox, @proxy_address=nil, @proxy_port=nil, @proxy_user=nil, @proxy_pass=nil, @ssl_version=nil>>
App 21246 output:
App 21246 output: gateway 74: #<Braintree::Gateway:0x00007ffd9493b928 @config=#<Braintree::Configuration:0x00007ffd9493b900 @custom_user_agent=nil, @endpoint=nil, @http_open_timeout=nil, @http_read_timeout=nil, @logger=nil, @merchant_id="6q2mkkkmmpvdjh66", @public_key="svpnrj7sd52n9wq8", @private_key="[FILTERED]", @environment=:sandbox, @proxy_address=nil, @proxy_port=nil, @proxy_user=nil, @proxy_pass=nil, @ssl_version=nil>>
App 21253 output:
App 21253 output: gateway 74: #<Braintree::Gateway:0x00007ffd9493bdd8 @config=#<Braintree::Configuration:0x00007ffd9493bd10 @custom_user_agent=nil, @endpoint=nil, @http_open_timeout=nil, @http_read_timeout=nil, @logger=nil, @merchant_id="6q2mkkkmmpvdjh66", @public_key="svpnrj7sd52n9wq8", @private_key="[FILTERED]", @environment=:sandbox, @proxy_address=nil, @proxy_port=nil, @proxy_user=nil, @proxy_pass=nil, @ssl_version=nil>>
App 21232 output: I, [2019-03-10T09:34:25.909295 #21232] INFO -- : [Braintree] [10/Mar/2019 13:34:25 UTC] POST /merchants/6q2mkkkmmpvdjh66/transactions 422
App 21232 output:
App 21232 output: result 86: #<Braintree::ErrorResult params:{...} errors:<transaction:[(91508) Cannot determine payment method.]>>
App 21232 output: Error: 91508: Cannot determine payment method.
App 21232 output: Transaction result: #<Braintree::ErrorResult params:{...} errors:<transaction:[(91508) Cannot determine payment method.]>>
App 21232 output: #############################################################
App 21232 output: 127.0.0.1 - - [10/Mar/2019:09:34:25 -0400] "POST /checkout HTTP/1.1" 200 - 3.6112
App 21246 output: I, [2019-03-10T09:34:26.010203 #21246] INFO -- : [Braintree] [10/Mar/2019 13:34:26 UTC] POST /merchants/6q2mkkkmmpvdjh66/transactions 422
App 21246 output:
App 21246 output: result 86: #<Braintree::ErrorResult params:{...} errors:<transaction:[(81502) Amount is required., (91508) Cannot determine payment method.]>>
App 21246 output: Error: 81502: Amount is required.
App 21246 output: Error: 91508: Cannot determine payment method.
App 21246 output: Transaction result: #<Braintree::ErrorResult params:{...} errors:<transaction:[(81502) Amount is required., (91508) Cannot determine payment method.]>>
App 21246 output: #############################################################
App 21246 output: 127.0.0.1 - - [10/Mar/2019:09:34:26 -0400] "POST /checkout HTTP/1.1" 200 - 3.6034
试用一个),然后在nonce
上引发错误,表明它不知道交易付款方式。但这就是gateway.transaction.sale
所确定的,因为它会嗅出卡的类型。 VISA以表格形式显示,并随着提交的进行而重新显示。很明显,我使用的是哪种付款方式。 nonce
以表格的形式设置,并提交以继续。因此,nonce
,amount
和card no
是以nonce
到POST
的形式发送的。由于某种原因,/submit
的{{1}}和payment method
都不为人所知,我也不知道为什么。我已经测试过了,它们在日志中。
考虑到我已经提交了所有必要的信息,如何使它正常工作?任何见解表示赞赏。