talon-one/talon-one-client

使用Talon.One API将您的应用程序与平台集成并管理应用程序和活动:- 使用[集成API部分](#integration-api)中的操作与我们的平台集成 - 使用[管理API部分](#management-api)中的操作来管理应用程序


README

使用Talon.One API将您的应用程序与平台集成并管理应用程序和活动

确定端点的基本URL

API与您的活动经理部署在同一主机名下。例如,如果您通过https://yourbaseurl.talon.one/访问活动经理,则updateCustomerSessionV2端点的URL为https://yourbaseurl.talon.one/v2/customer_sessions/{Id}

此PHP包由OpenAPI Generator项目自动生成

  • API版本
  • 包版本:8.0.0
  • 构建包:org.openapitools.codegen.languages.PhpClientCodegen

要求

PHP 7.1及更高版本

安装和用法

您有2种选择

  • 使用Composer(推荐)。
  • 使用发布版的源代码。

使用Composer

这是推荐的方法。

  1. 按照安装说明安装Composer。

  2. 在您的项目根目录中执行以下命令以安装此库

    composer require talon-one/talon-one-client
  3. 包含自动加载器

    require_once '/path/to/your-project/vendor/autoload.php';

使用发布版的源代码

如果您不想使用Composer,可以下载整个包。在发布页面列出了所有稳定版本。

  1. 下载所需版本的源代码,或直接从存储库检出源代码。

  2. 解压缩您下载的zip文件,并在您的项目中包含自动加载器

    require_once '/path/to/talon-one-client/vendor/autoload.php';

运行测试

要运行单元测试

composer install
./vendor/bin/phpunit

入门

  1. 遵循安装程序
  2. 如以下章节所示使用集成API或管理API。

集成API

<?php
require_once(__DIR__ . '/vendor/autoload.php');


// Configure Host, API key, & API key prefix for integration authentication
$config = \TalonOne\Client\Configuration::getDefaultConfiguration()
    ->setHost('https://yourbaseurl.talon.one')
    ->setApiKeyPrefix('Authorization', 'ApiKey-v1')
    ->setApiKey('Authorization', 'dbc644d33aa74d582bd9479c59e16f970fe13bf34a208c39d6c7fa7586968468');

// Initiating an integration api instance with the config
$apiInstance = new \TalonOne\Client\Api\IntegrationApi(
    // If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.
    // This is optional, `GuzzleHttp\Client` will be used as default when `null` is passed.
    null, // new YouClientImplementation(),
    $config
);

$customer_session_id = 'customer_session_id_example'; // string | The unique identifier for this session
$customer_session = new \TalonOne\Client\Model\NewCustomerSessionV2([
    'profileId' => 'example_prof_id',
    'couponCodes' => [
        'Cool-Summer!'
    ],
    'cartItems' => [
        new \TalonOne\Client\Model\CartItem([
            'name' => 'Hawaiian Pizza',
            'sku' => 'piz-hw-001',
            'quantity' => 1,
            'price' => 5.85
        ])
    ]
]);
$body = new \TalonOne\Client\Model\IntegrationRequest([
    'customerSession' => $customer_session,
    // Optional list of requested information to be present on the response.
    // See lib/Model/IntegrationRequest.php#getResponseContentAllowableValues for full list
    // 'responseContent' => [
    //     \TalonOne\Client\Model\IntegrationRequest::RESPONSE_CONTENT_CUSTOMER_SESSION,
    //     \TalonOne\Client\Model\IntegrationRequest::RESPONSE_CONTENT_COUPONS
    // ]
]);

try {
    // Create/Update a customer session using `updateCustomerSessionV2` function
    $integration_state = $apiInstance->updateCustomerSessionV2($customer_session_id, $body);
    print_r($integration_state);

    // Parsing the returned effects list, please consult https://developers.talon.one/Integration-API/handling-effects-v2 for the full list of effects and their corresponding properties
    foreach ($integration_state->getEffects() as $effect) {
        if ("addLoyaltyPoints" == $effect->getEffectType()) {
            // Initiating right props instance according to the effect type
            $props = new \TalonOne\Client\Model\AddLoyaltyPointsEffectProps((array) $effect->getProps());

            // Access the specific effect's properties
            echo $props->getName(), ':: ', $props->getRecipientIntegrationId(), ' just earned ',  $props->getValue(), ' points', PHP_EOL;
        }
        if ("acceptCoupon" == $effect->getEffectType()) {
            // Initiating right props instance according to the effect type
            $props = new \TalonOne\Client\Model\AcceptCouponEffectProps((array) $effect->getProps());
            // work with AcceptCouponEffectProps' properties
            // ...
        }
    }
} catch (Exception $e) {
    echo 'Exception when calling IntegrationApi->updateCustomerSessionV2: ', $e->getMessage(), PHP_EOL;
}

?>

管理API

<?php
require_once(__DIR__ . '/vendor/autoload.php');


// Configure Host, API key, & API key prefix for management authentication
$config = \TalonOne\Client\Configuration::getDefaultConfiguration()
    ->setHost('https://yourbaseurl.talon.one')
    ->setApiKeyPrefix('Authorization', 'ManagementKey-v1')
    ->setApiKey('Authorization', '2f0dce055da01ae595005d7d79154bae7448d319d5fc7c5b2951fadd6ba1ea07');

// Initiating a management api instance with the config
$apiInstance = new \TalonOne\Client\Api\ManagementApi(
    // If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.
    // This is optional, `GuzzleHttp\Client` will be used as default when `null` is passed.
    null, // new YouClientImplementation(),
    $config
);

try {
    $application_id = 7; // int | desired application identifier
    // Calling `getApplication` function
    $application = $apiInstance->getApplication($application_id);
    print_r($application);
} catch (Exception $e) {
    echo 'Exception when calling ManagementApi->getApplication: ', $e->getMessage(), PHP_EOL;
}

?>

API端点文档

所有URI相对于https://yourbaseurl.talon.one

模型文档

授权文档

api_key_v1

  • 类型: API密钥
  • API密钥参数名称: 授权
  • 位置: HTTP头

management_key

  • 类型: API密钥
  • API密钥参数名称: 授权
  • 位置: HTTP头

manager_auth

  • 类型: API密钥
  • API密钥参数名称: 授权
  • 位置: HTTP头

作者