ruby - Rails api error: Authorization has been denied for this request -


i trying call external web service api rails application, every time same error {"message":"authorization has been denied request."}.

here snippet of controller code:

# frozen_string_literal: true module store   class paymentscontroller < applicationcontroller     def initiate       url = store::payment.new.initiate  <---- error happens here       render plain: 'failed' && return unless url       redirect_to url     end   end end 

here snippet model code:

# frozen_string_literal: true module store   class payment     end_point = 'https://xxxxxxxxxxxxxxxxxxxxxxxxxxxxx'      def initiate <--- calling method controller fails, works in rails console       navigate_url = nil       restclient.post end_point, payload, header |response|         response_hash = json.parse(response).symbolize_keys         if response_hash[:success]           navigate_url = response_hash[:navigateurl]         else           rollbar.error(response_hash)         end       end        navigate_url     end      def payload       {         'amount': 100.0,         'currencycode': 'aud',         'merchantreference': 'reference',         'merchanthomepageurl': 'https://xxxxxxxxxxxxxxxxxx',         'successurl': 'https://xxxxxxxxxxxxxxx/payment_success',         'failureurl': 'https://xxxxxxxxxxxxxxx/payment_failed',         'cancellationurl': 'https://xxxxxxxxxxxxxxxxx/payment_cancelled',         'notificationurl': 'https://xxxxxxxxxxxxxxxxxxx/notification'       }.to_json     end      def header       { content_type: 'application/json', accept: :json, authorization: "basic #{authentication}" }     end      private      def authentication       user_id = rails.application.secrets.user_id       user_code = rails.application.secrets.user_code       basic_auth = "#{user_id}:#{user_code}"       base64.encode64(basic_auth).gsub!("\n", '')     end   end end 

when controller calling method model store::payment.new.initiate error {"message":"authorization has been denied request."}.

but if call method directly rails console works fine

$ rails c (irb) >> store = store::payment.new.initiate => "https://xxxxxxxxx" 

i not able figure out, why calling same method controller fails works fine rails console.


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -