2017 © Pedro Pelรกez
 

library sdk_php

bunq PHP SDK

image

bunq/sdk_php

bunq PHP SDK

  • Tuesday, July 24, 2018
  • by bunq
  • Repository
  • 8 Watchers
  • 44 Stars
  • 5,893 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 22 Forks
  • 5 Open issues
  • 33 Versions
  • 77 % Grown

The README.md

bunq PHP SDK

Introduction

Hi developers!, (*1)

Welcome to the bunq PHP SDK! ๐Ÿ‘จโ€๐Ÿ’ป, (*2)

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! ๐ŸŒˆ, (*3)

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 ๐ŸŽค, (*4)

Give us your feedback, create pull requests, build your very own bunq apps and most importantly: have fun! ๐Ÿ’ช, (*5)

This SDK is in beta. We cannot guarantee constant availability or stability. Thanks to your feedback we will make improvements on it., (*6)

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., (*7)

src/Util/InstallationUtil.php, (*8)

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:, (*9)

$ vendor/bin/bunq-install

And then follow the steps the script offers., (*10)

Creating an API context programmatically

The context can be created by executing the following code snippet:, (*11)

<?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:, (*12)

$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., (*13)

After saving the context, you can restore it at any time:, (*14)

$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., (*15)

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., (*16)

Make sure you have your unique eIDAS certificate number and certificates ready when you want to perform these tasks on our production environment., (*17)

Creating a PSD2 context is very easy:, (*18)

$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., (*19)

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., (*20)

$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., (*21)

If you rather save the context in a database, you can use the fromJson() and toJson() methods., (*22)

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., (*23)

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., (*24)

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., (*25)

Take a look at doc.bunq.com for the full documentation., (*26)

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, (*27)

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., (*28)

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., (*29)

This type of calls always returns a model., (*30)

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, (*31)

Updating objects

BunqContext::loadApiContext($apiContext); // if it has not been loaded yet. 

MonetaryAccountBank::update(
    $monetaryAccount->getId(),
    $description
);
Example

See tinker/updateBankAccountDescription, (*32)

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, (*33)

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., (*34)

Running Tests

Information regarding the test cases can be found in the README.md located in test., (*35)

Exceptions

The SDK can throw multiple exceptions. For an overview of these exceptions please take a look at EXCEPTIONS.md, (*36)

The Versions

24/07 2018
24/07 2018

dev-oauth-bunq/sdk_php#156

dev-oauth-bunq/sdk_php#156 https://bunq.com/

bunq PHP SDK

  Sources   Download

MIT

The Requires

 

The Development Requires

api payment sepa finance bunq open-banking

13/06 2018
30/05 2018
29/05 2018

dev-move-to-new-sandbox-bunq/sdk_php#149

dev-move-to-new-sandbox-bunq/sdk_php#149 https://bunq.com/

bunq PHP SDK

  Sources   Download

MIT

The Requires

 

The Development Requires

api payment sepa finance bunq open-banking

29/05 2018

dev-proper-check-for-curl-error-zero-bunq/sdk_php#7

dev-proper-check-for-curl-error-zero-bunq/sdk_php#7 https://bunq.com/

bunq PHP SDK

  Sources   Download

MIT

The Requires

 

The Development Requires

api payment sepa finance bunq open-banking

29/04 2018

dev-fix_joint_co_owner_error_bunq/sdk_php#76

dev-fix_joint_co_owner_error_bunq/sdk_php#76 https://bunq.com/

bunq PHP SDK

  Sources   Download

MIT

The Requires

 

The Development Requires

api payment sepa finance bunq open-banking

21/03 2018
20/03 2018
01/03 2018

dev-regenerate_code_for_release

dev-regenerate_code_for_release https://bunq.com/

bunq PHP SDK

  Sources   Download

MIT

The Requires

 

The Development Requires

api payment sepa finance bunq open-banking

01/02 2018

dev-bunq/sdk_php#80_remove_unneeded_doc_blcok

dev-bunq/sdk_php#80_remove_unneeded_doc_blcok https://bunq.com/

bunq PHP SDK

  Sources   Download

MIT

The Requires

 

The Development Requires

api payment sepa finance bunq open-banking

18/01 2018

dev-bunq/sdk_php#102-throw-exception-when-keygeneration-fails

dev-bunq/sdk_php#102-throw-exception-when-keygeneration-fails https://bunq.com/

bunq PHP SDK

  Sources   Download

MIT

The Requires

 

The Development Requires

api payment sepa finance bunq open-banking

03/01 2018

dev-feature/notification-filter-examples

dev-feature/notification-filter-examples https://bunq.com/

bunq PHP SDK

  Sources   Download

MIT

The Requires

 

The Development Requires

api payment sepa finance bunq open-banking

27/12 2017

dev-feature/bunq/sdk_php#89-imporve-issue-and-pr-tempplate

dev-feature/bunq/sdk_php#89-imporve-issue-and-pr-tempplate https://bunq.com/

bunq PHP SDK

  Sources   Download

MIT

The Requires

 

The Development Requires

api payment sepa finance bunq open-banking

27/12 2017

dev-feature/bunq/sdk_php#88-add_response_id_to_request_error

dev-feature/bunq/sdk_php#88-add_response_id_to_request_error https://bunq.com/

bunq PHP SDK

  Sources   Download

MIT

The Requires

 

The Development Requires

api payment sepa finance bunq open-banking

21/12 2017
15/11 2017
15/11 2017

dev-release/0.12.3

dev-release/0.12.3 https://bunq.com/

bunq PHP SDK

  Sources   Download

MIT

The Requires

 

The Development Requires

api payment sepa finance bunq open-banking

08/11 2017
08/11 2017

dev-release/0.12.2

dev-release/0.12.2 https://bunq.com/

bunq PHP SDK

  Sources   Download

MIT

The Requires

 

The Development Requires

api payment sepa finance bunq open-banking

11/10 2017
11/10 2017
26/09 2017

dev-52-strict-response

dev-52-strict-response https://bunq.com/

bunq PHP SDK

  Sources   Download

MIT

The Requires

 

The Development Requires

api payment sepa finance bunq open-banking

25/09 2017

dev-feature/exception-factory

dev-feature/exception-factory https://bunq.com/

bunq PHP SDK

  Sources   Download

MIT

The Requires

 

The Development Requires

api payment sepa finance bunq open-banking

06/09 2017

0.11.0

0.11.0.0 https://bunq.com/

bunq PHP SDK

  Sources   Download

MIT

The Requires

 

The Development Requires

api payment sepa finance bunq open-banking

06/09 2017

dev-release-0.11.0

dev-release-0.11.0 https://bunq.com/

bunq PHP SDK

  Sources   Download

MIT

The Requires

 

The Development Requires

api payment sepa finance bunq open-banking

22/08 2017

0.10.0

0.10.0.0 https://bunq.com/

bunq PHP SDK

  Sources   Download

MIT

The Requires

 

The Development Requires

api payment sepa finance bunq open-banking

22/08 2017

dev-release-0.10.0

dev-release-0.10.0 https://bunq.com/

bunq PHP SDK

  Sources   Download

MIT

The Requires

 

The Development Requires

api payment sepa finance bunq open-banking

07/08 2017

0.9.1

0.9.1.0 https://bunq.com/

bunq PHP SDK

  Sources   Download

MIT

The Requires

 

The Development Requires

api payment sepa finance bunq open-banking

07/08 2017

dev-release-0.9.1

dev-release-0.9.1 https://bunq.com/

bunq PHP SDK

  Sources   Download

MIT

The Requires

 

The Development Requires

api payment sepa finance bunq open-banking