Reputation: 13
Im uisng Braintree Paypal SDK to render paypal button in form with hosted feilds. however, I cannot figure out how to submit nonce to server. how do i do that in this section?.
onAuthorize: function (data, actions) {
return paypalCheckoutInstance.tokenizePayment(data)
.then(function (payload) {
// Submit `payload.nonce` to your server
//console.log (payload.nonce)
});
},
my controller action is
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
Upvotes: 1
Views: 530
Reputation: 2614
You will need to generate a request in javascript to pass the payment nonce to your server. Here's a simple example of generating a request using jQuery's ajax method:
$.ajax({
method: "POST",
url: "/payment",
data: { payment_method_nonce: payload.nonce }
})
Upvotes: 2