bunq / sdk_php
bunq PHP SDK
Installs: 164 623
Dependents: 2
Suggesters: 0
Security: 0
Stars: 85
Watchers: 14
Forks: 55
Open Issues: 28
Requires
- php: ^7.3 || ^8.0
- composer-plugin-api: ~1.0 || ~2.0
- ext-curl: *
- ext-json: *
- ext-mbstring: *
- guzzlehttp/guzzle: ~7
Requires (Dev)
- composer/composer: ^1.10.11 || ^2.0.1
- friendsofphp/php-cs-fixer: ^2.4
- php-parallel-lint/php-parallel-lint: ^1.2
- phpro/grumphp: ^v1.3.0
- phpstan/phpstan: ^0.12
- phpunit/phpunit: ^9.5
- dev-develop
- 1.26.11.47
- 1.26.11.43
- 1.26.11.35
- 1.26.9.65
- 1.26.9.61
- 1.26.9.57
- 1.26.8.42
- 1.26.8.11
- 1.26.5.27
- 1.26.0.32
- 1.25.17.62
- 1.25.17.44
- 1.25.17.21
- 1.25.16.51
- 1.25.15.29
- 1.25.15.12
- 1.25.15.9
- 1.25.14.39
- 1.25.13.16
- 1.25.11.26
- 1.25.10.6
- 1.25.8.44
- 1.25.6.9
- 1.25.5.44
- 1.25.5.42
- 1.25.4.28
- 1.25.0.1
- 1.24.23.4
- 1.24.20.51
- 1.24.20.50
- 1.24.20.30
- 1.24.20.27
- 1.24.20.9
- 1.24.19.14
- 1.24.18.41
- 1.24.16.36
- 1.24.15.19
- 1.24.15.18
- 1.24.11.29
- 1.24.10.22
- 1.24.9.34
- 1.24.9.22
- 1.24.8.23
- 1.24.4.64
- 1.24.4.38
- 1.24.4.28
- 1.24.3.65
- 1.24.3.38
- 1.24.3.7
- 1.24.2.35
- 1.24.2.9
- 1.24.2.5
- 1.24.1.6
- 1.24.0.30
- 1.23.21.80
- 1.23.21.64
- 1.23.21.48
- 1.23.20.18
- 1.23.20.5
- 1.23.19.51
- 1.23.18.34
- 1.23.16.31
- 1.23.16.28
- 1.23.13.27
- 1.23.10.58
- 1.23.10.40
- 1.23.8.73
- 1.23.5.40
- 1.23.4.27
- 1.23.3.16
- 1.23.3.10
- 1.23.2.12
- 1.23.2.2
- 1.23.0.51
- 1.23.0.18
- 1.22.17.75
- 1.22.17.54
- 1.22.17.47
- 1.22.17.44
- 1.22.17.37
- 1.22.17.16
- 1.22.17.4
- 1.22.15.21
- 1.22.13.30
- 1.22.10.12
- 1.22.8.18
- 1.22.7.49
- 1.22.7.20
- 1.22.5.46
- 1.22.3.28
- 1.22.2.28
- 1.22.1.81
- 1.21.21.42
- 1.21.21.34
- 1.21.21.31
- 1.21.20.45
- 1.21.19.15
- 1.21.18.21
- 1.21.17.51
- 1.21.16.22
- 1.21.15.56
- 1.21.12.4
- 1.21.11.15
- 1.21.9.39
- 1.21.9.28
- 1.21.7.6
- 1.21.5.66
- 1.21.5.18
- 1.21.4.16
- 1.21.3.24
- 1.21.1.26
- 1.21.0.51
- 1.20.22.71
- 1.20.22.26
- 1.20.21.26
- 1.20.21.7
- 1.20.20.9
- 1.20.13.15
- 1.20.10.33
- 1.20.10.29
- 1.20.10.19
- 1.20.10.15
- 1.20.6.14
- 1.19.11.35
- 1.19.9.6
- 1.19.0.83
- 1.19.0.78
- 1.19.0.11
- 1.19.0.10
- 1.18.19.15
- 1.18.16.27
- 1.18.16.10
- 1.18.15.39
- 1.18.13.62
- 1.18.13.53
- 1.18.11.64
- 1.15.0
- 1.14.18
- 1.14.17
- 1.14.2
- 1.14.1
- 1.14.0
- 1.13.1
- 1.13.0
- 1.12.1
- 1.12.0
- 1.10.16
- 1.10.2
- 1.10.1
- 1.10.0
- 1.2.2
- 1.2.1
- 1.2.0
- 1.1.0
- 1.0.1
- 1.0.0
- 0.13.2
- 0.13.1
- 0.13.0
- 0.12.4
- 0.12.3
- 0.12.2
- 0.12.1
- 0.12.0
- 0.11.0
- 0.10.0
- 0.9.1
- dev-master
- dev-release/1.0.0
- dev-develop-gihub
- dev-release/0.12.4
This package is auto-updated.
Last update: 2024-12-12 07:47:45 UTC
README
Introduction
Hi developers!
Welcome to the bunq PHP SDK! 👨💻
We're very happy to introduce yet another unique product: complete banking SDKs! Now you can build even bigger and better apps and integrate them with your bank of the free! 🌈
Before you dive into this brand new SDK, please consider:
- Learning how bunq works and what objects you will work with by reading the intro to our API 🤓
- Checking out our developer portal 🙌
- Grabbing your Production API key from our developer portal or the bunq app 🗝
- Generating a Sandbox API key using our developer portal or Tinker 🗝
- Visiting our forum where you can share your creations, questions and experience 🎤
Give us your feedback, create pull requests, build your very own bunq apps and most importantly: have fun! 💪
This SDK is in beta. We cannot guarantee constant availability or stability. Thanks to your feedback we will make improvements on it.
Installation
$ composer require bunq/sdk_php
Usage
Creating an API context
In order to start making calls with the bunq API, you must first register your API key and device, and create a session. In the SDKs, we group these actions and call it "creating an API context". There are two ways to do it. One is through our interactive script, and the other is programmatically from your code.
src/Util/InstallationUtil.php
Creating an API context using bunq-install
interactive script
After installing bunq SDK into your project, run the command below from your project root folder:
$ vendor/bin/bunq-install
And then follow the steps the script offers.
Creating an API context programmatically
The context can be created by executing the following code snippet:
<?php use bunq\Context\ApiContext; use bunq\Util\BunqEnumApiEnvironmentType; $environmentType = BunqEnumApiEnvironmentType::SANDBOX(); // Can also be BunqEnumApiEnvironmentType::PRODUCTION(); $apiKey = '### Your API Key ###'; // Replace with your API key $deviceDescription = '### Your device description ###'; // Replace with your device description $permittedIps = ['0.0.0.0']; // List the real expected IPs of this device or leave empty to use the current IP $apiContext = ApiContext::create( $environmentType, $apiKey, $deviceDescription, $permittedIps ); BunqContext::loadApiContext($apiContext);
The API context can then be saved with:
$fileName = '/path/to/save/bunq.conf/file/'; // Replace with your own secure location to store the API context details $apiContext->save($fileName);
Please note: initializing your application is a heavy task and it is recommended to do it only once per device.
After saving the context, you can restore it at any time:
$fileName = '/path/to/bunq.conf/file/'; $apiContext = ApiContext::restore($fileName); BunqContext::loadApiContext($apiContext);
Tip: both saving and restoring the context can be done without any arguments. In this case the context will be saved to/restored from the bunq.conf
file in the same folder with your script.
PSD2
It is possible to create an ApiContext as PSD2 Service Provider. Although this might seem a complex task, we wrote some helper implementations to get you started. You need to create a certificate and private key to get you started. Our sandbox environment currently accepts all certificates, if these criteria are met:
- Up to 64 characters
- PISP and/or AISP used in the end.
Make sure you have your unique eIDAS certificate number and certificates ready when you want to perform these tasks on our production environment.
Creating a PSD2 context is very easy:
$apiContext = ApiContext::createForPsd2( BunqEnumApiEnvironmentType::SANDBOX(), // Could be PRODUCTION as well. SecurityUtil::getCertificateFromFile($pathToCertificate), SecurityUtil::getPrivateKeyFromFile($pathToKey), [ SecurityUtil::getCertificateFromFile($pathToCertificateInChain), // Could be one file containing chain, or multiple certificate files in array. ], $description )
This context can be saved the same way as a normal ApiContext. After creating this context, create an OAuth client to get your users to grant you access. For a more detailed example, check the tinker_php repository.
Proxy
You can use a proxy with the bunq PHP SDK. This option must be a string. This proxy will be used for all requests done with the context for which it was provided. You will be prompted to provide a proxy URL when using the interactive installation script.
$proxyUrl = 'socks5://localhost:1080'; // The proxy for all requests, null to disable $apiContext = ApiContext::create( ... $proxyUrl );
Safety considerations
The file storing the context details (i.e. bunq.conf
) is a key to your account. Anyone having access to it is able to perform any Public API actions with your account. Therefore, we recommend choosing a truly safe place to store it.
If you rather save the context in a database, you can use the fromJson()
and toJson()
methods.
Making API calls
There is a class for each endpoint. Each class has functions for each supported action. These actions can be
create
, get
, update
, delete
and listing
.
Before you can start making calls, you must ensure that you have create an ApiContext and loaded in into BunqContext as shown in the examples above.
The SDK will take care of your user Id, as this id wil never change per ApiContext. The SDK also uses your first active monetary account as primary monetary account. This is almost always the same as your billing account. This means that when you do not explicitly pass a Monetary Account ID, the SDK will use the Monetary Account ID of your billing account.
Take a look at doc.bunq.com for the full documentation.
Creating objects
BunqContext::loadApiContext($apiContext); // if it has not been loaded yet. Payment::create( new Amount($amount, self::CURRENCY_TYPE_EUR), new Pointer(self::POINTER_TYPE_EMAIL, $recipient), $description, $monetaryAccount->getId() );
Example
See tinker/BunqLib
NotificationFilters / Callbacks
Note! Due to an in internal change in the way we handle NotificationFilters
(Callbacks), you should not use the default classes included in this SDK.
Please make sure you make use of the associated Internal
-classes. For example when you need NotificationFilterUrlUser
, make use of NotificationFilterUrlUserInternal
.
You can use every method of these classes, except for the create()
method. Always use createWithListResponse()
instead.
Example
NotificationFilterPushUserInternal::createWithListResponse(...)
NotificationFilterUrlUserInternal::createWithListResponse(...)
NotificationFilterUrlMonetaryAccountInternal::createWithListResponse(...)
Reading objects
To use the read method you must pass the identifier of the object to read (ID or UUID) except for the endpoints User
, UserPerson
, UserCompany
and MonetaryAccount
. The SDK will use the default IDs when none are passed. For all other endpoints you must pass the identifier.
This type of calls always returns a model.
BunqContext::loadApiContext($apiContext); // if it has not been loaded yet. $userCompany = UserCompany::get(); printf($userCompany->getPublicNickName());
Example
You can also retrieve this information from BunqContext
, see tinker/setupCurrentUser
Updating objects
BunqContext::loadApiContext($apiContext); // if it has not been loaded yet. MonetaryAccountBank::update( $monetaryAccount->getId(), $description );
Example
See tinker/updateBankAccountDescription
Deleting objects
BunqContext::loadApiContext($apiContext); // if it has not been loaded yet. CustomerStatementExport::delete($customerStatementExportId);
Listing objects
BunqContext::loadApiContext($apiContext); // if it has not been loaded yet. $monetaryAccountList = MonetaryAccount::listing(); foreach ($monetaryAccountList as $monetaryAccount) { printf($monetaryAccount->getMonetaryAccountBank->getDescription() . PHP_EOL); }
Example
See tinker/getAllActiveBankAccount
Running Examples
If you want to play around with the SDK before you actually start implementing something awesome you can use the tinker project and adjust the code in the scripts as you please.
Running Tests
Information regarding the test cases can be found in the README.md located in test.
Exceptions
The SDK can throw multiple exceptions. For an overview of these exceptions please take a look at EXCEPTIONS.md