weixin_33693070 2016-02-06 16:50 采纳率: 0%
浏览 32


I am not convinced my solution to submit a braintree transaction via Rails UJS and Ajax is correct, the reason being is i am seeing two ajax calls as opposed to one when submitting.

For example when turning ajax off (so removing remote: true) submitting a form seems to wait for a nonce before submitting the payment (I believe braintree takes over the submit event)

Parameters: {"utf8"=>"✓", "authenticity_token"=>"token_here", "first_name"=>"", "last_name"=>"", "payment_method_nonce"=>"nonce_here_populated"}

But when submitting with remote: true enabled the first call is

Parameters: {"utf8"=>"✓", "authenticity_token"=>"token_here=", "first_name"=>"", "last_name"=>""} 

So i read that i need to wait for that nonce using the onPaymentMethodRecieved callback function, append the nonce to the form and then submit

braintree.setup(gon.client_token, 'dropin', {
  container: 'dropin-container',
  onPaymentMethodReceived: function (paymentMethod) {
   $('#braintree-transaction-form').append("<input id='p_nonce' type='hidden' name='payment_method_nonce' value='" + paymentMethod.nonce + "'></input>");
   $("#braintree-transaction-form input[type='submit']").submit();

This results in two calls being made


Parameters: {"utf8"=>"✓", "authenticity_token"=>"token_here=", "first_name"=>"", "last_name"=>""}


Parameters: {"utf8"=>"✓", "authenticity_token"=>"token_here", "first_name"=>"", "last_name"=>"", "payment_method_nonce"=>"nonce_here_populated"}

Only problem being is i have this in my controller which dont think is correct

def create
  nonce = params[:payment_method_nonce]
  render action: :new and return unless nonce # Is this the way to wait for the nonce
  @result = Braintree::Transaction.sale(
              amount: 2500,
              payment_method_nonce: nonce,
              customer: {
                first_name: params[:first_name],
                last_name: params[:last_name]

my concern i guess is the two calls being made and my controller code.

Has anyone got any experience with Ajax calls with Braintree and Rails


  • 写回答

1条回答 默认 最新

  • weixin_33709364 2016-02-08 17:07

    Full disclosure: I work at Braintree. If you have any further questions, feel free to contact support.

    You might be running into a problem with the default behavior of your submit button, which is something you could try disabling. However, there's nothing here to think that is the issue. Most likely there is a problem elsewhere in your setup. I would really recommend contacting Braintree support with your full code samples to help them walk through your issue.




  • ¥15 三菱变频器模块怎么检测触发
  • ¥15 在C#方法中使用了.Refresh();刷新了控件,但是不是最新值
  • ¥30 求一下解题思路,完全不懂。
  • ¥30 关于#硬件工程#的问题:求一下解题思路
  • ¥15 运筹学对偶单纯行法构造扩充问题
  • ¥20 XP系统的老电脑一开机就提示找不到rundll.exe,付费求解
  • ¥15 milvus查询出来的score怎么转换成0-1之间的相似性
  • ¥15 lvgl V9移植到linux开发板
  • ¥15 VB.net中在窗体中创建一个button控件来关闭窗体,但是提示错误,我该怎么办
  • ¥15 网上下载好的程序但是arduinoIDE编程报错,运行不了,哪里出错了,能具体给改一下吗