piggy/piggy-php-sdk

3.7.4 2024-09-16 14:11 UTC

README

通过 Piggy 的全能平台,您可以加强客户忠诚度并自动化每一步。从奖励计划到品牌礼品卡和智能电子邮件营销——Piggy 一站式服务。

您可以使用此软件包将您的应用程序/POS系统(收银机)连接到Piggy账户。请确保选择适合您需求的正确API客户端。

有关我们API的完整文档可以在此处找到 https://docs.piggy.eu/

版本

您应使用此SDK的v3版本。然而,此版本与SDK的v1.*版本不兼容。

需求

此SDK需要PHP 7.2或更高版本。目前我们的测试套件在PHP 7.2、7.3、7.4、8.0、8.1上运行。

设置

Composer

composer require piggy/piggy-php-sdk

快速入门

使用Register客户端的示例

$apiKey = 'xxxx-xxxx-xxxx';  
$client = new Piggy\Api\RegisterClient($apiKey);

try {
    $contact = $client->contacts->findOneBy('test@domain.com'); // Example call to find a Contact by e-mail address
} catch(Piggy\Api\Exceptions\MaintenanceModeException $e) {
    // Catch maintenance mode specific.
} catch(Piggy\Api\Exceptions\PiggyRequestException $e) {
    // If no Contact is found, you'd know that from this exception
} catch(\Exception $e) {
    // Handle any other exceptions 
}

使用API密钥的静态函数示例

$apiKey = 'xxxxxxxx';
$baseUrl = "https://api.piggy.eu";

ApiClient::configure($apiKey, $baseUrl);

try {
    // Example call to update a Contact by UUID
    Contact::update("1234ab-7890-asdf-1234-a1b2c3d4", ["attributes" => ["firstname" => "henk", "housenumber" => 10]]);
} catch(Piggy\Api\Exceptions\MaintenanceModeException $e) {
    // Catch maintenance mode specific.
} catch(GuzzleHttp\Exception\GuzzleException $e) {
    // If no Contact is found, you'd know that from this exception
} catch(\Exception $e) {
    // Handle any other exceptions 
}