问题
I'm working on a Saas and have been using Keith Palmer's PHP Dev Kit.
For the most part, it has worked really well - I can download customers, add customers and add invoices which is what I wanted to achieve.
However, when Adding the customer, I don't seem to be able to add the address and phone details. I've tried various strategies and none have worked. As I need to sync the data to some degree, I really need it to add these fields.
My Customer object is created with $Customer = new QuickBooks_IPP_Object_Customer();
I tried creating a
$Address = new QuickBooks_IPP_Object_Address()
and then adding with $Customer->addAddress($Address)
after populating the address object, but still nothing.
The basic details are saved fine, but what am I doing wrong with the address?
I looked through the examples (which is how I got the basic details to save) but didn't see how to add this.
Does anyone know how to save the address details?
回答1:
Assuming you're using the newest, v3 APIs, and the latest code from GitHub, your code should look something like this:
$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 . ']');
}
else
{
print($CustomerService->lastError($Context));
}
You can get the latest code here:
- Open-source QuickBooks PHP DevKit on GitHub
It includes an example here:
- Example of adding a customer to QuickBooks Online with PHP
The methods available for the objects exactly mirror the XML node names that Intuit defines in their docs.
So, if they have a node named:
- BillAddr
Then you'll have a corresponding object:
- QuickBooks_IPP_Object_BillAddr
And if they have nodes names:
- Line1
- Line2
- City
- CountrySubDivisionCode
Then you'll have corresponding methods:
- ->setLine1($val) and ->getLine1()
- ->setLine2($val) and ->getLine2()
- ->setCity($val) and ->getCity()
- ->setCountrySubDivisionCode($val) and ->getCountrySubDivisionCode()
来源:https://stackoverflow.com/questions/20387302/adding-a-customer-with-address-details-to-quickbooks