diff --git a/stripe_api.module b/stripe_api.module index bcac1b7..60ce6fb 100644 --- a/stripe_api.module +++ b/stripe_api.module @@ -21,15 +21,33 @@ use Drupal\Component\Serialization\Json; * @param mixed $params * Additional params to pass to the method. Can be an array, string. * + * @param mixed $options + * Header options for request. + * * @return Stripe\ApiResource * Returns the ApiResource or NULL on error. */ -function stripe_api_call($obj, $method = NULL, $params = NULL) { +function stripe_api_call($obj, $method = NULL, $params = NULL, $options = NULL) { + $args = func_get_args(); + // Remove $obj from the arguments. + unset($args[0]); + // Remove $method from the arguments. + unset($args[1]); + $args_count = count($args); + $obj = ucfirst($obj); $class = '\\Stripe\\' . $obj; if ($method) { try { - return call_user_func([$class, $method], $params); + if ($args_count == 1) { + return call_user_func([$class, $method], $params); + } + elseif ($args_count == 2) { + return call_user_func_array([$class, $method], [$params, $options]); + } + else { + return call_user_func(array($class, $method)); + } } catch (Exception $e) { \Drupal::logger('stripe_api')->error('Error: @error
@args', [ '@args' => Json::encode([