|
| 1 | +# Retrieving payments |
| 2 | + |
| 3 | +Use these methods to retrieve payment details from ThePay API — either a single payment by UID or multiple payments using filters and pagination. |
| 4 | + |
| 5 | +## Get a Single Payment |
| 6 | + |
| 7 | +To retrieve information about a single payment, call: |
| 8 | + |
| 9 | +```php |
| 10 | +$payment = $thePayClient->getPayment('49096fe3-872d-3cbe-b908-2806ae2d7c79'); |
| 11 | +``` |
| 12 | + |
| 13 | +**Parameters:** |
| 14 | +- string `$uid` — Unique identifier (UID) of the payment. |
| 15 | + |
| 16 | +The payment must belong to the project configured in TheConfig. |
| 17 | + |
| 18 | +**Returns:** |
| 19 | + |
| 20 | +An object describing the payment. |
| 21 | + |
| 22 | +## Get Multiple Payments |
| 23 | + |
| 24 | +To retrieve multiple payments, you can use filters and pagination: |
| 25 | + |
| 26 | +```php |
| 27 | +/** @var \ThePay\ApiClient\TheClient $thePayClient */ |
| 28 | +$filters = new \ThePay\ApiClient\Filter\PaymentsFilter(); |
| 29 | +$paymentPaginatedCollection = $thePayClient->getPayments($filters); |
| 30 | +``` |
| 31 | + |
| 32 | +**Parameters:** |
| 33 | +- `$filters` — An instance of `\ThePay\ApiClient\Filter\PaymentsFilter()`. (See online API documentation for all available filter options.) |
| 34 | +- `$page` *(optional)* — Page number. |
| 35 | +- `$limit` *(optional)* — Number of records per page. |
| 36 | + |
| 37 | +**Returns:** |
| 38 | + |
| 39 | +A `PaymentCollection` object containing: |
| 40 | +- A collection of payments |
| 41 | +- Current page number |
| 42 | +- Number of records per page |
| 43 | +- Includes helper methods such as `hasNextPage()` and `getPage()` |
| 44 | + |
| 45 | +**Example: Iterate through all pages** |
| 46 | + |
| 47 | +```php |
| 48 | +/** @var \ThePay\ApiClient\TheClient $thePayClient */ |
| 49 | +$filters = new \ThePay\ApiClient\Filter\PaymentsFilter(); |
| 50 | +$page = 1; |
| 51 | + |
| 52 | +do { |
| 53 | + $collection = $thePayClient->getPayments($filters, $page); |
| 54 | + |
| 55 | + foreach ($collection->all() as $payment) { |
| 56 | + // print logic |
| 57 | + } |
| 58 | + |
| 59 | + $page = $collection->getPage() + 1; |
| 60 | +} while($collection->hasNextPage()); |
| 61 | +``` |
0 commit comments