QuickBooks API (php) Integration

后端 未结 2 1020
广开言路
广开言路 2020-12-12 17:39

I am a very new to QuickBooks. I have created a trial account in Quick Books and I want to add customers, create invoices or similar sort of things to my account. I have dow

2条回答
  •  半阙折子戏
    2020-12-12 18:00

    This is going to be a two-part answer, because you didn't specify if you're using QuickBooks ONLINE, or QuickBooks for WINDOWS.

    The process will be DIFFERENT depending on which you're using, so pay attention to the bold headers below:

    For QuickBooks ONLINE:

    If you're using the open source QuickBooks PHP DevKit from GitHub, then the best place to start is the QuickBooks Online with PHP quick-start guide.

    • http://www.consolibyte.com/docs/index.php/PHP_DevKit_for_QuickBooks_-_Intuit_Partner_Platform_Quick-Start

    The very first thing you'll have to do is register your app with Intuit. When you do this, Intuit will give you these variables:

    • app token
    • consumer secret
    • consumer key

    You will substitute these variables into the config.php file that is included in the example. You'll also update these values to point to your app:

    • oauth url (e.g. your-site.com/path/to/example/oauth.php)
    • success url (e.g. your-site.com/path/to/example/success.php)
    • menu url (e.g. your-site.com/path/to/example/menu.php)
    • dsn (your database credentails for OAuth token storage)

    Beyond that, you can leave all other variables in config.php at their defaults.

    If you then visit the index.php file, it will prompt you to connect to QuickBooks. You can connect, and then visit the example files. Here are some examples of adding customers/orders to QuickBooks Online:

    • QuickBooks Online - add customer with PHP
    • QuickBooks Online - add invoice with PHP

    The code ends up looking something like:

        $CustomerService = new QuickBooks_IPP_Service_Customer();
    
        $Customer = new QuickBooks_IPP_Object_Customer();
        $Customer->setTitle('Mr');
        $Customer->setGivenName('Keith');
        $Customer->setMiddleName('R');
        $Customer->setFamilyName('Palmer');
        $Customer->setDisplayName('Keith R Palmer Jr ' . mt_rand(0, 1000));
    
        // Phone #
        $PrimaryPhone = new QuickBooks_IPP_Object_PrimaryPhone();
        $PrimaryPhone->setFreeFormNumber('860-532-0089');
        $Customer->setPrimaryPhone($PrimaryPhone);
    
        // Bill address
        $BillAddr = new QuickBooks_IPP_Object_BillAddr();
        $BillAddr->setLine1('72 E Blue Grass Road');
        $BillAddr->setLine2('Suite D');
        $BillAddr->setCity('Mt Pleasant');
        $BillAddr->setCountrySubDivisionCode('MI');
        $BillAddr->setPostalCode('48858');
        $Customer->setBillAddr($BillAddr);
    
        if ($resp = $CustomerService->add($Context, $realm, $Customer))
        {
                print('Our new customer ID is: [' . $resp . ']');
        }
    

    To implement additional functionality, you'll find other examples included in the code.

    The objects/methods available also mirror Intuit's documentation so you'll want to look at that.

    For QuickBooks for WINDOWS:

    For QuickBooks for Windows, you'll use the Web Connector. Again, start with the open source QuickBooks PHP DevKit from GitHub. Use the QuickBooks for Windows + PHP quick-start guide instead.

    That will walk you through setting up a simple Web Connector service which adds test customers to QuickBooks.

    Basically you'll create a .QWC file which you'll load into the QuickBooks Web Connector (Start > All Programs > QuickBooks > Web Connector). That .QWC file will point to a PHP script which negotiates the connection between QuickBooks and PHP. All you have to do in that example script is swap this variable:

    • $dsn (point it to your own database)

    For each new piece of functionality you want to add, you'll end up writing a new request and response function, as detailed in the QuickBooks Web Connector + PHP docs.

    Your code will end up looking something like:

    function _quickbooks_customer_add_request($requestID, $user, $action, $ID, $extra, &$err, $last_action_time, $last_actionident_time, $version, $locale)
    {
            // You'd probably do some database access here to pull the record with 
            //        ID = $ID from your database and build a request to add that particular 
            //        customer to QuickBooks. 
            //        
            // So, when you implement this for your business, you'd probably do 
            //        something like this...: 
    
            /*
            // Fetch your customer record from your database
            $record = mysql_fetch_array(mysql_query("SELECT * FROM your_customer_table WHERE your_customer_ID_field = " . (int) $ID));
    
            // Create and return a qbXML request
            $qbxml = '
                    
                    
                            
                                    
                                            
                                                    ' . $record['your_customer_name_field'] . '
                                                    ' . $record['your_customer_company_field'] . '
    
                                                    ... lots of other customer related fields ...
    
                                            
                                    
                            
                    ';
    
            return $qbxml;
            */
    
            // But we're just testing, so we'll just use a static test request:
    
            $xml = '
                    
                    
                            
                                    
                                            
                                                    ConsoliBYTE, LLC (' . mt_rand() . ')
                                                    ConsoliBYTE, LLC
                                                    Keith
                                                    Palmer
                                                    
                                                            ConsoliBYTE, LLC
                                                            134 Stonemill Road
                                                            Mansfield
                                                            CT
                                                            06268
                                                            United States
                                                    
                                                    860-634-1602
                                                    860-429-0021
                                                    860-429-5183
                                                    Keith@ConsoliBYTE.com
                                                    Keith Palmer
                                            
                                    
                            
                    ';
    
            return $xml;
    }
    

    You can find additional qbXML reference using the QuickBooks OSR.

    We also provide a wiki with lots of example qbXML requests that you can use.

提交回复
热议问题