From 91f5608dc70ceba17509762cd42e595f39f9b4c3 Mon Sep 17 00:00:00 2001 From: Menno Holtkamp Date: Sat, 24 Jun 2017 17:18:00 +0200 Subject: [PATCH 01/12] Add new NotificationFilter categories --- src/Domain/NotificationFilter.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Domain/NotificationFilter.php b/src/Domain/NotificationFilter.php index bb5b65f..caaa8b8 100644 --- a/src/Domain/NotificationFilter.php +++ b/src/Domain/NotificationFilter.php @@ -7,6 +7,7 @@ final class NotificationFilter const DELIVERYMETHOD_PUSH = 'PUSH'; const DELIVERYMETHOD_CALLBACK = 'URL'; + const CATEGORY_BANK_SWITCH_SERVICE = 'BANK_SWITCH_SERVICE'; const CATEGORY_BILLING = 'BILLING'; const CATEGORY_CARD_TRANSACTION_FAILED = 'CARD_TRANSACTION_FAILED'; const CATEGORY_CARD_TRANSACTION_SUCCESSFUL = 'CARD_TRANSACTION_SUCCESSFUL'; @@ -27,7 +28,9 @@ final class NotificationFilter const CATEGORY_TAB_RESULT = 'TAB_RESULT'; const CATEGORY_USER_APPROVAL = 'USER_APPROVAL'; const CATEGORY_USE_RESPONSE = 'USE_RESPONSE'; - + const CATEGORY_USE_RESPONSE_NATIVE_COMMENT = 'USE_RESPONSE_NATIVE_COMMENT'; + const CATEGORY_USE_RESPONSE_NATIVE_TOPIC = 'USE_RESPONSE_NATIVE_TOPIC'; + const CATEGORY_SLICE_CHAT = 'SLICE_CHAT'; const CATEGORY_SLICE_REGISTRY_ENTRY = 'SLICE_REGISTRY_ENTRY'; const CATEGORY_SLICE_REGISTRY_MEMBERSHIP = 'SLICE_REGISTRY_MEMBERSHIP'; From f1e83814b9761e8b56a16d5b5b0720dddd646251 Mon Sep 17 00:00:00 2001 From: Menno Holtkamp Date: Sat, 24 Jun 2017 21:18:44 +0200 Subject: [PATCH 02/12] Add CATEGORY_BANK_SWITCH_SERVICE_PAYMENT --- src/Domain/NotificationFilter.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Domain/NotificationFilter.php b/src/Domain/NotificationFilter.php index caaa8b8..9764dda 100644 --- a/src/Domain/NotificationFilter.php +++ b/src/Domain/NotificationFilter.php @@ -8,6 +8,7 @@ final class NotificationFilter const DELIVERYMETHOD_CALLBACK = 'URL'; const CATEGORY_BANK_SWITCH_SERVICE = 'BANK_SWITCH_SERVICE'; + const CATEGORY_BANK_SWITCH_SERVICE_PAYMENT = 'BANK_SWITCH_SERVICE_PAYMENT'; const CATEGORY_BILLING = 'BILLING'; const CATEGORY_CARD_TRANSACTION_FAILED = 'CARD_TRANSACTION_FAILED'; const CATEGORY_CARD_TRANSACTION_SUCCESSFUL = 'CARD_TRANSACTION_SUCCESSFUL'; From 9ea928055d153b4a4db7e741c41248ef880bba8f Mon Sep 17 00:00:00 2001 From: Menno Holtkamp Date: Mon, 26 Jun 2017 20:13:11 +0200 Subject: [PATCH 03/12] Remove pointless PHPDoc --- src/Client.php | 28 +++++----------------------- 1 file changed, 5 insertions(+), 23 deletions(-) diff --git a/src/Client.php b/src/Client.php index 9db12b4..0c39bfa 100644 --- a/src/Client.php +++ b/src/Client.php @@ -33,9 +33,6 @@ final class Client */ private $handlerStack; - /** - * @param Environment $environment - */ public function __construct(Environment $environment, Keypair $keypair, PublicKey $serverPublicKey = null, string $sessionToken = '') { $this->handlerStack = HandlerStack::create(); @@ -54,10 +51,6 @@ public function __construct(Environment $environment, Keypair $keypair, PublicKe ]); } - /** - * @param string $endpoint - * @return array - */ public function get(string $endpoint, array $headers = []): array { return $this->processResponse( @@ -67,12 +60,6 @@ public function get(string $endpoint, array $headers = []): array ); } - /** - * @param string $endpoint - * @param array $body - * @param array $headers - * @return array - */ public function post(string $endpoint, array $body, array $headers = []): array { return $this->processResponse( @@ -83,12 +70,6 @@ public function post(string $endpoint, array $body, array $headers = []): array ); } - /** - * @param string $endpoint - * @param array $body - * @param array $headers - * @return array - */ public function put(string $endpoint, array $body, array $headers = []): array { return $this->processResponse( @@ -102,6 +83,7 @@ public function put(string $endpoint, array $body, array $headers = []): array /** * @param string $endpoint * @param array $headers + * * @return void */ public function delete(string $endpoint, array $headers = []) @@ -111,10 +93,6 @@ public function delete(string $endpoint, array $headers = []) ]); } - /** - * @param ResponseInterface $response - * @return array - */ private function processResponse(ResponseInterface $response): array { $contents = (string) $response->getBody(); @@ -164,6 +142,7 @@ private function mapResponse(string $key, array $value) /** * @param string $sessionToken + * * @return void */ private function addRequestIdMiddleware(string $sessionToken) @@ -176,6 +155,7 @@ private function addRequestIdMiddleware(string $sessionToken) /** * @param Keypair $keypair + * * @return void */ private function addRequestSignatureMiddleware(Keypair $keypair) @@ -189,6 +169,7 @@ private function addRequestSignatureMiddleware(Keypair $keypair) /** * @param PublicKey|null $serverPublicKey + * * @return void */ private function addServerResponseMiddleware(PublicKey $serverPublicKey = null) @@ -203,6 +184,7 @@ private function addServerResponseMiddleware(PublicKey $serverPublicKey = null) /** * @param Environment $environment + * * @return void */ private function addDebugMiddleware(Environment $environment) From a1d32a32819c623bf37a3918967c664f04c10dca Mon Sep 17 00:00:00 2001 From: Menno Holtkamp Date: Mon, 26 Jun 2017 20:13:27 +0200 Subject: [PATCH 04/12] Reformat code --- src/Client.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Client.php b/src/Client.php index 0c39bfa..5bc50f8 100644 --- a/src/Client.php +++ b/src/Client.php @@ -95,7 +95,7 @@ public function delete(string $endpoint, array $headers = []) private function processResponse(ResponseInterface $response): array { - $contents = (string) $response->getBody(); + $contents = (string)$response->getBody(); $json = json_decode($contents, true)['Response']; // Return empty responses From 1a7f0a3db6758947924c77ac5c489c0f83df62a8 Mon Sep 17 00:00:00 2001 From: Menno Holtkamp Date: Mon, 26 Jun 2017 20:14:35 +0200 Subject: [PATCH 05/12] Use single quotes when double quotes are not required --- src/Client.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Client.php b/src/Client.php index 5bc50f8..c1e55e8 100644 --- a/src/Client.php +++ b/src/Client.php @@ -136,7 +136,7 @@ private function mapResponse(string $key, array $value) case 'Token': return Token::fromArray($value); default: - throw new \Exception("Unknown struct type: " . $key); + throw new \Exception('Unknown struct type: ' . $key); } } From 88fadb767f53eb2bc33df297dacde2523d7b7848 Mon Sep 17 00:00:00 2001 From: Menno Holtkamp Date: Mon, 26 Jun 2017 20:16:10 +0200 Subject: [PATCH 06/12] Support for proxy configuration --- src/Client.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Client.php b/src/Client.php index c1e55e8..04180a1 100644 --- a/src/Client.php +++ b/src/Client.php @@ -33,7 +33,7 @@ final class Client */ private $handlerStack; - public function __construct(Environment $environment, Keypair $keypair, PublicKey $serverPublicKey = null, string $sessionToken = '') + public function __construct(Environment $environment, Keypair $keypair, PublicKey $serverPublicKey = null, string $sessionToken = '', array $proxy = null) { $this->handlerStack = HandlerStack::create(); @@ -42,13 +42,19 @@ public function __construct(Environment $environment, Keypair $keypair, PublicKe $this->addServerResponseMiddleware($serverPublicKey); $this->addDebugMiddleware($environment); - $this->guzzle = new GuzzleClient([ + $configuration = [ 'base_uri' => $environment->endpoint(), 'handler' => $this->handlerStack, 'headers' => [ 'User-Agent' => 'Link0 Bunq API Client' ] - ]); + ]; + + if(is_array($proxy)){ + $configuration['proxy'] = $proxy; + } + + $this->guzzle = new GuzzleClient($configuration); } public function get(string $endpoint, array $headers = []): array From 6fc16fc8bb07f5512816e189cc18e3f63b4654a7 Mon Sep 17 00:00:00 2001 From: Menno Holtkamp Date: Mon, 26 Jun 2017 20:24:07 +0200 Subject: [PATCH 07/12] Allow proxy parameter to be a string --- src/Client.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Client.php b/src/Client.php index 04180a1..d1255b4 100644 --- a/src/Client.php +++ b/src/Client.php @@ -2,6 +2,7 @@ namespace Link0\Bunq; +use Assert\Assertion; use GuzzleHttp\Client as GuzzleClient; use GuzzleHttp\HandlerStack; use GuzzleHttp\Middleware; @@ -33,8 +34,10 @@ final class Client */ private $handlerStack; - public function __construct(Environment $environment, Keypair $keypair, PublicKey $serverPublicKey = null, string $sessionToken = '', array $proxy = null) + public function __construct(Environment $environment, Keypair $keypair, PublicKey $serverPublicKey = null, string $sessionToken = '', $proxy = null) { + Assertion::true(is_null($proxy) || is_string($proxy) || is_array($proxy), 'In case a proxy parameter is provided, it should be either a string or an array.'); + $this->handlerStack = HandlerStack::create(); $this->addRequestIdMiddleware($sessionToken); From a9e977f4fb71a418ebff792fe5e3be67608317d3 Mon Sep 17 00:00:00 2001 From: Menno Holtkamp Date: Mon, 26 Jun 2017 23:19:50 +0200 Subject: [PATCH 08/12] Allow rejected promises --- src/Middleware/DebugMiddleware.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Middleware/DebugMiddleware.php b/src/Middleware/DebugMiddleware.php index bde545d..afc7c39 100644 --- a/src/Middleware/DebugMiddleware.php +++ b/src/Middleware/DebugMiddleware.php @@ -4,6 +4,7 @@ use GuzzleHttp\Middleware; use GuzzleHttp\Promise\FulfilledPromise; +use GuzzleHttp\Promise\RejectedPromise; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; @@ -47,7 +48,8 @@ public static function request() */ public static function response() { - return function (RequestInterface $request, $options, FulfilledPromise $responsePromise) { + return function (RequestInterface $request, $options, $responsePromise) { + /* @var FulfilledPromise | RejectedPromise $responsePromise */ $responsePromise->then(function (ResponseInterface $response) { echo chr(27) . '[33m' . "RESPONSE: HTTP/" . $response->getProtocolVersion() . ' ' . $response->getStatusCode() . ' ' . $response->getReasonPhrase() . chr(27) . "[0m\n"; From 1eb8193a56c2c3b6d802278411ef0897e66f7c26 Mon Sep 17 00:00:00 2001 From: Menno Holtkamp Date: Mon, 26 Jun 2017 23:20:09 +0200 Subject: [PATCH 09/12] Also respect proxies provided as string --- src/Client.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Client.php b/src/Client.php index d1255b4..35e212f 100644 --- a/src/Client.php +++ b/src/Client.php @@ -53,7 +53,7 @@ public function __construct(Environment $environment, Keypair $keypair, PublicKe ] ]; - if(is_array($proxy)){ + if(is_string($proxy) || is_array($proxy)){ $configuration['proxy'] = $proxy; } From 5aeae37494cd5c55acfcc86485705ff5ff185293 Mon Sep 17 00:00:00 2001 From: Menno Holtkamp Date: Tue, 27 Jun 2017 11:29:00 +0200 Subject: [PATCH 10/12] Use PromiseInterface --- src/Middleware/DebugMiddleware.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/Middleware/DebugMiddleware.php b/src/Middleware/DebugMiddleware.php index afc7c39..31b7416 100644 --- a/src/Middleware/DebugMiddleware.php +++ b/src/Middleware/DebugMiddleware.php @@ -3,8 +3,7 @@ namespace Link0\Bunq\Middleware; use GuzzleHttp\Middleware; -use GuzzleHttp\Promise\FulfilledPromise; -use GuzzleHttp\Promise\RejectedPromise; +use GuzzleHttp\Promise\PromiseInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; @@ -48,10 +47,9 @@ public static function request() */ public static function response() { - return function (RequestInterface $request, $options, $responsePromise) { - /* @var FulfilledPromise | RejectedPromise $responsePromise */ + return function (RequestInterface $request, $options, PromiseInterface $responsePromise) { $responsePromise->then(function (ResponseInterface $response) { - echo chr(27) . '[33m' . "RESPONSE: HTTP/" . $response->getProtocolVersion() . ' ' . $response->getStatusCode() . ' ' . $response->getReasonPhrase() . chr(27) . "[0m\n"; + echo chr(27) . '[33m' . 'RESPONSE: HTTP/' . $response->getProtocolVersion() . ' ' . $response->getStatusCode() . ' ' . $response->getReasonPhrase() . chr(27) . "[0m\n"; foreach ($response->getHeaders() as $key => $headers) { foreach ($headers as $header) { From 9eb1f4c031f4c56bb07395b6a1f426aa93b765ad Mon Sep 17 00:00:00 2001 From: Menno Holtkamp Date: Tue, 27 Jun 2017 11:31:08 +0200 Subject: [PATCH 11/12] Use Closure as return type and reduce double quotes --- src/Middleware/DebugMiddleware.php | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/Middleware/DebugMiddleware.php b/src/Middleware/DebugMiddleware.php index 31b7416..b62febb 100644 --- a/src/Middleware/DebugMiddleware.php +++ b/src/Middleware/DebugMiddleware.php @@ -2,6 +2,7 @@ namespace Link0\Bunq\Middleware; +use Closure; use GuzzleHttp\Middleware; use GuzzleHttp\Promise\PromiseInterface; use Psr\Http\Message\RequestInterface; @@ -18,13 +19,10 @@ */ final class DebugMiddleware { - /** - * @return \Closure - */ - public static function request() + public static function request(): Closure { return function (RequestInterface $request) { - echo chr(27) . '[33m' . "REQUEST: " . $request->getMethod() . ' ' . $request->getRequestTarget() . chr(27) . "[0m\n"; + echo chr(27) . '[33m' . 'REQUEST: ' . $request->getMethod() . ' ' . $request->getRequestTarget() . chr(27) . "[0m\n"; foreach ($request->getHeaders() as $key => $headers) { foreach ($headers as $header) { @@ -42,10 +40,7 @@ public static function request() }; } - /** - * @return \Closure - */ - public static function response() + public static function response(): Closure { return function (RequestInterface $request, $options, PromiseInterface $responsePromise) { $responsePromise->then(function (ResponseInterface $response) { @@ -67,9 +62,6 @@ public static function response() }; } - /** - * @return callable - */ public static function tap(): callable { return Middleware::tap( From a0efadce634923b337dd606ffc50bc7ab837fb15 Mon Sep 17 00:00:00 2001 From: Menno Holtkamp Date: Tue, 27 Jun 2017 16:22:55 +0200 Subject: [PATCH 12/12] Run PHP-CS-Fix --- src/Client.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Client.php b/src/Client.php index 35e212f..92eafb2 100644 --- a/src/Client.php +++ b/src/Client.php @@ -53,7 +53,7 @@ public function __construct(Environment $environment, Keypair $keypair, PublicKe ] ]; - if(is_string($proxy) || is_array($proxy)){ + if (is_string($proxy) || is_array($proxy)) { $configuration['proxy'] = $proxy; }