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

stripe / stripe-php / 6471862601

10 Oct 2023 04:02PM UTC coverage: 69.665% (-0.5%) from 70.141%
6471862601

push

github

web-flow
Merge pull request #1570 from localheinz/feature/coveralls

Enhancement: Use `coverallsapp/github-action` to report code coverage

2393 of 3435 relevant lines covered (69.67%)

3.5 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
     *
35
     * @throws \Stripe\Exception\ApiErrorException if the request fails
36
     *
37
     * @return array tuple containing (the JSON response, $options)
38
     */
39
    protected function _request($method, $url, $params = [], $options = null)
15✔
40
    {
41
        $opts = $this->_opts->merge($options);
15✔
42
        list($resp, $options) = static::_staticRequest($method, $url, $params, $opts);
15✔
43
        $this->setLastResponse($resp);
15✔
44

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

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

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

81
        return [$response, $opts];
15✔
82
    }
83

84
    /**
85
     * @param 'delete'|'get'|'post' $method HTTP method ('get', 'post', etc.)
86
     * @param string $url URL for the request
87
     * @param callable $readBodyChunk function that will receive chunks of data from a successful request body
88
     * @param array $params list of parameters for the request
89
     * @param null|array|string $options
90
     *
91
     * @throws \Stripe\Exception\ApiErrorException if the request fails
92
     */
93
    protected static function _staticStreamingRequest($method, $url, $readBodyChunk, $params, $options)
×
94
    {
95
        $opts = \Stripe\Util\RequestOptions::parse($options);
×
96
        $baseUrl = isset($opts->apiBase) ? $opts->apiBase : static::baseUrl();
×
97
        $requestor = new \Stripe\ApiRequestor($opts->apiKey, $baseUrl);
×
98
        $requestor->requestStream($method, $url, $readBodyChunk, $params, $opts->headers);
×
99
    }
100
}
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