Sha256: 5ebcb3906f8a243e5f10a1721028d6d3699de621ec110c3bb04c20880adc6b7d

Contents?: true

Size: 982 Bytes

Versions: 1

Compression:

Stored size: 982 Bytes

Contents

module WepayRails
  module Helpers
    module ControllerHelpers
      # Get the auth code for the customer
      # arguments are the redirect_uri and an array of permissions that your application needs
      # ex. ['manage_accounts','collect_payments','view_balance','view_user']
      def auth_code_url(redirect_uri, permissions)
        params = {
            :client_id => @config[:client_id],
            :redirect_uri => redirect_uri,
            :scope => permissions.join(',')
        }

        query = params.map do |k, v|
          "#{k.to_s}=#{v}"
        end.join('&')

        auth_base_uri = Rails.env.production? ? "https://api.wepay.com" : "https://stage.wepay.com"

        "#{auth_base_uri}/v2/oauth2/authorize?#{query}"
      end

      def redirect_to_wepay_for_auth(redirect_uri, scope)
        redirect_to gateway.auth_code_url(redirect_uri, scope)
      end

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
wepay-rails-0.1.23 lib/helpers/controller_helpers.rb