QuickBooks_Utilities::initialize($api_driver_dsn); // QuickBooks_Utilities::createUser($api_driver_dsn, 'api', 'password'); } $API = new QuickBooks_API($api_driver_dsn, $user, $source_type, $source_dsn, $api_options, $source_options, $driver_options); // CUSTOMERS $fname = 'Shannon ' . mt_rand(); $lname = 'Daniels'; $Customer = new QuickBooks_Object_Customer(); $Customer->setFirstName($fname); $Customer->setLastName($lname); $Customer->setShipAddress('56 Cowles Road', '', '', '', '', 'Willington', 'CT'); $Customer->setMiddleName('R'); $Customer->setSalutation('Mr.'); $Customer->setPhone('1.860.634.1602'); $API->addCustomer($Customer, '_quickbooks_customer_add_callback', 15); // INVOICES $Invoice = new QuickBooks_Object_Invoice(); //$Invoice->setOther('test of other'); // for some reason this field doesn't work... $Invoice->setMemo('test of a memo'); $Invoice->setCustomerApplicationID(15); $Invoice->setRefNumber(125); $InvoiceLine1 = new QuickBooks_Object_Invoice_InvoiceLine(); $InvoiceLine1->setItemApplicationID(12); $InvoiceLine1->setAmount(300.0); $InvoiceLine1->setQuantity(3); $InvoiceLine2 = new QuickBooks_Object_Invoice_InvoiceLine(); $InvoiceLine2->setItemApplicationID(11); $InvoiceLine2->setAmount(225.0); $InvoiceLine2->setQuantity(5); $Invoice->addInvoiceLine($InvoiceLine1);
// Country $Customer->setMiddleName('B.'); $Customer->setSalutation('Ms.'); $Customer->setPhone('1.860.634.1602'); // Queue up the actual request to be sent to QuickBooks via the Web Connector // // Notice that we also provide the primary key of this customer from within our // application, so we can create a mapping which maps this customer to the // QuickBooks primary key. // // We also provide a priority, we want to make sure that this request runs // *before* the request below, because we need to create the customer *before* // we create an invoice for them. Higher priorities run sooner. $primary_key_of_customer_in_your_application = 20; $priority_of_add_customer_request = 25; if ($API->addCustomer($Customer, '_quickbooks_ca_customer_add_callback', $primary_key_of_customer_in_your_application, $priority_of_add_customer_request)) { print 'Queued up a request to add customer #' . $primary_key_of_customer_in_your_application . ', "' . $Customer->getName() . '" to QuickBooks!' . "\n"; } // Adding an invoice to QuickBooks // // This shows an example of queueing up a request to add a new invoice to // QuickBooks. The process for adding estimates, purchase orders, and sales // receipts is *very* similar to the process for adding invoices. $primary_key_of_invoice_in_your_application = 125; // Create the new invoice object $Invoice = new QuickBooks_Object_Invoice(); // We're going to assign this invoice to the customer we created above, #20, // "Shannon Daniels". There are a few ways you can refer to that customer. You // can refer to them by their Name/FullName attribute ("Shannon's Company" in // the example shown above), by their ListID (a primary key within QuickBooks) // or, if you've created a mapping between the customer's primary key within
print 'Our real-time response from QuickBooks Online Edition was: '; print_r($return); } exit; // You can also create QuickBooks_Object_* instances and send them directly to // QBOE via the API as show below. The API takes care of transforming those // objects to valid qbXML requests for you. $name = 'Keith Palmer (' . mt_rand() . ')'; $Customer = new QuickBooks_Object_Customer(); $Customer->setName($name); $Customer->setShipAddress('134 Stonemill Road', '', '', '', '', 'Storrs', 'CT', '', '06268'); // Just a demo showing how to generate the raw qbXML request print 'Here is the qbXML request we\'re about to send to QuickBooks Online Edition: ' . "\n"; print $Customer->asQBXML('CustomerAdd'); // Send the request to QuickBooks $API->addCustomer($Customer, '_add_customer_callback', 15); // This is our callback function, this will get called when the customer is added successfully function _add_customer_callback($method, $action, $ID, &$err, $qbxml, $Customer, $qbres) { print 'Customer #' . $ID . ' looks like this within QuickBooks Online Edition: ' . "\n"; print_r($Customer); } // Here's a demo of querying for customers with a specific name: $name = 'Keith Palmer Jr.'; // Here's how to fetch that customer by name $API->getCustomerByName($name, '_get_customer_callback', 15); function _get_customer_callback($method, $action, $ID, &$err, $qbxml, $Iterator, $qbres) { print 'This is customer #' . $ID . ' we fetched: ' . "\n"; print_r($Iterator); }