Add Stripe terminal and department variables API endpoints

This update introduces new endpoints for managing Stripe terminal readers, locations, and department-specific configurations. It also adds support for creating, updating, and retrieving department variables along with enhanced validation, logging, and permission checks. These updates improve integration and expand functionality for Stripe and department-related operations.
This commit is contained in:
Jepp9350
2025-02-21 14:43:33 +01:00
parent ff12fbcbd0
commit d2c1cdda9a
9 changed files with 670 additions and 37 deletions
+72 -1
View File
@@ -4,6 +4,8 @@ namespace objects;
use classes\db;
use classes\object_property;
use classes\stripe;
use Exception;
use traits\db_object_t;
class departments_o extends db
@@ -14,6 +16,7 @@ class departments_o extends db
public object_property $description;
public object_property $economic_department_id; // The id of the department in the economic system (Can be null)
public object_property $slack_webhook; // The slack webhook for the department
public department_variables_o $variables; // The department variables object
public function structure(): void
{
@@ -26,6 +29,12 @@ class departments_o extends db
redis->clear_departments();
}
/**
* Add a department
* @param string $name
* @param string $description
* @throws Exception If the object was not created successfully
*/
public function create(string $name, string $description): void
{
global $db;
@@ -46,12 +55,18 @@ class departments_o extends db
redis->clear_departments();
}
/**
* Get the object properties of the department
* @throws Exception If the object is not selected
*/
public function getObjectProperties(): void
{
self::requireSelected();
$this->name = new object_property($this->table, $this->id, 'name', 'string', true);
$this->description = new object_property($this->table, $this->id, 'description', 'string', false);
$this->economic_department_id = new object_property($this->table, $this->id, 'economic_department_id', 'int', false);
$this->slack_webhook = new object_property($this->table, $this->id, 'slack_webhook', 'string', false);
$this->variables = (new department_variables_o())->selectDepartment($this->id);
}
public function edit(int $id, string $name, string $description, int $economic_department_id): void
@@ -193,11 +208,67 @@ class departments_o extends db
if (!empty($name)) {
redis->cache_department_name($department, $name);
}
} catch (\Exception $e) {
} catch (Exception $e) {
$name = 'Unable to get department name: ' . $department;
}
return $name;
}
return redis->get_department_name($department) ?? 'Unable to get department name: ' . $department;
}
/**
* Get the Stripe terminal location department variable
* @note This is a link to the department_variables_o::getVariable(stripe_terminal_location) method
* @return string The Stripe terminal location id
* @throws Exception If the department variable is not set
* @throws Exception If the department is not selected
*/
public function getStripeTerminalLocation(): string
{
self::requireSelected();
if (!$this->variables->isSet('stripe_terminal_location')) {
throw new Exception('The Stripe terminal location is not set for the department.');
}
return $this->variables->getVariable('stripe_terminal_location');
}
/**
* Check if the Stripe terminal location variable is set
* @note This is a link to the department_variables_o::isSet(stripe_terminal_location) method
* @return bool true If the Stripe terminal location is set
* @throws Exception If the department is not selected
*/
public function isStripeTerminalLocationSet(): bool
{
self::requireSelected();
return $this->variables->isSet('stripe_terminal_location');
}
/**
* Set the Stripe terminal location department variable
* @note This is a link to the department_variables_o::set(stripe_terminal_location) method
* @param string $location The Stripe terminal location id
* @throws Exception If the department is not selected
* @throws Exception If the department variable is not updated successfully
*/
public function setStripeTerminalLocation(string $location): void
{
self::requireSelected();
$this->variables->set('stripe_terminal_location', $location);
}
/**
* Get the Stripe terminal readers
* @note This is a link to the stripe_endpoint_readers::listLocation method
* @throws Exception If the department is not selected
* @throws Exception If the Stripe terminal location is not set for the department
*/
public function getStripeTerminalReaders(): \Stripe\Collection
{
self::requireSelected();
if (!$this->variables->isSet('stripe_terminal_location')) {
throw new Exception('The Stripe terminal location is not set for the department.');
}
return (new stripe())->readers->listLocation($this->variables->getVariable('stripe_terminal_location'));
}
}