To install this bundle, simply run the following command:
$ composer require mpp/lemon-way-client-bundle
First create a guzzle client:
eight_points_guzzle:
clients:
my_lemon_way_client:
base_url: '%env(LEMON_WAY_BASE_URL)%'
options:
headers:
PSU-Accept-Language: '%env(LEMON_WAY_PSU_ACCEPT_LANGUAGE)%' # optional (default: English)
PSU-IP-Address: '%env(LEMON_WAY_PSU_IP_ADRESS)%'
PSU-User-Agent: '%env(LEMON_WAY_PSU_USER_AGENT)%' # optional
Then configure this client to be used by the bundle:
mpp_lemon_way_client:
http_client: 'eight_points_guzzle.client.my_lemon_way_client'
# Generate one from backoffice (Developers > Access Token)
auth_access_token: '%env(LEMON_WAY_ACCESS_TOKEN)%'
# SandBox URL : https://sandbox-api.lemonway.fr/oauth/api/v1/oauth/token
# Production URL : https://auth.lemonway.com/oauth/api/v1/oauth/token
auth_access_token_url: '%env(LEMON_WAY_ACCESS_TOKEN_URL)%'
(Recommanded) Create the mpp lemon way cache pool in config/packages/cache.yaml
:
According to Lemon Way specification:
⚠️ You must not create a token for every API call you perform. We strongly advise you to create one only when your current token has expired, to replace it.
cache:
pools:
# ...
cache.mpp_lemon_way_client: ~
(Optional) If you want to use WebHooks configure the following routes in config/routes/mpp_lemon_way_client.yaml
:
mpp_lemon_way_webhooks:
path: /mpp/lemon-way/webhooks # make sure it is the same as defined in Lemonway backoffice
controller: Mpp\LemonWayClientBundle\Controller\WebHooksController::callbackAction
Here is the mapping of client for each specification name
Group | Base path | Client | Client domain alias |
---|---|---|---|
Accounts | /v2/accounts | LemonWayAccountClient | account |
MoneyIns | /v2/moneyins | LemonWayMoneyInClient | money_in |
MoneyOuts | /v2/moneyouts | LemonWayMoneyOutClient | money_out |
P2Ps | /v2/p2p | LemonWayP2PClient | p2p |
Refunds | /v2/refunds | LemonWayRefundClient | refund |
Disputes | /v2/disputes | LemonWayDisputeClient | dispute |
Group | Event id | Event name |
---|---|---|
Accounts | 8 | Account status change |
9 | Document status change | |
13 | Freeze/unfreeze wallet | |
MoneyIns | 10 | MoneyIn : by wire received |
11 | MoneyIn : by SDD received | |
12 | MoneyIn : by cheque received | |
17 | MoneyIn by SDD canceled | |
MoneyOuts | 15 | MoneyOut canceled |
Disputes | 14 | Chargeback received |
Here is a sample controller on how to get a specific client from registry:
<?php
namespace App\Controller;
use Mpp\LemonWayClientBundle\Client\LemonWayAccountClient;
use Mpp\LemonWayClientBundle\Client\LemonWayClientRegistryInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class ExampleController extends AbstractController
{
public function exampleAction(LemonWayClientRegistryInterface $lemonWayClientRegistry)
{
// Example with LemonWayAccountClient
$myClient = $lemonWayClientRegistry->get('account');
}
// You can also inject the client directly
public function exampleAction(LemonWayAccountClient $lemonWayAccountClient)
{
}
}
You'll find an exemple of usage of each client below
First you must configure the following routes in config/routes/mpp_lemon_way_client.yaml
:
mpp_lemon_way_webhooks:
path: /mpp/lemon-way/webhooks # make sure it is the same as defined in Lemonway backoffice
controller: Mpp\LemonWayClientBundle\Controller\WebHooksController::callbackAction
Then, you can attach to webhooks events in a custom subscriber:
<?php
namespace App\Event\Subscriber;
use Mpp\LemonWayClientBundle\Event\WebHooksEvents;
use Mpp\LemonWayClientBundle\Event\AccountStatusChangeEvent;
use Mpp\LemonWayClientBundle\Event\DocumentStatusChangeEvent;
use Mpp\LemonWayClientBundle\Event\FreezeUnfreezeWalletEvent;
use Mpp\LemonWayClientBundle\Event\MoneyInByWireReceivedEvent;
use Mpp\LemonWayClientBundle\Event\MoneyInBySddReceivedEvent;
use Mpp\LemonWayClientBundle\Event\MoneyInByChequeReceivedEvent;
use Mpp\LemonWayClientBundle\Event\MoneyInBySddCanceledEvent;
use Mpp\LemonWayClientBundle\Event\MoneyOutCanceledEvent;
use Mpp\LemonWayClientBundle\Event\ChargebackReceivedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class LemonWayWebHooksEventSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
return [
WebHooksEvents::ACCOUNT_STATUS_CHANGE => [
['handleAccountStatusChangeEvent', 0],
],
WebHooksEvents::DOCUMENT_STATUS_CHANGE => [
['handleDocumentStatusChangeEvent', 0],
],
WebHooksEvents::FREEZE_UNFREEZE_WALLET => [
['handleFreezeUnfreezeWalletEvent', 0],
],
WebHooksEvents::MONEY_IN_BY_WIRE_RECEIVED => [
['handleMoneyInByWireReceivedEvent', 0],
],
WebHooksEvents::MONEY_IN_BY_SDD_RECEIVED => [
['handleMoneyInBySddReceivedEvent', 0],
],
WebHooksEvents::MONEY_IN_BY_CHEQUE_RECEIVED => [
['handleMoneyInByChequeReceivedEvent', 0],
],
WebHooksEvents::MONEY_IN_BY_SDD_CANCELED => [
['handleMoneyInBySddCanceledEvent', 0],
],
WebHooksEvents::MONEY_OUT_CANCELED => [
['handleMoneyOutCanceledEvent', 0],
],
WebHooksEvents::CHARGEBACK_RECEIVED => [
['handleChargebackReceivedEvent', 0],
],
];
}
public function handleAccountStatusChangeEvent(AccountStatusChangeEvent $event)
{
// Do something
}
public function handleDocumentStatusChangeEvent(DocumentStatusChangeEvent $event)
{
// Do something
}
public function handleFreezeUnfreezeWalletEvent(FreezeUnfreezeWalletEvent $event)
{
// Do something
}
public function handleMoneyInByWireReceivedEvent(MoneyInByWireReceivedEvent $event)
{
// Do something
}
public function handleMoneyInBySddReceivedEvent(MoneyInBySddReceivedEvent $event)
{
// Do something
}
public function handleMoneyInByChequeReceivedEvent(MoneyInByChequeReceivedEvent $event)
{
// Do something
}
public function handleMoneyInBySddCanceledEvent(MoneyInBySddCanceledEvent $event)
{
// Do something
}
public function handleMoneyOutCanceledEvent(MoneyOutCanceledEvent $event)
{
// Do something
}
public function handleChargebackReceivedEvent(ChargebackReceivedEvent $event)
{
// Do something
}
}
Update the environment variables in phpunit.xml.dist:
<!-- ... -->
<php>
<!-- ... -->
<env name="APP_ENV" value="test" />
<env name="LEMON_WAY_BASE_URL" value="" />
<env name="LEMON_WAY_AUTH_ACCESS_TOKEN" value="" />
<env name="LEMON_WAY_AUTH_ACCESS_TOKEN_URL" value="" />
<!-- ... -->
</php>
<!-- ... -->
Then, use the following commands if you want to run the tests suite
$ make composer-install # once
$ make phpunit
- Find a way to better handle ApiResponse by remplacing the $classNameMapping argument of requestAndPopulate -> For example by creating model object for each client response to simplify deserialization, so, LemonWayMoneyInClient::getAccountCards() method return a GetAccountCardsApiResponse instead of an array
- Implement tests