diff --git a/src/Builders/Builder.php b/src/Builders/Builder.php index d3b137a..c59f7bf 100644 --- a/src/Builders/Builder.php +++ b/src/Builders/Builder.php @@ -13,7 +13,7 @@ class Builder { - private $request; + protected $request; protected $entity; protected $responseClass = PaginatedResponse::class; diff --git a/src/Builders/DepositAccountBuilder.php b/src/Builders/DepositAccountBuilder.php new file mode 100755 index 0000000..7e2124f --- /dev/null +++ b/src/Builders/DepositAccountBuilder.php @@ -0,0 +1,37 @@ +request->curl->get("{$this->entity}{$parameters}"); + + $jsonResponse = json_decode($dineroApiResponse->getBody()->getContents()); + } catch (ClientException $exception) { + throw new DineroRequestException($exception); + } catch (ServerException $exception) { + throw new DineroServerException($exception); + } + + $request = $this->request; + + $items = array_map(function ($item) use ($request) { + return new $this->model($request, $item); + }, $jsonResponse); + + return (object)['items' => $items]; + } +} diff --git a/src/Builders/EntryAccountBuilder.php b/src/Builders/EntryAccountBuilder.php new file mode 100755 index 0000000..7b37fcb --- /dev/null +++ b/src/Builders/EntryAccountBuilder.php @@ -0,0 +1,37 @@ +request->curl->get("{$this->entity}{$parameters}"); + + $jsonResponse = json_decode($dineroApiResponse->getBody()->getContents()); + } catch (ClientException $exception) { + throw new DineroRequestException($exception); + } catch (ServerException $exception) { + throw new DineroServerException($exception); + } + + $request = $this->request; + + $items = array_map(function ($item) use ($request) { + return new $this->model($request, $item); + }, $jsonResponse); + + return (object)['items' => $items]; + } +} diff --git a/src/Builders/PurchaseVoucherBuilder.php b/src/Builders/PurchaseVoucherBuilder.php new file mode 100644 index 0000000..0161eec --- /dev/null +++ b/src/Builders/PurchaseVoucherBuilder.php @@ -0,0 +1,11 @@ +request)); } + + public function entryAccounts() { + + return new EntryAccountRequestBuilder(new EntryAccountBuilder($this->request)); + } + + public function depositAccounts() { + + return new DepositAccountRequestBuilder(new DepositAccountBuilder($this->request)); + } + + public function purchaseVouchers() + { + + return new PurchaseVoucherRequestBuilder(new PurchaseVoucherBuilder($this->request)); + } } diff --git a/src/Models/DepositAccount.php b/src/Models/DepositAccount.php new file mode 100755 index 0000000..780802f --- /dev/null +++ b/src/Models/DepositAccount.php @@ -0,0 +1,14 @@ +parameters['fields'] = 'Name,AccountNumber'; + + parent::__construct( $builder ); + } +} diff --git a/src/Requests/EntryAccountRequestBuilder.php b/src/Requests/EntryAccountRequestBuilder.php new file mode 100755 index 0000000..a1ca025 --- /dev/null +++ b/src/Requests/EntryAccountRequestBuilder.php @@ -0,0 +1,15 @@ +parameters['fields'] = 'Name,AccountNumber,VatCode,Category,IsHidden,IsDefaultSalesAccount'; + + parent::__construct( $builder ); + } +} diff --git a/src/Requests/PurchaseVoucherRequestBuilder.php b/src/Requests/PurchaseVoucherRequestBuilder.php new file mode 100644 index 0000000..b3d9400 --- /dev/null +++ b/src/Requests/PurchaseVoucherRequestBuilder.php @@ -0,0 +1,16 @@ +parameters['fields'] = 'Number,Guid,ContactGuid,VoucherDate,PaymentDate,Status,Timestamp,VoucherNumber,FileGuid,RegionKey,$DepositAccountNumber,ExternalReference'; + + parent::__construct($builder); + } +} diff --git a/src/Utils/Model.php b/src/Utils/Model.php index 6dacab1..68c1a0f 100644 --- a/src/Utils/Model.php +++ b/src/Utils/Model.php @@ -69,7 +69,7 @@ protected function setAttribute($attribute, $value) public function delete() { // todo test - return $this->request->curl->delete("/{$this->entity}/{$this->{$this->primaryKey}}"); + return $this->request->curl->delete("{$this->entity}/{$this->{$this->primaryKey}}"); } /** @@ -81,8 +81,9 @@ public function delete() */ public function update($data = []) { - // todo test - $response = $this->request->curl->put("/{$this->entity}/{$this->{$this->primaryKey}}", [ + $data = array_merge($this->toArray(), $data); + + $response = $this->request->curl->put("{$this->entity}/{$this->{$this->primaryKey}}", [ 'json' => $data, ]); diff --git a/src/Utils/RequestBuilder.php b/src/Utils/RequestBuilder.php index f4c1c7f..8a6ecb9 100644 --- a/src/Utils/RequestBuilder.php +++ b/src/Utils/RequestBuilder.php @@ -27,17 +27,12 @@ public function __construct( Builder $builder ) { * @return $this */ public function select( $fields ) { - if ( ! isset( $this->parameters['fields'] ) ) { - $this->parameters['fields'] = []; - } - if ( is_array( $fields ) ) { - foreach ( $fields as $field ) { - $this->parameters['fields'][] = $field; - } - } elseif ( is_string( $fields ) || is_int( $fields ) ) { - $this->parameters['fields'][] = $fields; - } + if (is_array($fields)) { + $this->parameters['fields'] = implode(',', $fields); + } elseif (is_string($fields) || is_int($fields)) { + $this->parameters['fields'] = $fields; + } return $this; }