Add customer detail accessors and update usage in endpoints
Added individual getter methods for customer details such as name, email, address, zip code, city, and country in the economic_customer module. Updated the invoices drafts endpoint to use these accessors instead of directly accessing properties. Included an exception throw for failed requests in the endpoint.
This commit is contained in:
+7
-5
@@ -3,6 +3,7 @@
|
||||
namespace endpoints\orders;
|
||||
|
||||
use classes\economic;
|
||||
use Exception;
|
||||
use traits\economic_endpoint_t;
|
||||
|
||||
class economic_invoices_drafts_endpoint
|
||||
@@ -49,6 +50,7 @@ class economic_invoices_drafts_endpoint
|
||||
* @param int $customer_number The E-conomic customer number
|
||||
* @param string $external_id The external id of the invoice
|
||||
* @return object {id: number, getExternalId: string}
|
||||
* @throws Exception If the request fails
|
||||
*/
|
||||
public function add(int $customer_number, string $external_id = ''): object
|
||||
{
|
||||
@@ -65,10 +67,10 @@ class economic_invoices_drafts_endpoint
|
||||
$customer = (new economic())->getCustomer($customer_number);
|
||||
|
||||
// Set the recipient details
|
||||
$customer_name = $customer->name ?? 'Ukendt';
|
||||
$customer_address = $customer->address ?? 'Ukendt';
|
||||
$customer_zip = $customer->zip ?? 'Ukendt';
|
||||
$customer_city = $customer->city ?? 'Ukendt';
|
||||
$customer_name = $customer->getName() ?? 'Ukendt';
|
||||
$customer_address = $customer->getAddress() ?? 'Ukendt';
|
||||
$customer_zip = $customer->getZipCode() ?? 'Ukendt';
|
||||
$customer_city = $customer->getCity() ?? 'Ukendt';
|
||||
|
||||
// Send the request
|
||||
$response = $this->send_request(
|
||||
@@ -126,7 +128,7 @@ class economic_invoices_drafts_endpoint
|
||||
// Return the response as an object
|
||||
try {
|
||||
return json_decode($response)->draftInvoiceNumber == $draft_invoice_number;
|
||||
} catch (\Exception $e) {
|
||||
} catch (Exception $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,4 +126,71 @@ class economic_customer
|
||||
self::requireSelected();
|
||||
return $this->customer_data_object;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the customer name
|
||||
* @return string The customer name
|
||||
* @throws Exception if the customer data is invalid or empty
|
||||
*/
|
||||
public function getName(): string
|
||||
{
|
||||
self::requireSelected();
|
||||
return $this->customer_data_object->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the customer email
|
||||
* @return string The customer email
|
||||
* @throws Exception if the customer data is invalid or empty
|
||||
*/
|
||||
public function getEmail(): string
|
||||
{
|
||||
self::requireSelected();
|
||||
return $this->customer_data_object->email;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the customer address
|
||||
* @return string The customer address
|
||||
* @throws Exception if the customer data is invalid or empty
|
||||
*/
|
||||
public function getAddress(): string
|
||||
{
|
||||
self::requireSelected();
|
||||
return $this->customer_data_object->address;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the customer postal code
|
||||
* @return string The customer postal code
|
||||
* @throws Exception if the customer data is invalid or empty
|
||||
*/
|
||||
public function getZipCode(): string
|
||||
{
|
||||
self::requireSelected();
|
||||
return $this->customer_data_object->zip;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the customer city
|
||||
* @return string The customer city
|
||||
* @throws Exception if the customer data is invalid or empty
|
||||
*/
|
||||
public function getCity(): string
|
||||
{
|
||||
self::requireSelected();
|
||||
return $this->customer_data_object->city;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the customer country
|
||||
* @return string The customer country
|
||||
* @throws Exception if the customer data is invalid or empty
|
||||
*/
|
||||
public function getCountry(): string
|
||||
{
|
||||
self::requireSelected();
|
||||
return $this->customer_data_object->country;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,6 +14,7 @@ class customerSearchRoute
|
||||
|
||||
public function run(): void
|
||||
{
|
||||
//TODO: Remove this, this is deprecated in favor of the new search endpoint
|
||||
$this->post('/customers/search', function () {
|
||||
// Require the user to be logged in
|
||||
global $response;
|
||||
|
||||
Reference in New Issue
Block a user