Sha256: 9e34332fa8e8ec9d07fb202f01c147f97f9c57c4c8551e0391508645373a4a3e

Contents?: true

Size: 1.99 KB

Versions: 29

Compression:

Stored size: 1.99 KB

Contents

# frozen_string_literal: true

module Stripe
  module OAuth
    module OAuthOperations
      extend APIOperations::Request::ClassMethods

      def self.request(method, url, params, opts)
        opts = Util.normalize_opts(opts)
        opts[:client] ||= StripeClient.active_client
        opts[:api_base] ||= Stripe.connect_base

        super(method, url, params, opts)
      end
    end

    def self.get_client_id(params = {})
      client_id = params[:client_id] || Stripe.client_id
      unless client_id
        raise AuthenticationError, "No client_id provided. " \
          'Set your client_id using "Stripe.client_id = <CLIENT-ID>". ' \
          "You can find your client_ids in your Stripe dashboard at " \
          "https://dashboard.stripe.com/account/applications/settings, " \
          "after registering your account as a platform. See " \
          "https://stripe.com/docs/connect/standalone-accounts for details, " \
          "or email support@stripe.com if you have any questions."
      end
      client_id
    end

    def self.authorize_url(params = {}, opts = {})
      base = opts[:connect_base] || Stripe.connect_base

      params[:client_id] = get_client_id(params)
      params[:response_type] ||= "code"
      query = Util.encode_parameters(params)

      "#{base}/oauth/authorize?#{query}"
    end

    def self.token(params = {}, opts = {})
      opts = Util.normalize_opts(opts)
      resp, opts = OAuthOperations.request(
        :post, "/oauth/token", params, opts
      )
      # This is just going to return a generic StripeObject, but that's okay
      Util.convert_to_stripe_object(resp.data, opts)
    end

    def self.deauthorize(params = {}, opts = {})
      opts = Util.normalize_opts(opts)
      params[:client_id] = get_client_id(params)
      resp, opts = OAuthOperations.request(
        :post, "/oauth/deauthorize", params, opts
      )
      # This is just going to return a generic StripeObject, but that's okay
      Util.convert_to_stripe_object(resp.data, opts)
    end
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
stripe-4.4.1 lib/stripe/oauth.rb
stripe-4.4.0 lib/stripe/oauth.rb
stripe-4.3.0 lib/stripe/oauth.rb
stripe-4.2.0 lib/stripe/oauth.rb
stripe-4.1.0 lib/stripe/oauth.rb
stripe-4.0.3 lib/stripe/oauth.rb
stripe-4.0.2 lib/stripe/oauth.rb
stripe-4.0.1 lib/stripe/oauth.rb
stripe-4.0.0 lib/stripe/oauth.rb
stripe-3.31.1 lib/stripe/oauth.rb
stripe-3.31.0 lib/stripe/oauth.rb
stripe-3.30.0 lib/stripe/oauth.rb
stripe-3.29.0 lib/stripe/oauth.rb
stripe-3.28.0 lib/stripe/oauth.rb
stripe-3.27.0 lib/stripe/oauth.rb
stripe-3.26.1 lib/stripe/oauth.rb
stripe-3.26.0 lib/stripe/oauth.rb
stripe-3.25.0 lib/stripe/oauth.rb
stripe-3.24.0 lib/stripe/oauth.rb
stripe-3.23.0 lib/stripe/oauth.rb