Module: PayPalHelper

Included in:
PaypalExpressController
Defined in:
lib/generators/templates/pay_pal_helper.rb

Instance Method Summary collapse

Instance Method Details

#get_purchase_params(cart, request, params) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/generators/templates/pay_pal_helper.rb', line 33

def get_purchase_params(cart, request, params)
    subtotal = cart.total
    return to_cents(subtotal), {
      :ip => request.remote_ip,
      :token => params[:token],
      :payer_id => params[:payer_id],
      :subtotal => to_cents(subtotal),
      :handling => 0,
      :tax => 0,
      :items => cart.items_for_paypal,
    }
end

#order_info(gateway_response, cart) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/generators/templates/pay_pal_helper.rb', line 22

def order_info(gateway_response, cart)
  total = cart.total
  return {
    gateway_details: {
      :token => gateway_response.token,
      :payer_id => gateway_response.payer_id,
    },
    total: total,
  }
end

#purchase_params(cart, ip) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/generators/templates/pay_pal_helper.rb', line 3

def purchase_params(cart, ip) 
  subtotal = cart.total
  return to_cents(subtotal), {
    :ip => request.remote_ip,
    :return_url => url_for(:action => 'review', :only_path => false),
    :cancel_return_url => products_url,  
    :subtotal => to_cents(subtotal),
    :handling => 0,
    :tax => 0,
    :allow_note => true,
    :items => cart.items_for_paypal,
  } 
end

#to_cents(subtotal) ⇒ Object

Paypal gets the total with cents



18
19
20
# File 'lib/generators/templates/pay_pal_helper.rb', line 18

def to_cents(subtotal)
  (subtotal * 100).round
end