From f7183a713189acc83abb26136c693684a1d8a502 Mon Sep 17 00:00:00 2001 From: phuonghqh Date: Thu, 8 Dec 2016 01:49:43 +0700 Subject: [PATCH 01/13] Support capture authorization params --- src/Finix/Resources/Authorization.php | 9 +++++---- tests/Finix/ScenariosTest.php | 5 ++++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Finix/Resources/Authorization.php b/src/Finix/Resources/Authorization.php index ea29b91..d34a948 100644 --- a/src/Finix/Resources/Authorization.php +++ b/src/Finix/Resources/Authorization.php @@ -11,14 +11,15 @@ public static function init() self::getRegistry()->add(get_called_class(), new HrefSpec('authorizations', 'id', '/')); } - public function capture($amount, $fee = 0) + public function capture(array $cap = []) { - $this->state["capture_amount"] = $amount; - $this->state["fee"] = $fee; + foreach ($cap as $key => $value) { + $this->state[$key] = $value; + } return $this->save(); } - public function void($voidMe) + public function void($voidMe = true) { $this->state["void_me"] = $voidMe; return $this->save(); diff --git a/tests/Finix/ScenariosTest.php b/tests/Finix/ScenariosTest.php index b287a97..1728ca3 100644 --- a/tests/Finix/ScenariosTest.php +++ b/tests/Finix/ScenariosTest.php @@ -89,7 +89,10 @@ public function testDebitTransfer() { public function testCaptureAuthorization() { $authorization = Fixtures::createAuthorization($this->card, 100); - $authorization = $authorization->capture(50, 10); + $authorization = $authorization->capture([ + "capture_amount"=> 100, + "fee"=> 10 + ]); self::assertEquals($authorization->state, "SUCCEEDED", "Capture amount $10 of '" . $this->card->id . "' not succeeded"); } From 208ce9630977f1b7291d35e65ea206b250e598c1 Mon Sep 17 00:00:00 2001 From: phuonghqh Date: Thu, 8 Dec 2016 02:28:37 +0700 Subject: [PATCH 02/13] Add some support methods --- src/Finix/Bootstrap.php | 2 ++ src/Finix/Resources/BankAccount.php | 6 ++++ src/Finix/Resources/Identity.php | 5 +++ src/Finix/Resources/PaymentCard.php | 7 ++++ src/Finix/Resources/PaymentInstrument.php | 3 +- tests/Finix/ScenariosTest.php | 41 +++++++++++++++++++++++ 6 files changed, 62 insertions(+), 2 deletions(-) diff --git a/src/Finix/Bootstrap.php b/src/Finix/Bootstrap.php index 4d979b8..7969eae 100644 --- a/src/Finix/Bootstrap.php +++ b/src/Finix/Bootstrap.php @@ -66,6 +66,8 @@ private static function initializeResources() Resources\Processor::init(); Resources\Merchant::init(); Resources\PaymentInstrument::init(); + Resources\PaymentCard::init(); + Resources\BankAccount::init(); Resources\Authorization::init(); Resources\Transfer::init(); Resources\Reversal::init(); diff --git a/src/Finix/Resources/BankAccount.php b/src/Finix/Resources/BankAccount.php index 84cdc0a..086f34b 100644 --- a/src/Finix/Resources/BankAccount.php +++ b/src/Finix/Resources/BankAccount.php @@ -2,6 +2,7 @@ namespace Finix\Resources; +use Finix\Hal\HrefSpec; class BankAccount extends PaymentInstrument { @@ -10,4 +11,9 @@ public function __construct(array $state = [], array $links = null) $state["type"] = "BANK_ACCOUNT"; parent::__construct($state, $links); } + + public static function init() + { + self::getRegistry()->add(get_called_class(), new HrefSpec('payment_instruments', 'id', '/')); + } } diff --git a/src/Finix/Resources/Identity.php b/src/Finix/Resources/Identity.php index 3caa385..833ad37 100644 --- a/src/Finix/Resources/Identity.php +++ b/src/Finix/Resources/Identity.php @@ -11,6 +11,11 @@ public static function init() self::getRegistry()->add(get_called_class(), new HrefSpec('identities', 'id', '/')); } + public function createMerchantUser(User $user) + { + return $user->create($this->resource->getLink("users")->getHref()); + } + public function provisionMerchantOn(Merchant $merchant) { return $merchant->create($this->resource->getLink("merchants")->getHref()); diff --git a/src/Finix/Resources/PaymentCard.php b/src/Finix/Resources/PaymentCard.php index ee95e9c..48f7291 100644 --- a/src/Finix/Resources/PaymentCard.php +++ b/src/Finix/Resources/PaymentCard.php @@ -2,6 +2,8 @@ namespace Finix\Resources; +use Finix\Hal\HrefSpec; + class PaymentCard extends PaymentInstrument { @@ -11,4 +13,9 @@ public function __construct(array $state = [], array $links = null) $state["type"] = "PAYMENT_CARD"; parent::__construct($state, $links); } + + public static function init() + { + self::getRegistry()->add(get_called_class(), new HrefSpec('payment_instruments', 'id', '/')); + } } diff --git a/src/Finix/Resources/PaymentInstrument.php b/src/Finix/Resources/PaymentInstrument.php index 04d7875..4468abb 100644 --- a/src/Finix/Resources/PaymentInstrument.php +++ b/src/Finix/Resources/PaymentInstrument.php @@ -8,7 +8,6 @@ abstract class PaymentInstrument extends Resource { public static function init() { - self::getRegistry()->add(get_called_class(), - new HrefSpec('payment_instruments', 'id', '/')); + self::getRegistry()->add(get_called_class(), new HrefSpec('payment_instruments', 'id', '/')); } } diff --git a/tests/Finix/ScenariosTest.php b/tests/Finix/ScenariosTest.php index 1728ca3..784b7c8 100644 --- a/tests/Finix/ScenariosTest.php +++ b/tests/Finix/ScenariosTest.php @@ -4,6 +4,9 @@ use Finix\Resources\Dispute; use Finix\Resources\Verification; +use Finix\Resources\PaymentCard; +use Finix\Resources\BankAccount; +use Finix\Resources\User; use Finix\Settings; class ScenariosTest extends \PHPUnit_Framework_TestCase @@ -51,6 +54,44 @@ protected function setUp() $this->card = Fixtures::createCard($this->identity); } + + public function testCreateMerchantUser() { + $this->markTestSkipped("https://github.com/verygoodgroup/api-spec/issues/333"); + $user = $this->identity->createMerchantUser(new User([["enabled" => true]])); + self::assertNotNull($user->id); + } + + public function testCreateBankAccountDirectly() { + $bankAccount = new BankAccount( + array( + "account_type"=> "SAVINGS", + "name"=> "Fran Lemke", + "tags"=> array( + "Bank Account"=> "Company Account" + ), + "country"=> "USA", + "bank_code"=> "123123123", + "account_number"=> "123123123", + "type"=> "BANK_ACCOUNT", + "identity"=> $this->identity->id + )); + $bankAccount = $bankAccount->save(); + self::assertNotNull($bankAccount->id, "Invalid bank account"); + } + + public function testCreatePaymentCardDirectly() { + $card = new PaymentCard([ + "name" => "Joe Doe", + "expiration_month" => 12, + "expiration_year" => 2030, + "number" => "4111 1111 1111 1111", + "security_code" => 231, + "identity"=> $this->identity->id + ]); + $card = $card->save(); + self::assertNotNull($card->id, "Invalid card"); + } + public function testCreateWebhook() { $webhook = Fixtures::createWebhook("https://tools.ietf.org/html/rfc2606"); self::assertNotNull($webhook->id); From 7123036c1f2e284f800871ccbcc5f84543f3b825 Mon Sep 17 00:00:00 2001 From: phuonghqh Date: Fri, 23 Dec 2016 00:38:07 +0700 Subject: [PATCH 03/13] Support PaymentInstrumentUpdate --- src/Finix/Bootstrap.php | 1 + src/Finix/Hal/HrefSpec.php | 62 +++++++++++------------ src/Finix/Pagination.php | 33 +++++++++++- src/Finix/Resource.php | 40 +++++++++++---- src/Finix/Resources/InstrumentUpdate.php | 14 +++++ src/Finix/Resources/PaymentCard.php | 10 ++++ src/Finix/Resources/PaymentInstrument.php | 1 + tests/Finix/Fixtures.php | 2 +- tests/Finix/ScenariosTest.php | 62 ++++++++++++++++++++--- 9 files changed, 174 insertions(+), 51 deletions(-) create mode 100644 src/Finix/Resources/InstrumentUpdate.php diff --git a/src/Finix/Bootstrap.php b/src/Finix/Bootstrap.php index 7969eae..33ac528 100644 --- a/src/Finix/Bootstrap.php +++ b/src/Finix/Bootstrap.php @@ -77,6 +77,7 @@ private static function initializeResources() Resources\Verification::init(); Resources\Evidence::init(); Resources\Token::init(); + Resources\InstrumentUpdate::init(); self::$initialized = true; } diff --git a/src/Finix/Hal/HrefSpec.php b/src/Finix/Hal/HrefSpec.php index 289c2e5..d0c0058 100644 --- a/src/Finix/Hal/HrefSpec.php +++ b/src/Finix/Hal/HrefSpec.php @@ -31,35 +31,35 @@ public function __construct($name, $idNames, $root = null, $override = null) } } - public function match($uri) - { - $parts = explode('/', rtrim($uri, "/")); - - // collection - if ($parts[count($parts) - 1] == $this->name) { - - return array( - 'collection' => true, - ); - } - - // non-member - if (count($parts) < count($this->idNames) + 1 || - $parts[count($parts) - 1 - count($this->idNames)] != $this->name - ) { - return null; - } - - // member - $ids = array_combine( - $this->idNames, - array_slice($parts, -count($this->idNames)) - ); - $result = array( - 'collection' => false, - 'ids' => $ids, - ); - - return $result; - } +// public function match($uri) +// { +// $parts = explode('/', rtrim($uri, "/")); +// +// // collection +// if ($parts[count($parts) - 1] == $this->name) { +// +// return array( +// 'collection' => true, +// ); +// } +// +// // non-member +// if (count($parts) < count($this->idNames) + 1 || +// $parts[count($parts) - 1 - count($this->idNames)] != $this->name +// ) { +// return null; +// } +// +// // member +// $ids = array_combine( +// $this->idNames, +// array_slice($parts, -count($this->idNames)) +// ); +// $result = array( +// 'collection' => false, +// 'ids' => $ids, +// ); +// +// return $result; +// } } diff --git a/src/Finix/Pagination.php b/src/Finix/Pagination.php index f0af7b3..0fd10c9 100644 --- a/src/Finix/Pagination.php +++ b/src/Finix/Pagination.php @@ -2,9 +2,12 @@ namespace Finix; +use Finix\Http\Request; +use Iterator; -class Pagination extends Resource +class Pagination extends Resource implements Iterator { + private $resourceClass; public function __construct(Hal\Resource $halResource, $class) { @@ -16,5 +19,33 @@ public function __construct(Hal\Resource $halResource, $class) array_push($items, new $class($resource->getState(), $resource->getAllLinks())); } $this->state->items = $items; + $this->resourceClass = $class; + } + + public function current() + { + return $this->state->items; + } + + public function next() + { + $link = $this->resource->getLink('next')->getHref(); + $halResource = $this->client->sendRequest(new Request($link)); + $this->__construct($halResource, $this->resourceClass); + } + + public function key() + { + return $this->page["offset"]; + } + + public function valid() + { + return $this->page["offset"] < $this->page["count"]; + } + + public function rewind() + { + // TODO: Implement rewind() method. } } diff --git a/src/Finix/Resource.php b/src/Finix/Resource.php index ed6ca32..9746913 100644 --- a/src/Finix/Resource.php +++ b/src/Finix/Resource.php @@ -10,14 +10,10 @@ abstract class Resource { - /** @var Hal\Resource $resource */ protected $resource; - /** @var ArrayProxy $state */ protected $state; - - protected static $href; protected $client; -// protected static $client; + protected static $href; protected static $registry; /** @@ -105,18 +101,28 @@ public function __isset($name) * @throws Hal\Exception\HalRedirectionException * @throws Hal\Exception\HalServerErrorException */ - public static function retrieve($id) + public static function retrieve($id_or_url) { - $uri = self::getHrefSpec()->collection_uri . '/' . $id; + $uri = filter_var($id_or_url, FILTER_VALIDATE_URL) ? + $id_or_url : self::getHrefSpec()->collection_uri . '/' . $id_or_url; $resource = Bootstrap::createClient()->sendRequest(new Request($uri)); $class = get_called_class(); - return new $class($resource->getState(), $resource->getAllLinks()); + $state = $resource->getState(); + if (sizeof($resource->getAllEmbeddedResources()) > 0) { + $items = $resource->getAllEmbeddedResources(); + $items = reset($items); + if (sizeof($items) == 1) { + $state = $items[0]->getState(); + } + } + return new $class($state, $resource->getAllLinks()); } - public static function getPagination($href) + public static function getPagination($resource) { - $resource = Bootstrap::createClient()->sendRequest(new Request($href)); - return new Pagination($resource, get_called_class()); + $cls = get_called_class(); + $halResource = Bootstrap::createClient()->sendRequest(new Request($resource->getHref($cls::getHrefSpec()->name))); + return new Pagination($halResource, $cls); } public function refresh() @@ -218,4 +224,16 @@ public function verifyOn(Verification $verification) $verifyLink = $this->resource->getLink("verifications")->getHref(); return $verification->create($verifyLink); } + +// public function update(array $array=[]) +// { +// $updateLink = $this->resource->getLink("updates")->getHref(); +// $payload = new JsonBody($this->state->count() == 0 ? "{}" : iterator_to_array($this->state)); +// $request = new Request($href, 'POST', array(), $payload); +// $resource = $this->getClient()->sendRequest($request); +// $this->setResource($resource); +// return $this; +//// return $application->create($this->resource->getLink("applications")->getHref()); +//// return $verification->create($updateLink); +// } } diff --git a/src/Finix/Resources/InstrumentUpdate.php b/src/Finix/Resources/InstrumentUpdate.php new file mode 100644 index 0000000..5b5d2fa --- /dev/null +++ b/src/Finix/Resources/InstrumentUpdate.php @@ -0,0 +1,14 @@ +add(get_called_class(), new HrefSpec('payment_instruments/%s/updates', 'id', '/')); + } +} \ No newline at end of file diff --git a/src/Finix/Resources/PaymentCard.php b/src/Finix/Resources/PaymentCard.php index 48f7291..48fbfa4 100644 --- a/src/Finix/Resources/PaymentCard.php +++ b/src/Finix/Resources/PaymentCard.php @@ -18,4 +18,14 @@ public static function init() { self::getRegistry()->add(get_called_class(), new HrefSpec('payment_instruments', 'id', '/')); } + + public function createUpdate(InstrumentUpdate $action) + { + return $action->create($this->resource->getLink("updates")->getHref()); + } + + public static function getUpdateUri($card_id, $update_id) + { + return self::getHrefSpec()->name . "/" . $card_id . InstrumentUpdate::getHrefSpec()->name . "?id=" . $update_id; + } } diff --git a/src/Finix/Resources/PaymentInstrument.php b/src/Finix/Resources/PaymentInstrument.php index 4468abb..23a68a3 100644 --- a/src/Finix/Resources/PaymentInstrument.php +++ b/src/Finix/Resources/PaymentInstrument.php @@ -6,6 +6,7 @@ abstract class PaymentInstrument extends Resource { + public static function init() { self::getRegistry()->add(get_called_class(), new HrefSpec('payment_instruments', 'id', '/')); diff --git a/tests/Finix/Fixtures.php b/tests/Finix/Fixtures.php index 9bd48c3..bd4829f 100644 --- a/tests/Finix/Fixtures.php +++ b/tests/Finix/Fixtures.php @@ -23,7 +23,7 @@ class Fixtures extends \PHPUnit_Framework_TestCase public static function createAdminUser() { - $user = new User(["enabled" => true]); + $user = new User(["enabled" => true, "role" => "ROLE_ADMIN"]); $user = $user->save(); self::assertNotEmpty($user->id); self::assertNotEmpty($user->password); diff --git a/tests/Finix/ScenariosTest.php b/tests/Finix/ScenariosTest.php index 784b7c8..9a1f0f5 100644 --- a/tests/Finix/ScenariosTest.php +++ b/tests/Finix/ScenariosTest.php @@ -3,10 +3,13 @@ use Finix\Resources\Dispute; +use Finix\Resources\Identity; +use Finix\Resources\Transfer; use Finix\Resources\Verification; use Finix\Resources\PaymentCard; use Finix\Resources\BankAccount; use Finix\Resources\User; +use Finix\Resources\InstrumentUpdate; use Finix\Settings; class ScenariosTest extends \PHPUnit_Framework_TestCase @@ -44,17 +47,18 @@ protected function setUp() Settings::configure(["username" => $this->partnerUser->id, "password" => $this->partnerUser->password]); $this->identity = Fixtures::createIdentity(); - -// $entity = $this->identity->entity; -// $entity["last_name"] = "serna"; -// $this->identity->entity = $entity; -// $this->identity->save(); - + $this->bankAccount = Fixtures::createBankAccount($this->identity); $this->merchant = Fixtures::provisionMerchant($this->identity); $this->card = Fixtures::createCard($this->identity); } + public function testRetrieveIdentity() + { + $identity = Identity::retrieve($this->identity->id); + $this->assertEquals($this->identity->id, $identity->id); + } + public function testCreateMerchantUser() { $this->markTestSkipped("https://github.com/verygoodgroup/api-spec/issues/333"); $user = $this->identity->createMerchantUser(new User([["enabled" => true]])); @@ -181,9 +185,53 @@ public function testSettlement() public function testDispute() { $transfer = $this->testDebitTransfer(); - $disputePage = Dispute::getPagination($transfer->getHref("disputes")); + $disputePage = Dispute::getPagination($transfer); $dispute = $disputePage->items[0]; $file = $dispute->uploadEvidence($this->receiptImage); $this->assertEquals($file->dispute, $dispute->id); } + + public function testCreateAndFetchInstrumentUpdate() + { + $identity = Fixtures::createIdentity(); + Fixtures::createBankAccount($identity); + $merchant = Fixtures::provisionMerchant($identity); + $update = $this->card->createUpdate(new InstrumentUpdate(["merchant" => $merchant->id])); + $this->assertEquals($this->application->id, $update->application); + + $href = $this->card->getHref("updates") . "?id=" . $update->id; +// $fetchUpdate = InstrumentUpdate::retrieve(PaymentCard::getUpdateUri($this->card->id, $update->id)); + $fetchUpdate = InstrumentUpdate::retrieve($href); + $this->assertEquals($update->id, $fetchUpdate->id); + } + + public function testGetAllInstrumentUpdates() + { + $this->testCreateInstrumentUpdate(); + $instrumentUpdatePage = InstrumentUpdate::getPagination($this->card); + foreach ($instrumentUpdatePage as $indexPage => $instrumentUpdates) { + foreach ($instrumentUpdates as $index => $instrumentUpdate) { // read the first page + $this->assertEquals($this->application->id, $instrumentUpdate->application); + } + } + } + + public function testIterateAllTransfers() + { + for ($i = 0; $i <= 41; $i++) { + Fixtures::createTransfer([ + "identity" => $this->card->identity, + "amount" => Fixtures::$disputeAmount, + "source" => $this->card->id, + "tags" => ["_source" => "php_client"] + ]); + } + + $transferPage = Transfer::getPagination($this->card); + foreach ($transferPage as $indexPage => $items) { + foreach ($items as $index => $transfer) { // read the first page + $this->assertTrue($transfer->amount > 0); + } + } + } } From eb2808fb075c28d0eb13ee4344c73751ba7cdd32 Mon Sep 17 00:00:00 2001 From: phuonghqh Date: Fri, 23 Dec 2016 00:48:15 +0700 Subject: [PATCH 04/13] Remove payment_instruments in updates root --- src/Finix/Resources/InstrumentUpdate.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Finix/Resources/InstrumentUpdate.php b/src/Finix/Resources/InstrumentUpdate.php index 5b5d2fa..2845dd8 100644 --- a/src/Finix/Resources/InstrumentUpdate.php +++ b/src/Finix/Resources/InstrumentUpdate.php @@ -9,6 +9,6 @@ class InstrumentUpdate extends Resource { public static function init() { - self::getRegistry()->add(get_called_class(), new HrefSpec('payment_instruments/%s/updates', 'id', '/')); + self::getRegistry()->add(get_called_class(), new HrefSpec('updates', 'id', '/')); } } \ No newline at end of file From f9c09461f667f24d95777e364657240f5eb76a1d Mon Sep 17 00:00:00 2001 From: phuonghqh Date: Fri, 23 Dec 2016 01:00:15 +0700 Subject: [PATCH 05/13] Remove url link in the test --- src/Finix/Resource.php | 3 ++- src/Finix/Resources/PaymentCard.php | 3 ++- tests/Finix/ScenariosTest.php | 6 +++--- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Finix/Resource.php b/src/Finix/Resource.php index 9746913..40ca421 100644 --- a/src/Finix/Resource.php +++ b/src/Finix/Resource.php @@ -103,7 +103,8 @@ public function __isset($name) */ public static function retrieve($id_or_url) { - $uri = filter_var($id_or_url, FILTER_VALIDATE_URL) ? + + $uri = filter_var($id_or_url, FILTER_VALIDATE_URL) || (strpos($id_or_url, '/') !== false) ? $id_or_url : self::getHrefSpec()->collection_uri . '/' . $id_or_url; $resource = Bootstrap::createClient()->sendRequest(new Request($uri)); $class = get_called_class(); diff --git a/src/Finix/Resources/PaymentCard.php b/src/Finix/Resources/PaymentCard.php index 48fbfa4..dc6be1b 100644 --- a/src/Finix/Resources/PaymentCard.php +++ b/src/Finix/Resources/PaymentCard.php @@ -26,6 +26,7 @@ public function createUpdate(InstrumentUpdate $action) public static function getUpdateUri($card_id, $update_id) { - return self::getHrefSpec()->name . "/" . $card_id . InstrumentUpdate::getHrefSpec()->name . "?id=" . $update_id; + // TODO move this to Registry + return "/" . self::getHrefSpec()->name . "/" . $card_id . "/" . InstrumentUpdate::getHrefSpec()->name . "?id=" . $update_id; } } diff --git a/tests/Finix/ScenariosTest.php b/tests/Finix/ScenariosTest.php index 9a1f0f5..68ec68f 100644 --- a/tests/Finix/ScenariosTest.php +++ b/tests/Finix/ScenariosTest.php @@ -199,9 +199,9 @@ public function testCreateAndFetchInstrumentUpdate() $update = $this->card->createUpdate(new InstrumentUpdate(["merchant" => $merchant->id])); $this->assertEquals($this->application->id, $update->application); - $href = $this->card->getHref("updates") . "?id=" . $update->id; -// $fetchUpdate = InstrumentUpdate::retrieve(PaymentCard::getUpdateUri($this->card->id, $update->id)); - $fetchUpdate = InstrumentUpdate::retrieve($href); +// $href = $this->card->getHref("updates") . "?id=" . $update->id; + $fetchUpdate = InstrumentUpdate::retrieve(PaymentCard::getUpdateUri($this->card->id, $update->id)); +// $fetchUpdate = InstrumentUpdate::retrieve($href); $this->assertEquals($update->id, $fetchUpdate->id); } From 2d96c47f40657af8a943dd8f9f9532004e26d821 Mon Sep 17 00:00:00 2001 From: phuonghqh Date: Fri, 23 Dec 2016 01:00:52 +0700 Subject: [PATCH 06/13] Remove comments --- tests/Finix/ScenariosTest.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/Finix/ScenariosTest.php b/tests/Finix/ScenariosTest.php index 68ec68f..bcc6405 100644 --- a/tests/Finix/ScenariosTest.php +++ b/tests/Finix/ScenariosTest.php @@ -199,9 +199,7 @@ public function testCreateAndFetchInstrumentUpdate() $update = $this->card->createUpdate(new InstrumentUpdate(["merchant" => $merchant->id])); $this->assertEquals($this->application->id, $update->application); -// $href = $this->card->getHref("updates") . "?id=" . $update->id; $fetchUpdate = InstrumentUpdate::retrieve(PaymentCard::getUpdateUri($this->card->id, $update->id)); -// $fetchUpdate = InstrumentUpdate::retrieve($href); $this->assertEquals($update->id, $fetchUpdate->id); } From f470b456281fd985ce165e8bc2092ed4caaa11e1 Mon Sep 17 00:00:00 2001 From: phuonghqh Date: Fri, 23 Dec 2016 01:10:03 +0700 Subject: [PATCH 07/13] Remove comments in the code --- src/Finix/Hal/HrefSpec.php | 32 -------------------------------- src/Finix/Resource.php | 12 ------------ 2 files changed, 44 deletions(-) diff --git a/src/Finix/Hal/HrefSpec.php b/src/Finix/Hal/HrefSpec.php index d0c0058..04d613f 100644 --- a/src/Finix/Hal/HrefSpec.php +++ b/src/Finix/Hal/HrefSpec.php @@ -30,36 +30,4 @@ public function __construct($name, $idNames, $root = null, $override = null) } } } - -// public function match($uri) -// { -// $parts = explode('/', rtrim($uri, "/")); -// -// // collection -// if ($parts[count($parts) - 1] == $this->name) { -// -// return array( -// 'collection' => true, -// ); -// } -// -// // non-member -// if (count($parts) < count($this->idNames) + 1 || -// $parts[count($parts) - 1 - count($this->idNames)] != $this->name -// ) { -// return null; -// } -// -// // member -// $ids = array_combine( -// $this->idNames, -// array_slice($parts, -count($this->idNames)) -// ); -// $result = array( -// 'collection' => false, -// 'ids' => $ids, -// ); -// -// return $result; -// } } diff --git a/src/Finix/Resource.php b/src/Finix/Resource.php index 40ca421..f3dbf40 100644 --- a/src/Finix/Resource.php +++ b/src/Finix/Resource.php @@ -225,16 +225,4 @@ public function verifyOn(Verification $verification) $verifyLink = $this->resource->getLink("verifications")->getHref(); return $verification->create($verifyLink); } - -// public function update(array $array=[]) -// { -// $updateLink = $this->resource->getLink("updates")->getHref(); -// $payload = new JsonBody($this->state->count() == 0 ? "{}" : iterator_to_array($this->state)); -// $request = new Request($href, 'POST', array(), $payload); -// $resource = $this->getClient()->sendRequest($request); -// $this->setResource($resource); -// return $this; -//// return $application->create($this->resource->getLink("applications")->getHref()); -//// return $verification->create($updateLink); -// } } From 0018cd4530f5f5020e675eab60a54dc0b98d6504 Mon Sep 17 00:00:00 2001 From: phuonghqh Date: Fri, 23 Dec 2016 02:06:43 +0700 Subject: [PATCH 08/13] Use payline test link --- tests/Finix/Fixtures.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Finix/Fixtures.php b/tests/Finix/Fixtures.php index bd4829f..b193601 100644 --- a/tests/Finix/Fixtures.php +++ b/tests/Finix/Fixtures.php @@ -18,7 +18,7 @@ class Fixtures extends \PHPUnit_Framework_TestCase { - public static $apiUrl = "https://api-staging.finix.io/"; + public static $apiUrl = "https://api-test.payline.io"; public static $disputeAmount = 888888; public static function createAdminUser() From d3175aceb3bc95cf6b9a9dc54694a2e8b0f72bef Mon Sep 17 00:00:00 2001 From: phuonghqh Date: Fri, 23 Dec 2016 02:16:25 +0700 Subject: [PATCH 09/13] Init payment instrument update --- bootstrap.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/bootstrap.php b/bootstrap.php index cdc5242..1d261dd 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -8,6 +8,13 @@ use \Finix\Settings; use \Finix\Bootstrap; +$processing_url = getenv("PROCESSING_URL"); +if ($processing_url == null) { + $processing_url = "https://api-test.payline.io"; +} + +Fixtures::$apiUrl = $processing_url; + Settings::configure([ "root_url" => Fixtures::$apiUrl ]); From e5574ece9cd5a0a786e68258c12941806f8df965 Mon Sep 17 00:00:00 2001 From: phuonghqh Date: Fri, 23 Dec 2016 02:33:30 +0700 Subject: [PATCH 10/13] Fix undefined method in test --- bootstrap.php | 2 +- tests/Finix/ScenariosTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bootstrap.php b/bootstrap.php index 1d261dd..c723cc3 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -10,7 +10,7 @@ $processing_url = getenv("PROCESSING_URL"); if ($processing_url == null) { - $processing_url = "https://api-test.payline.io"; + $processing_url = "https://api-staging.finix.io/"; } Fixtures::$apiUrl = $processing_url; diff --git a/tests/Finix/ScenariosTest.php b/tests/Finix/ScenariosTest.php index bcc6405..6327c96 100644 --- a/tests/Finix/ScenariosTest.php +++ b/tests/Finix/ScenariosTest.php @@ -205,7 +205,7 @@ public function testCreateAndFetchInstrumentUpdate() public function testGetAllInstrumentUpdates() { - $this->testCreateInstrumentUpdate(); + $this->testCreateAndFetchInstrumentUpdate(); $instrumentUpdatePage = InstrumentUpdate::getPagination($this->card); foreach ($instrumentUpdatePage as $indexPage => $instrumentUpdates) { foreach ($instrumentUpdates as $index => $instrumentUpdate) { // read the first page From 7ad5256e042f70adeab81cd756b1acfeabd77d1e Mon Sep 17 00:00:00 2001 From: phuonghqh Date: Fri, 23 Dec 2016 03:09:42 +0700 Subject: [PATCH 11/13] Fix page loop --- src/Finix/Hal/Resource.php | 5 +++++ src/Finix/Pagination.php | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/src/Finix/Hal/Resource.php b/src/Finix/Hal/Resource.php index d2f12a7..6a65e37 100644 --- a/src/Finix/Hal/Resource.php +++ b/src/Finix/Hal/Resource.php @@ -92,6 +92,11 @@ public function getLink($rel) return $link; } + public function hasRel($rel) + { + return self::findByRel($this->links, $rel) != null; + } + /** * Finds an array of links by their relation type. * Note that there is no guarantees as to the order of the links. diff --git a/src/Finix/Pagination.php b/src/Finix/Pagination.php index 0fd10c9..ed4b2f0 100644 --- a/src/Finix/Pagination.php +++ b/src/Finix/Pagination.php @@ -29,6 +29,13 @@ public function current() public function next() { + if (!$this->resource->hasRel("next")) { + $this->state->items = array(); + $page = $this->state->page; + $page["offset"] = $page["count"]; + $this->page = $page; + return; + } $link = $this->resource->getLink('next')->getHref(); $halResource = $this->client->sendRequest(new Request($link)); $this->__construct($halResource, $this->resourceClass); From 4384644033d803fb97fb31adcd0bb0b7c2256e3e Mon Sep 17 00:00:00 2001 From: phuonghqh Date: Fri, 23 Dec 2016 03:21:54 +0700 Subject: [PATCH 12/13] Remove payline test link --- tests/Finix/Fixtures.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Finix/Fixtures.php b/tests/Finix/Fixtures.php index b193601..bf987a2 100644 --- a/tests/Finix/Fixtures.php +++ b/tests/Finix/Fixtures.php @@ -18,7 +18,7 @@ class Fixtures extends \PHPUnit_Framework_TestCase { - public static $apiUrl = "https://api-test.payline.io"; + public static $apiUrl; public static $disputeAmount = 888888; public static function createAdminUser() From 06c4f3f37bf920c6f6d9ee7c682940aada2913cd Mon Sep 17 00:00:00 2001 From: phuong Date: Fri, 23 Dec 2016 03:26:39 +0700 Subject: [PATCH 13/13] Bump version to 1.0.4 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 91512ac..423aa78 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "finix/processing-php", - "version": "1.0.3", + "version": "1.0.4", "description": "A PHP HTTP Client conforming to the HAL hypermedia type for the Finix processing API", "license": "Apache2", "authors": [