Skip to content
This repository has been archived by the owner on Nov 10, 2017. It is now read-only.

Way to handle quickbooks exceptions? #101

Open
przbadu opened this issue Sep 20, 2013 · 6 comments
Open

Way to handle quickbooks exceptions? #101

przbadu opened this issue Sep 20, 2013 · 6 comments

Comments

@przbadu
Copy link

przbadu commented Sep 20, 2013

Hello there,

Can you tell me the way to handle quickbooks exceptions in rails. I am getting strange errors and exceptions some times and sometime same code is working perfectly.

1. Another $$customer$$ is already using this \nname

2. The website address you entered is not valid

3.  java.lang.NumberFormatException: For input string: ""

First error rise up because I am pushing customer which is already exists in quickbooks online. Yes, there is another way to track this error, that is checking customer before pushing to the quickbooks.

I think, second error rise up because user have passed only "http://" in website field. Instead of checking these error seperately, Can I add the quickbook error message in my error message and display the current page instead of going to the error page?

Third one is an exception itself. So, I need a way to handle these exceptions and other unknown exceptions that may arise in near future. How can I fix that?

Thanks in advance

@ruckus
Copy link
Owner

ruckus commented Sep 20, 2013

You can call valid? on a Customer record to check for validity:

> c = Quickeebooks::Windows::Model::Customer.new
> c.valid?
=> false
> c.errors
 => #<ActiveModel::Errors:0x007fed283dc710 @base=#<Quickeebooks::Windows::Model::Customer:0x007fed283e4460 @validation_context=nil, @errors=#<ActiveModel::Errors:0x007fed283dc710 ...>>, @messages={:name=>["is too short (minimum is 1 characters)"], :addresses=>["Must provide at least one address for this Customer."]}>

But in the case of your 2nd error you might want to do your own URL format validation.

As for your 3rd error, I have no idea where that is coming from. Can you please give me more information on the source of that error? Nonetheless its definitely coming from Intuit as they are on the JVM.

@przbadu
Copy link
Author

przbadu commented Sep 21, 2013

Actually third exception is comming whenever I am trying to push sub-customer to quickbooks. Here, jobsites is used for indicating sub-customer My code looks like:

#push jobsite into quickbook as job
  def push_jobsite_to_quickbook(jobsites)
    #push data to quickbook
    oauth_client = OAuth::AccessToken.new($qb_oauth_consumer, current_company.access_token, current_company.access_secret)

    jobsite_service = Quickeebooks::Online::Service::Job.new
    jobsite_service.access_token = oauth_client
    jobsite_service.realm_id = current_company.realm_id


    jobsite = Quickeebooks::Online::Model::Job.new

    # find quickbook_customer_id
    # this is parent customer id
    @parent_customer = current_company.customers.find(@jobsite.customer_id)

    # parent customer information
    sub_customer = Quickeebooks::Online::Model::Id.new
    sub_customer.value = @parent_customer.quickbook_customer_id #push parent customer_id 
    jobsite.customer_name = @parent_customer.company_name    # parent customer name

    jobsite.customer_id = sub_customer
    # end of parent customer information

    # push sub-customer information
    jobsite.name = @jobsite.name

    address = Quickeebooks::Online::Model::Address.new
    address.city = @jobsite.city
    address.country_sub_division_code = @jobsite.state
    address.postal_code = @jobsite.zip
    jobsite.addresses = [address]

    jobsite_service.create(jobsite)
  end

Now I am calling this action in create action and getting :

java.lang.NumberFormatException: For input string: ""

It was pushing sub-customer data properly in the quickbook but suddenly It is generating above exceptions from 5/6 days.

@ruckus
Copy link
Owner

ruckus commented Sep 21, 2013

I'd like to see the XML this generates - here is how to do that: right before your create() call at the very end do something like this:

Rails.logger.info(jobsite.to_xml.to_s)

And reply back with the XML output.

On Sep 21, 2013, at 4:15 AM, Pushpa Raj Badu [email protected] wrote:

Actually third exception is comming whenever I am trying to push sub-customer to quickbooks. Here, jobsites is used for indicating sub-customer My code looks like:

#push jobsite into quickbook as job
def push_jobsite_to_quickbook(jobsites)
#push data to quickbook
oauth_client = OAuth::AccessToken.new($qb_oauth_consumer, current_company.access_token, current_company.access_secret)

jobsite_service = Quickeebooks::Online::Service::Job.new
jobsite_service.access_token = oauth_client
jobsite_service.realm_id = current_company.realm_id


jobsite = Quickeebooks::Online::Model::Job.new

# find quickbook_customer_id
# this is parent customer id
@parent_customer = current_company.customers.find(@jobsite.customer_id)

# parent customer information
sub_customer = Quickeebooks::Online::Model::Id.new
sub_customer.value = @parent_customer.quickbook_customer_id #push parent customer_id 
jobsite.customer_name = @parent_customer.company_name    # parent customer name

jobsite.customer_id = sub_customer
# end of parent customer information

# push sub-customer information
jobsite.name = @jobsite.name

address = Quickeebooks::Online::Model::Address.new
address.city = @jobsite.city
address.country_sub_division_code = @jobsite.state
address.postal_code = @jobsite.zip
jobsite.addresses = [address]

jobsite_service.create(jobsite)

end

Now I am calling this action in create action and getting :

java.lang.NumberFormatException: For input string: ""

It was pushing sub-customer data properly in the quickbook but suddenly It is generating above exceptions from 5/6 days.


Reply to this email directly or view it on GitHub.

@przbadu
Copy link
Author

przbadu commented Oct 1, 2013

Hello,

I have tried a lot but now third problem is working fine.

c = Quickeebooks::Windows::Model::Customer.new
> c.valid?
=> false
> c.errors
 => #<ActiveModel::Errors:0x007fed283dc710 @base=#<Quickeebooks::Windows::Model::Customer:0x007fed283e4460 @validation_context=nil, @errors=#<ActiveModel::Errors:0x007fed283dc710 ...>>, @messages={:name=>["is too short (minimum is 1 characters)"], :addresses=>["Must provide at least one address for this Customer."]}>

you have suggest me this for responding with error message, but first thing, I am using Quickbook Online version and it is generating NoMethodError:

NoMethodError: undefined method `valid?' for #<Quickeebooks::Online::Service::Customer:0xa426148>

@przbadu
Copy link
Author

przbadu commented Oct 1, 2013

Hello,

I have tried a lot but now third problem i.e.

java.lang.NumberFormatException: For input string: ""

not generating.

But,

c = Quickeebooks::Windows::Model::Customer.new
> c.valid?
=> false
> c.errors
 => #<ActiveModel::Errors:0x007fed283dc710 @base=#<Quickeebooks::Windows::Model::Customer:0x007fed283e4460 @validation_context=nil, @errors=#<ActiveModel::Errors:0x007fed283dc710 ...>>, @messages={:name=>["is too short (minimum is 1 characters)"], :addresses=>["Must provide at least one address for this Customer."]}>

you have suggest me aboce code for responding with error message [if any], but first thing, I am using Quickbook Online version and it is generating NoMethodError:

NoMethodError: undefined method `valid?' for #<Quickeebooks::Online::Service::Customer:0xa426148>

I think valid? function is defined in desktop version only.

@ruckus
Copy link
Owner

ruckus commented Oct 1, 2013

If you're using QB Online then why are you instantiating a QB Windows object?

c = Quickeebooks::Windows::Model::Customer.new

You should be generating a QB Online Customer object?

c = Quickeebooks::Online::Model::Customer.new

NoMethodError: undefined method `valid?' for #Quickeebooks::Online::Service::Customer:0xa426148

valid? is an instance method on an an instance of a Customer model object - not a Service object.

E.g.

c = Quickeebooks::Online::Model::Customer.new
c.valid?
=> false
c.errors
=> ... complains about name being too short...

On Sep 30, 2013, at 10:31 PM, Pushpa Raj Badu [email protected] wrote:

Hello,

I have tried a lot but now third problem is working fine.

c = Quickeebooks::Windows::Model::Customer.new

c.valid?
=> false
c.errors

=> #<ActiveModel::Errors:0x007fed283dc710 @base=#<Quickeebooks::Windows::Model::Customer:0x007fed283e4460 @validation_context=nil, @errors=#<ActiveModel::Errors:0x007fed283dc710 ...>>, @messages={:name=>["is too short (minimum is 1 characters)"], :addresses=>["Must provide at least one address for this Customer."]}>
you have suggest me this for responding with error message, but first thing, I am using Quickbook Online version and it is generating NoMethodError:

NoMethodError: undefined method `valid?' for #Quickeebooks::Online::Service::Customer:0xa426148

Reply to this email directly or view it on GitHub.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants