Skip to content

Commit 44cc6d3

Browse files
author
Berend Kapelle
committed
Merge branch 'feature/FAPI-1223--make-php-sdk-use-v3'
2 parents 0942461 + 4a5c061 commit 44cc6d3

File tree

8 files changed

+151
-180
lines changed

8 files changed

+151
-180
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
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)
22
========
33

4-
PHP bindings for the figo Connect API: http://docs.figo.io
4+
PHP bindings for the figo Connect API: http://docs.figo.io/v3/
55

66
Usage
77
=====

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "figo/figo",
33
"description": "API wrapper for figo Connect.",
44
"homepage": "https://github.com/figo-connect/php-figo",
5-
"version": "1.3.0",
5+
"version": "3.0.0",
66
"license": "MIT",
77
"autoload": {
88
"psr-0": {

figo/Config.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
*/
3030
class Config {
3131

32-
/** @var string figo Connect server hostname */
33-
public static $API_ENDPOINT = "api.figo.me";
32+
/** @var string figo Connect server address. This should be the full base url of the API */
33+
public static $API_ENDPOINT = "https://api.figo.me/v3";
3434

3535
/** @var string figo Connect SSL/TLS certificate fingerprints */
3636
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",
@@ -42,7 +42,7 @@ class Config {
4242
/**
4343
* @var string Version of this SDK, used in user agent for API requests
4444
*/
45-
public static $SDK_VERSION = '1.3.0';
45+
public static $SDK_VERSION = '2.0.0';
4646
}
4747

4848
?>

figo/Connection.php

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
namespace figo;
2525

26+
require_once("utils.php");
27+
2628
use Psr\Log\LoggerInterface;
2729
use Psr\Log\NullLogger;
2830

@@ -68,6 +70,7 @@ public function __construct($client_id, $client_secret, $redirect_uri = null, $a
6870
if ($apiEndpoint) {
6971
$this->apiEndpoint = $apiEndpoint;
7072
}
73+
$this->apiUrl = parse_api_endpoint($this->apiEndpoint);
7174

7275
if ($fingerprints) {
7376
$this->fingerprints = $fingerprints;
@@ -107,7 +110,8 @@ public function query_api($path, array $data = null, $method='POST', $encode='ht
107110
"Content-Type" => $content_type,
108111
"Content-Length" => strlen($data));
109112

110-
$request = new HttpsRequest($this->apiEndpoint, $this->fingerprints, $this->logger);
113+
$request = new HttpsRequest($this->apiUrl['host'], $this->fingerprints, $this->logger);
114+
$path = $this->apiUrl['path'] . $path;
111115
return $request->request($path, $data, $method, $headers, $language);
112116
}
113117

@@ -134,7 +138,7 @@ public function login_url($state, $scope = null) {
134138
if (!is_null($scope)) {
135139
$data["scope"] = $scope;
136140
}
137-
return "https://".Config::$API_ENDPOINT."/auth/code?".http_build_query($data);
141+
return $this->apiEndpoint."/auth/code?".http_build_query($data);
138142
}
139143

140144

@@ -288,16 +292,7 @@ public function create_user($name, $email, $password, $language='de') {
288292
*/
289293
public function credential_login($username, $password, $device_name = null, $device_type = null, $device_udid = null, $scope = null)
290294
{
291-
$options = [ "grant_type" => "password", "username" => $username, "password" => $password ];
292-
if ($device_name)
293-
$options["device_name"] = $device_name;
294-
if ($device_type)
295-
$options["device_type"] = $device_type;
296-
if ($device_udid)
297-
$options["device_udid"] = $device_udid;
298-
if ($scope)
299-
$options["scope"] = $scope;
300-
return $this->query_api("/auth/token", $options, "POST", "json_encode");
295+
return $this->native_client_login($username, $password, $scope);
301296
}
302297

303298

figo/HttpsRequest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public function request($path, $data, $method, array $headers, $language = 'de')
8686
}
8787

8888
// Setup common HTTP headers.
89-
$headers["Host"] = Config::$API_ENDPOINT;
89+
$headers["Host"] = parse_url(Config::$API_ENDPOINT)['host'];
9090
$headers["Accept"] = "application/json";
9191
$headers["User-Agent"] = Config::$USER_AGENT . '/' . Config::$SDK_VERSION;
9292
$headers["Connection"] = "close";
@@ -148,7 +148,7 @@ public function request($path, $data, $method, array $headers, $language = 'de')
148148

149149
if ($code >= 400 && $code < 500) {
150150
$this->logFailedRequest($path, $responseArray, $loggingData);
151-
throw new Exception($responseArray["error"]["name"] .": ". $responseArray["error"]["message"]." (Status: ".$responseArray["status"].")" , $responseArray["error"]["description"]);
151+
throw new Exception("Code: ".$responseArray["error"]["code"], $responseArray["error"]["description"]);
152152
}
153153

154154
if ($code === 503) {

figo/Session.php

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
namespace figo;
2525

26+
require_once("utils.php");
27+
2628
use Psr\Log\LoggerInterface;
2729
use Psr\Log\NullLogger;
2830

@@ -62,6 +64,7 @@ public function __construct($access_token, $apiEndpoint = null, array $fingerpri
6264
if ($apiEndpoint) {
6365
$this->apiEndpoint = $apiEndpoint;
6466
}
67+
$this->apiUrl = parse_api_endpoint($this->apiEndpoint);
6568

6669
if ($fingerprints) {
6770
$this->fingerprints = $fingerprints;
@@ -93,8 +96,8 @@ public function query_api($path, array $data = null, $method = "GET") {
9396
"Content-Type" => "application/json",
9497
"Content-Length" => strlen($data));
9598

96-
$request = new HttpsRequest($this->apiEndpoint, $this->fingerprints, $this->logger);
97-
99+
$request = new HttpsRequest($this->apiUrl['host'], $this->fingerprints, $this->logger);
100+
$path = $this->apiUrl['path'] . $path;
98101
return $request->request($path, $data, $method, $headers);
99102
}
100103

@@ -248,17 +251,6 @@ public function add_account($country, $credentials, $bank_code, $iban, $save_pin
248251
return (is_null($response) ? null : new Account($this, $response));
249252
}
250253

251-
/**
252-
* Modify an account
253-
*
254-
* @param Account the modified account to be saved
255-
* @return Account 'Account' object for the updated account returned by server
256-
*/
257-
public function modify_account($account) {
258-
$response = $this->query_api("/rest/accounts/".$account->account_id, $account->dump(), "PUT");
259-
return (is_null($response) ? null : new Account($this, $response));
260-
}
261-
262254
/**
263255
* Remove an account
264256
*
@@ -465,7 +457,7 @@ public function remove_bank_pin($bank_or_id) {
465457
public function get_sync_url($redirect_uri, $state) {
466458
$data = array("redirect_uri" => $redirect_uri, "state" => $state);
467459
$response = $this->query_api("/rest/sync", $data, "POST");
468-
return "https://".Config::$API_ENDPOINT."/task/start?id=".$response["task_token"];
460+
return $this->apiEndpoint."/task/start?id=".$response["task_token"];
469461
}
470462

471463

@@ -717,7 +709,7 @@ public function submit_payment($payment, $tan_scheme_id, $state, $redirect_uri=n
717709
if (is_null($response)) {
718710
return null;
719711
} else {
720-
return "https://".Config::$API_ENDPOINT."/task/start?id=".$response["task_token"];
712+
return $this->apiEndpoint."/task/start?id=".$response["task_token"];
721713
}
722714
}
723715
}

figo/utils.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
function parse_api_endpoint($api_endpoint) {
4+
$api_endpoint = rtrim($api_endpoint, "/");
5+
if (substr($api_endpoint, 0, 8) != "https://") {
6+
$api_endpoint = "https://" . $api_endpoint;
7+
}
8+
$api_url = parse_url($api_endpoint);
9+
if (array_key_exists("path", $api_url) == false) {
10+
$api_url["path"] = "";
11+
}
12+
return $api_url;
13+
}

0 commit comments

Comments
 (0)