Overview
Use the getCrossSellCampaign method to extract information about the cross-sell campaign identified by the provided campaign code.
Request parameters
Parameters | Type | Required/Optional | Description |
---|---|---|---|
sessionID |
String | Required |
Session identifier, the output of the Login method. Include sessionID into all your requests. 2Checkout throws an exception if the values are incorrect. The sessionID expires in 10 minutes. |
CampaignCode |
String | Required | The campaign code. |
Request sample
<?php
declare(strict_types=1);
class Configuration
{
public const MERCHANT_CODE = '';
public const MERCHANT_KEY = '';
public const URL = 'http://api.2checkout.com/soap/6.0';
public const ACTION = 'getCrossSellCampaign';
public const ADDITIONAL_OPTIONS = '2Xrl83KSnemB5XG3ea+9hQ==';
//array or JSON
public const PAYLOAD = <<<JSON
{}
JSON;
}
class Client
{
public function call(
string $url = Configuration::URL,
$payload = Configuration::PAYLOAD,
string $action = Configuration::ACTION
): ?object
{
if (is_array($payload)) {
$payload = json_encode($payload);
}
if (!empty($payload)) {
// SoapClient works with objects(StdClass)
$payload = json_decode($payload);
}
$soapClient = $this->getClient($url);
$sessionId = $this->getSession($soapClient);
$args = array_filter([$sessionId, Configuration::ADDITIONAL_OPTIONS]);
return $soapClient->$action(...$args);
}
public function getClient(string $url): SoapClient
{
return new SoapClient(
$url . '?wsdl',
[
'location' => $url,
'cache_wsdl' => WSDL_CACHE_NONE,
]
);
}
public function getSession(SoapClient $client)
{
$date = gmdate('Y-m-d H:i:s');
$merchantCode = Configuration::MERCHANT_CODE;
$key = Configuration::MERCHANT_KEY;
$string = strlen($merchantCode) . $merchantCode . strlen($date) . $date;
$hash = hash_hmac('md5', $string, $key);
$client->__setCookie('XDEBUG_SESSION', 'PHPSTORM');
return $client->login($merchantCode, $date, $hash);
}
}
try {
$client = new Client();
var_dump($client->call());
} catch (Exception $ex) {
var_dump($ex);
}
Response
Parameters | Type | Required/Optional | Description |
---|---|---|---|
CampaignCode |
String |
Required |
The campaign code that can be used when placing orders. |
MasterProducts |
Array of strings |
Required |
An array of product codes to apply to this campaign. |
DisplayType |
String |
Required |
The display type of the campaign; Can be cart, review, finish. |
DisplayInEmail |
Boolean |
Required |
Determines if the campaign will be displayed in payment receipt emails. Can be 'true' or 'false'. |
Products |
Array of objects |
Required |
An array of objects containing the product codes pointing to the promoted products when tied to each master product, the discount value, and the discount type (can only be percent). |
ProductCode |
String |
Required |
Product code of the product to be recommended to the shopper. |
Discount |
Float |
Required |
Value of the discount. |
DiscountType |
String |
Required |
Can only be 'PERCENT'. |
Name |
String |
Required |
Name of the campaign. |
CampaignStatus |
String |
Optional |
The status of the cross-sell campaign. |
StartDate |
String |
Required |
The date when the cross-sell campaign starts, formatted as YYYY-MM-DD. |
EndDate |
String |
Required |
The date when the cross-sell campaign ends, formatted as YYYY-MM-DD. |
CampaignOwnerType |
String |
Required |
Campaign owner type: Can be either MERCH or AFF. |