Skip to content

Commit

Permalink
Merge branch 'feature/FAPI-1223--make-php-sdk-use-v3'
Browse files Browse the repository at this point in the history
  • Loading branch information
Berend Kapelle committed Feb 26, 2018
2 parents 0942461 + 4a5c061 commit 44cc6d3
Show file tree
Hide file tree
Showing 8 changed files with 151 additions and 180 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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
=====
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "3.0.0",
"license": "MIT",
"autoload": {
"psr-0": {
Expand Down
6 changes: 3 additions & 3 deletions figo/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
*/
class Config {

/** @var string figo Connect server hostname */
public static $API_ENDPOINT = "api.figo.me";
/** @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 */
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",
Expand All @@ -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 = '2.0.0';
}

?>
19 changes: 7 additions & 12 deletions figo/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

namespace figo;

require_once("utils.php");

use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;

Expand Down Expand Up @@ -68,6 +70,7 @@ public function __construct($client_id, $client_secret, $redirect_uri = null, $a
if ($apiEndpoint) {
$this->apiEndpoint = $apiEndpoint;
}
$this->apiUrl = parse_api_endpoint($this->apiEndpoint);

if ($fingerprints) {
$this->fingerprints = $fingerprints;
Expand Down Expand Up @@ -107,7 +110,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);
}

Expand All @@ -134,7 +138,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);
}


Expand Down Expand Up @@ -288,16 +292,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);
}


Expand Down
4 changes: 2 additions & 2 deletions figo/HttpsRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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) {
Expand Down
22 changes: 7 additions & 15 deletions figo/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

namespace figo;

require_once("utils.php");

use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;

Expand Down Expand Up @@ -62,6 +64,7 @@ public function __construct($access_token, $apiEndpoint = null, array $fingerpri
if ($apiEndpoint) {
$this->apiEndpoint = $apiEndpoint;
}
$this->apiUrl = parse_api_endpoint($this->apiEndpoint);

if ($fingerprints) {
$this->fingerprints = $fingerprints;
Expand Down Expand Up @@ -93,8 +96,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);
}

Expand Down Expand Up @@ -248,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
*
Expand Down Expand Up @@ -465,7 +457,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"];
}


Expand Down Expand Up @@ -717,7 +709,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"];
}
}
}
Expand Down
13 changes: 13 additions & 0 deletions figo/utils.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

function parse_api_endpoint($api_endpoint) {
$api_endpoint = rtrim($api_endpoint, "/");
if (substr($api_endpoint, 0, 8) != "https://") {
$api_endpoint = "https://" . $api_endpoint;
}
$api_url = parse_url($api_endpoint);
if (array_key_exists("path", $api_url) == false) {
$api_url["path"] = "";
}
return $api_url;
}
Loading

0 comments on commit 44cc6d3

Please sign in to comment.