Module: WepayRails::Helpers::ControllerHelpers

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

Instance Method Summary collapse

Instance Method Details

#gatewayObject

Deprecated.

Use wepay_gateway instead of gateway



10
11
12
13
# File 'lib/helpers/controller_helpers.rb', line 10

def gateway
  warn "[DEPRECATION] Use wepay_gateway instead of gateway"
  wepay_gateway
end

#init_checkout_and_send_user_to_wepay(parms) ⇒ 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.



88
89
90
91
92
# File 'lib/helpers/controller_helpers.rb', line 88

def init_checkout_and_send_user_to_wepay(parms)
  response = wepay_gateway.perform_checkout(parms)
  raise WepayRails::Exceptions::InitializeCheckoutError.new("A problem occurred while trying to checkout. Wepay didn't send us back a checkout uri") unless response && response.has_key?('checkout_uri')
  redirect_to response['checkout_uri'] and return
end

#initialize_wepay_access_token(auth_code) ⇒ Object

From stage.wepay.com/developer/tutorial/authorization Request stage.wepay.com/v2/oauth2/token ?client_id=[your client id] &redirect_uri=[your redirect uri ex. ‘exampleapp.com/wepay’] &client_secret=[your client secret] &code=[the code you got in step one]

Response “user_id”:“123456”,“access_token”:“1337h4x0rzabcd12345”,“token_type”:“BEARER” Example



29
30
31
32
33
34
# File 'lib/helpers/controller_helpers.rb', line 29

def initialize_wepay_access_token(auth_code)
  session[unique_wepay_access_token_key] = wepay_gateway.access_token(auth_code)
  return
rescue WepayRails::Exceptions::ExpiredTokenError => e
  redirect_to_wepay_for_auth(wepay_gateway.scope) and return
end

#redirect_to_wepay_for_auth(wepayable_object, scope = wepay_gateway.scope) ⇒ Object



5
6
7
# File 'lib/helpers/controller_helpers.rb', line 5

def redirect_to_wepay_for_auth(wepayable_object, scope=wepay_gateway.scope)
  redirect_to wepay_gateway.auth_code_url(wepayable_object, scope)
end

#unique_wepay_access_token_keyObject

Since we are saving the access token in the session, ensure key uniqueness. Might be a good idea to have this be a setting in the wepay.yml file.



39
40
41
# File 'lib/helpers/controller_helpers.rb', line 39

def unique_wepay_access_token_key
  :IODDR8856UUFG6788
end

#wepay_access_tokenObject

Access token is the OAUTH access token that is used for future comunique



45
46
47
# File 'lib/helpers/controller_helpers.rb', line 45

def wepay_access_token
  session[unique_wepay_access_token_key]
end

#wepay_access_token_exists?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/helpers/controller_helpers.rb', line 49

def wepay_access_token_exists?
  @access_token_exists ||= wepay_access_token.present?
end

#wepay_gatewayObject



15
16
17
# File 'lib/helpers/controller_helpers.rb', line 15

def wepay_gateway
  @gateway ||= WepayRails::Payments::Gateway.new(wepay_access_token)
end