2017 © Pedro Peláez
 

library monzo-php

An API client for Monzo Bank (https://monzo.com)

image

amelia/monzo-php

An API client for Monzo Bank (https://monzo.com)

  • Thursday, March 22, 2018
  • by amelia
  • Repository
  • 3 Watchers
  • 6 Stars
  • 58 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 3 Forks
  • 1 Open issues
  • 22 Versions
  • 2 % Grown

The README.md

Monzo PHP Client

, (*1)

This library allows access to the Monzo API in PHP. This library requires PHP 7.1+., (*2)

Installation

composer require amelia/monzo-php

If you don't already have your own access tokens from completing oauth yourself, you'll need to also composer require laravel/socialite., (*3)

You should set the following variables in your .env (or otherwise):, (*4)

  • MONZO_CLIENT_ID
  • MONZO_CLIENT_SECRET
  • MONZO_REDIRECT_URI

You can create an application at https://developers.monzo.com., (*5)

Laravel integration

Amelia\Monzo\MonzoServiceProvider::class is registered automatically in Laravel 5.5., (*6)

A future version of this package will include automatic webhook handling per-user, and full automatic socialite integration., (*7)

The environment variables that control these will be:, (*8)

  • MONZO_WEBHOOKS=true
  • MONZO_SOCIALITE=true

Socialite integration

To automatically add callbacks for socialite, this package provides an optional authentication system., (*9)

Caveat This assumes you are adding existing users to an app on monzo. If you are not doing this, you'll need to set up your own routes to create/manage users based on API responses from socialite., (*10)

First, add the MonzoCredentials trait to your Authenticatable user model., (*11)

<?php

namespace App;

use Amelia\Monzo\MonzoCredentials;
use Amelia\Monzo\Contracts\HasMonzoCredentials;
use Illuminate\Database\Eloquent\Model;

class User extends Model implements HasMonzoCredentials
{
    use MonzoCredentials;
}

This adds a bunch of setters/getters to your user model for handling monzo credentials., (*12)

You can customise the columns used by adding methods to your user model:, (*13)

<?php

use Amelia\Monzo\MonzoCredentials;
use Amelia\Monzo\Contracts\HasMonzoCredentials;

class User implements HasMonzoCredentials {

    use MonzoCredentials;

    protected function getMonzoAccessTokenColumn()
    {
        return 'monzo_access_token';
    }

    protected function getMonzoRefreshTokenColumn()
    {
        return 'monzo_refresh_token';
    }

    protected function getMonzoUserIdColumn()
    {
        return 'monzo_user_id';
    }
}

Socialite migrations

Assuming your users table is named users, you can simply run php artisan vendor:publish --tag=monzo., (*14)

This will create a migration in your migrations directory that can be edited., (*15)

Run php artisan migrate to run this., (*16)

Usage

Caveat If not using Laravel, you'll need to set up an instance of Amelia\Monzo\Monzo and inject an Amelia\Monzo\Contracts\Client instance into it, as follows:, (*17)

<?php

$client = new Amelia\Monzo\Client(
    new GuzzleHttp\Client,
    getenv('MONZO_CLIENT_ID') ?: null,
    getenv('MONZO_CLIENT_SECRET') ?: null
);

$monzo = new Amelia\Monzo\Monzo($client);

// Amelia\Monzo\Monzo::setAccessToken($token) for single user mode

If using Laravel, you only need to inject Amelia\Monzo\Monzo via the service container, using resolve() or app()., (*18)

Using the API is pretty simple., (*19)

In general, you'll need an access token or a user object., (*20)

Examples

Grab a user's accounts.

<?php

$user = User::findOrFail($id);

$accounts = $monzo->as($user)->accounts();

Grab the last 100 transactions for a user account

<?php

$user = User::findOrFail($id);

$transactions = $monzo->as($user)->transactions('acc_12341243');

Grab the last 100 transactions for a user's default account

<?php

$user = User::findOrFail($id);

// will query accounts first, then use the default to query transactions.
$transactions = $monzo->as($user)->transactions();

Grab a paginator instance for a user's transactions

<?php

$user = User::findOrFail($id);

$transactions = $monzo->as($user)->paginate(50)->transactions('acc_12341243');

Expand (and hydrate) relations in the API

<?php

$user = User::findOrFail($id);

$transactions = $monzo->as($user)
    ->paginate(50)
    ->expand('account')
    ->transactions('acc_12341243');

See a user's balance

<?php

$user = User::findOrFail($id);

$balance = $monzo->as($user)->balance();

The Versions

22/03 2018

dev-master

9999999-dev

An API client for Monzo Bank (https://monzo.com)

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Amelia Ikeda

02/03 2018

v0.10.0

0.10.0.0

An API client for Monzo Bank (https://monzo.com)

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Amelia Ikeda

02/03 2018

dev-analysis-zOZNV4

dev-analysis-zOZNV4

An API client for Monzo Bank (https://monzo.com)

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Amelia Ikeda

02/03 2018

dev-analysis-q1D541

dev-analysis-q1D541

An API client for Monzo Bank (https://monzo.com)

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Amelia Ikeda

02/03 2018

dev-analysis-q1D5Ay

dev-analysis-q1D5Ay

An API client for Monzo Bank (https://monzo.com)

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Amelia Ikeda

02/03 2018

v0.9.0

0.9.0.0

An API client for Monzo Bank (https://monzo.com)

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Amelia Ikeda

26/01 2018

v0.8.0

0.8.0.0

An API client for Monzo Bank (https://monzo.com)

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Amelia Ikeda

19/01 2018

v0.8.0-beta

0.8.0.0-beta

An API client for Monzo Bank (https://monzo.com)

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Amelia Ikeda

19/01 2018

v0.7.0

0.7.0.0

An API client for Monzo Bank (https://monzo.com)

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Amelia Ikeda

22/11 2017

v0.6.0

0.6.0.0

An API client for Monzo Bank (https://monzo.com)

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Amelia Ikeda

21/11 2017

v0.5.1

0.5.1.0

An API client for Monzo Bank (https://monzo.com)

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Amelia Ikeda

21/11 2017

v0.5.0

0.5.0.0

An API client for Monzo Bank (https://monzo.com)

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Amelia Ikeda

20/11 2017

v0.4.4

0.4.4.0

An API client for Monzo Bank (https://monzo.com)

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Amelia Ikeda

20/11 2017

v0.4.3

0.4.3.0

An API client for Monzo Bank (https://monzo.com)

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Amelia Ikeda

20/11 2017

v0.4.2

0.4.2.0

An API client for Monzo Bank (https://monzo.com)

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Amelia Ikeda

20/11 2017

v0.4.1

0.4.1.0

An API client for Monzo Bank (https://monzo.com)

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Amelia Ikeda

20/11 2017

v0.4.0

0.4.0.0

An API client for Monzo Bank (https://monzo.com)

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Amelia Ikeda

20/11 2017

v0.3.0

0.3.0.0

An API client for Monzo Bank (https://monzo.com)

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Amelia Ikeda

24/03 2017

dev-analysis-8L9xw6

dev-analysis-8L9xw6

An API client for Monzo Bank (https://monzo.com)

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Amelia Ikeda

24/03 2017

v0.2.0

0.2.0.0

An API client for Monzo Bank (https://monzo.com)

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Amelia Ikeda

22/02 2017

dev-analysis-z40QZ7

dev-analysis-z40QZ7

An API client for Monzo Bank (https://monzo.com)

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Amelia Ikeda

22/02 2017

v0.1.0

0.1.0.0

An API client for Monzo Bank (https://monzo.com)

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Amelia Ikeda