Skip to content

Instantly share code, notes, and snippets.

@dr-r3d
Created October 3, 2011 10:00
Show Gist options
  • Save dr-r3d/1258802 to your computer and use it in GitHub Desktop.
Save dr-r3d/1258802 to your computer and use it in GitHub Desktop.
def paypal_checkout
values = {
:business => 'merch_1295771964_biz@gmail.com',
:cmd => '_cart',
:upload => 1,
:return => "http://61.12.14.178:4001#{checkout_sa_cart_items_path(params[:cart_item_ids])}"
}
cart_items = CartItem.any_in('_id' => params[:cart_item_ids])
cart_items.each_with_index do |item, index|
values.merge!({
"amount_#{index + 1}" => item.credits_package.price,
"item_name_#{index + 1}" => item.credits_package.title,
"item_number_#{index + 1}" => item.credits_package.id.to_s,
"quantity_#{index + 1}" => 1
})
end
redirect_to("https://www.sandbox.paypal.com/cgi-bin/webscr?" + values.map { |k,v| "#{k}=#{v}" }.join("&"))
end
Started POST "/sa/cart_items/paypal_checkout" for 192.168.2.1 at 2011-10-03 15:26:44 +0530
Processing by Sa::CartItemsController#paypal_checkout as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"EoX2MzUkOLToRkl8F83IvB+L/98RPgdYg0OaV6vJxTU=", "cart_item_ids"=>["4e897dabb8b9c642fd000375"]}
MONGODB conoverweb_development['system.namespaces'].find({})
MONGODB conoverweb_development['users'].find({:_id=>BSON::ObjectId('4e86e70eb8b9c66994000006')})
MONGODB conoverweb_development['users'].update({"_id"=>BSON::ObjectId('4e86e70eb8b9c66994000006')}, {"$set"=>{"last_request_at"=>2011-10-03 09:56:45 UTC}})
MONGODB conoverweb_development['system.namespaces'].find({})
MONGODB conoverweb_development['fss_configurations'].find({"configurable_id"=>BSON::ObjectId('4e86e70eb8b9c66994000006')})
MONGODB conoverweb_development['system.namespaces'].find({})
MONGODB conoverweb_development['line_items'].find({"_id"=>{"$in"=>[BSON::ObjectId('4e897dabb8b9c642fd000375')]}, :_type=>{"$in"=>["CartItem"]}})
MONGODB conoverweb_development['system.namespaces'].find({})
MONGODB conoverweb_development['credits_packages'].find({:_id=>BSON::ObjectId('4e86d644b8b9c656550000fa')})
Redirected to https://www.sandbox.paypal.com/cgi-bin/webscr?business=merch_1295771964_biz@gmail.com&cmd=_cart&upload=1&return=http://61.12.14.178:4001/sa/cart_items/checkout.4e897dabb8b9c642fd000375&amount_1=4000&item_name_1=1000 Credits&item_number_1=4e86d644b8b9c656550000fa&quantity_1=1
Completed 302 Found in 174ms
[2011-10-03 15:26:45] ERROR URI::InvalidURIError: bad URI(is not URI?): https://www.sandbox.paypal.com/cgi-bin/webscr?business=merch_1295771964_biz@gmail.com&cmd=_cart&upload=1&return=http://61.12.14.178:4001/sa/cart_items/checkout.4e897dabb8b9c642fd000375&amount_1=4000&item_name_1=1000 Credits&item_number_1=4e86d644b8b9c656550000fa&quantity_1=1
/home/abhishek/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/uri/generic.rb:746:in `rescue in merge'
/home/abhishek/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/uri/generic.rb:743:in `merge'
/home/abhishek/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/webrick/httpresponse.rb:163:in `setup_header'
/home/abhishek/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/webrick/httpresponse.rb:101:in `send_response'
/home/abhishek/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/webrick/httpserver.rb:86:in `run'
/home/abhishek/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment