From 9b5d49061ed2f4d693477372bf1531ac45123c52 Mon Sep 17 00:00:00 2001 From: Jan van Esdonk Date: Tue, 14 Nov 2017 15:43:31 +0100 Subject: [PATCH 01/17] remove fields from exception which aren't returned by the API anymore --- figo/HttpsRequest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/figo/HttpsRequest.php b/figo/HttpsRequest.php index 7318a04..37157e0 100644 --- a/figo/HttpsRequest.php +++ b/figo/HttpsRequest.php @@ -148,7 +148,7 @@ public function request($path, $data, $method, array $headers, $language = 'de') if ($code >= 400 && $code < 500) { $this->logFailedRequest($path, $responseArray, $loggingData); - throw new Exception($responseArray["error"]["name"] .": ". $responseArray["error"]["message"]." (Status: ".$responseArray["status"].")" , $responseArray["error"]["description"]); + throw new Exception("Code: ".$responseArray["error"]["code"], $responseArray["error"]["description"]); } if ($code === 503) { From b46c52c82c57a2ccb70c375d6c6d76fc552ae23a Mon Sep 17 00:00:00 2001 From: Jan van Esdonk Date: Tue, 14 Nov 2017 15:45:26 +0100 Subject: [PATCH 02/17] make sdk use url_parse to support configuring the api url base and not only the hostname --- figo/Config.php | 2 +- figo/Connection.php | 7 +++++-- figo/HttpsRequest.php | 2 +- figo/Session.php | 10 ++++++---- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/figo/Config.php b/figo/Config.php index 9f2f076..d9713c2 100644 --- a/figo/Config.php +++ b/figo/Config.php @@ -30,7 +30,7 @@ class Config { /** @var string figo Connect server hostname */ - public static $API_ENDPOINT = "api.figo.me"; + public static $API_ENDPOINT = "https://api.figo.me/v3"; /** @var string figo Connect SSL/TLS certificate fingerprints */ public static $VALID_FINGERPRINTS = array("07:0F:14:AE:B9:4A:FB:3D:F8:00:E8:2B:69:A8:51:5C:EE:D2:F5:B1:BA:89:7B:EF:64:32:45:8F:61:CF:9E:33", diff --git a/figo/Connection.php b/figo/Connection.php index 23c3f5c..efb6968 100644 --- a/figo/Connection.php +++ b/figo/Connection.php @@ -69,6 +69,8 @@ public function __construct($client_id, $client_secret, $redirect_uri = null, $a $this->apiEndpoint = $apiEndpoint; } + $this->apiUrl = parse_url($this->apiEndpoint); + if ($fingerprints) { $this->fingerprints = $fingerprints; } @@ -107,7 +109,8 @@ public function query_api($path, array $data = null, $method='POST', $encode='ht "Content-Type" => $content_type, "Content-Length" => strlen($data)); - $request = new HttpsRequest($this->apiEndpoint, $this->fingerprints, $this->logger); + $request = new HttpsRequest($this->apiUrl['host'], $this->fingerprints, $this->logger); + $path = $this->apiUrl['path'] . $path; return $request->request($path, $data, $method, $headers, $language); } @@ -134,7 +137,7 @@ public function login_url($state, $scope = null) { if (!is_null($scope)) { $data["scope"] = $scope; } - return "https://".Config::$API_ENDPOINT."/auth/code?".http_build_query($data); + return $this->apiEndpoint."/auth/code?".http_build_query($data); } diff --git a/figo/HttpsRequest.php b/figo/HttpsRequest.php index 37157e0..6a85078 100644 --- a/figo/HttpsRequest.php +++ b/figo/HttpsRequest.php @@ -86,7 +86,7 @@ public function request($path, $data, $method, array $headers, $language = 'de') } // Setup common HTTP headers. - $headers["Host"] = Config::$API_ENDPOINT; + $headers["Host"] = parse_url(Config::$API_ENDPOINT)['host']; $headers["Accept"] = "application/json"; $headers["User-Agent"] = Config::$USER_AGENT . '/' . Config::$SDK_VERSION; $headers["Connection"] = "close"; diff --git a/figo/Session.php b/figo/Session.php index 78f6ca4..24561f8 100644 --- a/figo/Session.php +++ b/figo/Session.php @@ -63,6 +63,8 @@ public function __construct($access_token, $apiEndpoint = null, array $fingerpri $this->apiEndpoint = $apiEndpoint; } + $this->apiUrl = parse_url($this->apiEndpoint); + if ($fingerprints) { $this->fingerprints = $fingerprints; } @@ -93,8 +95,8 @@ public function query_api($path, array $data = null, $method = "GET") { "Content-Type" => "application/json", "Content-Length" => strlen($data)); - $request = new HttpsRequest($this->apiEndpoint, $this->fingerprints, $this->logger); - + $request = new HttpsRequest($this->apiUrl['host'], $this->fingerprints, $this->logger); + $path = $this->apiUrl['path'] . $path; return $request->request($path, $data, $method, $headers); } @@ -465,7 +467,7 @@ public function remove_bank_pin($bank_or_id) { public function get_sync_url($redirect_uri, $state) { $data = array("redirect_uri" => $redirect_uri, "state" => $state); $response = $this->query_api("/rest/sync", $data, "POST"); - return "https://".Config::$API_ENDPOINT."/task/start?id=".$response["task_token"]; + return $this->apiEndpoint."/task/start?id=".$response["task_token"]; } @@ -717,7 +719,7 @@ public function submit_payment($payment, $tan_scheme_id, $state, $redirect_uri=n if (is_null($response)) { return null; } else { - return "https://".Config::$API_ENDPOINT."/task/start?id=".$response["task_token"]; + return $this->apiEndpoint."/task/start?id=".$response["task_token"]; } } } From 16c753c651226240ab61fc49812c18d408ba4cf6 Mon Sep 17 00:00:00 2001 From: Jan van Esdonk Date: Tue, 14 Nov 2017 15:47:07 +0100 Subject: [PATCH 03/17] fix tests --- test/FigoTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/FigoTest.php b/test/FigoTest.php index 0590f13..06338af 100644 --- a/test/FigoTest.php +++ b/test/FigoTest.php @@ -75,11 +75,11 @@ public function test_missing_handling() { public function test_error_handling() { $this->setExpectedException('Exception'); - $this->sut->get_sync_url("http://localhost:3003/", ""); + $this->sut->get_sync_url("edsa", ""); } public function test_sync_url() { - $sync_url = $this->sut->get_sync_url("qwe", "qew"); + $sync_url = $this->sut->get_sync_url("http://localhost:3003/", "qew"); $this->assertGreaterThan(0, strlen($sync_url)); } @@ -170,7 +170,7 @@ public function test_standing_order() { public function test_setup_bank_account() { $response = $this->sut->setup_bank_account( "90090042", ["demo", "demo"], - ["country" => "de", "save_pin" => true] + ["save_pin" => true] ); $this->assertTrue(isset($response["task_token"])); } From 6bdf13e0564c8fdb3609948fc69e0393202ad0fd Mon Sep 17 00:00:00 2001 From: Jan van Esdonk Date: Tue, 14 Nov 2017 15:57:39 +0100 Subject: [PATCH 04/17] extend config description --- figo/Config.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/figo/Config.php b/figo/Config.php index d9713c2..8eaf938 100644 --- a/figo/Config.php +++ b/figo/Config.php @@ -29,7 +29,7 @@ */ class Config { - /** @var string figo Connect server hostname */ + /** @var string figo Connect server address. This should be the full base url of the API */ public static $API_ENDPOINT = "https://api.figo.me/v3"; /** @var string figo Connect SSL/TLS certificate fingerprints */ From 57e5d91a4a1aab2f480350cb9da0bb10b80347a8 Mon Sep 17 00:00:00 2001 From: Jan van Esdonk Date: Thu, 16 Nov 2017 12:02:39 +0100 Subject: [PATCH 05/17] make tests run against staging system --- test/FigoTest.php | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/test/FigoTest.php b/test/FigoTest.php index 06338af..0de24a4 100644 --- a/test/FigoTest.php +++ b/test/FigoTest.php @@ -30,20 +30,23 @@ class SessionTest extends PHPUnit_Framework_TestCase { protected $sut; + protected $demo_access_token = "ASHWLIkouP2O6_bgA2wWReRhletgWKHYjLqDaqb0LFfamim9RjexTo22ujRIP_cjLiRiSyQXyt2kM1eXU2XLFZQ0Hro15HikJQT_eNeT_9XQ"; + protected $api_endpoint = "https://staging.figo.me/v3"; + protected $fingerprints = array("D0:03:9E:F0:8F:BD:48:67:86:71:CE:9D:A5:54:24:81:63:D7:D9:4D:ED:F1:6A:55:F0:52:C7:0A:AB:7B:B8:9D"); protected function setUp() { - $this->sut = new Session("ASHWLIkouP2O6_bgA2wWReRhletgWKHYjLqDaqb0LFfamim9RjexTo22ujRIP_cjLiRiSyQXyt2kM1eXU2XLFZQ0Hro15HikJQT_eNeT_9XQ"); + $this->sut = new Session($this->demo_access_token, $this->api_endpoint, $this->fingerprints); } public function test_accounts() { $accounts = $this->sut->get_accounts(); $this->assertGreaterThan(0, count($accounts)); - $account = $this->sut->get_account("A1.1"); - $this->assertEquals($account->account_id, "A1.1"); + $account = $this->sut->get_account("A13318.1"); + $this->assertEquals($account->account_id, "A13318.1"); - $account = $this->sut->get_account("A1.2"); - $this->assertEquals($account->account_id, "A1.2"); + $account = $this->sut->get_account("A13318.3"); + $this->assertEquals($account->account_id, "A13318.3"); $this->assertNotNull($account->balance->balance); $this->assertNotNull($account->balance->balance_date); @@ -70,7 +73,7 @@ public function test_global_payments() { } public function test_missing_handling() { - $this->assertNull($this->sut->get_account("A1.42")); + $this->assertNull($this->sut->get_account("A13318.42")); } public function test_error_handling() { @@ -107,15 +110,15 @@ public function test_create_update_delete_notification() { } public function test_create_update_delete_payment() { - $added_payment = $this->sut->add_payment(new Payment($this->sut, array("account_id" => "A1.1", "type" => "Transfer", "account_number" => "4711951501", "bank_code" => "90090042", "name" => "figo", "purpose" => "Thanks for all the fish.", "amount" => 0.89))); - $this->assertEquals($added_payment->account_id, "A1.1"); + $added_payment = $this->sut->add_payment(new Payment($this->sut, array("account_id" => "A13318.1", "type" => "Transfer", "account_number" => "4711951501", "bank_code" => "90090042", "name" => "figo", "purpose" => "Thanks for all the fish.", "amount" => 0.89))); + $this->assertEquals($added_payment->account_id, "A13318.1"); $this->assertEquals($added_payment->bank_name, "Demobank"); $this->assertEquals($added_payment->amount, 0.89); $added_payment->amount = 2.39; $modified_payment = $this->sut->modify_payment($added_payment); $this->assertEquals($modified_payment->payment_id, $added_payment->payment_id); - $this->assertEquals($modified_payment->account_id, "A1.1"); + $this->assertEquals($modified_payment->account_id, "A13318.1"); $this->assertEquals($modified_payment->bank_name, "Demobank"); $this->assertEquals($modified_payment->amount, 2.39); @@ -125,11 +128,11 @@ public function test_create_update_delete_payment() { } public function test_security() { - $security = $this->sut->get_security('A1.4', 'S1.1'); + $security = $this->sut->get_security('A13318.2', 'S13318.1'); $this->assertInstanceOf('figo\Security', $security); $this->assertEquals(1, count($security)); - $this->assertEquals('S1.1', $security->security_id); + $this->assertEquals('S13318.1', $security->security_id); $options = array( 'count' => 2, @@ -142,22 +145,22 @@ public function test_security() { $options = array( 'count' => 1, - 'account_id' =>'A1.4' + 'account_id' =>'A13318.2' ); $security = $this->sut->get_securities($options); $this->assertInternalType('array', $security); $this->assertInstanceOf('figo\Security', $security[0]); - $this->assertEquals('A1.4', $security[0]->account_id); + $this->assertEquals('A13318.2', $security[0]->account_id); } public function test_standing_order() { - $standing_order = $this->sut->get_standing_order('SO1.1'); + $standing_order = $this->sut->get_standing_order('SO13318.1'); $this->assertInstanceOf('figo\StandingOrder', $standing_order); $this->assertEquals(1, count($standing_order)); $this->assertEquals(100, $standing_order->amount); - $this->assertEquals('SO1.1', $standing_order->standing_order_id); + $this->assertEquals('SO13318.1', $standing_order->standing_order_id); $standing_order = null; $standing_order = $this->sut->get_standing_orders(true); From 064eea61976e301103d45c185219626487b536f7 Mon Sep 17 00:00:00 2001 From: Jan van Esdonk Date: Thu, 16 Nov 2017 12:03:55 +0100 Subject: [PATCH 06/17] remove tests which aren't possible on demo user on staging system --- test/FigoTest.php | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/test/FigoTest.php b/test/FigoTest.php index 0de24a4..c372408 100644 --- a/test/FigoTest.php +++ b/test/FigoTest.php @@ -154,30 +154,6 @@ public function test_security() { $this->assertEquals('A13318.2', $security[0]->account_id); } - - public function test_standing_order() { - $standing_order = $this->sut->get_standing_order('SO13318.1'); - $this->assertInstanceOf('figo\StandingOrder', $standing_order); - $this->assertEquals(1, count($standing_order)); - $this->assertEquals(100, $standing_order->amount); - $this->assertEquals('SO13318.1', $standing_order->standing_order_id); - - $standing_order = null; - $standing_order = $this->sut->get_standing_orders(true); - - $this->assertInternalType('array', $standing_order); - $this->assertInstanceOf('figo\StandingOrder', $standing_order[0]); - $this->assertEquals(100.00, $standing_order[0]->amount); - } - - public function test_setup_bank_account() { - $response = $this->sut->setup_bank_account( - "90090042", ["demo", "demo"], - ["save_pin" => true] - ); - $this->assertTrue(isset($response["task_token"])); - } - } From e65c28f737fb6be3887aa3e6977cf0760568343a Mon Sep 17 00:00:00 2001 From: Jan van Esdonk Date: Mon, 20 Nov 2017 13:46:54 +0100 Subject: [PATCH 07/17] unify credential_login and native_client login to keep backwards compatibility --- figo/Connection.php | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/figo/Connection.php b/figo/Connection.php index efb6968..3834299 100644 --- a/figo/Connection.php +++ b/figo/Connection.php @@ -291,16 +291,7 @@ public function create_user($name, $email, $password, $language='de') { */ public function credential_login($username, $password, $device_name = null, $device_type = null, $device_udid = null, $scope = null) { - $options = [ "grant_type" => "password", "username" => $username, "password" => $password ]; - if ($device_name) - $options["device_name"] = $device_name; - if ($device_type) - $options["device_type"] = $device_type; - if ($device_udid) - $options["device_udid"] = $device_udid; - if ($scope) - $options["scope"] = $scope; - return $this->query_api("/auth/token", $options, "POST", "json_encode"); + return $this->native_client_login($username, $password, $scope); } From e04429abfc7bf289fcd261718f7e0fe291384829 Mon Sep 17 00:00:00 2001 From: Jan van Esdonk Date: Mon, 20 Nov 2017 13:47:03 +0100 Subject: [PATCH 08/17] refactor tests rewritten tests to make them independent from the demo user --- test/FigoTest.php | 237 ++++++++++++++++++++++------------------------ 1 file changed, 111 insertions(+), 126 deletions(-) diff --git a/test/FigoTest.php b/test/FigoTest.php index c372408..f44edad 100644 --- a/test/FigoTest.php +++ b/test/FigoTest.php @@ -29,189 +29,174 @@ class SessionTest extends PHPUnit_Framework_TestCase { - protected $sut; - protected $demo_access_token = "ASHWLIkouP2O6_bgA2wWReRhletgWKHYjLqDaqb0LFfamim9RjexTo22ujRIP_cjLiRiSyQXyt2kM1eXU2XLFZQ0Hro15HikJQT_eNeT_9XQ"; - protected $api_endpoint = "https://staging.figo.me/v3"; - protected $fingerprints = array("D0:03:9E:F0:8F:BD:48:67:86:71:CE:9D:A5:54:24:81:63:D7:D9:4D:ED:F1:6A:55:F0:52:C7:0A:AB:7B:B8:9D"); + protected static $api_endpoint = "https://staging.figo.me/v3"; + protected static $fingerprints = array("D0:03:9E:F0:8F:BD:48:67:86:71:CE:9D:A5:54:24:81:63:D7:D9:4D:ED:F1:6A:55:F0:52:C7:0A:AB:7B:B8:9D"); - protected function setUp() { - $this->sut = new Session($this->demo_access_token, $this->api_endpoint, $this->fingerprints); + protected static $connection; + protected static $email; + protected static $password; + protected static $session; + + protected $access_token; + protected $account_id; + protected $sec_account_id; + + public static function setUpBeforeClass() + { + self::$connection = new Connection(getenv("FIGO_CLIENT_ID"), getenv("FIGO_CLIENT_SECRET"), + "http://my-domain.org/redirect-url", self::$api_endpoint, self::$fingerprints); + $name = "PHP SDK Test"; + self::$email = "php.sdk.".rand()."@figo.io"; + self::$password = "sdk_test_pass_".rand(); + self::$connection->create_user($name, self::$email, self::$password); + $response = self::$connection->native_client_login(self::$email, self::$password); + $access_token = $response["access_token"]; + self::$session = new Session($access_token, self::$api_endpoint, self::$fingerprints); + } + + public static function tearDownAfterClass() + { + self::$session->remove_user(); + } + + public function test_credential_login() { + + $accounts = $this::$session->get_accounts(); + $this->assertEquals([], $accounts); + } + + public function test_setup_account() { + $response = $this::$session->setup_bank_account("90090042", array("figo", "figo"), array()); + for($i = 0; $i <= 20; $i++) { + $task_state = $this::$session->get_task_state($response['task_token']); + if($task_state['is_ended'] == true) { + break; + } + sleep(1); + } } - public function test_accounts() { - $accounts = $this->sut->get_accounts(); - $this->assertGreaterThan(0, count($accounts)); + public function test_get_accounts() { + $accounts = $this::$session->get_accounts(); + $this->assertEquals(3, count($accounts)); + $this->account_id = $accounts[0]->account_id; + $single_account = $this::$session->get_account($this->account_id); + $this->assertEquals($this->account_id, $single_account->account_id); + $this->assertNotNull($single_account->balance->balance); + $this->assertNotNull($single_account->balance->balance_date); + } - $account = $this->sut->get_account("A13318.1"); - $this->assertEquals($account->account_id, "A13318.1"); + public function test_list_transactions() + { + $accounts = $this::$session->get_accounts(); + $this->account_id = $accounts[0]->account_id; + $transactions = $this::$session->get_transactions(); + $this->assertGreaterThan(0, $transactions); + $transactions = $this::$session->get_transactions($this->account_id); + $this->assertGreaterThan(0, $transactions); + } - $account = $this->sut->get_account("A13318.3"); - $this->assertEquals($account->account_id, "A13318.3"); - $this->assertNotNull($account->balance->balance); - $this->assertNotNull($account->balance->balance_date); + public function test_list_all_standing_orders() { + $standing_orders = $this::$session->get_standing_orders(); + $this->assertEquals(0, count($standing_orders)); + } - $transactions = $account->get_transactions(); - $this->assertGreaterThan(0, count($transactions)); + public function test_list_securities() { + $options = array(); + $securities = $this::$session->get_securities($options); + $this->assertGreaterThan(0, $securities); + $this->account_id = $securities[0]->account_id; + $options["account_id"] = $this->account_id; + $securities = $this::$session->get_securities($options); + $this->assertGreaterThan(0, $securities); + } - $payments = $account->get_payments(); - $this->assertGreaterThanOrEqual(0, count($payments)); + public function test_list_all_payments() { + $payments = $this::$session->get_payments(); + $this->assertEquals(0, count($payments)); } - public function test_global_transactions() { - $transactions = $this->sut->get_transactions(); - $this->assertGreaterThan(0, count($transactions)); + public function test_list_account_payments() { + $accounts = $this::$session->get_accounts(); + $this->account_id = $accounts[0]->account_id; + $payments = $this::$session->get_payments($this->account_id); + $this->assertEquals(0, count($payments)); } - public function test_global_notifications() { - $notifications = $this->sut->get_notifications(); - $this->assertGreaterThanOrEqual(0, count($notifications)); + public function test_list_all_notification_subscriptions() { + $notifications = $this::$session->get_notifications(); + $this->assertEquals(0, count($notifications)); } - public function test_global_payments() { - $payments = $this->sut->get_payments(); - $this->assertGreaterThanOrEqual(0, count($payments)); + public function test_list_user_information() { + $user = $this::$session->get_user(); + $this->assertEquals($this::$email, $user->email); } public function test_missing_handling() { - $this->assertNull($this->sut->get_account("A13318.42")); + $this->assertNull($this::$session->get_account("WRONG")); } public function test_error_handling() { $this->setExpectedException('Exception'); - $this->sut->get_sync_url("edsa", ""); + $this::$session->get_sync_url("random", ""); } public function test_sync_url() { - $sync_url = $this->sut->get_sync_url("http://localhost:3003/", "qew"); + $sync_url = $this::$session->get_sync_url("http://localhost:3003/", "qew"); $this->assertGreaterThan(0, strlen($sync_url)); } - public function test_user() { - $this->assertEquals($this->sut->get_user()->email, "demo@figo.me"); - } - public function test_create_update_delete_notification() { - $notification = $this->sut->add_notification(new Notification($this->sut, array("observe_key" => "/rest/transactions", "notify_uri" => "http://figo.me/test", "state" => "qwe"))); + $notification = $this::$session->add_notification(new Notification($this::$session, array("observe_key" => "/rest/transactions", "notify_uri" => "http://figo.me/test", "state" => "qwe"))); $this->assertEquals($notification->observe_key, "/rest/transactions"); $this->assertEquals($notification->notify_uri, "http://figo.me/test"); $this->assertEquals($notification->state, "qwe"); $notification->state = "asd"; - $this->sut->modify_notification($notification); + $this::$session->modify_notification($notification); - $notification = $this->sut->get_notification($notification->notification_id); + $notification = $this::$session->get_notification($notification->notification_id); $this->assertEquals($notification->observe_key, "/rest/transactions"); $this->assertEquals($notification->notify_uri, "http://figo.me/test"); $this->assertEquals($notification->state, "asd"); - $this->sut->remove_notification($notification); - $notification = $this->sut->get_notification($notification->notification_id); + $this::$session->remove_notification($notification); + $notification = $this::$session->get_notification($notification->notification_id); $this->assertNull($notification); } public function test_create_update_delete_payment() { - $added_payment = $this->sut->add_payment(new Payment($this->sut, array("account_id" => "A13318.1", "type" => "Transfer", "account_number" => "4711951501", "bank_code" => "90090042", "name" => "figo", "purpose" => "Thanks for all the fish.", "amount" => 0.89))); - $this->assertEquals($added_payment->account_id, "A13318.1"); + $accounts = $this::$session->get_accounts(); + $this->account_id = $accounts[0]->account_id; + $added_payment = $this::$session->add_payment(new Payment($this::$session, array("account_id" => $this->account_id, "type" => "Transfer", "account_number" => "4711951501", "bank_code" => "90090042", "name" => "figo", "purpose" => "Thanks for all the fish.", "amount" => 0.89))); + $this->assertEquals($added_payment->account_id, $this->account_id); $this->assertEquals($added_payment->bank_name, "Demobank"); $this->assertEquals($added_payment->amount, 0.89); $added_payment->amount = 2.39; - $modified_payment = $this->sut->modify_payment($added_payment); + $modified_payment = $this::$session->modify_payment($added_payment); $this->assertEquals($modified_payment->payment_id, $added_payment->payment_id); - $this->assertEquals($modified_payment->account_id, "A13318.1"); + $this->assertEquals($modified_payment->account_id, $this->account_id); $this->assertEquals($modified_payment->bank_name, "Demobank"); $this->assertEquals($modified_payment->amount, 2.39); - $this->sut->remove_payment($modified_payment); - $retrieved_payment = $this->sut->get_payment($modified_payment->account_id, $modified_payment->payment_id); + $this::$session->remove_payment($modified_payment); + $retrieved_payment = $this::$session->get_payment($modified_payment->account_id, $modified_payment->payment_id); $this->assertNull($retrieved_payment); } - public function test_security() { - $security = $this->sut->get_security('A13318.2', 'S13318.1'); - $this->assertInstanceOf('figo\Security', $security); - $this->assertEquals(1, count($security)); - - $this->assertEquals('S13318.1', $security->security_id); - - $options = array( - 'count' => 2, - ); - - $security = $this->sut->get_securities($options); - $this->assertInternalType('array', $security); - $this->assertInstanceOf('figo\Security', $security[0]); - $this->assertEquals(2, count($security)); - - $options = array( - 'count' => 1, - 'account_id' =>'A13318.2' - ); - - $security = $this->sut->get_securities($options); - $this->assertInternalType('array', $security); - $this->assertInstanceOf('figo\Security', $security[0]); - - $this->assertEquals('A13318.2', $security[0]->account_id); - } -} - - -class ConnectionTest extends PHPUnit_Framework_TestCase { - - /** @var Connection */ - protected $sut; - - protected function setUp() { - $this->sut = new Connection( - getenv('FIGO_CLIENT_ID'), - getenv('FIGO_CLIENT_SECRET'), - "http://my-domain.org/redirect-url", - getenv('FIGO_API_ENDPOINT'), - explode(',', getenv('FIGO_SSL_FINGERPRINT')) - ); - } - - public function test_native_login() { - $response = $this->sut->native_client_login("demo@figo.me", "demo1234"); - $access_token = $response["access_token"]; - $session = new Session($access_token); - try { - $this->assertEquals([], $session->get_accounts()); - } finally { - $session->remove_user(); - } - - } - - public function test_credentials_login() - { - $response = $this->sut->credential_login('php.sdk.testing@figo.io', 'phpsdk'); - $this->assertNotEmpty($response); - $this->assertNotNull($response['access_token']); + public function test_get_catalog_in_english() { + $response = $this::$connection->get_supported_payment_services(null, null, "en"); + $this->assertEquals("en", $response["banks"][0]["language"]["current_language"]); } - public function test_catalog_language_is_german_by_default() - { - $result = $this->sut->get_supported_payment_services(); - - $this->assertEquals('de', $result['banks'][0]['language']['current_language']); - } - - public function test_catalog_language_can_be_set_to_english() - { - $result = $this->sut->get_supported_payment_services(null, null, 'en'); - - $this->assertEquals('en', $result['banks'][0]['language']['current_language']); - } - - public function test_catalog_throws_exception_on_unsupported_language() + public function test_get_catalog_unsupported_language() { $this->setExpectedException( - \figo\Exception::class, 'Not Acceptable: Unsupported language (Status: 406), ' + \figo\Exception::class, 'Code: 1000, Unsupported language' ); - - $this->sut->get_supported_payment_services(null, null, 'fr'); + $this::$connection->get_supported_payment_services(null, null, 'fr'); } } ?> From 7fc1500bf988297ae952e939d035df467f4ce2f2 Mon Sep 17 00:00:00 2001 From: Jan van Esdonk Date: Mon, 20 Nov 2017 13:48:11 +0100 Subject: [PATCH 09/17] add test credentials --- .travis.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.travis.yml b/.travis.yml index cf38498..be25b3b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,3 +5,9 @@ php: - 7.1 before_script: composer install script: vendor/bin/phpunit +env: + global: + - secure: bKDnQnsML4R5+KInG3c3SCEOr5VJQ1moEdwQAVtQLJLNsajBviODY9L+G3ENER1kmtrpDwkWwI014Fna8fJuhJmkabg8DVQx7Zl0+Ok7+y7VjHevu9ggJqNJfyKFSVGN0/sNJdt6ImURkSYH4VX+CDkDPvuz7vOPmPgddZjxS60= + - secure: B/hWxuZvWHQAha90zIXEn9czWV9nTRxEw10WkmefqWWbEyT+40lXcY8mF626MFiIg3q1uwA1ikgh31EzOGXotqhqHCXheK/IbjBAf6JbgHvKi8+Ww4bwtESkqbUNDQO8HryG1SSU/TWhLDZDudHbwDZ6pF/5DNb1ZkhtyBnAZoo= + - secure: O5qYfh3gmh+OZUMBF2+4SyUNppcKgbrtv7xu9K1TS9YtFs6dNxh1ZOL0V+EouM1HTdHTFJSHaI4KINS5xsqo6iwL7pvXO35px1S2aItQuiYH35QB73qVU/28Y0W73lUgYm9MfYSNuUOpB+J5/lS5gKpDqGj6mb32+voc0K2w+fI= + - secure: TA1cdINl/YBJt4fAXmQK85L24DVyX7EpoA9An7LOwaQ4vDskvV62HR2iiM4elETHFqex+odAdT/kIlxvL0brhWBS8Tp7r5V0UhBavj8VO6iSDUivvkkw12fnC/17MTOLFs4/Ktj7QGTdhOxxX42sEavKFa4ZD5ys1ROj+xr5veQ= From 74f7f58269926c1370c3e306997c0dca0c9991a9 Mon Sep 17 00:00:00 2001 From: Jan van Esdonk Date: Tue, 21 Nov 2017 12:43:03 +0100 Subject: [PATCH 10/17] add utils.php with endpoint parser and make use of it --- figo/Connection.php | 5 +++-- figo/Session.php | 5 +++-- figo/utils.php | 12 ++++++++++++ 3 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 figo/utils.php diff --git a/figo/Connection.php b/figo/Connection.php index 3834299..49e04f3 100644 --- a/figo/Connection.php +++ b/figo/Connection.php @@ -23,6 +23,8 @@ namespace figo; +require_once("utils.php"); + use Psr\Log\LoggerInterface; use Psr\Log\NullLogger; @@ -68,8 +70,7 @@ public function __construct($client_id, $client_secret, $redirect_uri = null, $a if ($apiEndpoint) { $this->apiEndpoint = $apiEndpoint; } - - $this->apiUrl = parse_url($this->apiEndpoint); + $this->apiUrl = parse_api_endpoint($this->apiEndpoint); if ($fingerprints) { $this->fingerprints = $fingerprints; diff --git a/figo/Session.php b/figo/Session.php index 24561f8..d0c73d2 100644 --- a/figo/Session.php +++ b/figo/Session.php @@ -23,6 +23,8 @@ namespace figo; +require_once("utils.php"); + use Psr\Log\LoggerInterface; use Psr\Log\NullLogger; @@ -62,8 +64,7 @@ public function __construct($access_token, $apiEndpoint = null, array $fingerpri if ($apiEndpoint) { $this->apiEndpoint = $apiEndpoint; } - - $this->apiUrl = parse_url($this->apiEndpoint); + $this->apiUrl = parse_api_endpoint($this->apiEndpoint); if ($fingerprints) { $this->fingerprints = $fingerprints; diff --git a/figo/utils.php b/figo/utils.php new file mode 100644 index 0000000..90008a4 --- /dev/null +++ b/figo/utils.php @@ -0,0 +1,12 @@ + Date: Tue, 21 Nov 2017 12:45:14 +0100 Subject: [PATCH 11/17] use all envs in tests --- test/FigoTest.php | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/test/FigoTest.php b/test/FigoTest.php index f44edad..2c6321f 100644 --- a/test/FigoTest.php +++ b/test/FigoTest.php @@ -29,33 +29,31 @@ class SessionTest extends PHPUnit_Framework_TestCase { - protected static $api_endpoint = "https://staging.figo.me/v3"; - protected static $fingerprints = array("D0:03:9E:F0:8F:BD:48:67:86:71:CE:9D:A5:54:24:81:63:D7:D9:4D:ED:F1:6A:55:F0:52:C7:0A:AB:7B:B8:9D"); - + protected static $api_endpoint; protected static $connection; protected static $email; + protected static $fingerprints; protected static $password; protected static $session; protected $access_token; protected $account_id; - protected $sec_account_id; - public static function setUpBeforeClass() - { + public static function setUpBeforeClass() { + $fingerprints = explode(",", getenv("FIGO_SSL_FINGERPRINT")); + $api_endpoint = getenv("FIGO_API_ENDPOINT"); self::$connection = new Connection(getenv("FIGO_CLIENT_ID"), getenv("FIGO_CLIENT_SECRET"), - "http://my-domain.org/redirect-url", self::$api_endpoint, self::$fingerprints); + "http://example.com/callback.php", $api_endpoint, $fingerprints); $name = "PHP SDK Test"; self::$email = "php.sdk.".rand()."@figo.io"; self::$password = "sdk_test_pass_".rand(); self::$connection->create_user($name, self::$email, self::$password); $response = self::$connection->native_client_login(self::$email, self::$password); $access_token = $response["access_token"]; - self::$session = new Session($access_token, self::$api_endpoint, self::$fingerprints); + self::$session = new Session($access_token, $api_endpoint, $fingerprints); } - public static function tearDownAfterClass() - { + public static function tearDownAfterClass() { self::$session->remove_user(); } @@ -72,6 +70,7 @@ public function test_setup_account() { if($task_state['is_ended'] == true) { break; } + $this->assertFalse($task_state['is_erroneous']); sleep(1); } } @@ -143,7 +142,7 @@ public function test_error_handling() { } public function test_sync_url() { - $sync_url = $this::$session->get_sync_url("http://localhost:3003/", "qew"); + $sync_url = $this::$session->get_sync_url("http://example.com/callback.php", "qew"); $this->assertGreaterThan(0, strlen($sync_url)); } From b06524eb2a0be485b06e2b2396dd21e1d23df364 Mon Sep 17 00:00:00 2001 From: Jan van Esdonk Date: Tue, 21 Nov 2017 12:46:11 +0100 Subject: [PATCH 12/17] bump version --- composer.json | 2 +- figo/Config.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 8d972da..0a837fa 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "figo/figo", "description": "API wrapper for figo Connect.", "homepage": "https://github.com/figo-connect/php-figo", - "version": "1.3.0", + "version": "1.4.0", "license": "MIT", "autoload": { "psr-0": { diff --git a/figo/Config.php b/figo/Config.php index 8eaf938..8c81ebb 100644 --- a/figo/Config.php +++ b/figo/Config.php @@ -42,7 +42,7 @@ class Config { /** * @var string Version of this SDK, used in user agent for API requests */ - public static $SDK_VERSION = '1.3.0'; + public static $SDK_VERSION = '1.4.0'; } ?> From ef7896b8ab31752f1feb91636f49d3fa67f2d10a Mon Sep 17 00:00:00 2001 From: Jan van Esdonk Date: Tue, 21 Nov 2017 13:29:12 +0100 Subject: [PATCH 13/17] fix endpoint parsing --- figo/utils.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/figo/utils.php b/figo/utils.php index 90008a4..a8a97fa 100644 --- a/figo/utils.php +++ b/figo/utils.php @@ -2,11 +2,12 @@ function parse_api_endpoint($api_endpoint) { $api_endpoint = rtrim($api_endpoint, "/"); - $length = strlen($api_endpoint); - if (substr($api_endpoint, 0, $length) != "https://") { + if (substr($api_endpoint, 0, 8) != "https://") { $api_endpoint = "https://" . $api_endpoint; } $api_url = parse_url($api_endpoint); - $api_url["path"] = ""; + if (array_key_exists("path", $api_url) == false) { + $api_url["path"] = ""; + } return $api_url; } From dc6670932dc71d3da39438716adc1e8e3708b6ef Mon Sep 17 00:00:00 2001 From: Jan van Esdonk Date: Wed, 29 Nov 2017 15:20:00 +0100 Subject: [PATCH 14/17] update version --- composer.json | 2 +- figo/Config.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 0a837fa..7406114 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "figo/figo", "description": "API wrapper for figo Connect.", "homepage": "https://github.com/figo-connect/php-figo", - "version": "1.4.0", + "version": "2.0.0", "license": "MIT", "autoload": { "psr-0": { diff --git a/figo/Config.php b/figo/Config.php index 8c81ebb..33b6f81 100644 --- a/figo/Config.php +++ b/figo/Config.php @@ -42,7 +42,7 @@ class Config { /** * @var string Version of this SDK, used in user agent for API requests */ - public static $SDK_VERSION = '1.4.0'; + public static $SDK_VERSION = '2.0.0'; } ?> From d82c5804a7d60ec6efa2260261cde329b186b9c3 Mon Sep 17 00:00:00 2001 From: Berend Kapelle Date: Thu, 8 Feb 2018 15:35:43 +0100 Subject: [PATCH 15/17] added test for get_bank, other preparation for v3 --- composer.json | 2 +- figo/Session.php | 11 ----------- test/FigoTest.php | 8 ++++++++ 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/composer.json b/composer.json index 7406114..3ea56ad 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "figo/figo", "description": "API wrapper for figo Connect.", "homepage": "https://github.com/figo-connect/php-figo", - "version": "2.0.0", + "version": "3.0.0", "license": "MIT", "autoload": { "psr-0": { diff --git a/figo/Session.php b/figo/Session.php index d0c73d2..ee828b5 100644 --- a/figo/Session.php +++ b/figo/Session.php @@ -251,17 +251,6 @@ public function add_account($country, $credentials, $bank_code, $iban, $save_pin return (is_null($response) ? null : new Account($this, $response)); } - /** - * Modify an account - * - * @param Account the modified account to be saved - * @return Account 'Account' object for the updated account returned by server - */ - public function modify_account($account) { - $response = $this->query_api("/rest/accounts/".$account->account_id, $account->dump(), "PUT"); - return (is_null($response) ? null : new Account($this, $response)); - } - /** * Remove an account * diff --git a/test/FigoTest.php b/test/FigoTest.php index 2c6321f..5984339 100644 --- a/test/FigoTest.php +++ b/test/FigoTest.php @@ -197,5 +197,13 @@ public function test_get_catalog_unsupported_language() ); $this::$connection->get_supported_payment_services(null, null, 'fr'); } + + public function test_get_bank() + { + $accounts = $this::$session->get_accounts(); + $bank_id = $accounts[0]->bank_id; + $bank = $this::$session->get_bank($bank_id); + $this->assertNotNull($bank); + } } ?> From de453d3311ea2e505c2609e3a6d51fa3b81f3b04 Mon Sep 17 00:00:00 2001 From: Berend Kapelle Date: Thu, 8 Feb 2018 15:54:58 +0100 Subject: [PATCH 16/17] remove env variables from .travis.yml --- .travis.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index be25b3b..cf38498 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,9 +5,3 @@ php: - 7.1 before_script: composer install script: vendor/bin/phpunit -env: - global: - - secure: bKDnQnsML4R5+KInG3c3SCEOr5VJQ1moEdwQAVtQLJLNsajBviODY9L+G3ENER1kmtrpDwkWwI014Fna8fJuhJmkabg8DVQx7Zl0+Ok7+y7VjHevu9ggJqNJfyKFSVGN0/sNJdt6ImURkSYH4VX+CDkDPvuz7vOPmPgddZjxS60= - - secure: B/hWxuZvWHQAha90zIXEn9czWV9nTRxEw10WkmefqWWbEyT+40lXcY8mF626MFiIg3q1uwA1ikgh31EzOGXotqhqHCXheK/IbjBAf6JbgHvKi8+Ww4bwtESkqbUNDQO8HryG1SSU/TWhLDZDudHbwDZ6pF/5DNb1ZkhtyBnAZoo= - - secure: O5qYfh3gmh+OZUMBF2+4SyUNppcKgbrtv7xu9K1TS9YtFs6dNxh1ZOL0V+EouM1HTdHTFJSHaI4KINS5xsqo6iwL7pvXO35px1S2aItQuiYH35QB73qVU/28Y0W73lUgYm9MfYSNuUOpB+J5/lS5gKpDqGj6mb32+voc0K2w+fI= - - secure: TA1cdINl/YBJt4fAXmQK85L24DVyX7EpoA9An7LOwaQ4vDskvV62HR2iiM4elETHFqex+odAdT/kIlxvL0brhWBS8Tp7r5V0UhBavj8VO6iSDUivvkkw12fnC/17MTOLFs4/Ktj7QGTdhOxxX42sEavKFa4ZD5ys1ROj+xr5veQ= From 4a5c06154f48fe27dcea304af70afc3eaa4c81b8 Mon Sep 17 00:00:00 2001 From: Berend Kapelle Date: Thu, 8 Feb 2018 16:10:00 +0100 Subject: [PATCH 17/17] point to v3 docs --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6fda84e..c0e2f8a 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ php-figo [![Build Status](https://secure.travis-ci.org/figo-connect/php-figo.png)](https://travis-ci.org/figo-connect/php-figo) [![Packagist Version](http://img.shields.io/packagist/v/figo/figo.svg)](https://packagist.org/packages/figo/figo) ======== -PHP bindings for the figo Connect API: http://docs.figo.io +PHP bindings for the figo Connect API: http://docs.figo.io/v3/ Usage =====