Search code examples
ruby-on-rails-3.2rubygemsquickbooks

quickeebook gem : PUSH postal_code, city, line1, line2 fields in quickbook?


I am using rails 3.2 and quickeebook gem for connecting quickbooks online. Now the connection between my rails application and quickbook is done, but I am facing new problem in it.

When I am trying to save customer.name in quickbook it is successfully saving through my controller but if I try to pass fields like customer.id, customer.email, customer.zipcode, customer.phone, etc. It is generating errors. How can I save this data using quickeebook gem

Oh sory, I forget to explain about error and codes

oauth_client = OAuth::AccessToken.new($qb_oauth_consumer, current_login.access_token, current_login.access_secret)


    #creating customer in quickbooks
    customer_service = Quickeebooks::Online::Service::Customer.new
    customer_service.access_token = oauth_client
    customer_service.realm_id = current_login.realm_id
    customer_service.list

    customer = Quickeebooks::Online::Model::Customer.new
    customer.name = "New Customer2"
    customer.email_address = "[email protected]"
    customer.given_name = "New"
    customer.middle_name = "H."
    customer.family_name = "Customer"
    customer.phone = "9845845854"
    customer.web_site = "www.google.com"
    customer.billing_address = "this is billing address"
    customer.city = "Bangalore"
    customer_service.create(customer)

suppose, I want to insert these fields in quickbooks online. But this is generating errors like :

undefined method `to_xml' for "9845845854":String

Other fields upto family_name are working perfectly, But for fields like phone, address, web_site, city, whenever i want to push these values to quickbooks errors like:

undefined method `to_xml' for "9845845854":String
undefined method `to_xml' for "www.google.com":string
undefined method `city=' for #<Quickeebooks::Online::Model::Customer:0xb5150e68>

are comming. How to fix this error?


Solution

  • Finally, The problem is solved....

    postal_code, line1, line2, city, etc. fields are related to addresses field. so instead of writing

    customer.city = "Bangalore"
    

    we have to first inherit the address model and we have to pass address array in customer like:

        address = Quickeebooks::Online::Model::Address.new
        address.line1 = "address 1"
        address.line2 = "my fake address"
        address.city = "awesome city"
        address.country_sub_division_code = "wooooooo..."
        address.postal_code = "12345"
        customer.addresses = [address]
    

    similarly, for phone number:

        phone1 = Quickeebooks::Online::Model::Phone.new
        phone1.device_type = "Primary"
        phone1.free_form_number = "973-855-0394"
        phone2 = Quickeebooks::Online::Model::Phone.new
        phone2.device_type = "Mobile"
        phone2.free_form_number = "5458565298"
        phone3 = Quickeebooks::Online::Model::Phone.new
        phone3.device_type = "Fax"
        phone3.free_form_number = "5458565298"
        customer.phones = [phone1, phone2, phone3]
    

    and so on....