|
| 1 | +<?php |
| 2 | +namespace PaymentRails; |
| 3 | + |
| 4 | +use InvalidArgumentException; |
| 5 | + |
| 6 | +/** |
| 7 | + * PaymentRails Balance processor |
| 8 | + * Gets balances |
| 9 | + * |
| 10 | + * <b>== More information ==</b> |
| 11 | + * |
| 12 | + * For more detailed information on Balance, see {@link http://docs.paymentrails.com/#balances} |
| 13 | + * |
| 14 | + * @package PaymentRails |
| 15 | + * @category Resources |
| 16 | + */ |
| 17 | +class BalanceGateway |
| 18 | +{ |
| 19 | + private $_gateway; |
| 20 | + private $_config; |
| 21 | + private $_http; |
| 22 | + |
| 23 | + public function __construct($gateway) |
| 24 | + { |
| 25 | + $this->_gateway = $gateway; |
| 26 | + $this->_config = $gateway->config; |
| 27 | + $this->_config->assertHasAccessTokenOrKeys(); |
| 28 | + $this->_http = new Http($gateway->config); |
| 29 | + } |
| 30 | + |
| 31 | + /** |
| 32 | + * Returns a ResourceCollection of transactions matching the search query. |
| 33 | + * |
| 34 | + * If <b>query</b> is a string, the search will be a basic search. |
| 35 | + * If <b>query</b> is a hash, the search will be an advanced search. |
| 36 | + * For more detailed information and examples, see {@link http://docs.paymentrails.com/#balances} |
| 37 | + * |
| 38 | + * @param mixed $query search query |
| 39 | + * @param array $options options such as page number |
| 40 | + * @return ResourceCollection |
| 41 | + * @throws InvalidArgumentException |
| 42 | + */ |
| 43 | + public function search($query) |
| 44 | + { |
| 45 | + $response = $this->_http->get('/v1/balances', $query); |
| 46 | + |
| 47 | + if ($response['ok']) { |
| 48 | + $pager = [ |
| 49 | + 'object' => $this, |
| 50 | + 'method' => 'search', |
| 51 | + 'methodArgs' => $query |
| 52 | + ]; |
| 53 | + |
| 54 | + $items = array_map(function ($item) { |
| 55 | + return Balance::factory($item); |
| 56 | + }, $response['balances']); |
| 57 | + |
| 58 | + return new ResourceCollection($response, $items, $pager); |
| 59 | + } else { |
| 60 | + throw new Exception\DownForMaintenance(); |
| 61 | + } |
| 62 | + } |
| 63 | +} |
| 64 | + |
| 65 | +class_alias('PaymentRails\BalanceGateway', 'PaymentRails_BalanceGateway'); |
0 commit comments