Sha256: b4ff35a0e4b2bdd791c8a8acabe70c8484dbf8cfeee5ff959592a5222547e09b

Contents?: true

Size: 1.4 KB

Versions: 3

Compression:

Stored size: 1.4 KB

Contents

module Moneytree
  module Oauth
    class StripeController < Moneytree::ApplicationController
      def new
        redirect_to stripe_oauth_url
      end

      def callback
        # TODO: Remove this module prefix once we figure out how to properly autoload this.
        payment_gateway = Moneytree::PaymentGateway.create!(psp: 'stripe', account: current_account)
        payment_gateway.oauth_callback(payment_gateway_params)
        redirect_to Moneytree.oauth_redirect, notice: 'Connected to Stripe'
      end

      private

      def payment_gateway_params
        params.permit :scope, :code
      end

      def stripe_oauth_url
        # https://stripe.com/docs/connect/oauth-reference
        # https://stripe.com/docs/connect/oauth-reference#get-authorize
        URI::HTTPS.build(
          host: 'connect.stripe.com',
          path: '/oauth/authorize',
          query: {
            response_type: :code,
            client_id: Moneytree.stripe_credentials[:client_id],
            scope: Moneytree::PaymentProvider::Stripe::PERMISSION,
            redirect_uri: oauth_stripe_callback_url,
            'stripe_user[email]': current_account.email,
            'stripe_user[url]': current_account.website,
            'stripe_user[currency]': current_account.currency_code
          }.to_query
        ).to_s
      end

      def current_account
        send(Moneytree.current_account)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
moneytree-rails-0.1.11 app/controllers/moneytree/oauth/stripe_controller.rb
moneytree-rails-0.1.10 app/controllers/moneytree/oauth/stripe_controller.rb
moneytree-rails-0.1.9 app/controllers/moneytree/oauth/stripe_controller.rb