Im trying to integrate paypal with my ruby on rails application using the rest-api-sdk-ruby gem (https://github.com/paypal/rest-api-sdk-ruby), but could not find enough information around or a good tutorial to back me up.
The description provided above, although providing the necessary code, does not show how to handle the methods around or in which files should each method go to.
Could anyone give me a starting point here or point me to a good tutorial?
I am using rails version 4.
Many thanks.
In depth Step-by step procedure is given here
Integrating Paypal to your Rails application with a basic Checkout method:
Basic Checkout
If you want to accept credit cards for your payments:
Charge Credit Cards
If you want to accept recurring payments:
Recurring Payments
You can clone this app and test in your Local Machine
git clone https://github.com/gotealeaf/paypal-basics
cd paypal-basics
rake db:create
rake db:migrate
rake db:seed
rails s
I'm a bit late to the party but I found this in the PayPal docs
PayPal payments involve these 3 steps:
- Specify payment information to create a payment.
- Get payment approval.
- Execute the payment to the PayPal user's account.
1) Set the intent to sale
, and the payment_method to paypal
.
Include redirect URLs. The user is redirected to these URLs when they either approve or cancel the payment.
curl https://api.sandbox.paypal.com/v1/payments/payment \
-v \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer accessToken' \
-d '{
"intent":"sale",
"redirect_urls":{
"return_url":"http://return_URL_here",
"cancel_url":"http://cancel_URL_here"
},
"payer":{
"payment_method":"paypal"
},
"transactions":[
{
"amount":{
"total":"7.47",
"currency":"USD"
},
"description":"This is the payment transaction description."
}
]
}
Response:
{
"id":"PAY-6RV70583SB702805EKEYSZ6Y",
"create_time":"2013-03-01T22:34:35Z",
"update_time":"2013-03-01T22:34:36Z",
"state":"created",
"intent":"sale",
"payer":{
"payment_method":"paypal"
},
"transactions":[
{
"amount":{
"total":"7.47",
"currency":"USD",
"details":{
"subtotal":"7.47"
}
},
"description":"This is the payment transaction description."
}
],
"links":[
{
"href":"https://api.sandbox.paypal.com/v1/payments/payment/PAY-6RV70583SB702805EKEYSZ6Y",
"rel":"self",
"method":"GET"
},
{
"href":"https://www.sandbox.paypal.com/webscr?cmd=_express-checkout&token=EC-60U79048BN7719609",
"rel":"approval_url",
"method":"REDIRECT"
},
{
"href":"https://api.sandbox.paypal.com/v1/payments/payment/PAY-6RV70583SB702805EKEYSZ6Y/execute",
"rel":"execute",
"method":"POST"
}
]
}
2) Get payment approval
Please note the HATEOAS links in the example above. Direct the user to the approval_url
on the PayPal site, so that the user can approve the payment. The user must approve the payment before you can execute and complete the sale.
3) Execute the payment
When the user approves the payment, PayPal redirects the user to the return_url that was specified
when the payment was created. A payer Id and payment Id are appended to the return URL, as PayerID
and paymentId
:
http://return_url?paymentId=PAY-6RV70583SB702805EKEYSZ6Y&token=EC-60U79048BN7719609&PayerID=7E7MGXCWTTKK2
The token value appended to the return URL is not needed when you execute the payment.
To execute the payment after the user's approval, make a /payment/execute/
call. In the body of the request, use the payer_id
value that was appended to the return URL. In the header, use the access token that you used when you created the payment.
curl https://api.sandbox.paypal.com/v1/payments/payment/PAY-6RV70583SB702805EKEYSZ6Y/execute/ \
-v \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer accessToken' \
-d '{ "payer_id" : "7E7MGXCWTTKK2" }'
Note: Once a payment is complete, it is referred to as a sale. You can then look up the sale and refund it.
Hope it helps!