diff --git a/src/API.php b/src/API.php index 885fc09..c235a5f 100644 --- a/src/API.php +++ b/src/API.php @@ -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 * diff --git a/src/Models/Payment.php b/src/Models/Payment.php new file mode 100644 index 0000000..6cab95e --- /dev/null +++ b/src/Models/Payment.php @@ -0,0 +1,183 @@ + {#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)); + } +} \ No newline at end of file diff --git a/src/Response/ListList.php b/src/Response/ListList.php index 55904fe..4d6c0bf 100644 --- a/src/Response/ListList.php +++ b/src/Response/ListList.php @@ -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; diff --git a/src/Response/Payment.php b/src/Response/Payment.php new file mode 100644 index 0000000..9eec7c4 --- /dev/null +++ b/src/Response/Payment.php @@ -0,0 +1,23 @@ +time); + + $this->_model = new PaymentModel((array)$response->Payment); + } +} \ No newline at end of file