diff --git a/app/helpers/admin/stripe_helper.rb b/app/helpers/admin/stripe_helper.rb index a78ebf8e55..4fdc16355c 100644 --- a/app/helpers/admin/stripe_helper.rb +++ b/app/helpers/admin/stripe_helper.rb @@ -21,7 +21,7 @@ module Admin options ) - def get_stripe_token(code, options={scope: 'read_write'}) + def get_stripe_token(code, options={}) StripeHelper.client.auth_code.get_token(code, options) end @@ -29,7 +29,7 @@ module Admin options = options.merge({enterprise_id: enterprise_id}) jwt = jwt_encode options # State param will be passed back after auth - StripeHelper.client.auth_code.authorize_url(state: jwt) + StripeHelper.client.auth_code.authorize_url(state: jwt, scope: 'read_write') end def deauthorize_stripe(account_id) diff --git a/spec/helpers/admin/stripe_helper_spec.rb b/spec/helpers/admin/stripe_helper_spec.rb index 27591d2705..c15ca4a59f 100644 --- a/spec/helpers/admin/stripe_helper_spec.rb +++ b/spec/helpers/admin/stripe_helper_spec.rb @@ -6,13 +6,14 @@ describe Admin::StripeHelper do let!(:stripe_account) { create(:stripe_account, enterprise: enterprise) } it "calls the Stripe API to get a token" do - expect(Admin::StripeHelper.client.auth_code).to receive(:get_token).with("abc",{scope: "read_write"}) + expect(Admin::StripeHelper.client.auth_code).to receive(:get_token).with("abc", {}) helper.get_stripe_token("abc") end - it "calls the Stripe API for authorization, passing appropriate JWT in the state param" do + it "calls the Stripe API for authorization with read_write permission, passing appropriate JWT in the state param" do expect(Admin::StripeHelper.client.auth_code).to receive(:authorize_url).with({ - state: JWT.encode({enterprise_id: "enterprise-permalink"}, Openfoodnetwork::Application.config.secret_token, 'HS256') + state: JWT.encode({enterprise_id: "enterprise-permalink"}, Openfoodnetwork::Application.config.secret_token, 'HS256'), + scope: "read_write" }) helper.authorize_stripe("enterprise-permalink") end @@ -47,6 +48,5 @@ describe Admin::StripeHelper do it "encodes and decodes JWT" do jwt_decode(jwt_encode({test: "string"})).should eq({"test" => "string"}) end - end end