From 6e60040b7808129445a097cea3282ee118d89d0d Mon Sep 17 00:00:00 2001 From: Marco Stuurman Date: Tue, 28 Aug 2018 18:28:57 +0200 Subject: [PATCH 1/3] Added confirmation code to login credentials overview (bunq/tinker_php#25) --- src/SharedLib.php | 125 +++++++++++++++++++++++++--------------------- 1 file changed, 68 insertions(+), 57 deletions(-) diff --git a/src/SharedLib.php b/src/SharedLib.php index 3dccf3d..e29e685 100644 --- a/src/SharedLib.php +++ b/src/SharedLib.php @@ -80,6 +80,7 @@ class SharedLib */ const POINTER_TYPE_IBAN = 'IBAN'; const POINTER_TYPE_EMAIL = 'EMAIL'; + const POINTER_TYPE_PHONE = 'PHONE_NUMBER'; /** * Echo constants. @@ -166,11 +167,11 @@ public static function printUser($user) echo vsprintf(self::ECHO_USER, [self::INDENTATION_NORMAL]); echo <<getId()} - ├────────────────┼─────────────────────────────────────────────────────── - │ Username │ {$user->getDisplayName()} - └────────────────┴─────────────────────────────────────────────────────── + ┌───────────────────┬──────────────────────────────────────────────────── + │ ID │ {$user->getId()} + ├───────────────────┼──────────────────────────────────────────────────── + │ Username │ {$user->getDisplayName()} + └───────────────────┴──────────────────────────────────────────────────── EOL; } @@ -208,18 +209,18 @@ public static function printBankAccount(MonetaryAccountBank $monetaryAccount) BunqLib::getIbanAliasForBankAccount($monetaryAccount); echo <<getId()} - ├────────────────┼─────────────────────────────────────────────────────── - │ Description │ {$monetaryAccount->getDescription()} - ├────────────────┼─────────────────────────────────────────────────────── - │ IBAN │ {$firstAliasOfTypeForMonetaryAccount->getValue()} + ┌───────────────────┬──────────────────────────────────────────────────── + │ ID │ {$monetaryAccount->getId()} + ├───────────────────┼──────────────────────────────────────────────────── + │ Description │ {$monetaryAccount->getDescription()} + ├───────────────────┼──────────────────────────────────────────────────── + │ IBAN │ {$firstAliasOfTypeForMonetaryAccount->getValue()} EOL; if (!is_null($monetaryAccount->getBalance())) { echo <<getBalance()->getCurrency()} {$monetaryAccount->getBalance()->getValue()} + ├───────────────────┼──────────────────────────────────────────────────── + │ Balance │ {$monetaryAccount->getBalance()->getCurrency()} {$monetaryAccount->getBalance()->getValue()} EOL; } else { // Cannot show balance, as we dont have permission to view it. @@ -227,7 +228,7 @@ public static function printBankAccount(MonetaryAccountBank $monetaryAccount) echo <<getId()} - ├────────────────┼─────────────────────────────────────────────────────── - │ Date │ {$payment->getCreated()} - ├────────────────┼─────────────────────────────────────────────────────── - │ Description │ {$payment->getDescription()} - ├────────────────┼─────────────────────────────────────────────────────── - │ Amount │ {$payment->getAmount()->getCurrency()} {$payment->getAmount()->getValue()} - ├────────────────┼─────────────────────────────────────────────────────── - │ Recipient │ {$payment->getCounterpartyAlias()->getDisplayName()} - └────────────────┴─────────────────────────────────────────────────────── + ┌───────────────────┬──────────────────────────────────────────────────── + │ ID │ {$payment->getId()} + ├───────────────────┼──────────────────────────────────────────────────── + │ Date │ {$payment->getCreated()} + ├───────────────────┼──────────────────────────────────────────────────── + │ Description │ {$payment->getDescription()} + ├───────────────────┼──────────────────────────────────────────────────── + │ Amount │ {$payment->getAmount()->getCurrency()} {$payment->getAmount()->getValue()} + ├───────────────────┼──────────────────────────────────────────────────── + │ Recipient │ {$payment->getCounterpartyAlias()->getDisplayName()} + └───────────────────┴──────────────────────────────────────────────────── EOL; } @@ -293,19 +294,19 @@ public static function printRequest(RequestInquiry $request) { echo <<getId()} - ├────────────────┼─────────────────────────────────────────────────────── - │ Date │ {$request->getCreated()} - ├────────────────┼─────────────────────────────────────────────────────── - │ Description │ {$request->getDescription()} - ├────────────────┼─────────────────────────────────────────────────────── - │ Status │ {$request->getStatus()} - ├────────────────┼─────────────────────────────────────────────────────── - │ Amount │ {$request->getAmountInquired()->getCurrency()} {$request->getAmountInquired()->getValue()} - ├────────────────┼─────────────────────────────────────────────────────── - │ Recipient │ {$request->getCounterpartyAlias()->getDisplayName()} - └────────────────┴─────────────────────────────────────────────────────── + ┌───────────────────┬──────────────────────────────────────────────────── + │ ID │ {$request->getId()} + ├───────────────────┼──────────────────────────────────────────────────── + │ Date │ {$request->getCreated()} + ├───────────────────┼──────────────────────────────────────────────────── + │ Description │ {$request->getDescription()} + ├───────────────────┼──────────────────────────────────────────────────── + │ Status │ {$request->getStatus()} + ├───────────────────┼──────────────────────────────────────────────────── + │ Amount │ {$request->getAmountInquired()->getCurrency()} {$request->getAmountInquired()->getValue()} + ├───────────────────┼──────────────────────────────────────────────────── + │ Recipient │ {$request->getCounterpartyAlias()->getDisplayName()} + └───────────────────┴──────────────────────────────────────────────────── EOL; } @@ -358,17 +359,17 @@ public static function printCard(Card $card, $allMonetaryAccount) $cardDescription = ($card->getSecondLine() ? $card->getSecondLine() : self::DEFAULT_CARD_DESCRIPTION); echo <<getId()} - ├────────────────┼─────────────────────────────────────────────────────── - │ Type │ {$card->getType()} - ├────────────────┼─────────────────────────────────────────────────────── - │ Name on Card │ {$card->getNameOnCard()} - ├────────────────┼─────────────────────────────────────────────────────── - │ Description │ {$cardDescription} - ├────────────────┼─────────────────────────────────────────────────────── - │ Linked Account │ {$accountLinked} - └────────────────┴─────────────────────────────────────────────────────── + ┌───────────────────┬──────────────────────────────────────────────────── + │ ID │ {$card->getId()} + ├───────────────────┼──────────────────────────────────────────────────── + │ Type │ {$card->getType()} + ├───────────────────┼──────────────────────────────────────────────────── + │ Name on Card │ {$card->getNameOnCard()} + ├───────────────────┼──────────────────────────────────────────────────── + │ Description │ {$cardDescription} + ├───────────────────┼──────────────────────────────────────────────────── + │ Linked Account │ {$accountLinked} + └───────────────────┴──────────────────────────────────────────────────── EOL; } @@ -592,14 +593,24 @@ public static function printAllUserAlias(array $allUserAlias) foreach ($allUserAlias as $alias) { echo <<getValue()} - ├────────────────┼─────────────────────────────────────────────────────── - │ Type │ {$alias->getType()} - ├────────────────┼─────────────────────────────────────────────────────── - │ Login Code │ 000000 - └────────────────┴─────────────────────────────────────────────────────── - + ┌───────────────────┬──────────────────────────────────────────────────── + │ Value │ {$alias->getValue()} + ├───────────────────┼──────────────────────────────────────────────────── + │ Type │ {$alias->getType()} +EOL; + if ($alias->getType() == self::POINTER_TYPE_PHONE) { + echo << Date: Fri, 13 Sep 2019 17:43:28 +0200 Subject: [PATCH 2/3] Added PSD2 examples to Tinker --- composer.json | 2 +- composer.lock | 76 ++++++++++++++++---- go-pro | 20 ++++++ go-tinker | 20 ++++++ tinker/create-oauth-client.php | 91 ++++++++++++++++++++++++ tinker/create-psd2-configuration.php | 66 +++++++++++++++++ tinker/test-oauth.php | 102 +++++++++++++++++++++++++++ 7 files changed, 361 insertions(+), 16 deletions(-) create mode 100644 tinker/create-oauth-client.php create mode 100644 tinker/create-psd2-configuration.php create mode 100644 tinker/test-oauth.php diff --git a/composer.json b/composer.json index d998152..0bf7205 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ ], "require": { "php": "^7.0.13", - "bunq/sdk_php": "^1.0.0" + "bunq/sdk_php": "^1.12.0" }, "autoload": { "psr-4": { diff --git a/composer.lock b/composer.lock index 3292971..92d25c6 100644 --- a/composer.lock +++ b/composer.lock @@ -4,20 +4,20 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "37c15b9b5eac7bcfced85d4917272f0c", + "content-hash": "00a927df97967dd6d9d4bc9959558258", "packages": [ { "name": "bunq/sdk_php", - "version": "1.0.0", + "version": "1.12.0", "source": { "type": "git", "url": "https://github.com/bunq/sdk_php.git", - "reference": "e8024cf633593dbec11d67fa806456111d2a80fb" + "reference": "cfde75f644e5105a8634b0cd9a891c49c50b0e28" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/bunq/sdk_php/zipball/e8024cf633593dbec11d67fa806456111d2a80fb", - "reference": "e8024cf633593dbec11d67fa806456111d2a80fb", + "url": "https://api.github.com/repos/bunq/sdk_php/zipball/cfde75f644e5105a8634b0cd9a891c49c50b0e28", + "reference": "cfde75f644e5105a8634b0cd9a891c49c50b0e28", "shasum": "" }, "require": { @@ -35,7 +35,7 @@ "phpstan/phpstan": "^0.8", "phpunit/phpunit": "^6.0.13", "sebastian/phpcpd": "^3.0", - "sensiolabs/security-checker": "^4.1" + "sensiolabs/security-checker": "^5.0" }, "bin": [ "bin/bunq-install" @@ -68,7 +68,7 @@ "payment", "sepa" ], - "time": "2018-07-24T18:37:12+00:00" + "time": "2019-09-10T15:00:27+00:00" }, { "name": "guzzlehttp/guzzle", @@ -188,32 +188,37 @@ }, { "name": "guzzlehttp/psr7", - "version": "1.4.2", + "version": "1.6.1", "source": { "type": "git", "url": "https://github.com/guzzle/psr7.git", - "reference": "f5b8a8512e2b58b0071a7280e39f14f72e05d87c" + "reference": "239400de7a173fe9901b9ac7c06497751f00727a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/psr7/zipball/f5b8a8512e2b58b0071a7280e39f14f72e05d87c", - "reference": "f5b8a8512e2b58b0071a7280e39f14f72e05d87c", + "url": "https://api.github.com/repos/guzzle/psr7/zipball/239400de7a173fe9901b9ac7c06497751f00727a", + "reference": "239400de7a173fe9901b9ac7c06497751f00727a", "shasum": "" }, "require": { "php": ">=5.4.0", - "psr/http-message": "~1.0" + "psr/http-message": "~1.0", + "ralouphie/getallheaders": "^2.0.5 || ^3.0.0" }, "provide": { "psr/http-message-implementation": "1.0" }, "require-dev": { - "phpunit/phpunit": "~4.0" + "ext-zlib": "*", + "phpunit/phpunit": "~4.8.36 || ^5.7.27 || ^6.5.8" + }, + "suggest": { + "zendframework/zend-httphandlerrunner": "Emit PSR-7 responses" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.4-dev" + "dev-master": "1.6-dev" } }, "autoload": { @@ -243,13 +248,14 @@ "keywords": [ "http", "message", + "psr-7", "request", "response", "stream", "uri", "url" ], - "time": "2017-03-20T17:10:46+00:00" + "time": "2019-07-01T23:21:34+00:00" }, { "name": "psr/http-message", @@ -300,6 +306,46 @@ "response" ], "time": "2016-08-06T14:39:51+00:00" + }, + { + "name": "ralouphie/getallheaders", + "version": "3.0.3", + "source": { + "type": "git", + "url": "https://github.com/ralouphie/getallheaders.git", + "reference": "120b605dfeb996808c31b6477290a714d356e822" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/ralouphie/getallheaders/zipball/120b605dfeb996808c31b6477290a714d356e822", + "reference": "120b605dfeb996808c31b6477290a714d356e822", + "shasum": "" + }, + "require": { + "php": ">=5.6" + }, + "require-dev": { + "php-coveralls/php-coveralls": "^2.1", + "phpunit/phpunit": "^5 || ^6.5" + }, + "type": "library", + "autoload": { + "files": [ + "src/getallheaders.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ralph Khattar", + "email": "ralph.khattar@gmail.com" + } + ], + "description": "A polyfill for getallheaders.", + "time": "2019-03-08T08:55:37+00:00" } ], "packages-dev": [], diff --git a/go-pro b/go-pro index 0346cc8..a912677 100755 --- a/go-pro +++ b/go-pro @@ -22,6 +22,26 @@ USAGE="\ ┌───────────────────────┬──────────────────────────────────────────────┐ │ │ Run │ ├───────────────────────┼──────────────────────────────────────────────┤ + │ 🔐 Create PSD2 Provider! │ ${ANSI_FORMAT_VERBOSE}tinker/create-psd2-configuration.php --production${ANSI_FORMAT_CLEAR} │ + │ │ │ + │ │ ${ANSI_FORMAT_DIM}Required parameters:${ANSI_FORMAT_CLEAR} │ + │ │ ${ANSI_FORMAT_DIM}--certificate [path]${ANSI_FORMAT_CLEAR} │ + │ │ ${ANSI_FORMAT_DIM}--chain [path]${ANSI_FORMAT_CLEAR} │ + │ │ ${ANSI_FORMAT_DIM}--key [path]${ANSI_FORMAT_CLEAR} │ + ├───────────────────────┼──────────────────────────────────────────────┤ + │ 🔒 Create PSD2 OAuth Client │ ${ANSI_FORMAT_VERBOSE}tinker/create-oauth-client.php --production${ANSI_FORMAT_CLEAR} │ + │ │ │ + │ │ ${ANSI_FORMAT_DIM}Required parameters:${ANSI_FORMAT_CLEAR} │ + │ │ ${ANSI_FORMAT_DIM}--context [path]${ANSI_FORMAT_CLEAR} │ + │ │ ${ANSI_FORMAT_DIM}--redirect [uri]${ANSI_FORMAT_CLEAR} │ + ├───────────────────────┼──────────────────────────────────────────────┤ + │ 🔓 Test PSD2 OAuth │ ${ANSI_FORMAT_VERBOSE}tinker/test-oauth.php --production${ANSI_FORMAT_CLEAR} │ + │ │ │ + │ │ ${ANSI_FORMAT_DIM}Required parameters:${ANSI_FORMAT_CLEAR} │ + │ │ ${ANSI_FORMAT_DIM}--code [authcode]${ANSI_FORMAT_CLEAR} │ + │ │ ${ANSI_FORMAT_DIM}--configuration [path]${ANSI_FORMAT_CLEAR} │ + │ │ ${ANSI_FORMAT_DIM}--redirect [uri]${ANSI_FORMAT_CLEAR} │ + ├───────────────────────┼──────────────────────────────────────────────┤ │ ✅ Show Overview │ ${ANSI_FORMAT_VERBOSE}tinker/user-overview.php --production${ANSI_FORMAT_CLEAR} │ ├───────────────────────┼──────────────────────────────────────────────┤ │ 🔼 Make a payment │ ${ANSI_FORMAT_VERBOSE}tinker/make-payment.php --production${ANSI_FORMAT_CLEAR} │ diff --git a/go-tinker b/go-tinker index 1bcdfdc..64d1312 100755 --- a/go-tinker +++ b/go-tinker @@ -19,6 +19,26 @@ USAGE="\ ┌───────────────────────┬─────────────────────────────────┐ │ │ Run │ ├───────────────────────┼─────────────────────────────────┤ + │ 🔐 Create PSD2 Provider! │ ${ANSI_FORMAT_VERBOSE}tinker/create-psd2-configuration.php${ANSI_FORMAT_CLEAR} │ + │ │ │ + │ │ ${ANSI_FORMAT_DIM}Required parameters:${ANSI_FORMAT_CLEAR} │ + │ │ ${ANSI_FORMAT_DIM}--certificate [path]${ANSI_FORMAT_CLEAR} │ + │ │ ${ANSI_FORMAT_DIM}--chain [path]${ANSI_FORMAT_CLEAR} │ + │ │ ${ANSI_FORMAT_DIM}--key [path]${ANSI_FORMAT_CLEAR} │ + ├───────────────────────┼─────────────────────────────────┤ + │ 🔒 Create PSD2 OAuth Client │ ${ANSI_FORMAT_VERBOSE}tinker/create-oauth-client.php${ANSI_FORMAT_CLEAR} │ + │ │ │ + │ │ ${ANSI_FORMAT_DIM}Required parameters:${ANSI_FORMAT_CLEAR} │ + │ │ ${ANSI_FORMAT_DIM}--context [path]${ANSI_FORMAT_CLEAR} │ + │ │ ${ANSI_FORMAT_DIM}--redirect [uri]${ANSI_FORMAT_CLEAR} │ + ├───────────────────────┼─────────────────────────────────┤ + │ 🔓 Test PSD2 OAuth │ ${ANSI_FORMAT_VERBOSE}tinker/test-oauth.php${ANSI_FORMAT_CLEAR} │ + │ │ │ + │ │ ${ANSI_FORMAT_DIM}Required parameters:${ANSI_FORMAT_CLEAR} │ + │ │ ${ANSI_FORMAT_DIM}--code [authcode]${ANSI_FORMAT_CLEAR} │ + │ │ ${ANSI_FORMAT_DIM}--configuration [path]${ANSI_FORMAT_CLEAR} │ + │ │ ${ANSI_FORMAT_DIM}--redirect [uri]${ANSI_FORMAT_CLEAR} │ + ├───────────────────────┼─────────────────────────────────┤ │ ✅ Show Overview │ ${ANSI_FORMAT_VERBOSE}tinker/user-overview.php${ANSI_FORMAT_CLEAR} │ ├───────────────────────┼─────────────────────────────────┤ │ 🔼 Make a payment │ ${ANSI_FORMAT_VERBOSE}tinker/make-payment.php${ANSI_FORMAT_CLEAR} │ diff --git a/tinker/create-oauth-client.php b/tinker/create-oauth-client.php new file mode 100644 index 0000000..4eadb8f --- /dev/null +++ b/tinker/create-oauth-client.php @@ -0,0 +1,91 @@ +#!/usr/bin/env php +getValue())->getValue(); + + // Store the oauth details + try { + FileUtil::saveObjectAsJson(FILE_OAUTH_CONFIGURATION, $oauthClient); + } catch (\bunq\Exception\BunqException $e) { + error_log($e->getTraceAsString()); + } + + // Create the callback + OauthCallbackUrl::create( + $oauthClient->getId(), + $allOption[OPTION_REDIRECT_URI] + ); +} + +// We're set up correctly now. Continue by authorizing the user. +$oauthAuthorizationUri = OauthAuthorizationUri::create( + BunqEnumOauthResponseType::CODE(), + $allOption[OPTION_REDIRECT_URI], + $oauthClient +); + +echo <<getAuthorizationUriString()}. + + | ✅ Obtain the code from the redirect URL. + + | ▶️ Continue with test-oauth.php + + +EOL; diff --git a/tinker/create-psd2-configuration.php b/tinker/create-psd2-configuration.php new file mode 100644 index 0000000..82b3df7 --- /dev/null +++ b/tinker/create-psd2-configuration.php @@ -0,0 +1,66 @@ +#!/usr/bin/env php +save(FILE_PSD2_CONFIGURATION); + +echo <<getAccessTokenString(); + +// Create context using token. +$apiContext = ApiContext::create( + BunqEnumApiEnvironmentType::SANDBOX(), + $apiToken, + API_DEVICE_DESCRIPTION +); +BunqContext::loadApiContext($apiContext); + +echo <<getValue() as $monetaryAccount) { + if (!is_null($monetaryAccount->getMonetaryAccountBank())) { + echo vsprintf( + ' | MonetaryAccountBank found with balance of: %s %s%s', + [ + $monetaryAccount->getMonetaryAccountBank()->getBalance()->getValue(), + $monetaryAccount->getMonetaryAccountBank()->getBalance()->getCurrency(), + PHP_EOL, + ] + ); + } +} From 4826bbf16a48dee97daaae38fb35bb5068de3772 Mon Sep 17 00:00:00 2001 From: Nick van de Groes Date: Tue, 17 Sep 2019 09:22:40 +0200 Subject: [PATCH 3/3] Updated SDK version --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 0bf7205..ba1039a 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ ], "require": { "php": "^7.0.13", - "bunq/sdk_php": "^1.12.0" + "bunq/sdk_php": "^1.12.1" }, "autoload": { "psr-4": {