diff --git a/composer.json b/composer.json index dce1a41..adf9f7c 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,7 @@ ], "require": { "php": ">=7.1", - "laravel/framework": "^5.5|^6|^7", + "laravel/framework": "^5.5|^6.20.12|^7.30.3", "ext-json": "*", "guzzlehttp/guzzle": "*" }, diff --git a/src/Builders/CustomerAddressBuilder.php b/src/Builders/CustomerAddressBuilder.php new file mode 100644 index 0000000..32d663e --- /dev/null +++ b/src/Builders/CustomerAddressBuilder.php @@ -0,0 +1,21 @@ +initRequest( $token, $options, $headers ); - } + /** + * Rackbeat constructor. + * + * @param null $token API token + * @param array $options Custom Guzzle options + * @param array $headers Custom Guzzle headers + */ + public function __construct( $token = null, $options = [], $headers = [] ) { + $this->initRequest( $token, $options, $headers ); + } - /** - * @param $token - * @param array $options - * @param array $headers - */ - private function initRequest( $token, $options = [], $headers = [] ) - { - $this->request = new Request( $token, $options, $headers ); - } + /** + * @param $token + * @param array $options + * @param array $headers + */ + private function initRequest( $token, $options = [], $headers = [] ): void { + $this->request = new Request( $token, $options, $headers ); + } - /** - * @return \KgBot\Magento\Builders\OrderBuilder - */ - public function orders() - { - return new OrderBuilder( $this->request ); - } + /** + * @return OrderBuilder + */ + public function orders(): OrderBuilder { + return new OrderBuilder( $this->request ); + } - /** - * @return \KgBot\Magento\Builders\CustomerBuilder - */ - public function customers() - { - return new CustomerBuilder( $this->request ); - } + /** + * @return CustomerBuilder + */ + public function customers(): CustomerBuilder { + return new CustomerBuilder( $this->request ); + } - /** - * @return \KgBot\Magento\Builders\ProductBuilder - */ - public function products() - { - return new ProductBuilder( $this->request ); - } + /** + * @return CustomerAddressBuilder + */ + public function customer_addresses(): CustomerAddressBuilder { + return new CustomerAddressBuilder( $this->request ); + } - /** - * @return \KgBot\Magento\Builders\CustomerGroupBuilder - */ - public function customer_groups() - { + /** + * @return ProductBuilder + */ + public function products(): ProductBuilder { + return new ProductBuilder( $this->request ); + } - return new CustomerGroupBuilder( $this->request ); - } + /** + * @return CustomerGroupBuilder + */ + public function customer_groups(): CustomerGroupBuilder { + + return new CustomerGroupBuilder( $this->request ); + } } \ No newline at end of file diff --git a/src/Models/Customer.php b/src/Models/Customer.php index 6e9d711..326a688 100644 --- a/src/Models/Customer.php +++ b/src/Models/Customer.php @@ -13,6 +13,34 @@ class Customer extends Model { - protected $entity = 'customers'; - protected $primaryKey = 'id'; + protected $entity = 'customers'; + protected $primaryKey = 'id'; + + public function getBillingAddress() { + return $this->request->handleWithExceptions( function () { + + $address = $this->request->client->get( "{$this->entity}/{$this->{$this->primaryKey}}/billingAddress" ); + $responseData = json_decode( (string) $address->getBody() ); + + if ( ! empty( $responseData ) ) { + return new CustomerAddress( $this->request, $responseData ); + } + + return null; + } ); + } + + public function getShippingAddress() { + return $this->request->handleWithExceptions( function () { + + $address = $this->request->client->get( "{$this->entity}/{$this->{$this->primaryKey}}/shippingAddress" ); + $responseData = json_decode( (string) $address->getBody() ); + + if ( ! empty( $responseData ) ) { + return new CustomerAddress( $this->request, $responseData ); + } + + return null; + } ); + } } diff --git a/src/Models/CustomerAddress.php b/src/Models/CustomerAddress.php new file mode 100644 index 0000000..eb7f308 --- /dev/null +++ b/src/Models/CustomerAddress.php @@ -0,0 +1,18 @@ +