-
-
Save alekpopovic/7aaae8c8fce1fa6a651430d79df3f57a to your computer and use it in GitHub Desktop.
Parallel Payment in PayPal Express Gem
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require File.join(File.dirname(__FILE__), 'paypal_debugger') | |
| Paypal.sandbox! | |
| mode = :setup | |
| paypal = Payment::Paypal.new | |
| request1 = Paypal::Payment::Request.new( | |
| :amount => 10, | |
| :description => 'Instant Payment Request', | |
| :notify_url => 'http://merchant.example.com/notify', | |
| :items => [{ | |
| :name => 'Item1', | |
| :description => 'Item1 Desc', | |
| :amount => 10, | |
| :category => :Digital | |
| }] | |
| ) | |
| request2 = request1.dup | |
| request1.seller_id = "[email protected]" | |
| request1.request_id = "To Cerego" | |
| request2.seller_id = "[email protected]" | |
| request2.request_id = "To Nov" | |
| payment_requests = [ | |
| request1, | |
| request2 | |
| ] | |
| token = 'EC-7CM94787EV257815N' | |
| payer_id = 'CMJLWADKVFQYJ' | |
| transaction_id = '52B66941CM521935F' | |
| begin | |
| response = case mode | |
| when :setup | |
| response = paypal.client.setup( | |
| payment_requests, | |
| RETURN_URL, | |
| CANCEL_URL, | |
| :pay_on_paypal => true, | |
| :no_shipping => true | |
| ) | |
| puts response.redirect_uri | |
| puts response.popup_uri | |
| `open "#{response.redirect_uri}"` | |
| when :details | |
| p paypal.client.details(token) | |
| when :checkout | |
| p paypal.client.checkout!( | |
| token, | |
| payer_id, | |
| payment_requests | |
| ) | |
| when :refund | |
| p paypal.client.refund!( | |
| transaction_id, | |
| :type => :Partial, | |
| :amount => 3 | |
| ) | |
| end | |
| rescue => e | |
| p e.message | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment