ApiOperations
6 years ago
Checkout
6 years ago
Error
6 years ago
HttpClient
6 years ago
Issuing
6 years ago
Radar
6 years ago
Reporting
6 years ago
Sigma
6 years ago
Terminal
6 years ago
Util
6 years ago
Account.php
6 years ago
AccountLink.php
6 years ago
AlipayAccount.php
6 years ago
ApiRequestor.php
6 years ago
ApiResource.php
6 years ago
ApiResponse.php
6 years ago
ApplePayDomain.php
6 years ago
ApplicationFee.php
6 years ago
ApplicationFeeRefund.php
6 years ago
Balance.php
6 years ago
BalanceTransaction.php
6 years ago
BankAccount.php
6 years ago
BitcoinReceiver.php
6 years ago
BitcoinTransaction.php
6 years ago
Capability.php
6 years ago
Card.php
6 years ago
Charge.php
6 years ago
Collection.php
6 years ago
CountrySpec.php
6 years ago
Coupon.php
6 years ago
CreditNote.php
6 years ago
Customer.php
6 years ago
CustomerBalanceTransaction.php
6 years ago
Discount.php
6 years ago
Dispute.php
6 years ago
EphemeralKey.php
6 years ago
Event.php
6 years ago
ExchangeRate.php
6 years ago
File.php
6 years ago
FileLink.php
6 years ago
FileUpload.php
6 years ago
Invoice.php
6 years ago
InvoiceItem.php
6 years ago
InvoiceLineItem.php
6 years ago
IssuerFraudRecord.php
6 years ago
LoginLink.php
6 years ago
OAuth.php
6 years ago
Order.php
6 years ago
OrderItem.php
6 years ago
OrderReturn.php
6 years ago
PaymentIntent.php
6 years ago
PaymentMethod.php
6 years ago
Payout.php
6 years ago
Person.php
6 years ago
Plan.php
6 years ago
Product.php
6 years ago
Recipient.php
6 years ago
RecipientTransfer.php
6 years ago
Refund.php
6 years ago
RequestTelemetry.php
6 years ago
Review.php
6 years ago
SKU.php
6 years ago
SetupIntent.php
6 years ago
SingletonApiResource.php
6 years ago
Source.php
6 years ago
SourceTransaction.php
6 years ago
Stripe.php
6 years ago
StripeObject.php
6 years ago
Subscription.php
6 years ago
SubscriptionItem.php
6 years ago
SubscriptionSchedule.php
6 years ago
TaxId.php
6 years ago
TaxRate.php
6 years ago
ThreeDSecure.php
6 years ago
Token.php
6 years ago
Topup.php
6 years ago
Transfer.php
6 years ago
TransferReversal.php
6 years ago
UsageRecord.php
6 years ago
UsageRecordSummary.php
6 years ago
Webhook.php
6 years ago
WebhookEndpoint.php
6 years ago
WebhookSignature.php
6 years ago
Collection.php
108 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Stripe; |
| 4 | |
| 5 | /** |
| 6 | * Class Collection |
| 7 | * |
| 8 | * @property string $object |
| 9 | * @property string $url |
| 10 | * @property bool $has_more |
| 11 | * @property mixed $data |
| 12 | * |
| 13 | * @package Stripe |
| 14 | */ |
| 15 | class Collection extends StripeObject implements \IteratorAggregate |
| 16 | { |
| 17 | const OBJECT_NAME = "list"; |
| 18 | |
| 19 | use ApiOperations\Request; |
| 20 | |
| 21 | protected $_requestParams = []; |
| 22 | |
| 23 | /** |
| 24 | * @return string The base URL for the given class. |
| 25 | */ |
| 26 | public static function baseUrl() |
| 27 | { |
| 28 | return Stripe::$apiBase; |
| 29 | } |
| 30 | |
| 31 | public function setRequestParams($params) |
| 32 | { |
| 33 | $this->_requestParams = $params; |
| 34 | } |
| 35 | |
| 36 | public function all($params = null, $opts = null) |
| 37 | { |
| 38 | list($url, $params) = $this->extractPathAndUpdateParams($params); |
| 39 | |
| 40 | list($response, $opts) = $this->_request('get', $url, $params, $opts); |
| 41 | $this->_requestParams = $params; |
| 42 | return Util\Util::convertToStripeObject($response, $opts); |
| 43 | } |
| 44 | |
| 45 | public function create($params = null, $opts = null) |
| 46 | { |
| 47 | list($url, $params) = $this->extractPathAndUpdateParams($params); |
| 48 | |
| 49 | list($response, $opts) = $this->_request('post', $url, $params, $opts); |
| 50 | $this->_requestParams = $params; |
| 51 | return Util\Util::convertToStripeObject($response, $opts); |
| 52 | } |
| 53 | |
| 54 | public function retrieve($id, $params = null, $opts = null) |
| 55 | { |
| 56 | list($url, $params) = $this->extractPathAndUpdateParams($params); |
| 57 | |
| 58 | $id = Util\Util::utf8($id); |
| 59 | $extn = urlencode($id); |
| 60 | list($response, $opts) = $this->_request( |
| 61 | 'get', |
| 62 | "$url/$extn", |
| 63 | $params, |
| 64 | $opts |
| 65 | ); |
| 66 | $this->_requestParams = $params; |
| 67 | return Util\Util::convertToStripeObject($response, $opts); |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * @return \ArrayIterator An iterator that can be used to iterate |
| 72 | * across objects in the current page. |
| 73 | */ |
| 74 | public function getIterator() |
| 75 | { |
| 76 | return new \ArrayIterator($this->data); |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * @return Util\AutoPagingIterator An iterator that can be used to iterate |
| 81 | * across all objects across all pages. As page boundaries are |
| 82 | * encountered, the next page will be fetched automatically for |
| 83 | * continued iteration. |
| 84 | */ |
| 85 | public function autoPagingIterator() |
| 86 | { |
| 87 | return new Util\AutoPagingIterator($this, $this->_requestParams); |
| 88 | } |
| 89 | |
| 90 | private function extractPathAndUpdateParams($params) |
| 91 | { |
| 92 | $url = parse_url($this->url); |
| 93 | if (!isset($url['path'])) { |
| 94 | throw new Error\Api("Could not parse list url into parts: $url"); |
| 95 | } |
| 96 | |
| 97 | if (isset($url['query'])) { |
| 98 | // If the URL contains a query param, parse it out into $params so they |
| 99 | // don't interact weirdly with each other. |
| 100 | $query = []; |
| 101 | parse_str($url['query'], $query); |
| 102 | $params = array_merge($params ?: [], $query); |
| 103 | } |
| 104 | |
| 105 | return [$url['path'], $params]; |
| 106 | } |
| 107 | } |
| 108 |