Callback creates a new StripeAccount with id and publishable key.

This commit is contained in:
Steve Pettitt
2016-09-17 23:59:36 +01:00
committed by Rob Harrington
parent 06279848c6
commit 03f590ccc4
2 changed files with 12 additions and 4 deletions

View File

@@ -119,12 +119,20 @@ module Admin
end
def stripe_connect_callback
# Check CSRF?
if params["code"]
# Get the deets from Stripe
response_params = get_stripe_token(params["code"]).params
# Get the Enterprise
state = JSON.parse(params["state"].gsub("=>",":"))
@enterprise = Enterprise.find_by_permalink(state["enterprise_id"])
stripe_account = StripeAccount.new(stripe_user_id: params["stripe_user_id"], stripe_publishable_key: params["stripe_publishable_key"], enterprise: enterprise)
stripe_account = StripeAccount.new(stripe_user_id: response_params["stripe_user_id"], stripe_publishable_key: response_params["stripe_publishable_key"], enterprise: @enterprise)
if stripe_account.save
render json: stripe_account
respond_to do |format|
format.html { redirect_to main_app.edit_admin_enterprise_path(@enterprise), notice: "Stripe account connected successfully."}
format.json { render json: stripe_account }
end
else
render text: "Failed to save Stripe token", status: 500
end

View File

@@ -14,8 +14,8 @@ module Admin
options
)
def get_stripe_token(code, options={params: {scope: 'read_write'}})
StripeHelper.client.get_token(code, options)
def get_stripe_token(code, options={scope: 'read_write'})
StripeHelper.client.auth_code.get_token(code, options)
end
def authorize_stripe(enterprise_id, options={})