cleverage / colissimo-bundle
为Symfony提供的简单Colissimo REST包
v1.1.0
2023-12-05 08:55 UTC
Requires
- php: >=7.4
- symfony/config: >=4.0
- symfony/dependency-injection: >=4.0
- symfony/http-client: >=4.0
- symfony/http-foundation: >=4.0
- symfony/http-kernel: >=4.0
README
简介
此包提供访问和消费Colissimo WS的服务。
服务
需求
- Php >= 7.4
- Symfony 4, 5或6
安装
使用Composer(https://packagist.org.cn)非常简单,运行
composer require cleverage/colissimo-bundle
在您的应用程序中注册包
// config/bundles.php CleverAge\ColissimoBundle\CleverAgeColissimoBundle::class => ['all' => true],
配置示例
在config/packages/cleverage_colissimo.yaml
中
clever_age_colissimo: testModeEnabled: true auth: contractNumber: '22020' password: 'password' letter: service: commercialName: 'CommercialName' sender: companyName: 'CompanyName' line0: null line1: null line2: '9 rue André darbon' line3: null countryCode: 'FR' zipCode: '33300' city: 'Bordeaux'
用法示例
获取自提点
class PickupPointsController extends AbstractController { private PickupPointsService $pickupPointsService; public function __construct( PickupPointsService $pickupPointsService ) { $this->pickupPointsService = $pickupPointsService; } public function index() { $searchModel = new PickupPointsSearchModel( '33300', 'Bordeaux', 'FR', '18/07/2022', ); // Return an array of PickupPoint::class $pickupPoints = $this->pickupPointsService->call($searchModel); foreach ($pickupPoints as $pickupPoint) { // Get data by identifier. // @see PickupPoint to show all identifiers available. echo $pickupPoint->get('id'); // 987178 echo $pickupPoint->get('name'); // ALEX TISSUS } // .... } }
通过ID获取自提点
class PickupPointByIdController extends AbstractController { private PickupPointByIdService $pickupPointByIdService; public function __construct( PickupPointByIdService $pickupPointByIdService ) { $this->pickupPointByIdService = $pickupPointByIdService; } public function index() { $searchByIdModel = new PickupPointSearchByIdModel('987178', '18/07/2022'); $pickupPoint = $this->pickupPointByIdService->call($searchByIdModel); if (null !== $pickupPoint) { echo $pickupPoint->get('name'); // ALEX TISSUS } // .... } }
跟踪
class TrackingController extends AbstractController { private TrackingService $trackingService; public function __construct( TrackingService $trackingService ) { $this->trackingService = $trackingService; } public function index() { $trackingSearchModel = new TrackingSearchModel(); $trackingSearchModel ->setLang('FR') // FR is set by default. This line is optionnal. ->setParcelNumber('ABNUABSASNLK'); $tracking = $this->trackingService->call($trackingSearchModel); $tracking->getParcel(); $tracking->getSteps(); $tracking->getEvents(); // @see TrackingResponse::class for usable getters. // .... } }
运输
class ShippingController extends AbstractController { private ShippingService $shippingService; public function __construct( ShippingService $shippingService ) { $this->shippingService = $shippingService; } public function index() { $label = new Label(); $outputFormat = new OutputFormat(); $outputFormat->setOutputPrintingType(OutputPrintingType::ZPL_10x10_300dpi); $label->setOutputFormat($outputFormat); $letter = new Letter(); $service = new Letter\Service(); $service->setProductCode(ProductCode::DOM) ->setDepositDate((new \DateTime())->format('Y-d-m')) ->setOrderNumber('orderNumber'); $letter->setService($service); $parcel = new Letter\Parcel(); $parcel->setWeight(3); // If it's delivery on pickup point $parcel->setPickupLocationId('987178'); $letter->setParcel($parcel); $addressee = new Letter\Addressee(); $addressee->setEmail('test@clever-age.com') ->setFirstName('John') ->setLastName('Doe') ->setLine2('9 rue André darbon') ->setCity('Bordeaux') ->setCountryCode('FR') ->setZipCode('33300'); $letter->setAddressee($addressee); $label->setLetter($letter); $shipping = $this->shippingService->call($label); echo $shipping->getParcelNumber(); // AIAOBOIABS echo $shipping->getPdfUrl(); // null or the pdf url. echo $shipping->getParcelNumberPartner(); // null or the parcel number partner. echo $shipping->getFields(); // Array of custom fields. // ... } }
产品交互
class ProductInterController extends AbstractController { private ProductInterService $productInterService; public function __construct( ProductInterService $productInterService ) { $this->productInterService = $productInterService; } public function index() { $productInter = new ProductInter(); $productInter->setCountryCode('FR') ->setZipCode('33300') ->setProductCode(ProductCode::DOM) ->setInsurance(false) // Default false. Optional. ->setNonMachinable(false) // Default false. Optional. ->setReturnReceipt(false); // Default false. Optional. $response = $this->productInterService->call($productInter); $response->getProduct(); // Array of product codes. $response->getReturnTypeChoice(); // Array of return choice types. // ... } }
许可证
MIT许可证(MIT)。更多信息请参阅许可证文件。