lexik/colissimo-bundle

此插件为 lexik/ws-colissimo 库提供了一个包装器

安装: 134

依赖: 0

建议者: 0

安全: 0

星标: 17

关注者: 12

分支: 3

开放问题: 0

类型:symfony-bundle

v1.0.0 2014-03-22 09:25 UTC

This package is not auto-updated.

Last update: 2024-09-11 11:49:05 UTC


README

此插件提供服务以使用 Lexik WSColissimo 库访问和消费 WSColiPosteLetterService。

Project Status

SensioLabsInsight

此插件已弃用

WSColiPosteLetterService

使用 WSColiPosteLetterService 生成 Colissimo 包裹的运单。

安装

使用 composer 下载

将插件添加到您的 composer.json

{
    "require": {
        "lexik/colissimo-bundle": "dev-master"
    }
}

运行以下命令下载:

php composer.phar update lexik/colissimo-bundle

启用插件

在您的 app/AppKernel.php 中启用插件

public function registerBundles()
{
    $bundles = array(
        // ...
        new Lexik\Bundle\ColissimoBundle\LexikColissimoBundle(),
    );
}

配置

以下是使用 LexikColissimoBundle 在应用程序中配置的必要的最小示例

lexik_colissimo:
    ws_coliposte_letter_service:
        contract_number:         123456               # mandatory
        password:                'abcdef'             # mandatory
        service_call_context:
            commercial_name:     'ACME COMPANY'
        sender:                                       # you can overwrite this part from your code
            company_name:        'ACME COMPANY'
            line_0:              null   
            line_1:              null
            line_2:              'Place de la Comedie'
            line_3:              null
            postal_code:         '34000'
            city:                'Montpellier'

使用方法

从容器中获取服务,使用您的包裹和收件人信息作为参数调用 getLabel 方法

// use Lexik\Bundle\ColissimoBundle\Exception\InvalidRequestException;
// use Lexik\Bundle\ColissimoBundle\Exception\FailedRequestException;

$colissimo = $this->container->get('lexik_colissimo.ws_coliposte_letter_service.service');

try {

    $response = $colissimo->getLabel(
        array('weight' => 1.780),
        array(
            'name'       => 'Client Name',
            'surname'    => 'Client Surname',
            'email'      => 'client@email.com',
            'line2'      => 'Client Address',
            'city'       => 'Client City',
            'postalCode' => 'Client Postal Code'
        )
	// you can overwrite the sender configured in you app/config.yml by passing an array as 3rd argument
	// you can disable validation by setting the 4th argument to false
    );
    
    // $response looks like this
    object(WSColissimo\WSColiPosteLetterService\Response\ValueObject\ReturnLetter)[1102]
      protected 'file' => null
      protected 'parcelNumber' => string '13xc1v654d123' (length=13)
      protected 'PdfUrl' => string 'https://ws.colissimo.fr/path/to/pdf-file' (length=40)
      protected 'errorID' => int 0
      protected 'error' => string '' (length=0)
      protected 'signature' => null
      protected 'dateCreation' => null

} catch (InvalidRequestException $e) {
    // validation problems : you can iterate over errors with $e->getViolations()
} catch (FailedRequestException $e) {
    // webservice returned an error : you can get the error message with $e->getMessage()
}