Created
April 25, 2012 15:05
-
-
Save nov/2490428 to your computer and use it in GitHub Desktop.
Parallel Payment in PayPal Express Gem
This file contains 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 = "paypal@cerego.co.jp" | |
request1.request_id = "To Cerego" | |
request2.seller_id = "nov@matake.jp" | |
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