Skip to content

Commit d3ed316

Browse files
authored
Merge pull request #46 from finix-payments/master
v1.0.4
2 parents b0e12a5 + 06c4f3f commit d3ed316

File tree

15 files changed

+223
-61
lines changed

15 files changed

+223
-61
lines changed

bootstrap.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@
88
use \Finix\Settings;
99
use \Finix\Bootstrap;
1010

11+
$processing_url = getenv("PROCESSING_URL");
12+
if ($processing_url == null) {
13+
$processing_url = "https://api-staging.finix.io/";
14+
}
15+
16+
Fixtures::$apiUrl = $processing_url;
17+
1118
Settings::configure([
1219
"root_url" => Fixtures::$apiUrl
1320
]);

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "finix/processing-php",
3-
"version": "1.0.3",
3+
"version": "1.0.4",
44
"description": "A PHP HTTP Client conforming to the HAL hypermedia type for the Finix processing API",
55
"license": "Apache2",
66
"authors": [

src/Finix/Bootstrap.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ private static function initializeResources()
6666
Resources\Processor::init();
6767
Resources\Merchant::init();
6868
Resources\PaymentInstrument::init();
69+
Resources\PaymentCard::init();
70+
Resources\BankAccount::init();
6971
Resources\Authorization::init();
7072
Resources\Transfer::init();
7173
Resources\Reversal::init();
@@ -75,6 +77,7 @@ private static function initializeResources()
7577
Resources\Verification::init();
7678
Resources\Evidence::init();
7779
Resources\Token::init();
80+
Resources\InstrumentUpdate::init();
7881

7982
self::$initialized = true;
8083
}

src/Finix/Hal/HrefSpec.php

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -30,36 +30,4 @@ public function __construct($name, $idNames, $root = null, $override = null)
3030
}
3131
}
3232
}
33-
34-
public function match($uri)
35-
{
36-
$parts = explode('/', rtrim($uri, "/"));
37-
38-
// collection
39-
if ($parts[count($parts) - 1] == $this->name) {
40-
41-
return array(
42-
'collection' => true,
43-
);
44-
}
45-
46-
// non-member
47-
if (count($parts) < count($this->idNames) + 1 ||
48-
$parts[count($parts) - 1 - count($this->idNames)] != $this->name
49-
) {
50-
return null;
51-
}
52-
53-
// member
54-
$ids = array_combine(
55-
$this->idNames,
56-
array_slice($parts, -count($this->idNames))
57-
);
58-
$result = array(
59-
'collection' => false,
60-
'ids' => $ids,
61-
);
62-
63-
return $result;
64-
}
6533
}

src/Finix/Hal/Resource.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ public function getLink($rel)
9292
return $link;
9393
}
9494

95+
public function hasRel($rel)
96+
{
97+
return self::findByRel($this->links, $rel) != null;
98+
}
99+
95100
/**
96101
* Finds an array of links by their relation type.
97102
* Note that there is no guarantees as to the order of the links.

src/Finix/Pagination.php

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22

33
namespace Finix;
44

5+
use Finix\Http\Request;
6+
use Iterator;
57

6-
class Pagination extends Resource
8+
class Pagination extends Resource implements Iterator
79
{
10+
private $resourceClass;
811

912
public function __construct(Hal\Resource $halResource, $class)
1013
{
@@ -16,5 +19,40 @@ public function __construct(Hal\Resource $halResource, $class)
1619
array_push($items, new $class($resource->getState(), $resource->getAllLinks()));
1720
}
1821
$this->state->items = $items;
22+
$this->resourceClass = $class;
23+
}
24+
25+
public function current()
26+
{
27+
return $this->state->items;
28+
}
29+
30+
public function next()
31+
{
32+
if (!$this->resource->hasRel("next")) {
33+
$this->state->items = array();
34+
$page = $this->state->page;
35+
$page["offset"] = $page["count"];
36+
$this->page = $page;
37+
return;
38+
}
39+
$link = $this->resource->getLink('next')->getHref();
40+
$halResource = $this->client->sendRequest(new Request($link));
41+
$this->__construct($halResource, $this->resourceClass);
42+
}
43+
44+
public function key()
45+
{
46+
return $this->page["offset"];
47+
}
48+
49+
public function valid()
50+
{
51+
return $this->page["offset"] < $this->page["count"];
52+
}
53+
54+
public function rewind()
55+
{
56+
// TODO: Implement rewind() method.
1957
}
2058
}

src/Finix/Resource.php

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,10 @@
1010

1111
abstract class Resource
1212
{
13-
/** @var Hal\Resource $resource */
1413
protected $resource;
15-
/** @var ArrayProxy $state */
1614
protected $state;
17-
18-
protected static $href;
1915
protected $client;
20-
// protected static $client;
16+
protected static $href;
2117
protected static $registry;
2218

2319
/**
@@ -105,18 +101,29 @@ public function __isset($name)
105101
* @throws Hal\Exception\HalRedirectionException
106102
* @throws Hal\Exception\HalServerErrorException
107103
*/
108-
public static function retrieve($id)
104+
public static function retrieve($id_or_url)
109105
{
110-
$uri = self::getHrefSpec()->collection_uri . '/' . $id;
106+
107+
$uri = filter_var($id_or_url, FILTER_VALIDATE_URL) || (strpos($id_or_url, '/') !== false) ?
108+
$id_or_url : self::getHrefSpec()->collection_uri . '/' . $id_or_url;
111109
$resource = Bootstrap::createClient()->sendRequest(new Request($uri));
112110
$class = get_called_class();
113-
return new $class($resource->getState(), $resource->getAllLinks());
111+
$state = $resource->getState();
112+
if (sizeof($resource->getAllEmbeddedResources()) > 0) {
113+
$items = $resource->getAllEmbeddedResources();
114+
$items = reset($items);
115+
if (sizeof($items) == 1) {
116+
$state = $items[0]->getState();
117+
}
118+
}
119+
return new $class($state, $resource->getAllLinks());
114120
}
115121

116-
public static function getPagination($href)
122+
public static function getPagination($resource)
117123
{
118-
$resource = Bootstrap::createClient()->sendRequest(new Request($href));
119-
return new Pagination($resource, get_called_class());
124+
$cls = get_called_class();
125+
$halResource = Bootstrap::createClient()->sendRequest(new Request($resource->getHref($cls::getHrefSpec()->name)));
126+
return new Pagination($halResource, $cls);
120127
}
121128

122129
public function refresh()

src/Finix/Resources/Authorization.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@ public static function init()
1111
self::getRegistry()->add(get_called_class(), new HrefSpec('authorizations', 'id', '/'));
1212
}
1313

14-
public function capture($amount, $fee = 0)
14+
public function capture(array $cap = [])
1515
{
16-
$this->state["capture_amount"] = $amount;
17-
$this->state["fee"] = $fee;
16+
foreach ($cap as $key => $value) {
17+
$this->state[$key] = $value;
18+
}
1819
return $this->save();
1920
}
2021

21-
public function void($voidMe)
22+
public function void($voidMe = true)
2223
{
2324
$this->state["void_me"] = $voidMe;
2425
return $this->save();

src/Finix/Resources/BankAccount.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Finix\Resources;
44

5+
use Finix\Hal\HrefSpec;
56

67
class BankAccount extends PaymentInstrument
78
{
@@ -10,4 +11,9 @@ public function __construct(array $state = [], array $links = null)
1011
$state["type"] = "BANK_ACCOUNT";
1112
parent::__construct($state, $links);
1213
}
14+
15+
public static function init()
16+
{
17+
self::getRegistry()->add(get_called_class(), new HrefSpec('payment_instruments', 'id', '/'));
18+
}
1319
}

src/Finix/Resources/Identity.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ public static function init()
1111
self::getRegistry()->add(get_called_class(), new HrefSpec('identities', 'id', '/'));
1212
}
1313

14+
public function createMerchantUser(User $user)
15+
{
16+
return $user->create($this->resource->getLink("users")->getHref());
17+
}
18+
1419
public function provisionMerchantOn(Merchant $merchant)
1520
{
1621
return $merchant->create($this->resource->getLink("merchants")->getHref());

0 commit comments

Comments
 (0)