1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
namespace Stripe;
/**
* Class Collection
*
* @property string $object
* @property string $url
* @property bool $has_more
* @property mixed $data
*
* @package Stripe
*/
class Collection extends StripeObject implements \IteratorAggregate
{
const OBJECT_NAME = "list";
use ApiOperations\Request;
protected $_requestParams = [];
/**
* @return string The base URL for the given class.
*/
public static function baseUrl()
{
return Stripe::$apiBase;
}
public function setRequestParams($params)
{
$this->_requestParams = $params;
}
public function all($params = null, $opts = null)
{
list($url, $params) = $this->extractPathAndUpdateParams($params);
list($response, $opts) = $this->_request('get', $url, $params, $opts);
$this->_requestParams = $params;
return Util\Util::convertToStripeObject($response, $opts);
}
public function create($params = null, $opts = null)
{
list($url, $params) = $this->extractPathAndUpdateParams($params);
list($response, $opts) = $this->_request('post', $url, $params, $opts);
$this->_requestParams = $params;
return Util\Util::convertToStripeObject($response, $opts);
}
public function retrieve($id, $params = null, $opts = null)
{
list($url, $params) = $this->extractPathAndUpdateParams($params);
$id = Util\Util::utf8($id);
$extn = urlencode($id);
list($response, $opts) = $this->_request(
'get',
"$url/$extn",
$params,
$opts
);
$this->_requestParams = $params;
return Util\Util::convertToStripeObject($response, $opts);
}
/**
* @return \ArrayIterator An iterator that can be used to iterate
* across objects in the current page.
*/
public function getIterator()
{
return new \ArrayIterator($this->data);
}
/**
* @return Util\AutoPagingIterator An iterator that can be used to iterate
* across all objects across all pages. As page boundaries are
* encountered, the next page will be fetched automatically for
* continued iteration.
*/
public function autoPagingIterator()
{
return new Util\AutoPagingIterator($this, $this->_requestParams);
}
private function extractPathAndUpdateParams($params)
{
$url = parse_url($this->url);
if (!isset($url['path'])) {
throw new Error\Api("Could not parse list url into parts: $url");
}
if (isset($url['query'])) {
// If the URL contains a query param, parse it out into $params so they
// don't interact weirdly with each other.
$query = [];
parse_str($url['query'], $query);
$params = array_merge($params ?: [], $query);
}
return [$url['path'], $params];
}
}