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(); $this->invoice = new stripe_endpoint_invoice(); } /** * @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'); } } }