-
Notifications
You must be signed in to change notification settings - Fork 0
Xml Helper
Michael Newman edited this page Jul 28, 2017
·
2 revisions
Included in the Xero wrapper package is an XML Helper Trait.
There are two helper methods available; one for a single resource and one for multiple resources. Each method converts an array into an XML string.
<?php
namespace App\Http\Controllers\XeroApplication;
use Xero\helpers\XmlHelper;
class XeroAppController
{
use XmlHelper;
//do something here
}
$newInvoiceArray = [
'Type' => 'ACCREC',
'Contact' => [
'ContactID' => 'e32e2130-3d27-443a-8313-48fffa03cf53'
],
'Date' => '2017-03-28',
'LineAmountTypes' => 'Exclusive',
'LineItems' => [
'LineItem' => [
'Description' => 'Line Item 1',
'Quantity' => 10.000,
'UnitAmount' => 11.00,
'AccountCode' => 200
]
]
];
return $this->xml_one_resource($newInvoiceArray, 'Invoice');
<Invoice>
<Type>ACCREC</Type>
<Contact>
<ContactID>e32e2130-3d27-443a-8313-48fffa03cf53</ContactID>
</Contact>
<LineAmountTypes>Exclusive</LineAmountTypes>
<LineItems>
<Description>Line Item 1</Description>
<Quantity>10.000</Quantity>
<UnitAmount>11.0</UnitAmount>
<AccountCode>200</AccountCode>
</LineItems>
</Invoice>
$newInvoicesArray = [
[
'Type' => 'ACCREC',
'Contact' => [
'ContactID' => 'e32e2130-3d27-443a-8313-48fffa03cf53'
],
'Date' => '2017-03-28',
'LineAmountTypes' => 'Exclusive',
'LineItems' => [
'LineItem' => [
'Description' => 'Line Item 1',
'Quantity' => 10.000,
'UnitAmount' => 11.00,
'AccountCode' => 200
]
]
],
[
'Type' => 'ACCREC',
'Contact' => [
'ContactID' => 'e32e2130-3d27-443a-8313-48fffa03cf53'
],
'Date' => '2017-03-28',
'LineAmountTypes' => 'Exclusive',
'LineItems' => [
'LineItem' => [
'Description' => 'Line Item 1',
'Quantity' => 10.000,
'UnitAmount' => 11.00,
'AccountCode' => 200
]
]
]
];
return $this->xml_multiple_resources($newInvoiceArray, 'Invoice');
<Invoices>
<Invoice>
<Type>ACCREC</Type>
<Contact>
<ContactID>e32e2130-3d27-443a-8313-48fffa03cf53</ContactID>
</Contact>
<LineAmountTypes>Exclusive</LineAmountTypes>
<LineItems>
<Description>Line Item 1</Description>
<Quantity>10.000</Quantity>
<UnitAmount>11.0</UnitAmount>
<AccountCode>200</AccountCode>
</LineItems>
</Invoice>
<Invoice>
<Type>ACCREC</Type>
<Contact>
<ContactID>e32e2130-3d27-443a-8313-48fffa03cf53</ContactID>
</Contact>
<LineAmountTypes>Exclusive</LineAmountTypes>
<LineItems>
<Description>Line Item 1</Description>
<Quantity>10.000</Quantity>
<UnitAmount>11.0</UnitAmount>
<AccountCode>200</AccountCode>
</LineItems>
</Invoice>
</Invoices>