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

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

            // Everything else is for a new charge.
            // A new charge requires a customer ID.
            'customer'      => '', // Customer ID to charge.
            'receipt_email' => '', // Force email receipt w/ this.
            // i.e., An email receipt is sent regardless of account-level setting.

            'amount'      => .50, // New charge amount.
            'currency'    => 'USD', // New charge currency.
            'description' => '', // New charge description.

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

        $Charge = null; // Initialize.

        if ($args['charge']) {
            try { // Acquire charge by ID.
                $Charge = Charge::retrieve($args['charge'], $opts);
            } catch (\Throwable $Exception) {
                return $this->exceptionError($Exception);
            }
        } else { // Create a new charge.
            try {
                $new_charge_args = [
                    'customer'      => $args['customer'],
                    'receipt_email' => $args['receipt_email'] ?: null,

                    'amount'      => $args['amount'],
                    'currency'    => $args['currency'],
                    'description' => $args['description'] ?: null,

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

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

            // Everything else is for a new charge.
            // A new charge requires a customer ID.
            'customer'      => '', // Customer ID to charge.
            'receipt_email' => '', // Force email receipt w/ this.
            // i.e., An email receipt is sent regardless of account-level setting.

            'amount'      => .50, // New charge amount.
            'currency'    => 'USD', // New charge currency.
            'description' => '', // New charge description.

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

        $Charge = null; // Initialize.

        if ($args['charge']) {
            try { // Acquire charge by ID.
                $Charge = Charge::retrieve($args['charge'], $opts);
            } catch (\Throwable $Exception) {
                return $this->exceptionError($Exception);
            }
        } else { // Create a new charge.
            try {
                $new_charge_args = [
                    'customer'      => $args['customer'],
                    'receipt_email' => $args['receipt_email'] ?: null,

                    'amount'      => $args['amount'],
                    'currency'    => $args['currency'],
                    'description' => $args['description'] ?: null,

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

@since 170329.13807 Stripe utils.

@param string|array $args ID or args.

@return Charge|Error Charge on success.