Git Product home page Git Product 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 much welcome though issues and/or pull requests.

Basic usage

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

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

Before you copy/paste this code besure you've a 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 only once. After the first call you can comment this rule away.

<?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

Watchers

 avatar  avatar

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.