Last active
August 29, 2015 13:56
-
-
Save delba/9167957 to your computer and use it in GitHub Desktop.
Gribouillis / Scrawl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ConnectController | |
def authorize | |
redirect_to stripe_authorize_url | |
end | |
def callback | |
if code = params[:code] | |
auth_token = client.auth_code.get_token(code) | |
current_user.update!(token: auth_token) | |
flash.notice = 'Connected to Stripe.' | |
elsif error = params[:error] | |
flash.alert = case error | |
when 'access_denied' then 'Access denied.' | |
end | |
end | |
redirect_to params[:state] | |
end | |
private | |
def client | |
OAuth2::Client.new( | |
ENV['STRIPE_ID'], | |
ENV['STRIPE_SECRET'], | |
site: STRIPE_URL ) | |
end | |
def stripe_authorize_url | |
client.auth_code.authorize_url( | |
scope: 'read_write', | |
state: request.referer, | |
stripe_user: stripe_user_attributes, | |
redirect_uri: oauth_callback_url ) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment