Files
api/services/nginx/app/objects/stripe_module_orders_o.php
T
Jepp9350 410ca84bf1 Add Stripe integration for customers, payments, and products
This commit introduces a comprehensive Stripe module with support for managing customers, products, prices, and payment links. It also includes endpoint routes, helpers, and database updates to support Stripe operations, such as creating and retrieving entities or handling payment workflows. Additionally, a stripe module was integrated into existing routes and objects to enable seamless interaction with Stripe APIs.
2025-02-18 18:31:23 +01:00

93 lines
2.7 KiB
PHP

<?php
namespace objects;
use classes\db;
use classes\object_property;
use classes\stripe;
use Exception;
use Stripe\Exception\ApiErrorException;
use traits\db_object_t;
class stripe_module_orders_o extends db
{
use db_object_t;
public object_property $payment_link_id;
public object_property $email;
public object_property $email_sent;
public object_property $url;
public object_property $created_at;
public function structure(): void
{
$this->setTable('stripe_module_orders');
}
/**
* Add a payment link to the database
* @param int $order_id
* @param string $email
* @param string $payment_link_id
* @param string $url The URL of the payment link
* @return void
* @throws Exception If the object was not created successfully
*/
public function add(int $order_id, string $email, string $payment_link_id, string $url): void
{
$tmp_id = self::add_object([
'id' => $order_id,
'email' => $email,
'payment_link_id' => $payment_link_id,
'url' => $url,
]);
$this->id = $tmp_id;
self::getObjectProperties();
self::objectChanged();
}
public function getObjectProperties(): void
{
$this->payment_link_id = new object_property($this->table, $this->id, 'payment_link_id', 'string', false);
$this->email = new object_property($this->table, $this->id, 'email', 'string', false);
$this->email_sent = new object_property($this->table, $this->id, 'email_sent', 'timestamp', false);
$this->url = new object_property($this->table, $this->id, 'url', 'string', false);
$this->created_at = new object_property($this->table, $this->id, 'created_at', 'timestamp', false);
}
public function objectChanged(): void
{
//TODO: Add cache invalidation
}
/**
* @throws ApiErrorException
*/
public function asArray(): array
{
return [
'id' => (int)$this->id,
'payment_link_id' => (string)$this->payment_link_id->value(),
'email' => (string)$this->email->value(),
'email_sent' => $this->email_sent->value() ? (string)$this->email_sent->value() : null,
'url' => (string)$this->url->value(),
'created_at' => (string)$this->created_at->value(),
'object' => self::retrievePaymentLink()
];
}
/**
* @throws ApiErrorException
* @throws Exception
*/
public function retrievePaymentLink(): object
{
// Validate the object
self::requireSelected();
// Return the payment link
return (new stripe())->payment_link->retrieve($this->payment_link_id->value());
}
}