/home/desid573/public_html/verde/xero/XeroOAuth-PHP-master
Edit: /home/desid573/public_html/verde/xero/XeroOAuth-PHP-master/addBillingContact.php (6378B)
'51DABYIYXXBZDHAZTVAXBX6TU7T3AT',
'shared_secret' => 'RE390CCDJV1VD29SUZI9VBWTVUV7VF',
// API versions
'core_version' => '2.0',
'payroll_version' => '1.0',
'file_version' => '1.0'
);
if (XRO_APP_TYPE == "Private" || XRO_APP_TYPE == "Partner") {
$signatures ['rsa_private_key'] = BASE_PATH . '/certs/privatekey.pem';
$signatures ['rsa_public_key'] = BASE_PATH . '/certs/publickey.cer';
}
$XeroOAuth = new XeroOAuth ( array_merge ( array (
'application_type' => XRO_APP_TYPE,
'oauth_callback' => OAUTH_CALLBACK,
'user_agent' => $useragent
), $signatures ) );
include 'tests/testRunner.php';
$initialCheck = $XeroOAuth->diagnostics ();
$checkErrors = count ( $initialCheck );
if ($checkErrors > 0) {
// you could handle any config errors here, or keep on truckin if you like to live dangerously
foreach ( $initialCheck as $check ) {
error_log( 'Error: ' . $check . PHP_EOL);
}
} else {
$session = persistSession ( array (
'oauth_token' => $XeroOAuth->config ['consumer_key'],
'oauth_token_secret' => $XeroOAuth->config ['shared_secret'],
'oauth_session_handle' => ''
) );
$oauthSession = retrieveSession ();
}
// function checkEmail($XeroOAuth) {
// $params = array(
// 'Where' => 'EmailAddress != null AND EmailAddress.Contains("'.$_POST['email'].'")'
// );
// $response = $XeroOAuth->request('GET', $XeroOAuth->url('Contacts', 'core'), $params);
// if ($XeroOAuth->response['code'] == 200) {
// $contacts = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
// if(count($contacts->Contacts[0]) > 0) {
// error_log("There are " . count($contacts->Contacts[0]). " contacts with email ".$_POST['email']." in this Xero organisation
");
// updateContact($XeroOAuth, $contacts->Contacts[0]->Contact->ContactID);
// } else {
// checkPhone($XeroOAuth);
// }
// } else {
// error_log(outputError($XeroOAuth));
// }
// }
function checkName($XeroOAuth) {
$params = array(
'Where' => 'Name.Contains("'.$_POST['name'].'")'
);
$response = $XeroOAuth->request('GET', $XeroOAuth->url('Contacts', 'core'), $params);
if ($XeroOAuth->response['code'] == 200) {
$contacts = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
if(count($contacts->Contacts[0]) > 0) {
error_log("There are " . count($contacts->Contacts[0]). " contacts named ".$_POST['name']." in this Xero organisation
");
error_log(Contacts[0]->Contact->Name);
updateContact($XeroOAuth, $contacts->Contacts[0]->Contact->ContactID);
} else {
createContact($XeroOAuth);
}
} else {
error_log(outputError($XeroOAuth));
}
}
function updateContact($XeroOAuth, $contactID) {
if($_POST['name'] != "") {
$name = "
".$_POST['name']."";
} else {
$name = "";
}
if($_POST['email'] != "") {
$email = "
".$_POST['email']."";
} else {
$email = "";
}
if($_POST['line2'] != "") {
$address = "
STREET
".$_POST['line1']."
".$_POST['line2']."
";
} else {
$address = "";
}
$xml = "
".$contactID."
".$name.$email.$address."
".$_POST["abn"]."
".$_POST["bsb"].$_POST["acc"]."
";
//error_log($xml);
$response = $XeroOAuth->request('POST', $XeroOAuth->url('Contacts/'.$contactID, 'core'), array(), $xml);
if ($XeroOAuth->response['code'] == 200) {
$contact = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
error_log("" . count($contact->Contacts[0]). " contact updated in this Xero organisation.");
if (count($contact->Contacts[0])>0) {
error_log($contact->Contacts[0]->Contact);
}
} else {
//error_log(outputError($XeroOAuth));
}
}
function createContact($XeroOAuth) {
if($_POST['name'] != "") {
$name = "
".$_POST['name']."";
} else {
return;
}
if($_POST['email'] != "") {
$email = "
".$_POST['email']."";
} else {
$email = "";
}
if($_POST['address'] != "") {
$address = "
STREET
".$_POST['address']."
".$_POST['line2']."
";
} else {
$address = "";
}
$xml = "
".$name.$email.$address."
".$_POST["abn"]."
".$_POST["bsb"].$_POST["acc"]."
";
$response = $XeroOAuth->request('POST', $XeroOAuth->url('Contacts', 'core'), array(), $xml);
if ($XeroOAuth->response['code'] == 200) {
$contact = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
error_log("" . count($contact->Contacts[0]). " contact created in this Xero organisation.");
if (count($contact->Contacts[0])>0) {
error_log("The first one is: ".$contact->Contacts[0]->Contact);
}
} else {
// error_log(outputError($XeroOAuth));
}
}