Skip to content

Instantly share code, notes, and snippets.

@sivabudh
Created October 23, 2011 22:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sivabudh/1308007 to your computer and use it in GitHub Desktop.
Save sivabudh/1308007 to your computer and use it in GitHub Desktop.
PaypalExpressHelper
module PaypalExpressHelper
def get_setup_purchase_params(cart, request)
subtotal, shipping, total = get_totals(cart)
return to_cents(total), {
:ip => request.remote_ip,
:return_url => url_for(:action => 'review', :only_path => false),
:cancel_return_url => home_url,
:subtotal => to_cents(subtotal),
:shipping => to_cents(shipping),
:handling => 0,
:tax => 0,
:allow_note => true,
:items => get_items(cart),
}
end
def get_shipping(cart)
# define your own shipping rule based on your cart here
# this method should return an integer
end
def get_items(cart)
cart.line_items.collect do |line_item|
product = line_item.product
{
:name => product.title,
:number => product.serial_number,
:quantity => line_item.quantity,
:amount => to_cents(product.price),
}
end
end
def get_totals(cart)
subtotal = cart.subtotal
shipping = get_shipping(cart)
total = subtotal + shipping
return subtotal, shipping, total
end
def to_cents(money)
(money*100).round
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment