Added retrieving payment information

This commit is contained in:
Deon George 2023-05-13 21:17:36 +10:00
parent ffe70058ba
commit 2f75c7dd1f
4 changed files with 228 additions and 1 deletions

View File

@ -289,6 +289,22 @@ final class API
return new ListList($this->execute('query',$parameters),$key);
}
/**
* Get a list of our payments
*
* @param array $parameters
* @return ListList
* @throws \Exception
*/
public function getPayments(array $parameters=[]): ListList
{
Log::debug(sprintf('%s:Get a list of payments',static::LOGKEY));
$key = 'Payment';
$parameters['query'] = 'select * from Payment';
return new ListList($this->execute('query',$parameters),$key);
}
/**
* Get a list of our invoices
*

183
src/Models/Payment.php Normal file
View File

@ -0,0 +1,183 @@
<?php
namespace Intuit\Models;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
use Jenssegers\Model\Model;
use Intuit\Traits\CompareAttributes;
/*
{#5731
+"QueryResponse": {#5730
+"Payment": array:1 [
0 => {#5729
+"CustomerRef": {#5728
+"value": "70"
+"name": "Customer Name"
}
+"DepositToAccountRef": {#5727
+"value": "135"
}
+"TotalAmt": 133.0
+"UnappliedAmt": 0
+"ProcessPayment": false
+"domain": "QBO"
+"sparse": false
+"Id": "208"
+"SyncToken": "0"
+"MetaData": {#5726
+"CreateTime": "2023-05-12T22:19:55-07:00"
+"LastUpdatedTime": "2023-05-12T22:19:55-07:00"
}
+"TxnDate": "2023-05-13"
+"CurrencyRef": {#5725
+"value": "AUD"
+"name": "Australian Dollar"
}
+"Line": array:2 [
0 => {#5724
+"Amount": 1.0
+"LinkedTxn": array:1 [
0 => {#5723
+"TxnId": "202"
+"TxnType": "Invoice"
}
]
+"LineEx": {#5722
+"any": array:3 [
0 => {#5721
+"name": "{http://schema.intuit.com/finance/v3}NameValue"
+"declaredType": "com.intuit.schema.finance.v3.NameValue"
+"scope": "javax.xml.bind.JAXBElement$GlobalScope"
+"value": {#5720
+"Name": "txnId"
+"Value": "202"
}
+"nil": false
+"globalScope": true
+"typeSubstituted": false
}
1 => {#5719
+"name": "{http://schema.intuit.com/finance/v3}NameValue"
+"declaredType": "com.intuit.schema.finance.v3.NameValue"
+"scope": "javax.xml.bind.JAXBElement$GlobalScope"
+"value": {#5718
+"Name": "txnOpenBalance"
+"Value": "132.00"
}
+"nil": false
+"globalScope": true
+"typeSubstituted": false
}
2 => {#5717
+"name": "{http://schema.intuit.com/finance/v3}NameValue"
+"declaredType": "com.intuit.schema.finance.v3.NameValue"
+"scope": "javax.xml.bind.JAXBElement$GlobalScope"
+"value": {#5716
+"Name": "txnReferenceNumber"
+"Value": "006825.4"
}
+"nil": false
+"globalScope": true
+"typeSubstituted": false
}
]
}
}
1 => {#5715
+"Amount": 132.0
+"LinkedTxn": array:1 [
0 => {#5714
+"TxnId": "206"
+"TxnType": "Invoice"
}
]
+"LineEx": {#5713
+"any": array:3 [
0 => {#5712
+"name": "{http://schema.intuit.com/finance/v3}NameValue"
+"declaredType": "com.intuit.schema.finance.v3.NameValue"
+"scope": "javax.xml.bind.JAXBElement$GlobalScope"
+"value": {#5711
+"Name": "txnId"
+"Value": "206"
}
+"nil": false
+"globalScope": true
+"typeSubstituted": false
}
1 => {#5710
+"name": "{http://schema.intuit.com/finance/v3}NameValue"
+"declaredType": "com.intuit.schema.finance.v3.NameValue"
+"scope": "javax.xml.bind.JAXBElement$GlobalScope"
+"value": {#5709
+"Name": "txnOpenBalance"
+"Value": "132.00"
}
+"nil": false
+"globalScope": true
+"typeSubstituted": false
}
2 => {#5708
+"name": "{http://schema.intuit.com/finance/v3}NameValue"
+"declaredType": "com.intuit.schema.finance.v3.NameValue"
+"scope": "javax.xml.bind.JAXBElement$GlobalScope"
+"value": {#5707
+"Name": "txnReferenceNumber"
+"Value": "006813"
}
+"nil": false
+"globalScope": true
+"typeSubstituted": false
}
]
}
}
]
}
]
+"startPosition": 1
+"maxResults": 1
}
+"time": "2023-05-12T22:20:40.937-07:00"
}
*/
final class Payment extends Model
{
use CompareAttributes;
public function __get($key) {
$keymap = [
'id' => 'Id',
'synctoken' => 'SyncToken',
'date_paid' => 'TxnDate',
'total_amt' => 'TotalAmt',
'unapplied' => 'UnappliedAmt',
];
switch ($key) {
case 'created_at':
return object_get($this->getAttribute('MetaData'),'CreateTime');
case 'updated_at':
return object_get($this->getAttribute('MetaData'),'LastUpdatedTime');
case 'account_ref':
return object_get($this->getAttribute('CustomerRef'),'value');
default:
return parent::__get(Arr::get($keymap,$key,$key));
}
}
public function lines(): Collection
{
$result = collect($this->getAttribute('Line'))->transform(function($item) {
return $item->LinkedTxn[0]->TxnType === 'Invoice' ? [ $item->LinkedTxn[0]->TxnId => $item->Amount] : [];
});
return collect(array_replace(...$result));
}
}

View File

@ -7,7 +7,7 @@ use Illuminate\Support\Collection;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Log;
use Intuit\Models\{Category,Customer,Invoice,Item,Taxcode};
use Intuit\Models\{Category,Customer,Invoice,Item,Payment,Taxcode};
/**
* This is a Generic Intuit Response to API calls that produces a list of objects
@ -27,6 +27,7 @@ class ListList extends Base implements \Countable, \ArrayAccess, \Iterator
'Customer' => Customer::class,
'Invoice' => Invoice::class,
'Item' => Item::class,
'Payment' => Payment::class,
'TaxCode' => Taxcode::class,
];
@ -163,6 +164,10 @@ class ListList extends Base implements \Countable, \ArrayAccess, \Iterator
$data = collect(Item::hydrate($x));
break;
case Payment::class:
$data = collect(Payment::hydrate($x));
break;
case Taxcode::class:
$data = collect(Taxcode::hydrate($x));
break;

23
src/Response/Payment.php Normal file
View File

@ -0,0 +1,23 @@
<?php
namespace Intuit\Response;
use Intuit\Models\Payment as PaymentModel;
/**
* This is an Invoice Intuit Response to API calls
*/
class Payment extends Base
{
protected const LOGKEY = 'RIP';
public function __construct(object $response)
{
parent::__construct($response);
if (object_get($response,'time'))
unset($response->time);
$this->_model = new PaymentModel((array)$response->Payment);
}
}