Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/ameliaikeda/monzo-php

PHP Library for use with https://monzo.com
https://github.com/ameliaikeda/monzo-php

api api-client laravel monzo php socialite

Last synced: 30 days ago
JSON representation

PHP Library for use with https://monzo.com

Awesome Lists containing this project

README

        

Monzo PHP Client
















This library allows access to the Monzo API in PHP. This library requires PHP 7.1+.

## 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`.

You should set the following variables in your `.env` (or otherwise):

- `MONZO_CLIENT_ID`
- `MONZO_CLIENT_SECRET`
- `MONZO_REDIRECT_URI`

You can create an application at [https://developers.monzo.com](https://developers.monzo.com).

## Laravel integration

`Amelia\Monzo\MonzoServiceProvider::class` is registered automatically in Laravel 5.5.

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

The environment variables that control these will be:

- `MONZO_WEBHOOKS=true`
- `MONZO_SOCIALITE=true`

### Socialite integration

To automatically add callbacks for socialite, this package provides an optional authentication system.

> **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.

First, add the `MonzoCredentials` trait to your `Authenticatable` user model.

```php
as($user)->accounts();
```

### Grab the last 100 transactions for a user account

```php
as($user)->transactions('acc_12341243');
```

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

```php
as($user)->transactions();
```

### Grab a paginator instance for a user's transactions

```php
as($user)->paginate(50)->transactions('acc_12341243');
```

### Expand (and hydrate) relations in the API

```php
as($user)
->paginate(50)
->expand('account')
->transactions('acc_12341243');
```

### See a user's balance

```php
as($user)->balance();
```