public function customer($args)
    {
        if (is_string($args)) {
            $args = ['customer' => $args];
        } // Convert customer ID into args.

        $default_args = [
            'api_key'  => '', // Stripe API key.
            'customer' => '', // Existing customer ID.

            // Everything else is for a new customer, or for an update.
            // i.e., If `update_existing=true`, customer is updated to this info.
            // ~ Anything that is not passed in will not be changed in any way.
            'update_existing' => false, // Update if exists?

            'ip'    => '', // New customer IP address.
            'email' => '', // New customer email address.

            'fname' => '', // New customer first name.
            'lname' => '', // New customer last name.

            'source'            => '', // New customer source.
            'is_default_source' => true, // Is the default source?
            'description'       => '', // New customer description.

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

        if (!$args['description']) { // Full name.
            $args['description'] = $this->c::mbTrim($args['fname'].' '.$args['lname']);
        }
        $Customer = null; // Initialize.

        if ($args['customer']) {
            try { // Acquire customer by ID.
                $Customer = Customer::retrieve($args['customer'], $opts);
            } catch (\Throwable $Exception) {
                return $this->exceptionError($Exception);
            }
            if ($Customer instanceof Customer && $args['update_existing']) {
                $Customer = $this->updateCustomer($args, $Customer);
            }
        } else { // Create a new customer.
            try {
                $new_customer_args = [
                    'email'       => $args['email'] ?: null,
                    'source'      => $args['source'] ?: null,
                    'description' => $args['description'] ?: null,

                    'metadata' => array_merge([
                        'ip'    => $args['ip'],
                        'email' => $args['email'],

                        'fname' => $args['fname'],
                        'lname' => $args['lname'],

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

        $default_args = [
            'api_key'  => '', // Stripe API key.
            'customer' => '', // Existing customer ID.

            // Everything else is for a new customer, or for an update.
            // i.e., If `update_existing=true`, customer is updated to this info.
            // ~ Anything that is not passed in will not be changed in any way.
            'update_existing' => false, // Update if exists?

            'ip'    => '', // New customer IP address.
            'email' => '', // New customer email address.

            'fname' => '', // New customer first name.
            'lname' => '', // New customer last name.

            'source'            => '', // New customer source.
            'is_default_source' => true, // Is the default source?
            'description'       => '', // New customer description.

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

        if (!$args['description']) { // Full name.
            $args['description'] = $this->c::mbTrim($args['fname'].' '.$args['lname']);
        }
        $Customer = null; // Initialize.

        if ($args['customer']) {
            try { // Acquire customer by ID.
                $Customer = Customer::retrieve($args['customer'], $opts);
            } catch (\Throwable $Exception) {
                return $this->exceptionError($Exception);
            }
            if ($Customer instanceof Customer && $args['update_existing']) {
                $Customer = $this->updateCustomer($args, $Customer);
            }
        } else { // Create a new customer.
            try {
                $new_customer_args = [
                    'email'       => $args['email'] ?: null,
                    'source'      => $args['source'] ?: null,
                    'description' => $args['description'] ?: null,

                    'metadata' => array_merge([
                        'ip'    => $args['ip'],
                        'email' => $args['email'],

                        'fname' => $args['fname'],
                        'lname' => $args['lname'],

                        'user_id' => $args['user_id'],
                    ], $args['metadata']),
                ];
                $new_customer_args = $this->c::removeNulls($new_customer_args);
                $Customer          = Customer::create($new_customer_args, $opts);
            } catch (\Throwable $Exception) {
                return $this->exceptionError($Exception);
            }
        }
        if (!($Customer instanceof Customer)) {
            $_error = sprintf('Failed to acquire customer.');
            return $this->exceptionError(new Exception($_error));
        }
        return $Customer;
    }
public function customer ( $ args ) { if ( is_string ( $ args ) ) { $ args = [ 'customer' => $ args ] ; } // Convert customer ID into args. $ default_args = [ 'api_key' => '' , // Stripe API key. 'customer' => '' , // Existing customer ID. // Everything else is for a new customer, or for an update. // i.e., If `update_existing=true`, customer is updated to this info. // ~ Anything that is not passed in will not be changed in any way. 'update_existing' => false , // Update if exists? 'ip' => '' , // New customer IP address. 'email' => '' , // New customer email address. 'fname' => '' , // New customer first name. 'lname' => '' , // New customer last name. 'source' => '' , // New customer source. 'is_default_source' => true , // Is the default source? 'description' => '' , // New customer description. 'user_id' => '' , // New customer user ID. 'metadata' => '' , // New customer metadata. ] ; $ args = ( array ) $ args ; // Force array. $ args = array_merge ( $ default_args , $ args ) ; $ args = array_intersect_key ( $ args , $ default_args ) ; extract ( $ this -> parseArgs ( __FUNCTION__ , $ args ) ) ; if ( ! $ args [ 'description' ] ) { // Full name. $ args [ 'description' ] = $ this -> c :: mbTrim ( $ args [ 'fname' ] . ' ' . $ args [ 'lname' ] ) ; } $ Customer = null ; // Initialize. if ( $ args [ 'customer' ] ) { try { // Acquire customer by ID. $ Customer = Customer :: retrieve ( $ args [ 'customer' ] , $ opts ) ; } catch ( \ Throwable $ Exception ) { return $ this -> exceptionError ( $ Exception ) ; } if ( $ Customer instanceof Customer && $ args [ 'update_existing' ] ) { $ Customer = $ this -> updateCustomer ( $ args , $ Customer ) ; } } else { // Create a new customer. try { $ new_customer_args = [ 'email' => $ args [ 'email' ] ? : null , 'source' => $ args [ 'source' ] ? : null , 'description' => $ args [ 'description' ] ? : null , 'metadata' => array_merge ( [ 'ip' => $ args [ 'ip' ] , 'email' => $ args [ 'email' ] , 'fname' => $ args [ 'fname' ] , 'lname' => $ args [ 'lname' ] , 'user_id' => $ args [ 'user_id' ] , ] , $ args [ 'metadata' ] ) , ] ; $ new_customer_args = $ this -> c :: removeNulls ( $ new_customer_args ) ; $ Customer = Customer :: create ( $ new_customer_args , $ opts ) ; } catch ( \ Throwable $ Exception ) { return $ this -> exceptionError ( $ Exception ) ; } } if ( ! ( $ Customer instanceof Customer ) ) { $ _error = sprintf ( 'Failed to acquire customer.' ) ; return $ this -> exceptionError ( new Exception ( $ _error ) ) ; } return $ Customer ; }
Get, update, or create customer.

@since 170329.13807 Stripe utils.

@param string|array $args ID or args.

@return Customer|Error Customer on success.
Get update or create customer .