• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

stripe / stripe-php / 7065595149

01 Dec 2023 09:55PM UTC coverage: 68.923% (-0.08%) from 69.002%
7065595149

push

github

web-flow
Merge pull request #1612 from stripe/richardm-usage

Report usage of .save and StripeClient

9 of 22 new or added lines in 5 files covered. (40.91%)

1 existing line in 1 file now uncovered.

2393 of 3472 relevant lines covered (68.92%)

3.48 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

51.85
/lib/ApiOperations/Request.php
1
<?php
2

3
namespace Stripe\ApiOperations;
4

5
/**
6
 * Trait for resources that need to make API requests.
7
 *
8
 * This trait should only be applied to classes that derive from StripeObject.
9
 */
10
trait Request
11
{
12
    /**
13
     * @param null|array|mixed $params The list of parameters to validate
14
     *
15
     * @throws \Stripe\Exception\InvalidArgumentException if $params exists and is not an array
16
     */
17
    protected static function _validateParams($params = null)
15✔
18
    {
19
        if ($params && !\is_array($params)) {
15✔
20
            $message = 'You must pass an array as the first argument to Stripe API '
×
21
               . 'method calls.  (HINT: an example call to create a charge '
×
22
               . "would be: \"Stripe\\Charge::create(['amount' => 100, "
×
23
               . "'currency' => 'usd', 'source' => 'tok_1234'])\")";
×
24

25
            throw new \Stripe\Exception\InvalidArgumentException($message);
×
26
        }
27
    }
28

29
    /**
30
     * @param 'delete'|'get'|'post' $method HTTP method ('get', 'post', etc.)
31
     * @param string $url URL for the request
32
     * @param array $params list of parameters for the request
33
     * @param null|array|string $options
34
     * @param string[] $usage names of tracked behaviors associated with this request
35
     *
36
     * @throws \Stripe\Exception\ApiErrorException if the request fails
37
     *
38
     * @return array tuple containing (the JSON response, $options)
39
     */
40
    protected function _request($method, $url, $params = [], $options = null, $usage = [])
15✔
41
    {
42
        $opts = $this->_opts->merge($options);
15✔
43
        list($resp, $options) = static::_staticRequest($method, $url, $params, $opts, $usage);
15✔
44
        $this->setLastResponse($resp);
15✔
45

46
        return [$resp->json, $options];
15✔
47
    }
48

49
    /**
50
     * @param 'delete'|'get'|'post' $method HTTP method ('get', 'post', etc.)
51
     * @param string $url URL for the request
52
     * @param callable $readBodyChunk function that will receive chunks of data from a successful request body
53
     * @param array $params list of parameters for the request
54
     * @param null|array|string $options
55
     * @param string[] $usage names of tracked behaviors associated with this request
56
     *
57
     * @throws \Stripe\Exception\ApiErrorException if the request fails
58
     */
NEW
59
    protected function _requestStream($method, $url, $readBodyChunk, $params = [], $options = null, $usage = [])
×
60
    {
61
        $opts = $this->_opts->merge($options);
×
NEW
62
        static::_staticStreamingRequest($method, $url, $readBodyChunk, $params, $opts, $usage);
×
63
    }
64

65
    /**
66
     * @param 'delete'|'get'|'post' $method HTTP method ('get', 'post', etc.)
67
     * @param string $url URL for the request
68
     * @param array $params list of parameters for the request
69
     * @param null|array|string $options
70
     * @param string[] $usage names of tracked behaviors associated with this request
71
     *
72
     * @throws \Stripe\Exception\ApiErrorException if the request fails
73
     *
74
     * @return array tuple containing (the JSON response, $options)
75
     */
76
    protected static function _staticRequest($method, $url, $params, $options, $usage = [])
15✔
77
    {
78
        $opts = \Stripe\Util\RequestOptions::parse($options);
15✔
79
        $baseUrl = isset($opts->apiBase) ? $opts->apiBase : static::baseUrl();
15✔
80
        $requestor = new \Stripe\ApiRequestor($opts->apiKey, $baseUrl);
15✔
81
        list($response, $opts->apiKey) = $requestor->request($method, $url, $params, $opts->headers, $usage);
15✔
82
        $opts->discardNonPersistentHeaders();
15✔
83

84
        return [$response, $opts];
15✔
85
    }
86

87
    /**
88
     * @param 'delete'|'get'|'post' $method HTTP method ('get', 'post', etc.)
89
     * @param string $url URL for the request
90
     * @param callable $readBodyChunk function that will receive chunks of data from a successful request body
91
     * @param array $params list of parameters for the request
92
     * @param null|array|string $options
93
     * @param string[] $usage names of tracked behaviors associated with this request
94
     *
95
     * @throws \Stripe\Exception\ApiErrorException if the request fails
96
     */
NEW
97
    protected static function _staticStreamingRequest($method, $url, $readBodyChunk, $params, $options, $usage = [])
×
98
    {
99
        $opts = \Stripe\Util\RequestOptions::parse($options);
×
100
        $baseUrl = isset($opts->apiBase) ? $opts->apiBase : static::baseUrl();
×
101
        $requestor = new \Stripe\ApiRequestor($opts->apiKey, $baseUrl);
×
102
        $requestor->requestStream($method, $url, $readBodyChunk, $params, $opts->headers);
×
103
    }
104
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc