RailsCasts Pro episodes are now free!

Learn more or hide this

Francisco Sandoval's Profile

GitHub User: fjsandov

Comments by Francisco Sandoval

Avatar

This is not a solution for your specific problem, but I'm performing the same integration using the gem 'paypal-sdk-rest' which helps to connect to the Paypal REST API.

With this gem you can create a Payment using the payment_method: 'paypal' which behaviour is similar to the express checkout of the classic API.

This is a simple working test code, hope it helps:

Into a controller:

def test
p = PayPal::SDK::REST::Payment.new(
{
intent: 'sale',
payer: {
payment_method: 'paypal'
},
redirect_urls: {
return_url: paypal_return_url,
cancel_url: your_cancel_url
},
transactions: [
{
amount: {
total: '1',
currency: 'USD'
},
description: "Test item'
}
]
}
)
if p.create
redirect_url = p.links.find{|v| v.method == 'REDIRECT'}.href
Rails.logger.info "Paypal Payment ID: #{p.id}"
Rails.logger.info "Redirect to: #{redirect_url}"
redirect_to redirect_url
else
Rails.logger.info p.error.inspect
end
end

def paypal_return
p= PayPal::SDK::REST::Payment.find(params[:paymentId])
# at this point p.state == 'created'
if p.execute(payer_id: params[:PayerID])
if p.state == 'approved'
redirect_to your_success_path
else
redirect_to your_failure_path
end
else
redirect_to your_failure_path
end
end