Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 91 additions & 0 deletions lib/PaymentRails/Balance.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?php
namespace PaymentRails;

/**
* PaymentRails Balance module
* PHP Version 5
* Gets merchant balances
*
* @package PaymentRails
*
*/
class Balance extends Base
{
/**
* @access protected
* @var array registry of customer data
*/
protected $_attributes = [
"accountNumber",
"amount",
"amountCleared",
"amountPending",
"currency",
"display",
"pendingCredit",
"pendingDebit",
"primary",
"provider",
"providerAcct",
"providerId",
"type"
];

/**
* Show all balances
*
* @return Balance
*/
public static function all()
{
return Configuration::gateway()->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');
65 changes: 65 additions & 0 deletions lib/PaymentRails/BalanceGateway.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php
namespace PaymentRails;

use InvalidArgumentException;

/**
* PaymentRails Balance processor
* Gets balances
*
* <b>== More information ==</b>
*
* 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 <b>query</b> is a string, the search will be a basic search.
* If <b>query</b> 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');
12 changes: 10 additions & 2 deletions lib/PaymentRails/Gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ public function recipient()
}

/**
* @return RecipientGateway
* @return RecipientAccountGateway
*/
public function recipientAccount()
{
return new RecipientAccountGateway($this);
}

/**
* @return RecipientGateway
* @return BatchGateway
*/
public function batch()
{
Expand All @@ -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');