src/Service/StripeManager.php
public function callStripeApi(string $endpoint, string $action, array $arguments)
    {
        try {
            switch (count($arguments)) {
                // Method with 1 argument only accept "options"
                case 1:
                    // If the value is an empty array, then set it as null
                    $options = empty($arguments['options']) ? null : $arguments['options'];
                    $return  = $endpoint::$action($options);
                    break;
                case 2:
                    // If the ID exists, we have to call for sure a method that in the signature has the ID and the options
                    if (isset($arguments['id'])) {
                        // If the value is an empty array, then set it as null
                        $options = empty($arguments['options']) ? null : $arguments['options'];
                        $return  = $endpoint::$action($arguments['id'], $options);
                    }
                    // Else the method has params and options
                    else {
                        // If the value is an empty array, then set it as null
                        $params  = empty($arguments['params']) ? null : $arguments['params'];
                        $options = empty($arguments['options']) ? null : $arguments['options'];
                        $return  = $endpoint::$action($params, $options);
                    }
                    break;
                // Method with 3 arguments accept id, params and options
                case 3:
                    // If the value is an empty array, then set it as null
                    $params  = empty($arguments['params']) ? null : $arguments['params'];
                    $options = empty($arguments['options']) ? null : $arguments['options'];
                    $return  = $endpoint::$action($arguments['id'], $params, $options);
                    break;
                default:
                    throw new \RuntimeException('The arguments passed don\'t correspond to the allowed number. Please, review them.');
            }
        } catch (Base $e) {
            $return = $this->handleException($e);

            if ('retry' === $return) {
                $return = $this->callStripeApi($endpoint, $action, $arguments);
            }
        }

        // Reset the number of retries
        $this->retries = 0;

        return $return;
    }
public function callStripeApi(string $endpoint, string $action, array $arguments)
    {
        try {
            switch (count($arguments)) {
                // Method with 1 argument only accept "options"
                case 1:
                    // If the value is an empty array, then set it as null
                    $options = empty($arguments['options']) ? null : $arguments['options'];
                    $return  = $endpoint::$action($options);
                    break;
                case 2:
                    // If the ID exists, we have to call for sure a method that in the signature has the ID and the options
                    if (isset($arguments['id'])) {
                        // If the value is an empty array, then set it as null
                        $options = empty($arguments['options']) ? null : $arguments['options'];
                        $return  = $endpoint::$action($arguments['id'], $options);
                    }
                    // Else the method has params and options
                    else {
                        // If the value is an empty array, then set it as null
                        $params  = empty($arguments['params']) ? null : $arguments['params'];
                        $options = empty($arguments['options']) ? null : $arguments['options'];
                        $return  = $endpoint::$action($params, $options);
                    }
                    break;
                // Method with 3 arguments accept id, params and options
                case 3:
                    // If the value is an empty array, then set it as null
                    $params  = empty($arguments['params']) ? null : $arguments['params'];
                    $options = empty($arguments['options']) ? null : $arguments['options'];
                    $return  = $endpoint::$action($arguments['id'], $params, $options);
                    break;
                default:
                    throw new \RuntimeException('The arguments passed don\'t correspond to the allowed number. Please, review them.');
            }
        } catch (Base $e) {
            $return = $this->handleException($e);

            if ('retry' === $return) {
                $return = $this->callStripeApi($endpoint, $action, $arguments);
            }
        }

        // Reset the number of retries
        $this->retries = 0;

        return $return;
    }
public function callStripeApi ( string $ endpoint , string $ action , array $ arguments ) { try { switch ( count ( $ arguments ) ) { // Method with 1 argument only accept "options" case 1 : // If the value is an empty array, then set it as null $ options = empty ( $ arguments [ 'options' ] ) ? null : $ arguments [ 'options' ] ; $ return = $ endpoint :: $ action ( $ options ) ; break ; case 2 : // If the ID exists, we have to call for sure a method that in the signature has the ID and the options if ( isset ( $ arguments [ 'id' ] ) ) { // If the value is an empty array, then set it as null $ options = empty ( $ arguments [ 'options' ] ) ? null : $ arguments [ 'options' ] ; $ return = $ endpoint :: $ action ( $ arguments [ 'id' ] , $ options ) ; } // Else the method has params and options else { // If the value is an empty array, then set it as null $ params = empty ( $ arguments [ 'params' ] ) ? null : $ arguments [ 'params' ] ; $ options = empty ( $ arguments [ 'options' ] ) ? null : $ arguments [ 'options' ] ; $ return = $ endpoint :: $ action ( $ params , $ options ) ; } break ; // Method with 3 arguments accept id, params and options case 3 : // If the value is an empty array, then set it as null $ params = empty ( $ arguments [ 'params' ] ) ? null : $ arguments [ 'params' ] ; $ options = empty ( $ arguments [ 'options' ] ) ? null : $ arguments [ 'options' ] ; $ return = $ endpoint :: $ action ( $ arguments [ 'id' ] , $ params , $ options ) ; break ; default : throw new \ RuntimeException ( 'The arguments passed don\'t correspond to the allowed number. Please, review them.' ) ; } } catch ( Base $ e ) { $ return = $ this -> handleException ( $ e ) ; if ( 'retry' === $ return ) { $ return = $ this -> callStripeApi ( $ endpoint , $ action , $ arguments ) ; } } // Reset the number of retries $ this -> retries = 0 ; return $ return ; }
Method to call the Stripe PHP SDK's static methods.

This method wraps the calls in a try / catch statement to intercept exceptions raised by the Stripe client.

It receives three arguments:

1) The FQN of the Stripe Entity class;
2) The method of the class to invoke;
3) The arguments to pass to the method.

As the methods of the Stripe PHP SDK have all the same structure, it is possible to extract a pattern.

So, the alternatives are as following:

1) options
2) id, options
3) params, options
4) id, params, options

Only the case 2 and 3 are confusable.

To make this method able to match the right Stripe SDK's method signature, always set all the required arguments.
If one argument is not required (only options or params are allowed to be missed), anyway set it as an empty array.
BUT ANYWAY SET IT to make the switch able to match the proper method signature.

So, to call a Stripe API's entity with a method with signature that matches case 1:

$arguments = [
'options' => [...] // Or an empty array
];
$this->callStripe(Customer::class, 'save', $arguments)

To call a Stripe API's entity with a method with signature that matches case 2:

$arguments = [
'id' => 'the_id_of_the_entity',
'options' => [...] // Or an empty array
];
$this->callStripe(Customer::class, 'save', $arguments)

To call a Stripe API's entity with a method with signature that matches case 3:

$arguments = [
'params' => [...] // Or an empty array,
'options' => [...] // Or an empty array
];
$this->callStripe(Customer::class, 'save', $arguments)

To call a Stripe API's entity with a method with signature that matches case 4:

$arguments = [
'id' => 'the_id_of_the_entity',
'params' => [...] // Or an empty array,
'options' => [...] // Or an empty array
];
$this->callStripe(Customer::class, 'save', $arguments)

@param string $endpoint
@param string $action
@param array  $arguments

@return ApiResource|bool
Method to call the Stripe PHP SDK s static methods .