Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/wp-conte.../plugins/wpforms-.../vendor_p.../stripe/stripe-p.../lib
File: BaseStripeClient.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace WPForms\Vendor\Stripe;
[2] Fix | Delete
[3] Fix | Delete
class BaseStripeClient implements StripeClientInterface, StripeStreamingClientInterface
[4] Fix | Delete
{
[5] Fix | Delete
/** @var string default base URL for Stripe's API */
[6] Fix | Delete
const DEFAULT_API_BASE = 'https://api.stripe.com';
[7] Fix | Delete
/** @var string default base URL for Stripe's OAuth API */
[8] Fix | Delete
const DEFAULT_CONNECT_BASE = 'https://connect.stripe.com';
[9] Fix | Delete
/** @var string default base URL for Stripe's Files API */
[10] Fix | Delete
const DEFAULT_FILES_BASE = 'https://files.stripe.com';
[11] Fix | Delete
/** @var array<string, null|string> */
[12] Fix | Delete
const DEFAULT_CONFIG = ['api_key' => null, 'client_id' => null, 'stripe_account' => null, 'stripe_version' => \WPForms\Vendor\Stripe\Util\ApiVersion::CURRENT, 'api_base' => self::DEFAULT_API_BASE, 'connect_base' => self::DEFAULT_CONNECT_BASE, 'files_base' => self::DEFAULT_FILES_BASE];
[13] Fix | Delete
/** @var array<string, mixed> */
[14] Fix | Delete
private $config;
[15] Fix | Delete
/** @var \Stripe\Util\RequestOptions */
[16] Fix | Delete
private $defaultOpts;
[17] Fix | Delete
/**
[18] Fix | Delete
* Initializes a new instance of the {@link BaseStripeClient} class.
[19] Fix | Delete
*
[20] Fix | Delete
* The constructor takes a single argument. The argument can be a string, in which case it
[21] Fix | Delete
* should be the API key. It can also be an array with various configuration settings.
[22] Fix | Delete
*
[23] Fix | Delete
* Configuration settings include the following options:
[24] Fix | Delete
*
[25] Fix | Delete
* - api_key (null|string): the Stripe API key, to be used in regular API requests.
[26] Fix | Delete
* - client_id (null|string): the Stripe client ID, to be used in OAuth requests.
[27] Fix | Delete
* - stripe_account (null|string): a Stripe account ID. If set, all requests sent by the client
[28] Fix | Delete
* will automatically use the {@code Stripe-Account} header with that account ID.
[29] Fix | Delete
* - stripe_version (null|string): a Stripe API verion. If set, all requests sent by the client
[30] Fix | Delete
* will include the {@code Stripe-Version} header with that API version.
[31] Fix | Delete
*
[32] Fix | Delete
* The following configuration settings are also available, though setting these should rarely be necessary
[33] Fix | Delete
* (only useful if you want to send requests to a mock server like stripe-mock):
[34] Fix | Delete
*
[35] Fix | Delete
* - api_base (string): the base URL for regular API requests. Defaults to
[36] Fix | Delete
* {@link DEFAULT_API_BASE}.
[37] Fix | Delete
* - connect_base (string): the base URL for OAuth requests. Defaults to
[38] Fix | Delete
* {@link DEFAULT_CONNECT_BASE}.
[39] Fix | Delete
* - files_base (string): the base URL for file creation requests. Defaults to
[40] Fix | Delete
* {@link DEFAULT_FILES_BASE}.
[41] Fix | Delete
*
[42] Fix | Delete
* @param array<string, mixed>|string $config the API key as a string, or an array containing
[43] Fix | Delete
* the client configuration settings
[44] Fix | Delete
*/
[45] Fix | Delete
public function __construct($config = [])
[46] Fix | Delete
{
[47] Fix | Delete
if (\is_string($config)) {
[48] Fix | Delete
$config = ['api_key' => $config];
[49] Fix | Delete
} elseif (!\is_array($config)) {
[50] Fix | Delete
throw new \WPForms\Vendor\Stripe\Exception\InvalidArgumentException('$config must be a string or an array');
[51] Fix | Delete
}
[52] Fix | Delete
$config = \array_merge(self::DEFAULT_CONFIG, $config);
[53] Fix | Delete
$this->validateConfig($config);
[54] Fix | Delete
$this->config = $config;
[55] Fix | Delete
$this->defaultOpts = \WPForms\Vendor\Stripe\Util\RequestOptions::parse(['stripe_account' => $config['stripe_account'], 'stripe_version' => $config['stripe_version']]);
[56] Fix | Delete
}
[57] Fix | Delete
/**
[58] Fix | Delete
* Gets the API key used by the client to send requests.
[59] Fix | Delete
*
[60] Fix | Delete
* @return null|string the API key used by the client to send requests
[61] Fix | Delete
*/
[62] Fix | Delete
public function getApiKey()
[63] Fix | Delete
{
[64] Fix | Delete
return $this->config['api_key'];
[65] Fix | Delete
}
[66] Fix | Delete
/**
[67] Fix | Delete
* Gets the client ID used by the client in OAuth requests.
[68] Fix | Delete
*
[69] Fix | Delete
* @return null|string the client ID used by the client in OAuth requests
[70] Fix | Delete
*/
[71] Fix | Delete
public function getClientId()
[72] Fix | Delete
{
[73] Fix | Delete
return $this->config['client_id'];
[74] Fix | Delete
}
[75] Fix | Delete
/**
[76] Fix | Delete
* Gets the base URL for Stripe's API.
[77] Fix | Delete
*
[78] Fix | Delete
* @return string the base URL for Stripe's API
[79] Fix | Delete
*/
[80] Fix | Delete
public function getApiBase()
[81] Fix | Delete
{
[82] Fix | Delete
return $this->config['api_base'];
[83] Fix | Delete
}
[84] Fix | Delete
/**
[85] Fix | Delete
* Gets the base URL for Stripe's OAuth API.
[86] Fix | Delete
*
[87] Fix | Delete
* @return string the base URL for Stripe's OAuth API
[88] Fix | Delete
*/
[89] Fix | Delete
public function getConnectBase()
[90] Fix | Delete
{
[91] Fix | Delete
return $this->config['connect_base'];
[92] Fix | Delete
}
[93] Fix | Delete
/**
[94] Fix | Delete
* Gets the base URL for Stripe's Files API.
[95] Fix | Delete
*
[96] Fix | Delete
* @return string the base URL for Stripe's Files API
[97] Fix | Delete
*/
[98] Fix | Delete
public function getFilesBase()
[99] Fix | Delete
{
[100] Fix | Delete
return $this->config['files_base'];
[101] Fix | Delete
}
[102] Fix | Delete
/**
[103] Fix | Delete
* Sends a request to Stripe's API.
[104] Fix | Delete
*
[105] Fix | Delete
* @param 'delete'|'get'|'post' $method the HTTP method
[106] Fix | Delete
* @param string $path the path of the request
[107] Fix | Delete
* @param array $params the parameters of the request
[108] Fix | Delete
* @param array|\Stripe\Util\RequestOptions $opts the special modifiers of the request
[109] Fix | Delete
*
[110] Fix | Delete
* @return \Stripe\StripeObject the object returned by Stripe's API
[111] Fix | Delete
*/
[112] Fix | Delete
public function request($method, $path, $params, $opts)
[113] Fix | Delete
{
[114] Fix | Delete
$opts = $this->defaultOpts->merge($opts, \true);
[115] Fix | Delete
$baseUrl = $opts->apiBase ?: $this->getApiBase();
[116] Fix | Delete
$requestor = new \WPForms\Vendor\Stripe\ApiRequestor($this->apiKeyForRequest($opts), $baseUrl);
[117] Fix | Delete
list($response, $opts->apiKey) = $requestor->request($method, $path, $params, $opts->headers, ['stripe_client']);
[118] Fix | Delete
$opts->discardNonPersistentHeaders();
[119] Fix | Delete
$obj = \WPForms\Vendor\Stripe\Util\Util::convertToStripeObject($response->json, $opts);
[120] Fix | Delete
$obj->setLastResponse($response);
[121] Fix | Delete
return $obj;
[122] Fix | Delete
}
[123] Fix | Delete
/**
[124] Fix | Delete
* Sends a request to Stripe's API, passing chunks of the streamed response
[125] Fix | Delete
* into a user-provided $readBodyChunkCallable callback.
[126] Fix | Delete
*
[127] Fix | Delete
* @param 'delete'|'get'|'post' $method the HTTP method
[128] Fix | Delete
* @param string $path the path of the request
[129] Fix | Delete
* @param callable $readBodyChunkCallable a function that will be called
[130] Fix | Delete
* @param array $params the parameters of the request
[131] Fix | Delete
* @param array|\Stripe\Util\RequestOptions $opts the special modifiers of the request
[132] Fix | Delete
* with chunks of bytes from the body if the request is successful
[133] Fix | Delete
*/
[134] Fix | Delete
public function requestStream($method, $path, $readBodyChunkCallable, $params, $opts)
[135] Fix | Delete
{
[136] Fix | Delete
$opts = $this->defaultOpts->merge($opts, \true);
[137] Fix | Delete
$baseUrl = $opts->apiBase ?: $this->getApiBase();
[138] Fix | Delete
$requestor = new \WPForms\Vendor\Stripe\ApiRequestor($this->apiKeyForRequest($opts), $baseUrl);
[139] Fix | Delete
list($response, $opts->apiKey) = $requestor->requestStream($method, $path, $readBodyChunkCallable, $params, $opts->headers, ['stripe_client']);
[140] Fix | Delete
}
[141] Fix | Delete
/**
[142] Fix | Delete
* Sends a request to Stripe's API.
[143] Fix | Delete
*
[144] Fix | Delete
* @param 'delete'|'get'|'post' $method the HTTP method
[145] Fix | Delete
* @param string $path the path of the request
[146] Fix | Delete
* @param array $params the parameters of the request
[147] Fix | Delete
* @param array|\Stripe\Util\RequestOptions $opts the special modifiers of the request
[148] Fix | Delete
*
[149] Fix | Delete
* @return \Stripe\Collection of ApiResources
[150] Fix | Delete
*/
[151] Fix | Delete
public function requestCollection($method, $path, $params, $opts)
[152] Fix | Delete
{
[153] Fix | Delete
$obj = $this->request($method, $path, $params, $opts);
[154] Fix | Delete
if (!$obj instanceof \WPForms\Vendor\Stripe\Collection) {
[155] Fix | Delete
$received_class = \get_class($obj);
[156] Fix | Delete
$msg = "Expected to receive `Stripe\\Collection` object from Stripe API. Instead received `{$received_class}`.";
[157] Fix | Delete
throw new \WPForms\Vendor\Stripe\Exception\UnexpectedValueException($msg);
[158] Fix | Delete
}
[159] Fix | Delete
$obj->setFilters($params);
[160] Fix | Delete
return $obj;
[161] Fix | Delete
}
[162] Fix | Delete
/**
[163] Fix | Delete
* Sends a request to Stripe's API.
[164] Fix | Delete
*
[165] Fix | Delete
* @param 'delete'|'get'|'post' $method the HTTP method
[166] Fix | Delete
* @param string $path the path of the request
[167] Fix | Delete
* @param array $params the parameters of the request
[168] Fix | Delete
* @param array|\Stripe\Util\RequestOptions $opts the special modifiers of the request
[169] Fix | Delete
*
[170] Fix | Delete
* @return \Stripe\SearchResult of ApiResources
[171] Fix | Delete
*/
[172] Fix | Delete
public function requestSearchResult($method, $path, $params, $opts)
[173] Fix | Delete
{
[174] Fix | Delete
$obj = $this->request($method, $path, $params, $opts);
[175] Fix | Delete
if (!$obj instanceof \WPForms\Vendor\Stripe\SearchResult) {
[176] Fix | Delete
$received_class = \get_class($obj);
[177] Fix | Delete
$msg = "Expected to receive `Stripe\\SearchResult` object from Stripe API. Instead received `{$received_class}`.";
[178] Fix | Delete
throw new \WPForms\Vendor\Stripe\Exception\UnexpectedValueException($msg);
[179] Fix | Delete
}
[180] Fix | Delete
$obj->setFilters($params);
[181] Fix | Delete
return $obj;
[182] Fix | Delete
}
[183] Fix | Delete
/**
[184] Fix | Delete
* @param \Stripe\Util\RequestOptions $opts
[185] Fix | Delete
*
[186] Fix | Delete
* @throws \Stripe\Exception\AuthenticationException
[187] Fix | Delete
*
[188] Fix | Delete
* @return string
[189] Fix | Delete
*/
[190] Fix | Delete
private function apiKeyForRequest($opts)
[191] Fix | Delete
{
[192] Fix | Delete
$apiKey = $opts->apiKey ?: $this->getApiKey();
[193] Fix | Delete
if (null === $apiKey) {
[194] Fix | Delete
$msg = 'No API key provided. Set your API key when constructing the ' . 'StripeClient instance, or provide it on a per-request basis ' . 'using the `api_key` key in the $opts argument.';
[195] Fix | Delete
throw new \WPForms\Vendor\Stripe\Exception\AuthenticationException($msg);
[196] Fix | Delete
}
[197] Fix | Delete
return $apiKey;
[198] Fix | Delete
}
[199] Fix | Delete
/**
[200] Fix | Delete
* @param array<string, mixed> $config
[201] Fix | Delete
*
[202] Fix | Delete
* @throws \Stripe\Exception\InvalidArgumentException
[203] Fix | Delete
*/
[204] Fix | Delete
private function validateConfig($config)
[205] Fix | Delete
{
[206] Fix | Delete
// api_key
[207] Fix | Delete
if (null !== $config['api_key'] && !\is_string($config['api_key'])) {
[208] Fix | Delete
throw new \WPForms\Vendor\Stripe\Exception\InvalidArgumentException('api_key must be null or a string');
[209] Fix | Delete
}
[210] Fix | Delete
if (null !== $config['api_key'] && '' === $config['api_key']) {
[211] Fix | Delete
$msg = 'api_key cannot be the empty string';
[212] Fix | Delete
throw new \WPForms\Vendor\Stripe\Exception\InvalidArgumentException($msg);
[213] Fix | Delete
}
[214] Fix | Delete
if (null !== $config['api_key'] && \preg_match('/\\s/', $config['api_key'])) {
[215] Fix | Delete
$msg = 'api_key cannot contain whitespace';
[216] Fix | Delete
throw new \WPForms\Vendor\Stripe\Exception\InvalidArgumentException($msg);
[217] Fix | Delete
}
[218] Fix | Delete
// client_id
[219] Fix | Delete
if (null !== $config['client_id'] && !\is_string($config['client_id'])) {
[220] Fix | Delete
throw new \WPForms\Vendor\Stripe\Exception\InvalidArgumentException('client_id must be null or a string');
[221] Fix | Delete
}
[222] Fix | Delete
// stripe_account
[223] Fix | Delete
if (null !== $config['stripe_account'] && !\is_string($config['stripe_account'])) {
[224] Fix | Delete
throw new \WPForms\Vendor\Stripe\Exception\InvalidArgumentException('stripe_account must be null or a string');
[225] Fix | Delete
}
[226] Fix | Delete
// stripe_version
[227] Fix | Delete
if (null !== $config['stripe_version'] && !\is_string($config['stripe_version'])) {
[228] Fix | Delete
throw new \WPForms\Vendor\Stripe\Exception\InvalidArgumentException('stripe_version must be null or a string');
[229] Fix | Delete
}
[230] Fix | Delete
// api_base
[231] Fix | Delete
if (!\is_string($config['api_base'])) {
[232] Fix | Delete
throw new \WPForms\Vendor\Stripe\Exception\InvalidArgumentException('api_base must be a string');
[233] Fix | Delete
}
[234] Fix | Delete
// connect_base
[235] Fix | Delete
if (!\is_string($config['connect_base'])) {
[236] Fix | Delete
throw new \WPForms\Vendor\Stripe\Exception\InvalidArgumentException('connect_base must be a string');
[237] Fix | Delete
}
[238] Fix | Delete
// files_base
[239] Fix | Delete
if (!\is_string($config['files_base'])) {
[240] Fix | Delete
throw new \WPForms\Vendor\Stripe\Exception\InvalidArgumentException('files_base must be a string');
[241] Fix | Delete
}
[242] Fix | Delete
// check absence of extra keys
[243] Fix | Delete
$extraConfigKeys = \array_diff(\array_keys($config), \array_keys(self::DEFAULT_CONFIG));
[244] Fix | Delete
if (!empty($extraConfigKeys)) {
[245] Fix | Delete
// Wrap in single quote to more easily catch trailing spaces errors
[246] Fix | Delete
$invalidKeys = "'" . \implode("', '", $extraConfigKeys) . "'";
[247] Fix | Delete
throw new \WPForms\Vendor\Stripe\Exception\InvalidArgumentException('Found unknown key(s) in configuration array: ' . $invalidKeys);
[248] Fix | Delete
}
[249] Fix | Delete
}
[250] Fix | Delete
}
[251] Fix | Delete
[252] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function