Sha256: fb154baa5cc18484eee654097e8655f423edf626e3ac2eba238a7c195bc9ac99

Contents?: true

Size: 1.76 KB

Versions: 4

Compression:

Stored size: 1.76 KB

Contents

module WepayRails
  module Helpers
    module ControllerHelpers

      def redirect_to_wepay_for_auth(scope=gateway.scope)
        redirect_to gateway.auth_code_url(scope)
      end

      def redirect_to_wepay_for_token
        redirect_to gateway.token_url
      end

      def gateway
        @gateway ||= WepayRails::Payments::Gateway.new
      end

      # From https://stage.wepay.com/developer/tutorial/authorization
      # Request
      # https://stage.wepay.com/v2/oauth2/token
      # ?client_id=[your client id]
      # &redirect_uri=[your redirect uri ex. 'http://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
      def initialize_wepay_access_token(auth_code)
        wepay_access_token = gateway.access_token(auth_code)
      rescue WepayRails::Exceptions::ExpiredTokenError => e
        redirect_to_wepay_for_auth gateway.scope
        return
      end

      # 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.
      def unique_wepay_access_token_key
        :IODDR8856UUFG6788
      end

      # Access token is the OAUTH access token that is used for future
      # comunique
      def wepay_access_token=(value)
        session[unique_wepay_access_token_key] = value
      end

      # Access token is the OAUTH access token that is used for future
      # comunique
      def wepay_access_token
        session[unique_wepay_access_token_key]
      end

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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
wepay-rails-0.1.37 lib/helpers/controller_helpers.rb
wepay-rails-0.1.36 lib/helpers/controller_helpers.rb
wepay-rails-0.1.35 lib/helpers/controller_helpers.rb
wepay-rails-0.1.34 lib/helpers/controller_helpers.rb