Closed erik-maas closed 12 years ago
Can you give example code how this fails? How is the contact you're validating created?
There is a newer version of the library btw
I'm creating a whmcs hook. And this is what the used function looks like: function create_contact($vars) { require dirname(FILE) . '/moneybird/libConnector.php'; $contactService = $connector->getService('Contact'); $contact = new Moneybird\Contact(array( 'companyName' => $vars['companyname'], // 'attention' => '', 'contactName' => $vars['firstname'] . ' ' . $vars['lastname'], 'address1' => $vars['address1'], 'address2' => $vars['address2'], 'zipcode' => $vars['postcode'], 'city' => $vars['city'], 'country' => $vars['country'], // 'bankAccount' => '', // 'chamberOfCommerce' => '', 'email' => $vars['email'], 'customerId' => $vars['userid'], 'phone' => $vars['phonenumber'], 'sendMethod' => 'email', // 'taxNumber' => '', )); $contact->save($contactService); }
and in libconnector i have: require_once dirname(FILE) . '/ApiConnector.php'; spl_autoload_register('Moneybird\ApiConnector::autoload'); $transport = new Moneybird\HttpClient(); $transport->setAuth( 'username', // put your username here 'password' // put your password here ); $connector = new Moneybird\ApiConnector( 'clientname', // put your client name here (<...>.moneybird.nl) $transport, new Moneybird\XmlMapper() // create a mapper );
When did this newer version come out? And what is changed?
You are setting a read-only attribute (contactName), use firstname and lastname. This won't fix your issue though.
The new version was pushed yesterday. Issues #16, #17 and #18 were resolved. Issue #18 fixes a bug in getByIds(), which is used for syncing contacts and invoices.
Aah, yes, so i've seen. Though moneybird is pure slave in this matter, with no oAuth needed (and i still require the customerId for myself). So i havn't yet implemented that version (first get things running, then update and fix).
With the following values for $vars, validate() returns true:
$vars = array(
'companyname' => 'company',
'firstname' => 'fn',
'lastname' => 'ln',
'address1' => 'add1',
'address2' => 'add2',
'postcode' => 'pc',
'city' => 'city',
'country' => 'country',
'email' => 'email',
'userid' => 'uid',
'phonenumber' => 'tel',
);
My guess is that your $vars array contains null values.
Any progress?
No feedback in 17 days, closing the ticket. Please reopen if needed
The function validate in domaincontroller/Abstract.php always returns false. This is becouse the function checks for empty attributes in an array that only has those.
function: protected function validate() { foreach ($this->_requiredAttr as $attr) { if (is_array($attr)) { $valid = false; foreach ($attr as $sub) { if (!is_null($this->$sub)) { $valid = true; break; } } if (!$valid) { return false; } } elseif (is_null($this->$attr)) { return false; } } return true; }
what it checks: protected $_requiredAttr = array( 'customerId', 'email', array('companyName', 'firstname', 'lastname',), );
My dirty workaround is just skipping the whole validation, and just return true. It does work so far.