diff --git a/src/Client.php b/src/Client.php index 9db12b4..92eafb2 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,11 +34,10 @@ final class Client */ private $handlerStack; - /** - * @param Environment $environment - */ - public function __construct(Environment $environment, Keypair $keypair, PublicKey $serverPublicKey = null, string $sessionToken = '') + 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); @@ -45,19 +45,21 @@ 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_string($proxy) || is_array($proxy)) { + $configuration['proxy'] = $proxy; + } + + $this->guzzle = new GuzzleClient($configuration); } - /** - * @param string $endpoint - * @return array - */ public function get(string $endpoint, array $headers = []): array { return $this->processResponse( @@ -67,12 +69,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 +79,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 +92,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,13 +102,9 @@ public function delete(string $endpoint, array $headers = []) ]); } - /** - * @param ResponseInterface $response - * @return array - */ private function processResponse(ResponseInterface $response): array { - $contents = (string) $response->getBody(); + $contents = (string)$response->getBody(); $json = json_decode($contents, true)['Response']; // Return empty responses @@ -158,12 +145,13 @@ 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); } } /** * @param string $sessionToken + * * @return void */ private function addRequestIdMiddleware(string $sessionToken) @@ -176,6 +164,7 @@ private function addRequestIdMiddleware(string $sessionToken) /** * @param Keypair $keypair + * * @return void */ private function addRequestSignatureMiddleware(Keypair $keypair) @@ -189,6 +178,7 @@ private function addRequestSignatureMiddleware(Keypair $keypair) /** * @param PublicKey|null $serverPublicKey + * * @return void */ private function addServerResponseMiddleware(PublicKey $serverPublicKey = null) @@ -203,6 +193,7 @@ private function addServerResponseMiddleware(PublicKey $serverPublicKey = null) /** * @param Environment $environment + * * @return void */ private function addDebugMiddleware(Environment $environment) diff --git a/src/Domain/NotificationFilter.php b/src/Domain/NotificationFilter.php index bb5b65f..9764dda 100644 --- a/src/Domain/NotificationFilter.php +++ b/src/Domain/NotificationFilter.php @@ -7,6 +7,8 @@ final class NotificationFilter const DELIVERYMETHOD_PUSH = 'PUSH'; 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'; @@ -27,7 +29,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'; diff --git a/src/Middleware/DebugMiddleware.php b/src/Middleware/DebugMiddleware.php index bde545d..b62febb 100644 --- a/src/Middleware/DebugMiddleware.php +++ b/src/Middleware/DebugMiddleware.php @@ -2,8 +2,9 @@ namespace Link0\Bunq\Middleware; +use Closure; use GuzzleHttp\Middleware; -use GuzzleHttp\Promise\FulfilledPromise; +use GuzzleHttp\Promise\PromiseInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; @@ -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,14 +40,11 @@ public static function request() }; } - /** - * @return \Closure - */ - public static function response() + public static function response(): Closure { - return function (RequestInterface $request, $options, FulfilledPromise $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) { @@ -67,9 +62,6 @@ public static function response() }; } - /** - * @return callable - */ public static function tap(): callable { return Middleware::tap(