assoconnect/linxo-client

PHP Client for the Linxo API

v1.0.5 2024-11-28 14:33 UTC

This package is auto-updated.

Last update: 2024-11-28 14:42:47 UTC


README

Build Status Quality Gate Status

Installation

composer require assoconnect/linxo-client

Documentation

Use the official documentation.

Quick start

<?php

use AssoConnect\LinxoClient\AuthClient;

// Set up the AuthClient with your credentials
$authClient = new AuthClient(
    'clientId',
    'clientSecret',
    'http://your-app.com/linxo/redirect'
);

// OAuth2 code exchange
$token = $authClient->getTokenFromCode('code');

// OAuth2 token refresh
$newToken = $authClient->refreshToken($token->getRefreshToken());

// Get an API Client for a given user identified by its access token
$apiClient = $authClient->createApiClient($token->getToken());
$apiClient->getAccounts(); // List of Linxo bank accounts

Tests

This lib ships with a Guzzle system to mock API responses.

It will answer a mocked response if one is defined for a given request, or will call the API.

How to use it

<?php

use AssoConnect\LinxoClient\Dto\AccountDto;
use AssoConnect\LinxoClient\Test\MockAuthClient;
use AssoConnect\LinxoClient\Test\MockFactory;

$authClient = new MockAuthClient(
    'clientId',
    'clientSecret',
    'http://your-app.com/linxo/redirect'
);
$middleware = $authClient->getMiddleware();
// Create your own mock responses
$middleware->stackAccount([
    'id' => '1',
    'connection_id' => '2',
    'name' => 'My account',
    'iban' => 'FR4930003000703896912638U72',
    'status' => AccountDto::STATUS_ACTIVE,
    'currency' => 'EUR',
]);
// You can also mock you or transactions
$middleware->stackMe(...);
$middleware->stackTransaction(...);

$apiClient = $authClient->createApiClient('token');
$apiClient->getAccount('1'); // Will return the mocked DTO
$apiClient->getAccount('2'); // Will call the API

// Or you can use a factory to get predefined content
$factory = new MockFactory($middleware);
$factory->mockAccount([
    'name' => 'My 2nd account' // Replace only what you want
]);
$factory->mockMe(...);
$factory->mockTransaction(...);