Skip to content

Commit

Permalink
Refactored to use the API rather than Screenscraping
Browse files Browse the repository at this point in the history
  • Loading branch information
owenobyrne committed Mar 23, 2019
1 parent 28aa9bd commit 01f8f4f
Show file tree
Hide file tree
Showing 27 changed files with 671 additions and 501 deletions.
65 changes: 39 additions & 26 deletions Fire/Business/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
use Fire\Business\Api\Login;
use Fire\Business\Api\AccountList;
use Fire\Business\Api\AccountDetails;
use Fire\Business\Api\CardList;
use Fire\Business\Api\CardDetails;
use Fire\Business\Api\PayeeList;
use Fire\Business\Api\PayeeDetails;
use Fire\Business\Api\BatchList;
use Fire\Business\Api\BatchDetails;
use Fire\Business\Api\UserDetails;
use Fire\Business\Api\PinGrid;
use Fire\Business\Api\ServiceDetails;
Expand All @@ -16,60 +20,69 @@
class Api {
protected $client;
protected $baseUrl;
protected $pinDigits = array();
protected $totpSeed;

protected $_login = null;
// cache the results of these lists
protected $_userDetails = null;
protected $_accounts = null;
protected $_cards = null;
protected $_payees = null;
protected $_serviceDetails = null;

public function __construct(Client $client, $baseUrl) {
$this->client = $client;
$this->baseUrl = $baseUrl;
}

protected function contextLogin($businessId, $email, $password, $pinDigits, $totpSeed) {
$this->pinDigits = str_split($pinDigits);
$this->totpSeed = $totpSeed;

if (!$this->_login) {
$this->_login = new Login($this);
}
return $this->_login->login($businessId, $email, $password);
protected function contextInitialise($config) {
$login = new Login($this);
return $login->initialise($config);
}

protected function getAccounts() {
if (!$this->_accounts) {
protected function getAccounts($useCache = true) {
if (!$this->_accounts || !$useCache) {
$this->_accounts = new AccountList($this);
}
return $this->_accounts;
}

protected function contextAccounts($accountId) {
return new AccountDetails($this, $accountId, $this->pinDigits);
return new AccountDetails($this, $accountId);
}

protected function contextPayees($payeeId) {
return new PayeeDetails($this, $payeeId, $this->pinDigits);
protected function getCards($useCache = true) {
if (!$this->_cards || !$useCache) {
$this->_cards = new CardList($this);
}
return $this->_cards;
}

protected function contextCards($cardId) {
return new CardDetails($this, $cardId);
}

protected function contextServiceDetails($service) {
return new ServiceDetails($this, $service);
protected function getPayees($useCache = true) {
if (!$this->_payees || !$useCache) {
$this->_payees = new PayeeList($this);
}
return $this->_payees;
}

protected function getPinGrid() {
return new PinGrid($this);
protected function contextPayees($payeeId) {
return new PayeeDetails($this, $payeeId);
}

protected function getBatches() {
return new BatchList($this);
}

protected function getPayees() {
if (!$this->_payees) {
$this->_payees = new PayeeList($this, $this->pinDigits, $this->totpSeed);
}
return $this->_payees;
protected function contextBatches($batchId) {
return new BatchDetails($this, $batchId);
}

protected function contextServiceDetails($service) {
return new ServiceDetails($this, $service);
}


protected function getUserDetails() {
if (!$this->_userDetails) {
$this->_userDetails = new UserDetails($this);
Expand Down
12 changes: 7 additions & 5 deletions Fire/Business/Api/AccountDetails.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@
use Fire\Business\InstanceResource;

class AccountDetails extends InstanceResource {
protected $pinDigits = array();

public function __construct(Api $api, $accountId, array $pinDigits) {
public function __construct(Api $api, $accountId) {
parent::__construct($api);
$this->pinDigits = $pinDigits;

$this->solution = array(
'accountId' => $accountId,
Expand All @@ -22,19 +20,23 @@ public function read() {
return $this->api->fetch("GET", $this->uri);
}

/*
// This changes to batches
public function bankTransfer($transfer) {
$bt = new BankTransfer($this->api, $this->solution['accountId'], $this->pinDigits);
return $bt->transfer($transfer);
}
*/

// TODO change to internal transfer batch
public function fireTransfer($transfer) {
$ft = new FireTransfer($this->api, $this->solution['accountId']);
return $ft->transfer($transfer);
}

public function transactions() {
public function transactions($options = array()) {
$tl = new TransactionList($this->api, "accounts", $this->solution['accountId']);
return $tl->read();
return $tl->read($options);
}

}
3 changes: 3 additions & 0 deletions Fire/Business/Api/AccountList.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public function read() {
return $this->api->fetch("GET", $this->uri);
}

/*
// This will change when the Add Account API call is introduced
public function newAccount($account) {
$feeRules = $this->api->serviceDetails("ADD_ACCOUNT")->read();
Expand All @@ -29,5 +31,6 @@ public function newAccount($account) {
);
return $this->api->fetch("POST", $this->uri, null, $postData);
}
*/

}
42 changes: 0 additions & 42 deletions Fire/Business/Api/BankTransfer.php

This file was deleted.

25 changes: 25 additions & 0 deletions Fire/Business/Api/BankTransferDetails.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Fire\Business\Api;

use Fire\Business\Api;
use Fire\Business\InstanceResource;

class BankTransferDetails extends InstanceResource {

public function __construct(Api $api, $batchUuid, $batchItemUuid) {
parent::__construct($api);

$this->solution = array(
'batchUuid' => $batchUuid,
'batchItemUuid' => $batchItemUuid
);
$this->uri = "v1/batches/$batchUuid/banktransfers/$batchItemUuid";
}

public function delete() {
return $this->api->fetch("DELETE", $this->uri);
}


}
28 changes: 28 additions & 0 deletions Fire/Business/Api/BankTransferList.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Fire\Business\Api;

use Fire\Business\Api;
use Fire\Business\ListResource;

class BankTransferList extends ListResource {

public function __construct(Api $api, $batchId) {
parent::__construct($api);

$this->solution = array(
'batchId' => $batchId,
);
$this->uri = "v1/batches/$batchId/banktransfers";
}

public function read() {
return $this->api->fetch("GET", $this->uri);
}

public function add($transfer) {
return $this->api->fetch("POST", $this->uri, null, $transfer);
}


}
88 changes: 88 additions & 0 deletions Fire/Business/Api/BatchDetails.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?php

namespace Fire\Business\Api;

use Fire\Business\Api;
use Fire\Business\InstanceResource;

class BatchDetails extends InstanceResource {

public function __construct(Api $api, $batchId) {
parent::__construct($api);

$this->solution = array(
'batchId' => $batchId,
);
$this->uri = "v1/batches/$batchId";
}

public function read() {
return $this->api->fetch("GET", $this->uri);
}

public function cancel() {
return $this->api->fetch("DELETE", $this->uri);
}

public function submit() {
return $this->api->fetch("PUT", $this->uri);
}

public function addInternalTransfer($transfer) {
$internalTransfer = new InternalTransferList($this->api, $this->solution['batchId']);
return $internalTransfer->add($transfer);
}

protected function getInternalTransfers() {
return new InternalTransferList($this->api, $this->solution['batchId']);
}

protected function contextInternalTransfer($batchItemUuid) {
return new InternalTransferDetails($this->api, $this->solution['batchId'], $batchItemUuid);
}

public function addBankTransfer($transfer) {
$bankTransfer = new BankTransferList($this->api, $this->solution['batchId']);
return $bankTransfer->add($transfer);
}

protected function getBankTransfers() {
return new BankTransferList($this->api, $this->solution['batchId']);
}

protected function contextBankTransfer($batchItemUuid) {
return new BankTransferDetails($this->api, $this->solution['batchId'], $batchItemUuid);
}

/**
* Magic getter to lazy load domains
*
* @param string $name Domain to return
* @return \Twilio\Domain The requested domain
* @throws TwilioException For unknown domains
*/
public function __get($name) {
$method = 'get' . ucfirst($name);
if (method_exists($this, $method)) {
return $this->$method();
}
throw new FireException('Unknown domain ' . $name);
}
/**
* Magic call to lazy load contexts
*
* @param string $name Context to return
* @param mixed[] $arguments Context to return
* @return \Twilio\InstanceContext The requested context
* @throws TwilioException For unknown contexts
*/
public function __call($name, $arguments) {
$method = 'context' . ucfirst($name);
if (method_exists($this, $method)) {
return call_user_func_array(array($this, $method), $arguments);
}
throw new FireException('Unknown context ' . $name);
}


}
24 changes: 24 additions & 0 deletions Fire/Business/Api/BatchList.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Fire\Business\Api;

use Fire\Business\Api;
use Fire\Business\ListResource;

class BatchList extends ListResource {

public function __construct(Api $api) {
parent::__construct($api);

$this->solution = array();
$this->uri = "v1/batches";
}

public function read() {
return $this->api->fetch("GET", $this->uri);
}

public function create(array $batchDetails) {
return $this->api->fetch("POST", $this->uri, null, $batchDetails);
}
}
Loading

0 comments on commit 01f8f4f

Please sign in to comment.