diff --git a/app/controllers/admin/enterprises_controller.rb b/app/controllers/admin/enterprises_controller.rb index 86be4b58f0..c3d515649e 100644 --- a/app/controllers/admin/enterprises_controller.rb +++ b/app/controllers/admin/enterprises_controller.rb @@ -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 diff --git a/app/helpers/admin/stripe_helper.rb b/app/helpers/admin/stripe_helper.rb index 0109b7ba2b..babcaec14f 100644 --- a/app/helpers/admin/stripe_helper.rb +++ b/app/helpers/admin/stripe_helper.rb @@ -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={})