function acumulus_inject_gateway($vars) { $vars = array_merge($vars, getAddonVars()); if ($vars['filename'] != 'configgateways') { return; } $api = new api($vars['code'], $vars['username'], $vars['password']); $api->setCategory('picklists')->setAction('picklist_accounts'); $api->execute(); $response = $api->getResponse(); if ($api->hasErrors()) { $response = array(); $response['accounts'] = array(); $response['accounts']['account'] = array(); $response['accounts']['account'][] = array('accountid' => '', 'accountnumber' => 'API errors', 'accountdescription' => null); foreach ($api->getErrors() as $error) { $response['accounts']['account'][] = array('accountid' => '', 'accountnumber' => $error['code'], 'accountdescription' => $error['message']); } } $inject = '<script>'; $gatewayQuery = mysql_query('SELECT name.gateway, acumulus_account.value AS acumulus_account FROM tblpaymentgateways AS name LEFT JOIN tblpaymentgateways AS acumulus_account ON acumulus_account.setting = "acumulusAccount" AND acumulus_account.gateway = name.gateway WHERE name.setting = "name"'); while ($gatewayFetch = mysql_fetch_assoc($gatewayQuery)) { $inject .= '$(\'#Payment-Gateway-Config-' . $gatewayFetch['gateway'] . '\').find(\'tr:last\').before(\'<tr><td class="fieldlabel">Acumulus rekening</td><td class="fieldarea"><select name="field[acumulusAccount]">'; foreach ($response['accounts']['account'] as $action) { $inject .= '<option value="' . $action['accountid'] . '" ' . ($gatewayFetch['acumulus_account'] == $action['accountid'] ? 'selected="selected"' : '') . '>' . $action['accountnumber'] . '' . (is_string($action['accountdescription']) ? ' - ' . $action['accountdescription'] : '') . '</option>'; } $inject .= '</select>Voeg alle facturen met deze betaalmethode toe aan een bepaalde rekening, <a href="https://wiki.acumulus.nl/index.php?page=payment-service-provider" target="_blank">zie hier waarom</a>.</td></tr>\');'; } $inject .= '</script>'; return $inject; }
/** * Updates a customer at Acumulus * @param $vars : $vars from the hook for API credentials * @param $clientid : clientid to update * @param null $customerid : customerid at Acumulus to update * @throws Exception * @return $customerid : new/updated customerid at Acumulus */ function updateCustomer($vars, $clientid, $customerid = null) { global $whmcs; $whmcs->load_function('invoice'); $clientQuery = mysql_query('SELECT tblclients.*, tblcustomfieldsvalues.value AS vatnumber FROM tblclients LEFT JOIN tblcustomfieldsvalues ON tblclients.id = tblcustomfieldsvalues.relid AND tblcustomfieldsvalues.fieldid = (SELECT id FROM tblcustomfields WHERE type = "client" AND fieldname = "' . $vars['vat_field'] . '" LIMIT 1) WHERE tblclients.id = ' . $clientid . ' LIMIT 1'); if (mysql_num_rows($clientQuery) != 1) { throw new Exception('Failed to receive client ' . $clientid); } $clientFetch = mysql_fetch_assoc($clientQuery); $api = new api($vars['code'], $vars['username'], $vars['password']); $api->setCategory('contacts')->setAction('contact_manage'); if (isset($vars['debug']) && $vars['debug'] == 'on') { $api->enableDebug($vars['debug_email']); } if ($clientFetch['acumulusid'] != null) { $api->setParam('contact/contactid', $clientFetch['acumulusid']); } if ($customerid != null) { $api->setParam('contact/contactid', $customerid); } if ($clientFetch['country'] == 'NL') { $api->setParam('contact/contactlocationcode', 1); } elseif (inEurope($clientFetch['country'])) { $api->setParam('contact/contactlocationcode', 2); } else { $api->setParam('contact/contactlocationcode', 3); } $taxData = getTaxRate(1, $clientQuery['state'], $clientQuery['country']); $api->setParams(array('contact' => array('contactemail' => $clientFetch['email'], 'contacttype' => 1, 'overwriteifexists' => 1, 'contactname1' => ucfirst($clientFetch['firstname']) . ' ' . $clientFetch['lastname'], 'contactname2' => '', 'contactperson' => '', 'contactsalutation' => '', 'contactaddress1' => $clientFetch['address1'], 'contactaddress2' => $clientFetch['address2'], 'contactpostalcode' => $clientFetch['postcode'], 'contactcity' => $clientFetch['city'], 'contactcountrycode' => inEurope($clientFetch['country']) ? $clientFetch['country'] : '', 'contactvatnumber' => $clientFetch['vatnumber'], 'contactvatratebase' => $clientFetch['taxexempt'] == 'on' ? -1 : round($taxData['rate']), 'contacttelephone' => $clientFetch['phonenumber'], 'contactfax' => '', 'contactsepaincassostatus' => 'FRST', 'contactinvoicetemplateid' => '', 'contactstatus' => 1))); if (!empty($clientFetch['companyname'])) { $api->setParams(array('contact' => array('contactname1' => $clientFetch['companyname'], 'contactperson' => ucfirst($clientFetch['firstname']) . ' ' . $clientFetch['lastname']))); } $api->execute(); $response = $api->getResponse(); if ($api->hasErrors()) { $errors = ''; foreach ($api->getErrors() as $error) { $errors = $error['code'] . ' - ' . $error['message'] . ', '; } logActivity('Acumulus API error(s): ' . substr($errors, 0, -2)); return false; } else { mysql_query('UPDATE tblclients SET acumulusid = ' . $response['contact']['contactid'] . ' WHERE id = ' . $clientid . ' LIMIT 1'); return $response['contact']['contactid']; } }
function acumulus_sync_vat($vars) { $taxQuery = select_query('tbltax'); while ($taxFetch = mysql_fetch_assoc($taxQuery)) { $api = new api($vars['code'], $vars['username'], $vars['password']); $api->setCategory('lookups')->setAction('lookup_vatinfo'); $api->setParam('vatcountry', $taxFetch['country']); $api->execute(); $response = $api->getResponse(); foreach ($response['vatinfo']['vat'] as $vat) { if ($vat['vattype'] == 'normal') { update_query('tbltax', array('taxrate' => $vat['vatrate']), array('id' => $taxFetch['id'])); } } } }