src/includes/classes/Core/Utils/Stripe.php
public function subscription($args)
    {
        if (is_string($args)) {
            $args = ['subscription' => $args];
        } // Convert subscription ID into args.

        $default_args = [
            'api_key'       => '', // Stripe API key.
            'subscription'  => '', // Get existing ID.

            // Everything else is for a new subscription.
            // A new subscription requires a customer ID + plan.

            'customer' => '', // Customer ID to subscribe.
            'plan'     => '', // Plan ID to subscribe them to.

            'order_id' => '', // New subscription order ID.
            'metadata' => '', // New subscription metadata.
        ];
        $args = (array) $args; // Force array.
        $args = array_merge($default_args, $args);
        $args = array_intersect_key($args, $default_args);
        extract($this->parseArgs(__FUNCTION__, $args));

        $Subscription = null; // Initialize.

        if ($args['subscription']) {
            try { // Acquire subscription by ID.
                $Subscription = Subscription::retrieve($args['subscription'], $opts);
            } catch (\Throwable $Exception) {
                return $this->exceptionError($Exception);
            }
        } else { // Create a new subscription.
            try {
                $new_subscription_args = [
                    'customer' => $args['customer'],
                    'plan'     => $args['plan'],

                    'metadata' => array_merge([
                        'order_id' => $args['order_id'],
                    ], $args['metadata']),
                ];
                $new_subscription_args = $this->c::removeNulls($new_subscription_args);
                $Subscription          = Subscription::create($new_subscription_args, $opts);
            } catch (\Throwable $Exception) {
                return $this->exceptionError($Exception);
            }
        }
        if (!($Subscription instanceof Subscription)) {
            $_error = sprintf('Failed to acquire subscription.');
            return $this->exceptionError(new Exception($_error));
        }
        return $Subscription;
    }
public function subscription($args)
    {
        if (is_string($args)) {
            $args = ['subscription' => $args];
        } // Convert subscription ID into args.

        $default_args = [
            'api_key'       => '', // Stripe API key.
            'subscription'  => '', // Get existing ID.

            // Everything else is for a new subscription.
            // A new subscription requires a customer ID + plan.

            'customer' => '', // Customer ID to subscribe.
            'plan'     => '', // Plan ID to subscribe them to.

            'order_id' => '', // New subscription order ID.
            'metadata' => '', // New subscription metadata.
        ];
        $args = (array) $args; // Force array.
        $args = array_merge($default_args, $args);
        $args = array_intersect_key($args, $default_args);
        extract($this->parseArgs(__FUNCTION__, $args));

        $Subscription = null; // Initialize.

        if ($args['subscription']) {
            try { // Acquire subscription by ID.
                $Subscription = Subscription::retrieve($args['subscription'], $opts);
            } catch (\Throwable $Exception) {
                return $this->exceptionError($Exception);
            }
        } else { // Create a new subscription.
            try {
                $new_subscription_args = [
                    'customer' => $args['customer'],
                    'plan'     => $args['plan'],

                    'metadata' => array_merge([
                        'order_id' => $args['order_id'],
                    ], $args['metadata']),
                ];
                $new_subscription_args = $this->c::removeNulls($new_subscription_args);
                $Subscription          = Subscription::create($new_subscription_args, $opts);
            } catch (\Throwable $Exception) {
                return $this->exceptionError($Exception);
            }
        }
        if (!($Subscription instanceof Subscription)) {
            $_error = sprintf('Failed to acquire subscription.');
            return $this->exceptionError(new Exception($_error));
        }
        return $Subscription;
    }
Get (or create) a subscription.

@since 170329.13807 Stripe utils.

@param string|array $args ID or args.

@return Subscription|Error Subscription on success.