GithubHelp home page GithubHelp logo

bunq's Introduction

link0/bunq

Latest Stable Version Total Downloads License Scrutinizer Code Quality Code Coverage Build Status

This library implements the bunq API.

Any feedback and testing is very welcome through issues and/or pull requests.

Basic usage

The following code example does a few things to get you started as fast as possible:

  1. Create an InstallationServer
  2. Create an DeviceServer
  3. Retrieve a session from the SessionServer to be able to use the API

Before you copy/paste this code be sure you have an API key to use. When developing and testing the API you probably don't want to use the API key for production. Instead you want to use a developer API key. A developer API key can be obtained by asking the support desk from bunq itself (using the bunq app). Once you've got that API key you can fill it in into the $apiKey variable.

The function registerInstallationAndDeviceServer() is only supposed to be called once. After the first call you can comment this rule out.

<?php

use Link0\Bunq\Client;
use Link0\Bunq\Domain\Keypair;
use Link0\Bunq\Domain\Keypair\PublicKey;
use Link0\Bunq\Environment\Production;
use Link0\Bunq\Environment\Sandbox;
use Link0\Bunq\Service\InstallationService;

require_once('vendor/autoload.php');

/**
 * @param $installationService
 * @param $keypair
 * @param $apiKey
 * @return mixed
 */
function registerInstallationAndDeviceServer(InstallationService $installationService, $keypair, $apiKey)
{
    $installation = $installationService->createInstallation($keypair);

    $installationToken = $installation[1];
    $serverPublicKey = $installation[2];

    // Cache the server public key somewhere
    file_put_contents('server-public-key.txt', $serverPublicKey);

    // Cache the installation token somehere
    file_put_contents('installation-token.txt', $installationToken);

    $installationService->createDeviceServer($installationToken, $apiKey, 'I pasted this from README.md');
}

// openssl genpkey -algorithm RSA -out private.pem -pkeyopt rsa_keygen_bits:2048
// openssl rsa -pubout -in private.pem -out public.pem
$keypair = Keypair::fromStrings(
    file_get_contents('public.pem'),
    file_get_contents('private.pem')
);

// Replace this with what you received from the app
$apiKey = 'your-api-key';

$debugMode = true;

//$environment = new Production($debugMode);
$environment = new Sandbox($debugMode);
$client = new Client($environment, $keypair);

$installationService = new InstallationService($client);

registerInstallationAndDeviceServer($installationService, $keypair, $apiKey);

$installationToken = file_get_contents('installation-token.txt');

$sessionServer = $installationService->createSessionServer($installationToken, $apiKey);

$sessionServerId = $sessionServer[0];
$sessionToken = $sessionServer[1];
$user = $sessionServer[2];

file_put_contents('session-token.txt', $sessionToken);

// After this, you can use the client with all other services as followed
$client = new Client(
    $environment,
    $keypair,
    new PublicKey(file_get_contents('server-public-key.txt')),
    file_get_contents('session-token.txt')
);

bunq's People

Contributors

dennisdegreef avatar holtkamp avatar jargij avatar koter84 avatar patrickkivits avatar wslaghekke avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

bunq's Issues

Unexpected response field from Bunq API: "id" => "Id"

It seems Bunq has updated its API.

The documentation at https://doc.bunq.com/api/1/call/session-server/method/post

Suggests to return:

{

    "Response": [
        {
            "Id": {
                "id": 49
            }
        }
    ]
}

But it seems to return (note the casing of "id" => "Id":

{

    "Response": [
        {
            "Id": {
                "Id": 49
            }
        }
    ]
}

Since fetching the value is hard-coded to "id", this results in an error like:

Uncaught TypeError: Argument 1 passed to Link0\Bunq\Domain\Id::fromInteger() must be of the type integer, null given, called in /app/vendor/link0/bunq/src/Client.php on line 141 and defined in /app/vendor/link0/bunq/src/Domain/Id.php:27
Stack trace:
#0 /app/vendor/link0/bunq/src/Client.php(141): Link0\Bunq\Domain\Id::fromInteger(NULL)
#1 /app/vendor/link0/bunq/src/Client.php(120): Link0\Bunq\Client->mapResponse('Id', Array)
#2 /app/vendor/link0/bunq/src/Client.php(78): Link0\Bunq\Client->processResponse(Object(GuzzleHttp\Psr7\Response))
#3 /app/vendor/link0/bunq/src/Service/InstallationService.php(74): Link0\Bunq\Client->post('session-server', Array, Array)

Foutmelding bij composer

Hi Dennis,

We hadden via de Bunq Together pagina al een berichtje gestuurd n.a.v. je geposte library. Alleen als we de library proberen te laden in composer krijgen we een foutmelding, zie onderstaand:

[InvalidArgumentException]
Could not find package link0/bunq@dev-master at any version for your minimum-stability (stable). Check the package spelling or your minimum-stability

Wat doen we verkeerd?

Groet,
Joeri

Unknown struct type: Invoice

$client = getClient($apiKey);

$userService = new UserService($client);
print_r($client->get('user/1810/invoice'));

screencapture-localhost-8000-invoices-1493317384819

Empty X-Bunq-Client-Authentication headers result in HTTP 403 forbidden errors

Currently an 'empty' X-Bunq-Client-Authentication header is used in some initial request (like POST Installation), which results in a HTTP 403 forbidden error since 27-03-2018.

if (!isset($headers['X-Bunq-Client-Authentication'])) {
$headers['X-Bunq-Client-Authentication'] = $this->sessionToken;
}

It should only be set when required:

        if (\is_string($this->sessionToken) && $this->sessionToken !== '' && !isset($headers['X-Bunq-Client-Authentication'])) {
            $headers['X-Bunq-Client-Authentication'] = $this->sessionToken;
        }

Would a PR be accepted? Or is none of the maintainers monitoring this?

Sending payments

Hi,

I'm trying yo send payments to IBAN with this API wrapper, but can't quite get it working. Can someone help me out?

In the console on https://doc.bunq.com/api/1/call/payment/method/post I get it working by posting:
{ "amount": { "value": "12.50", "currency": "EUR" }, "counterparty_alias": { "type": "IBAN", "name": "J. Lastname", "value": "NLXXXXXX0123456789" }, "description": "Payment for drinks." }
to POST https://public.api.app51.dev1.nl1.bunq.net/v1/user/1234/monetary-account/1234/payment
headers

Why final is kinda final

Hi @dennisdegreef ,

Thanks for writing this client, was looking at writing my own, but that seems to be unnecessary. Something that blew my mind though is your relentless use of the final keyword for classes. I can imagine you want to do so for aesthetic reasons, but it would make extending your classes (eg enriching them with other functionality) a lot easier if they were not final.

Can you shed some light on this? Because imo declaring any class final in open source work is very obstructing.

Hope to hear from you.

Implementing api action

Currently this library does not implement the different api endpoint. Is this on purpose or is this something you are thinking to implement in the future?

Incorrect API key or IP address. Error after reregistering new device/installation

I wanted to proceed with my little app but im stuck with the following error

Fatal error: Uncaught GuzzleHttp\Exception\ClientException: Client error: `POST https://sandbox.public.api.bunq.com/v1/device-server` resulted in a `400 Bad Request` response: {"Error":[{"error_description":"User credentials are incorrect. Incorrect API key or IP address.","error_description_tra (truncated...) in /vagrant/bunq-insights/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php on line 111

Before rerunning the code, including the registerInstallationAndDeviceServer() method. I regenerated a public and private key pair. The bunq documentation says that the device and installation are ip-address bound but I'm getting the idea that once you've registered an installation/device to an api key you can no longer use this api key on a different ip-address.

Could you help me getting some more understanding of this issue

balance is shown as string in object instead of float

screen shot 2017-05-16 at 18 45 01

Here it shows that the amount of money i have is 29164 which i sadly dont have i only have 291,64. is there an way to let it show an float?
$monetaryAccountService` = new MonetaryAccountService($client);
$monetaryAccounts = $monetaryAccountService->listByUser($user);
echo json_encode($monetaryAccounts[0]->balance());

Here is the noob code i used. haha

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.