mpp/generali-client-bundle

Symfony Generali Client Bundle

该软件包的官方仓库似乎已消失,因此该软件包已被冻结。

v3.11.4 2024-06-21 13:15 UTC

README

Symfony Bundle用于与Generali API交互

安装

要安装此软件包,请运行以下命令

$ composer require mpp/generali-client-bundle

配置

首先,您必须使用八点Guzzle在文件config/packages/eight_points_guzzle.yaml中配置一个Guzzle客户端

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)%'

然后,您必须在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)%'

将这些环境变量放入您的.env文件中

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

客户端

规范名称 基本路径 客户端 客户端别名
套利 /v2.0/transaction/arbitrage GeneraliArbitrationClient arbitration
合同 /v2.0/contrats GeneraliContractClient contract
基金 /v1.0/fonds GeneraliFundsClient funds
证明文件 /v1.0/transaction/piecesAFournir & /v1.0/transaction/fournirPiece GeneraliAttachmentClient document
部分回购 /v1.0/donnees/rachatpartiel GeneraliPartialRepurchaseClient partial_repruchase
文档管理 /v2.0/document GeneraliDocumentClient document
订阅 /v2.0/transaction/souscription GeneraliSubscriptionClient subscription
自由支付 /v2.0/transaction/versementLibre GeneraliFreePaymentClient free_payment
计划自由支付 /v2.0/transaction/versementsLibresProgrammes GeneraliScheduledFreePaymentClient scheduled_free_payment
计划自由支付 - 修改 /v1.0/transaction/modificationVersementsLibresProgrammes GeneraliScheduledFreePaymentEditClient scheduled_free_payment_edit
计划自由支付 - 暂停 /v1.0/transaction/suspensionVersementsLibresProgrammes GeneraliScheduledFreePaymentSuspendClient scheduled_free_payment_suspend

如何使用?

如何获取特定客户端域名?

<?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
        // ...
    }
}

如何使用每个客户端?

下面提供了每个客户端的用法示例

如何轻松创建模型对象?

感谢 ModelFactory,您可以通过 createFromArraycreateFromJson 方法创建具有深层关系的对象。

以下是一个示例

<?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'));
    }
}

API 的工作原理(已过时)

首先,您需要创建一个 订阅,在订阅中,您将发送有关客户和所需订阅的所有必要信息。

然后,您将获得一个合同编号,该编号将用于创建

您将使用特定代码来设置某些属性,请在构建数据结构时查看这里

如何获取合同编号?

  • 在开发环境中:您需要联系您的Generali合作伙伴
  • 在预生产和生产环境中:您需要解析由sftp访问提供的某些csv文件。您可以通过搜索在订阅创建过程中提供的内部参考1和/或内部参考2来找到合同编号。

测试

更新 phpunit.xml.dist 中的环境变量或创建一个 phpunit.xml 文件

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

然后,如果您想运行测试套件,请使用以下命令

$ make composer-install # once
$ make phpunit

待办事项

  • 在GeneraliFundsClient和其他客户中,“avenant”字段存在问题,该字段可能根据上下文为布尔值或对象
  • 完成客户测试