src/Service/StripeManager.php
public function callStripeObject(ApiResource $object, string $method, array $arguments = [])
    {
        try {
            switch (count($arguments)) {
                // Method has no signature (it doesn't accept any argument)
                case 0:
                    $return = $object->$method();
                    break;
                // Method with 1 argument only accept one between "options" or "params"
                case 1:
                    // So we simply use the unique value in the array
                    $return = $object->$method($arguments[0]);
                    break;
                // Method with 3 arguments accept id, params and options
                case 2:
                    // 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  = $object->$method($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->callStripeObject($object, $method);
            }
        }

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

        return $return;
    }
public function callStripeObject(ApiResource $object, string $method, array $arguments = [])
    {
        try {
            switch (count($arguments)) {
                // Method has no signature (it doesn't accept any argument)
                case 0:
                    $return = $object->$method();
                    break;
                // Method with 1 argument only accept one between "options" or "params"
                case 1:
                    // So we simply use the unique value in the array
                    $return = $object->$method($arguments[0]);
                    break;
                // Method with 3 arguments accept id, params and options
                case 2:
                    // 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  = $object->$method($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->callStripeObject($object, $method);
            }
        }

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

        return $return;
    }
public function callStripeObject ( ApiResource $ object , string $ method , array $ arguments = [ ] ) { try { switch ( count ( $ arguments ) ) { // Method has no signature (it doesn't accept any argument) case 0 : $ return = $ object -> $ method ( ) ; break ; // Method with 1 argument only accept one between "options" or "params" case 1 : // So we simply use the unique value in the array $ return = $ object -> $ method ( $ arguments [ 0 ] ) ; break ; // Method with 3 arguments accept id, params and options case 2 : // 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 = $ object -> $ method ( $ 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 -> callStripeObject ( $ object , $ method ) ; } } // Reset the number of retries $ this -> retries = 0 ; return $ return ; }
Method to call the Stripe PHP SDK's NON static methods.

This method is usually used to call methods of a Stripe entity that is already initialized.

For example, it can be used to call "cancel" or "save" methods after they have been retrieved through
$this->callStripe(...).

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) params, options
3) params
4) [No arguments]

There are no confusable cases.

To make this method able to match the right Stripe SDK's method signature, set all the required arguments only
for methods that match the case 2 and if If one argument is not required, 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 SDK's method with signature that matches case 1 or case 3:

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

You can give the key a name for clarity, but in the callStripeObject method it is anyway referenced to as
$arguments[0], so is irrelevant you give a key or not.

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

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

You can give the key a name for clarity, but in the callStripeObject method it is anyway referenced to as
$arguments[0], so is irrelevant you give a key or not.

@param ApiResource $object
@param string      $method
@param array       $arguments

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