diff --git a/lib/PaymentRails/Balance.php b/lib/PaymentRails/Balance.php new file mode 100644 index 0000000..d1090c3 --- /dev/null +++ b/lib/PaymentRails/Balance.php @@ -0,0 +1,91 @@ +balance()->search([]); + } + + /** + * sets instance properties from an array of values + * + * @ignore + * @access protected + * @param array $transactionAttribs array of transaction data + * @return void + */ + protected function _initialize($attributes) { + $fields = [ + "accountNumber", + "amount", + "amountCleared", + "amountPending", + "currency", + "display", + "pendingCredit", + "pendingDebit", + "primary", + "provider", + "providerAcct", + "providerId", + "type" + ]; + + foreach ($fields as $field) { + if (isset($attributes[$field])) { + $this->_set($field, $attributes[$field]); + } + } + } + + /** + * factory method: returns an instance of Transaction + * to the requesting method, with populated properties + * + * @ignore + * @return Transaction + */ + public static function factory($attributes) + { + $instance = new self(); + $instance->_initialize($attributes); + return $instance; + } +} + +class_alias('PaymentRails\Balance', 'PaymentRails_Balance'); diff --git a/lib/PaymentRails/BalanceGateway.php b/lib/PaymentRails/BalanceGateway.php new file mode 100644 index 0000000..e6d7c2c --- /dev/null +++ b/lib/PaymentRails/BalanceGateway.php @@ -0,0 +1,65 @@ +== More information == + * + * For more detailed information on Balance, see {@link http://docs.paymentrails.com/#balances} + * + * @package PaymentRails + * @category Resources + */ +class BalanceGateway +{ + private $_gateway; + private $_config; + private $_http; + + public function __construct($gateway) + { + $this->_gateway = $gateway; + $this->_config = $gateway->config; + $this->_config->assertHasAccessTokenOrKeys(); + $this->_http = new Http($gateway->config); + } + + /** + * Returns a ResourceCollection of transactions matching the search query. + * + * If query is a string, the search will be a basic search. + * If query is a hash, the search will be an advanced search. + * For more detailed information and examples, see {@link http://docs.paymentrails.com/#balances} + * + * @param mixed $query search query + * @param array $options options such as page number + * @return ResourceCollection + * @throws InvalidArgumentException + */ + public function search($query) + { + $response = $this->_http->get('/v1/balances', $query); + + if ($response['ok']) { + $pager = [ + 'object' => $this, + 'method' => 'search', + 'methodArgs' => $query + ]; + + $items = array_map(function ($item) { + return Balance::factory($item); + }, $response['balances']); + + return new ResourceCollection($response, $items, $pager); + } else { + throw new Exception\DownForMaintenance(); + } + } +} + +class_alias('PaymentRails\BalanceGateway', 'PaymentRails_BalanceGateway'); diff --git a/lib/PaymentRails/Gateway.php b/lib/PaymentRails/Gateway.php index 284e289..a4a02b8 100644 --- a/lib/PaymentRails/Gateway.php +++ b/lib/PaymentRails/Gateway.php @@ -31,7 +31,7 @@ public function recipient() } /** - * @return RecipientGateway + * @return RecipientAccountGateway */ public function recipientAccount() { @@ -39,7 +39,7 @@ public function recipientAccount() } /** - * @return RecipientGateway + * @return BatchGateway */ public function batch() { @@ -61,6 +61,14 @@ public function offlinePayments() { return new OfflinePaymentGateway($this); } + + /** + * @return BalanceGateway + */ + public function balance() + { + return new BalanceGateway($this); + } } class_alias('PaymentRails\Gateway', 'PaymentRails_Gateway');