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.
127 lines
3.5 KiB
PHP
127 lines
3.5 KiB
PHP
<?php
|
|
|
|
namespace classes;
|
|
|
|
require_once WD . '/modules/stripe/stripe_c.php';
|
|
require_once WD . '/modules/stripe/endpoints/stripe_endpoint_customers.php';
|
|
require_once WD . '/modules/stripe/endpoints/stripe_endpoint_payment_link.php';
|
|
require_once WD . '/modules/stripe/endpoints/stripe_endpoint_product.php';
|
|
require_once WD . '/modules/stripe/endpoints/stripe_endpoint_prices.php';
|
|
|
|
|
|
// Require all helper classes
|
|
require_once WD . '/modules/stripe/helpers/stripe_line_items.php';
|
|
require_once WD . '/modules/stripe/helpers/stripe_line_item.php';
|
|
require_once WD . '/modules/stripe/helpers/stripe_product.php';
|
|
require_once WD . '/modules/stripe/helpers/stripe_price.php';
|
|
|
|
|
|
use Exception;
|
|
use interfaces\stripe_i;
|
|
use stripe\endpoints\stripe_endpoint_customers;
|
|
use stripe\endpoints\stripe_endpoint_payment_link;
|
|
use stripe\endpoints\stripe_endpoint_prices;
|
|
use stripe\endpoints\stripe_endpoint_product;
|
|
use stripe\stripe_c;
|
|
use Stripe\StripeClient;
|
|
|
|
class stripe implements stripe_i
|
|
{
|
|
/**
|
|
* Configuration of the stripe module
|
|
* @var stripe_c
|
|
*/
|
|
public stripe_c $config;
|
|
/**
|
|
* Customers endpoint
|
|
* @var stripe_endpoint_customers
|
|
*/
|
|
public stripe_endpoint_customers $customers;
|
|
/**
|
|
* Payment link endpoint
|
|
* @var stripe_endpoint_payment_link
|
|
*/
|
|
public stripe_endpoint_payment_link $payment_link;
|
|
/**
|
|
* Product endpoint
|
|
* @var stripe_endpoint_product
|
|
*/
|
|
public stripe_endpoint_product $product;
|
|
/**
|
|
* Prices endpoint
|
|
* @var stripe_endpoint_prices
|
|
*/
|
|
public stripe_endpoint_prices $prices;
|
|
/**
|
|
* Stripe client
|
|
* @var StripeClient
|
|
*/
|
|
protected StripeClient $client;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->config = new stripe_c();
|
|
$this->customers = new stripe_endpoint_customers();
|
|
$this->payment_link = new stripe_endpoint_payment_link();
|
|
$this->product = new stripe_endpoint_product();
|
|
$this->prices = new stripe_endpoint_prices();
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
* @throws Exception
|
|
*/
|
|
public function getClient(): StripeClient
|
|
{
|
|
// Get the stripe client
|
|
if (!isset($this->client)) {
|
|
// Require the module to be enabled
|
|
self::requireModuleEnabled();
|
|
// Require the secret key to be set
|
|
self::requireValidSecretKey();
|
|
// Require the publishable key to be set
|
|
self::requireValidPublishableKey();
|
|
// Create the client
|
|
$this->client = new StripeClient([
|
|
'api_key' => $this->config->secret_key->getVariableValue()
|
|
]);
|
|
}
|
|
return $this->client;
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
* @throws Exception
|
|
*/
|
|
function requireModuleEnabled(): void
|
|
{
|
|
// Check if the module is enabled
|
|
if (!$this->config->enabled->isTrue()) {
|
|
throw new Exception('The Stripe module is not enabled');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
* @throws Exception
|
|
*/
|
|
function requireValidSecretKey(): void
|
|
{
|
|
// Check if the secret key is valid
|
|
if ($this->config->secret_key->getVariableValue() === null) {
|
|
throw new Exception('Invalid secret key');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
* @throws Exception
|
|
*/
|
|
public function requireValidPublishableKey(): void
|
|
{
|
|
// Check if the publishable key is valid
|
|
if ($this->config->publishable_key->getVariableValue() === null) {
|
|
throw new Exception('Invalid publishable key');
|
|
}
|
|
}
|
|
} |