martijnpieters/pakketmail

API版本2.0的PakketMail SDK

dev-master 2017-11-19 16:20 UTC

This package is not auto-updated.

Last update: 2024-09-29 04:31:29 UTC


README

需求

安装

安装PakketMail SDK的最简单方法是使用 Composer 进行要求。

$ composer require martijnpieters/pakketmail:dev-master

入门

要求Composer自动加载器并包含PakketMail命名空间。

require 'vendor/autoload.php';

use MartijnPieters\PakketMail;

使用您的用户名和密码初始化请求,可选地设置开发标志 true

$pakketMailRequest = new PakketMail\Request('username', 'password', true);

创建一个新的包裹并将其添加到请求中。

$shipmentProperties = [
    'pakketMailProduct' => PakketMail\Shipment::PAKKETMAIL_PRODUCT_DPD,
    'clientReference' => 'A123',
    'name1' => 'John Doe',
    'streetName' => 'Main street',
    'city' => 'Foo City',
    'postalCode' => '1234 AB',
    'country' => 'NLD',
];
$shipment = new PakketMail\Shipment($shipmentProperties);

$pakketMailRequest->addShipment($shipment);

执行请求并检索日关闭URL(dagafsluiting)。

$pakketMailRequest->sendToApi();

print($pakketMailRequest->getDayCloseUrl());

异常

捕获API调用过程中的异常。

try {
    $pakketMailRequest->sendToApi();
} catch (PakketMail\Exception $e) {
    throw new Exception($e->getMessage());
}