Ruby on Rails integration with Quickbooks not working

我的梦境 提交于 2019-12-12 03:17:19

问题


I followed the instructions from this blog, aware that it is quite old. http://minimul.com/integrating-rails-and-quickbooks-online-via-the-version-3-api-part-1.html

I successfully get the 'Connect to Quickbooks' button on my web app but on clicking it, I get the following error.

NoMethodError in VendorsController#authenticate
undefined method `get_request_token' for nil:NilClass

The source of the error seems to be this line in my vendors controller authenticate action:

token = $qb_oauth_consumer.get_request_token(:oauth_callback => callback)

I have found answers on intuit forum that I should check the box in front of Quickbooks and uncheck it for Payments in my App settings. I have done tht too. This doesn't take me to the authorize page either!

/app/contollers/vendors.rb

class VendorsController < ApplicationController
  before_action :set_vendor, only: [:show, :edit, :update, :destroy]

  # GET /vendors
  # GET /vendors.json
  def index
    @vendors = Vendor.all
  end

  # GET /vendors/1
  # GET /vendors/1.json
  def show
  end

  # GET /vendors/new
  def new
    @vendor = Vendor.new
  end

  # GET /vendors/1/edit
  def edit
  end

  # POST /vendors
  # POST /vendors.json
  def create
    @vendor = Vendor.new(vendor_params)

    respond_to do |format|
      if @vendor.save
        format.html { redirect_to @vendor, notice: 'Vendor was     successfully created.' }
        format.json { render action: 'show', status: :created, location: @vendor }
      else
        format.html { render action: 'new' }
        format.json { render json: @vendor.errors, status: :unprocessable_entity }
      end
    end
  end

  # PATCH/PUT /vendors/1
  # PATCH/PUT /vendors/1.json
  def update
    respond_to do |format|
      if @vendor.update(vendor_params)
        format.html { redirect_to @vendor, notice: 'Vendor was successfully updated.' }
        format.json { head :no_content }
      else
        format.html { render action: 'edit' }
        format.json { render json: @vendor.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /vendors/1
  # DELETE /vendors/1.json
  def destroy
    @vendor.destroy
    respond_to do |format|
      format.html { redirect_to vendors_url }
      format.json { head :no_content }
    end
  end

  def authenticate
    callback = oauth_callback_vendors_url
   *token = $qb_oauth_consumer.get_request_token(:oauth_callback => callback)*
    session[:qb_request_token] = Marshal.dump(token)
    redirect_to("https://appcenter.intuit.com/Connect/Begin?oauth_token=#{token.token}") and return
  end

  def oauth_callback
    at =  Marshal.load(session[:qb_request_token]).get_access_token(:oauth_verifier => params[:oauth_verifier])
    session[:token] = at.token
    session[:secret] = at.secret
    session[:realm_id] = params['realmId']
    redirect_to root_url, notice: "Your QuickBooks account has been successfully linked."
  end


  private
    # Use callbacks to share common setup or constraints between actions.
      def set_vendor
      @vendor = Vendor.find(params[:id])
    end

# Never trust parameters from the scary internet, only allow the white list through.
    def vendor_params
  params.require(:vendor).permit(:name)
end
end

The view file is as follows:

<!--Quickbooks stuff-->
<!-- this will display a button that the user clicks to start the flow -->
<% unless session[:token] %>
<ipp:connectToIntuit></ipp:connectToIntuit>
 <% end %>`

<script type="text/javascript" src="https://appcenter.intuit.com/Content/IA/intuit.ipp.anywhere.js"></script>
                <!-- configure the Intuit object: 'grantUrl' is a URL in your application which kicks off the flow, see below -->
                <script>
  intuit.ipp.anywhere.setup({menuProxy: '/path/to/blue-dot', grantUrl: '<%= authenticate_vendors_url %>'});
</script>

</body>

the config/initializer/quickbooks.rb file

#Trying with custom code from "https://github.com/ruckus/quickbooks-ruby"
OAUTH_CONSUMER_KEY = "my app key"
OAUTH_CONSUMER_SECRET = "My APP Secret"


::QB_OAUTH_CONSUMER = OAuth::Consumer.new(OAUTH_CONSUMER_KEY,     OAUTH_CONSUMER_SECRET, {
    :site                 => "https://oauth.intuit.com",
    :request_token_path   => "/oauth/v1/get_request_token",
    :authorize_url        => "https://appcenter.intuit.com/Connect/Begin",
    :access_token_path    => "/oauth/v1/get_access_token"
})

The following is my gemfile.

source 'https://rubygems.org'
gem 'nokogiri'
gem 'rack'
gem 'rails', '4.2.6'
#Action caching for Action Pack (removed from core in Rails 4.0).
gem 'actionpack-action_caching'
gem 'bootstrap-sass'
gem 'autoprefixer-rails'
gem 'bundler', '~>1.12.5' 
# Use SCSS for stylesheets
gem 'sass-rails'
#charting rails
gem 'highcharts-rails'
gem 'quickbooks-ruby'
gem 'oauth-plugin'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read     more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc

gem 'heroku'
#Passwordless Authentication
gem 'omniauth', '~> 1.3.1'
gem 'omniauth-auth0', '~> 1.4.1'
#DynoPoker to ping dyno every 30 mins so that loading time is not     slow....hopefully!
gem 'dynopoker'
gem 'stripe'

group :development do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  #gem 'byebug'
  # Use sqlite3 as the database for Active Record
gem 'pg'
end

group :production do 
gem 'rails_12factor'
gem 'therubyracer'
end

group :test do
gem 'rspec'
end

And i use ruby 2.3.0

Any ideas what I am doing wrong?


回答1:


Your grant URL is incorrect:

<!-- configure the Intuit object: 'grantUrl' is a URL in your application which kicks off the flow, see below -->
...
 grantUrl: 'https://appcenter.intuit.com/Playground/OAuth/BeginIAFlow', 

The grant URL is a URL that you control, in your application. You should not be setting it to an intuit.com URL. It should be YOUR URL that kicks off the OAuth process.



来源:https://stackoverflow.com/questions/39027482/ruby-on-rails-integration-with-quickbooks-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!