Skip to content

Instantly share code, notes, and snippets.

@tijs
Created October 23, 2009 14:00
Show Gist options
  • Save tijs/216896 to your computer and use it in GitHub Desktop.
Save tijs/216896 to your computer and use it in GitHub Desktop.
<?php
//...snip...
/**
* Update MoneyBird Contact
*
* Update and existing contact using the MoneyBird API
*
* @access private
* @return contact
*/
function __updateContact($user_id) {
// load MoneyBird API
Configure::load('settings');
App::import('Vendor', 'moneybird' . DS . 'Api', array('file' => 'Api.php'));
$mbapi = new MoneybirdApi(Configure::read('MoneyBird.company'), Configure::read('MoneyBird.login'), Configure::read('MoneyBird.password'));
$user = $this->read(null, $user_id);
// get country list
$country = ClassRegistry::init('Country')->find('first', array(
'conditions'=>array('id'=>$user['User']['country_id'])
));
if (!empty($user['User']['moneybird_id'])) {
// Update existing contact
$contact = new MoneybirdContact;
$contact = $mbapi->getContact($user['User']['moneybird_id']);
$contact->name = (!empty($user['User']['organisation'])) ? $user['User']['organisation'] : $user['User']['name'];
$contact->contact_name = $user['User']['name'];
$contact->email = $user['User']['email'];
$contact->address1 = $user['User']['address'];
$contact->zipcode = $user['User']['zipcode'];
$contact->city = $user['User']['city'];
$contact->phone = $user['User']['tel'];
$contact->tax_number = $user['User']['tax_number'];
$contact->country = $country['Country']['name'];
return $mbapi->saveContact($contact);
}
}
//...snip...
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment