youngguns-nl / moneybird_php_api

A PHP Library for the MoneyBird API
http://www.moneybird.nl
MIT License
37 stars 14 forks source link

Incorrect validation #19

Closed erik-maas closed 12 years ago

erik-maas commented 12 years ago

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.

pluijm commented 12 years ago

Can you give example code how this fails? How is the contact you're validating created?

pluijm commented 12 years ago

There is a newer version of the library btw

erik-maas commented 12 years ago

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?

pluijm commented 12 years ago

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.

erik-maas commented 12 years ago

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).

pluijm commented 12 years ago

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.

pluijm commented 12 years ago

Any progress?

pluijm commented 12 years ago

No feedback in 17 days, closing the ticket. Please reopen if needed