Skip to content

Instantly share code, notes, and snippets.

@delba
Last active August 29, 2015 13:56
Show Gist options
  • Save delba/9167957 to your computer and use it in GitHub Desktop.
Save delba/9167957 to your computer and use it in GitHub Desktop.
Gribouillis / Scrawl
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