Files
api/services/nginx/app/modules/stripe/helpers/stripe_line_items.php
T
Jepp9350 53b61654bf Add Stripe invoice generation and customer management
Introduced functionality for creating and managing invoices using Stripe APIs, replacing the previous payment link system. Added customer account creation and retrieval, invoice line-item handling, and extended database object structures to support invoices. Updated order routing to include Stripe customer and invoice details.
2025-02-19 17:25:19 +01:00

50 lines
1.1 KiB
PHP

<?php
namespace stripe\helpers;
class stripe_line_items
{
/**
* @var array $line_items
*/
protected array $line_items = [];
protected array $types = [
'invoice',
'payment_link'
];
protected string $type;
/**
* @throws \Exception
*/
public function __construct($type = 'payment_link')
{
if (!in_array($type, $this->types)) {
throw new \Exception('Invalid type');
}
$this->type = $type;
}
public function __toString(): string
{
// Return the line items as a JSON string
return json_encode(self::get());
}
public function get(): array
{
$line_items = [];
/** @var stripe_line_item|array $line_item */
foreach ( $this->line_items as $line_item ) {
$line_items[] = is_array($line_item)
? $line_item
: $line_item->get($this->type);
}
return $line_items;
}
public function add(stripe_line_item|array $line_item): void
{
$this->line_items[] = $line_item;
}
}