gpt4 book ai didi

ruby-on-rails - 将有效载荷随机数提交到服务器 Braintree SDK Paypal ruby​​ rails

转载 作者:太空宇宙 更新时间:2023-11-03 15:54:23 24 4
gpt4 key购买 nike

我正在使用 Braintree Paypal SDK 以托管字段的形式呈现 Paypal 按钮。但是,我无法弄清楚如何将随机数提交给服务器。在本节中我该怎么做?

onAuthorize: function (data, actions) {
return paypalCheckoutInstance.tokenizePayment(data)
.then(function (payload) {
// Submit `payload.nonce` to your server

//console.log (payload.nonce)
});
},

我的 Controller Action 是

def payment
Cart.find(session[:cart_id])
result = Braintree::Transaction.sale(
amount: current_order.subtotal,
payment_method_nonce: params[:payment_method_nonce],
:options => {
:submit_for_settlement => true},
)
response = {:success => result.success?}
if result.success?
response[:transaction_id] = result.transaction.id
current_order.update(status: "purchased")
ReceiptMailer.purchase_order(current_passenger,
current_order).deliver_now
redirect_to root_path,
notice: "Thank you for booking, Please check your email for invoice"
session.delete(:cart_id)

elsif result.transaction
redirect_to cart_path, alert: "something went wrong, your transactions was not successful!"
end
end

最佳答案

您需要在 javascript 中生成一个请求,以将付款随机数传递到您的服务器。下面是一个使用 jQuery 的 ajax 方法生成请求的简单示例:

$.ajax({
method: "POST",
url: "/payment",
data: { payment_method_nonce: payload.nonce }
})

关于ruby-on-rails - 将有效载荷随机数提交到服务器 Braintree SDK Paypal ruby​​ rails,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46778494/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com