Module: WepayRails::Helpers::ControllerHelpers

Included in:
Payments
Defined in:
lib/helpers/controller_helpers.rb

Instance Method Summary collapse

Instance Method Details

#init_charge(params, access_token = nil) ⇒ Object



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/helpers/controller_helpers.rb', line 115

def init_charge(params, access_token=nil)
  wepay_gateway = WepayRails::Payments::Gateway.new(access_token)
  response      = wepay_gateway.perform_charge(params)

  params.merge!({
      :access_token   => wepay_gateway.access_token,
      :preapproval_id => response[:preapproval_id],
      :checkout_id    => response[:checkout_id],
      :security_token => response[:security_token],
  })
  
  params.delete_if {|k,v| !WepayCheckoutRecord.attribute_names.include? k.to_s}

  WepayCheckoutRecord.create(params)
end

#init_charge_and_return_success(params, access_token = nil) ⇒ Object



131
132
133
134
# File 'lib/helpers/controller_helpers.rb', line 131

def init_charge_and_return_success(params, access_token=nil)
  record = init_charge(params, access_token)
  redirect_to charge_success_url and return record
end

#init_checkout(params, access_token = nil) ⇒ Object

Many of the settings you pass in here are already factored in from the wepay.yml file and only need to be overridden if you insist on doing so when this method is called. The following list of key values are pulled in for you from your wepay.yml file:

Note: @wepay_config is your wepay.yml as a Hash :callback_uri => @wepay_config, :redirect_uri => @wepay_config, :fee_payer => @wepay_config, :type => @wepay_config, :charge_tax => @wepay_config ? 1 : 0, :app_fee => @wepay_config, :auto_capture => @wepay_config ? 1 : 0, :require_shipping => @wepay_config ? 1 : 0, :shipping_fee => @wepay_config, :charge_tax => @wepay_config, :account_id => wepay_user # wepay-rails goes and gets this for you, but you can override it if you want to.

params hash key values possibilities are: Parameter: Required: Description: :account_id Yes The unique ID of the account you want to create a checkout for. :short_description Yes A short description of what is being paid for. :long_description No A long description of what is being paid for. :type Yes The the checkout type (one of the following: GOODS, SERVICE, DONATION, or PERSONAL) :reference_id No The unique reference id of the checkout (set by the application in /checkout/create :amount Yes The amount that the payer will pay. :app_fee No The amount that the application will receive in fees. :fee_payer No Who will pay the fees (WePay’s fees and any app fees). Set to “Payer” to charge fees to the person paying (Payer will pay amount + fees, payee will receive amount). Set to “Payee” to charge fees to the person receiving money (Payer will pay amount, Payee will receive amount - fees). Defaults to “Payer”. :redirect_uri No The uri the payer will be redirected to after paying. :callback_uri No The uri that will receive any Instant Payment Notifications sent. Needs to be a full uri (ex www.wepay.com ) :auto_capture No A boolean value (0 or 1). Default is 1. If set to 0 then the payment will not automatically be released to the account and will be held by WePay in payment state ‘reserved’. To release funds to the account you must call /checkout/capture :require_shipping No A boolean value (0 or 1). If set to 1 then the payer will be asked to enter a shipping address when they pay. After payment you can retrieve this shipping address by calling /checkout :shipping_fee No The amount that you want to charge for shipping. :charge_tax No A boolean value (0 or 1). If set to 1 and the account has a relevant tax entry (see /account/set_tax), then tax will be charged.



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/helpers/controller_helpers.rb', line 40

def init_checkout(params, access_token=nil)
  wepay_gateway = WepayRails::Payments::Gateway.new(access_token)
  response      = wepay_gateway.perform_checkout(params)

  if response[:checkout_uri].blank?
    raise WepayRails::Exceptions::WepayCheckoutError.new("An error occurred: #{response.inspect}")
  end

  params.merge!({
      :access_token   => wepay_gateway.access_token,
      :checkout_id    => response[:checkout_id],
      :security_token => response[:security_token],
      :checkout_uri   => response[:checkout_uri]
  })
  
  params.delete_if {|k,v| !WepayCheckoutRecord.attribute_names.include? k.to_s}

  WepayCheckoutRecord.create(params)
end

#init_checkout_and_send_user_to_wepay(params, access_token = nil) ⇒ Object



60
61
62
63
# File 'lib/helpers/controller_helpers.rb', line 60

def init_checkout_and_send_user_to_wepay(params, access_token=nil)
  record = init_checkout(params, access_token)
  redirect_to record.checkout_uri and return record
end

#init_preapproval(params, access_token = nil) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/helpers/controller_helpers.rb', line 90

def init_preapproval(params, access_token=nil)
  wepay_gateway = WepayRails::Payments::Gateway.new(access_token)
  response      = wepay_gateway.perform_preapproval(params)

  if response[:preapproval_uri].blank?
    raise WepayRails::Exceptions::WepayPreapprovalError.new("An error occurred: #{response.inspect}")
  end

  params.merge!({
      :access_token   => wepay_gateway.access_token,
      :preapproval_id    => response[:preapproval_id],
      :security_token => response[:security_token],
      :preapproval_uri   => response[:preapproval_uri]
  })
  
  params.delete_if {|k,v| !WepayCheckoutRecord.attribute_names.include? k.to_s}

  WepayCheckoutRecord.create(params)
end

#init_preapproval_and_send_user_to_wepay(params, access_token = nil) ⇒ Object



110
111
112
113
# File 'lib/helpers/controller_helpers.rb', line 110

def init_preapproval_and_send_user_to_wepay(params, access_token=nil)
  record = init_preapproval(params, access_token)
  redirect_to record.preapproval_uri and return record
end