Skip to main content

PHP

The PHP SDK supports both Integration API and Management API, and it can be used on PHP 5.5 or newer.

<?php
require_once(__DIR__ . '/vendor/autoload.php');
// Configure Host, API key, & API key prefix for integration authentication
$config = \TalonOne\Client\Configuration::getDefaultConfiguration()
->setHost('https://mycompany.europe-west1.talon.one')
->setApiKeyPrefix('Authorization', 'ApiKey-v1')
->setApiKey('Authorization', 'dbc644d33aa74d582bd9479c59e16f970fe13bf34a208c39d6c7fa7586968468');
// Initiating an integration api instance with the config
$this->apiInstance = new \TalonOne\Client\Api\IntegrationApi($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.
// Consult the UpdateCustomerSessionV2 endpoint docs for a full list of supported values
// '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 = $this->apiInstance->updateCustomerSessionV2($customer_session_id, $body);
print_r($integration_state);
} catch (Exception $e) {
echo 'Exception when calling IntegrationApi->updateCustomerSessionV2: ', $e->getMessage(), PHP_EOL;
}
?>