Skip to content
This repository was archived by the owner on Nov 21, 2019. It is now read-only.

Added test for invoice and credit notes allocations #47

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions tests/testRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ function testLinks()
if (isset($_SESSION['access_token']) || XRO_APP_TYPE == 'Private')
echo '<ul>
<li><a href="?=1">Home</a></li>
<li><a href="?=1">home</a></li>
<li><a href="?organisation=1">Organisation</a></li>
<li><a href="?organisation=1&request=json">Organisation (JSON response)</a></li>
<li><a href="?accounts=1">Accounts GET</a></li>
<li><a href="?accountsfilter=1">Accounts GET - Where Type is BANK</a></li>
<li><a href="?banktransactions=1">BankTransactions GET</a></li>
<li><a href="?banktransactions=1&method=put">BankTransactions PUT</a></li>
<li><a href="?CreditNotesallocation=1&method=PUT"> Credit Notes Allocation</a></li>
<li><a href="?contacts=1">Contacts GET</a></li>
<li><a href="?contacts=1&method=post">Contacts POST</a></li>
<li><a href="?contacts=1&method=put">Contacts PUT</a></li>
Expand All @@ -25,7 +27,7 @@ function testLinks()
<li><a href="?invoice=1">Invoices GET (with order by Total example)</a></li>
<li><a href="?invoicesfilter=1">Invoices GET - Where Contact Name contains "Martin"</a></li>
<li><a href="?invoicesmodified=1">Invoices GET - If-Modified-Since</a></li>
<li><a href="?invoice=1&method=put">Invoices PUT</a></li>
<li><a href="?invoice=1&method=put">Invoices PUT (With SummarizeErrors=false)</a></li>
<li><a href="?invoice=1&method=4dp">Invoices PUT (4 decimal places)</a></li>
<li><a href="?invoice=1&method=post">Invoices POST</a></li>
<li><a href="?invoice=attachment&method=put">Invoice attachment PUT</a></li>
Expand All @@ -37,7 +39,9 @@ function testLinks()
<li><a href="?trackingcategories=1&method=getarchived">Tracking Categories - GET (+ archived)</a></li>
<li><a href="?trackingcategories=1&method=put">Tracking Categories - PUT</a></li>
<li><a href="?trackingcategories=1&method=archive">Tracking Categories - ARCHIVE</a></li>
<li><a href="?trackingcategories=1&method=restore">Tracking Categories - restore to active</a></li>';
<li><a href="?trackingcategories=1&method=restore">Tracking Categories - restore to active</a></li>
<li><a href="?GetAllLinkedTransactions=1">Get All LinkedTransactions</a></li>
<li><a href="?LinkedTransaction=1">LinkedTransaction POST</a></li>';

if (XRO_APP_TYPE == 'Partner') echo '<li><a href="?refresh=1">Refresh access token</a></li>';
if (XRO_APP_TYPE !== 'Private' && isset($_SESSION['access_token'])) {
Expand Down
61 changes: 53 additions & 8 deletions tests/tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,24 @@
}
}

if(isset($_REQUEST['CreditNotesallocation']) && $_REQUEST['method']=="PUT"){
$xml="<Allocations>
<Allocation>
<AppliedAmount>1.50</AppliedAmount>
<Invoice>
<InvoiceID>2404f66d-76a2-4e85-b80e-7dd692fe3588</InvoiceID>
</Invoice>
</Allocation>
</Allocations>";
$response = $XeroOAuth->request('PUT', $XeroOAuth->url('CreditNotes/1e2d74e7-2fa8-45ec-9fd5-b459778c0752/Allocations', 'core'), array('SummarizeErrors' => 'false'), $xml);
if ($XeroOAuth->response['code'] == 200) {
$TrackingCategories = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
echo "The CreditNotes is now Allocated to invoice specified: " . $CreditNotes->CreditNotes[0]->CreditNotes;
} else {
outputError($XeroOAuth);
}
}

if (isset($_REQUEST['payments'])) {
if (!isset($_REQUEST['method'])) {
$response = $XeroOAuth->request('GET', $XeroOAuth->url('Payments', 'core'), array('Where' => 'Status=="AUTHORISED"'));
Expand Down Expand Up @@ -81,7 +99,7 @@
}
}
if (isset($_REQUEST['payrollemployees'])) {
$response = $XeroOAuth->request('GET', $XeroOAuth->url('Employees', 'payroll'), array());
$response = $XeroOAuth->request('GET', $XeroOAuth->url('Employees', 'payroll'), array('If-Modified-Since' => "2015-08-01T01:16:10.853"));
if ($XeroOAuth->response['code'] == 200) {
$employees = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
echo "There are " . count($employees->Employees[0]). " employees in this Xero organisation, the first one is: </br>";
Expand Down Expand Up @@ -147,22 +165,22 @@
<Invoice>
<Type>ACCREC</Type>
<Contact>
<Name>Martin Hudson</Name>
<Name>Martin1 Hudson</Name>
</Contact>
<Date>2013-05-13T00:00:00</Date>
<DueDate>2013-05-20T00:00:00</DueDate>
<Date>2013-06-13T00:00:00</Date>
<DueDate>2013-06-20T00:00:00</DueDate>
<LineAmountTypes>Exclusive</LineAmountTypes>
<LineItems>
<LineItem>
<Description>Monthly rental for property at 56a Wilkins Avenue</Description>
<Quantity>4.3400</Quantity>
<UnitAmount>395.00</UnitAmount>
<Quantity>4.3500</Quantity>
<UnitAmount>396.00</UnitAmount>
<AccountCode>200</AccountCode>
</LineItem>
</LineItems>
</Invoice>
</Invoices>";
$response = $XeroOAuth->request('PUT', $XeroOAuth->url('Invoices', 'core'), array(), $xml);
$response = $XeroOAuth->request('PUT', $XeroOAuth->url('Invoices', 'core'), array('SummarizeErrors' => 'false'), $xml);
if ($XeroOAuth->response['code'] == 200) {
$invoice = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
echo "" . count($invoice->Invoices[0]). " invoice created in this Xero organisation.";
Expand Down Expand Up @@ -365,7 +383,7 @@
}elseif(isset($_REQUEST['method']) && $_REQUEST['method'] == "put" ){
$xml = "<Contacts>
<Contact>
<Name>Orlena Greenville</Name>
<Name>Orlena1 Greenville</Name>
</Contact>
</Contacts>";
$response = $XeroOAuth->request('PUT', $XeroOAuth->url('Contacts', 'core'), array(), $xml);
Expand Down Expand Up @@ -596,4 +614,31 @@

}

if (isset($_REQUEST['GetAllLinkedTransactions'])) {
$response = $XeroOAuth->request('GET', $XeroOAuth->url('LinkedTransactions', 'core'), array('Where' => $_REQUEST['where']));
if ($XeroOAuth->response['code'] == 200) {
$LinkedTransactions = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
echo "There are " . count($LinkedTransactions->LinkedTransactions[0]). " LinkedTransactions in this Xero organisation, the first one is: </br>";
pr($LinkedTransactions->LinkedTransactions[0]->LinkedTransaction);
} else {
outputError($XeroOAuth);
}
}

if (isset($_REQUEST['LinkedTransaction'])) {
$xml = "<LinkedTransaction>
<SourceTransactionID>4a44f84d-cb7c-4f6f-81cb-5314fd3f2f0f</SourceTransactionID>
<SourceLineItemID>f93f11fb-d4a1-4d87-9830-a9bd2169cdca</SourceLineItemID>
<ContactID>b4bb131a-72b0-4543-bf36-6dc9703605ea</ContactID>
</LinkedTransaction>";
$response = $XeroOAuth->request('POST', $XeroOAuth->url('LinkedTransaction', 'core'), array(), $xml);
if ($XeroOAuth->response['code'] == 200) {
$LinkedTransaction = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
echo "There are " . count($LinkedTransaction->LinkedTransaction[0]). " Item created: </br>";
pr($LinkedTransaction->LinkedTransaction[0]->LinkedTransaction);
} else {
outputError($XeroOAuth);
}
}

}