Skip to content

Instantly share code, notes, and snippets.

@miloops
Created April 29, 2010 16:28
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 miloops/383852 to your computer and use it in GitHub Desktop.
Save miloops/383852 to your computer and use it in GitHub Desktop.
module PaypalHelper
PAYPAL_API_PEM = File.read(File.join(RAILS_ROOT, 'certs', 'paypal_api.pem'))
# paypal_transfer(100.0, "yacare@example.com", "USD", "Your earnings", "This is a receipt"
def paypal_transfer(amount, email, currency, subject = nil, note = nil)
gateway = ActiveMerchant::Billing::PaypalGateway.new(:login => APP_CONFIG[:paypal_api_username],
:password => APP_CONFIG[:paypal_api_password],
:pem => PAYPAL_API_PEM)
gateway.transfer amount_in_cents(amount), email,
:subject => subject, :note => note, :currency => currency
end
def amount_in_cents(amount)
(amount *100).round
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment