mpp/generali-client-bundle

Symfony Generali Client Bundle

v2.3.2 2021-09-24 12:32 UTC

README

Installation

To install this bundle, simply run the following command:

$ composer require mpp/generali-client-bundle

Configuration

First you must configure a guzzle client using eight point guzzle in the file config/packages/eight_points_guzzle.yaml:

eight_points_guzzle:
    clients:
        my_generali_client:
            base_url: '%env(GENERALI_BASE_URL)%'
            options:
                timeout: 30
                http_errors: true
                headers:
                    User-Agent: "MppGeneraliClient/v1.0"
                    Accept: 'application/json'
                    Content-Type: 'application/json'
                    apiKey: '%env(GENERALI_API_KEY)%'

Then you have to configure your credentials in config/packages/mpp_generali_client.yaml:

mpp_generali_client:
    http_client: 'eight_points_guzzle.client.mpp_generali' # reference to guzzle client
    app_code: '%env(string:GENERALI_APP_CODE)%'
    default_context:
        codeApporteur: '%env(string:GENERALI_DEFAULT_PROVIDER_CODE)%'
        codeSouscription: '%env(string:GENERALI_DEFAULT_SUBSCRIPTION_CODE)%'

Put these environment variables i your .env file:

###> mpp/generali-client-bundle ###
GENERALI_BASE_URL=https://generalifrprod-recette.apigee.net/epart
GENERALI_API_KEY=YOUR_API_KEY
GENERALI_APP_CODE=YOUR_APP_CODE
GENERALI_DEFAULT_PROVIDER_CODE=YOUR_PROVIDER_CODE
GENERALI_DEFAULT_SUBSCRIPTION_CODE=YOUR_SUBSCRIPTION_CODE
###< mpp/generali-client-bundle ###

Clients

Specification name Base path Client Client alias
Arbitrage /v2.0/transaction/arbitrage GeneraliArbitrationClient arbitration
Contrat /v2.0/contrats GeneraliContractClient contract
Fonds /v1.0/fonds GeneraliFundsClient funds
Pièces justificatives /v1.0/transaction/piecesAFournir & /v1.0/transaction/fournirPiece GeneraliAttachmentClient document
Rachat partiel /v1.0/donnees/rachatpartiel GeneraliPartialRepurchaseClient partial_repruchase
Gestion des documents /v2.0/document GeneraliDocumentClient document
Souscription /v2.0/transaction/souscription GeneraliSubscriptionClient subscription
Versement Libre /v2.0/transaction/versementLibre GeneraliFreePaymentClient free_payment
Versement libre programmé /v2.0/transaction/versementsLibresProgrammes GeneraliScheduledFreePaymentClient scheduled_free_payment
Versement libre programmé - Modification /v1.0/transaction/modificationVersementsLibresProgrammes GeneraliScheduledFreePaymentEditClient scheduled_free_payment_edit
Versement libre programmé - Suspension /v1.0/transaction/suspensionVersementsLibresProgrammes GeneraliScheduledFreePaymentSuspendClient scheduled_free_payment_suspend

How to use ?

How to get a specific client domain ?

<?php

namespace App\Controller;

use Mpp\GeneraliClientBundle\Client\GeneraliClientRegistryInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;

class ExampleController extends AbstractController
{
    public function exampleAction(GeneraliClientRegistryInterface $generaliClientRegistry)
    {
        // Here are the three different available methods on how to retrieve a client domain by its alias (choose the one you prefer)
        $myClient = $generaliClientRegistry->get('client_domain_alias');
        // or
        $myClient = $generaliClientRegistry->getClientDomainAlias();

        // Execute operations from the retrieved client domain
        // ...
    }
}

How to use each clients ?

You'll find an exemple of usage of each client below

How can I create model object easily

Thanks to the ModelFactory you can create objects with deep relationships thanks to createFromArray & createFromJson methods:

Here is an example:

<?php

namespace App\Controller;

use Mpp\GeneraliClientBundle\Factory\ModelFactory;
use Mpp\GeneraliClientBundle\Model\Arbitrage;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;

class ExampleController extends AbstractController
{
    public function exampleAction(ModelFactory $generaliModelFactory)
    {
        $arbitration = $generaliModelFactory->createFromArray(Arbitrage::class, [
            'numOperationExterne' => 1234,
            'mandatTransmissionOrdre' => true,
            'mandatArbitrage' => false,
            'fondsInvestis' => [],
            'fondsDesinvestis' => [
                [
                    'codeFonds' => 'FP12SN73DU4EJ',
                    'montant' => 750.40,
                    'pourcentage' => 0.4,
                    'avenantValide' => true,
                    'taux' => 5,
                    'duree' => 2,
                    'numeroEngagement' => 1,
                ],
            ],
        ]);

        // or

        $arbitration = $generaliModelFactory->createFromJson(Arbitrage::class, file_get_contents('/path/to/arbitration.json'));
    }
}

How the api works (outdated)

First you will have to create a Subscription, where you will send all the needed information on your customer and the subscription asked.

Then you will get a contractNumber which will be used to create:

You will use specifics code for some attributes, please check here when you will build your data structure.

How can you get the contract number ?

  • On development environment: you will have to contact your Generali Partner
  • On pre-production and on production environment: you will have to parse some csv files given by sftp access. You will find your contractNumber by searching for your internalReference1 and/or internalReference2 that you have given during your subscription creation

Tests

Update the environment variables in phpunit.xml.dist or create a phpunit.xml file:

<!-- ... -->
<php>
    <!-- ... -->
    <env name="APP_ENV" value="test" />
    <env name="GENERALI_BASE_URL" value="" />
    <env name="GENERALI_API_KEY" value="" />
    <env name="GENERALI_APP_CODE" value="" />
    <env name="GENERALI_DEFAULT_PROVIDER_CODE" value="" />
    <env name="GENERALI_DEFAULT_SUBSCRIPTION_CODE" value="" />
    <!-- ... -->
</php>
<!-- ... -->

Then, use the following commands if you want to run the tests suite

$ make composer-install # once
$ make phpunit

TODO

  • There is a problem with "avenant" field which can be bool or objet depending on context in GeneraliFundsClient & other clients
  • Finish client tests