These examples demonstrate how you can easily obtain a single resource once you have its own id
. The array representation of the resource can be obtained calling $resource->toArray()
method.
It assumes that you have already instantiated a Soldo
object.
To get the Company
object you don't need an id
since it is unique.
try {
$resource = $soldo->getCompany();
} catch (\Soldo\Exceptions\SoldoException $e) {
echo 'Soldo returned an error: ' . $e->getMessage();
}
echo get_class($resource);
echo PHP_EOL;
print_r($resource->toArray());
The output of the code above is
Soldo\Resources\Company
Array
(
[id] =>
[name] => S24 Demo
[vat_number] => 321456
[company_account_id] => SDMD7784
)
Once you have the id
you can do as follows:
try {
$resource = $soldo->getEmployee('SDMD7784-000001');
} catch (\Soldo\Exceptions\SoldoException $e) {
echo 'Soldo returned an error: ' . $e->getMessage();
}
You can update the following Employee properties
custom_reference_id
: the employee reference id into the calling systemdepartment
: the department the employee belongs to
doing as follows:
try {
$employee = $soldo->updateEmployee('SDMD7784-000001', [
'department' => 'Department name',
'custom_reference_id' => 'a-random-string',
]);
} catch (\Soldo\Exceptions\SoldoException $e) {
echo 'Soldo returned an error: ' . $e->getMessage();
}
Any key different from the supported ones will be ignored. If no supported keys are provided an InvalidArgumentException
will be thrown.
Printing out $employee->department
will show Department name
and the value of custom_reference_id
will be a-random-string
.
try {
$resource = $soldo->getGroup('SDMD7784-000002');
} catch (\Soldo\Exceptions\SoldoException $e) {
echo 'Soldo returned an error: ' . $e->getMessage();
}
try {
$resource = $soldo->getWallet('SDMD7784-000003');
} catch (\Soldo\Exceptions\SoldoException $e) {
echo 'Soldo returned an error: ' . $e->getMessage();
}
try {
$resource = $soldo->getCard('SDMD7784-000004');
} catch (\Soldo\Exceptions\SoldoException $e) {
echo 'Soldo returned an error: ' . $e->getMessage();
}
try {
$resource = $soldo->getTransaction('SDMD7784-000005');
} catch (\Soldo\Exceptions\SoldoException $e) {
echo 'Soldo returned an error: ' . $e->getMessage();
}
print_r($resource->toArray());
The output generated by the code above is:
Array
(
[id] => 1308-977b3487-5775-4855-b662-eb10c858b908
[wallet_id] => f086f25b-1526-11e7-9287-0a89c8769141
[wallet_name] => EURO
[status] => Settled
[category] => Transfer
[transaction_sign] => Negative
[amount] => 500
[amount_currency] => EUR
[tx_amount] => 500
[tx_amount_currency] => EUR
[fee_amount] => 0
[fee_currency] => EUR
[date] => 2017-07-28T13:29:59
[settlement_date] => 2017-07-28T13:29:59Z
[merchant_category] => Array
(
)
[tags] => Array
(
)
[owner_id] => SDMD7784-000001
[owner_type] => company
)
If you want to add more details to the Transaction
object pass true
as second parameter:
try {
$resource = $soldo->getTransaction('SDMD7784-000005', true);
} catch (\Soldo\Exceptions\SoldoException $e) {
echo 'Soldo returned an error: ' . $e->getMessage();
}
print_r($resource->toArray());
It prints:
Array
(
[id] => 1308-977b3487-5775-4855-b662-eb10c858b908
[wallet_id] => f086f25b-1526-11e7-9287-0a89c8769141
[wallet_name] => EURO
[status] => Settled
[category] => Transfer
[transaction_sign] => Negative
[amount] => 500
[amount_currency] => EUR
[tx_amount] => 500
[tx_amount_currency] => EUR
[fee_amount] => 0
[fee_currency] => EUR
[date] => 2017-07-28T13:29:59
[settlement_date] => 2017-07-28T13:29:59Z
[merchant_category] => Array
(
)
[tags] => Array
(
)
[owner_id] => SDMD7784-000001
[owner_type] => company
[details] => Array
(
[is_card_present] =>
[is_atm_transaction] =>
[denied_info_description] =>
)
)