Create promotion
Overview
Use the addPromotion method via SOAP API 6.0 to create a new promotion.
Parameters
Parameters |
Type/Description |
|||||||
---|---|---|---|---|---|---|---|---|
sessionID |
Required (String) |
|||||||
|
Output of the Login method. |
|||||||
Promotion |
Object |
|||||||
|
Name |
Optional(String) |
||||||
|
|
Promotion name |
||||||
|
Description |
Optional(String) |
||||||
|
|
Promotion description |
||||||
|
StartDate |
Optional(String) |
||||||
|
|
Starting date. The date when you set the promotion to start. Is NULL for promotions that start immediately after they're created. Format: Y-m-d |
||||||
|
EndDate |
Optional(String) |
||||||
|
|
Ending date. The date when you set the promotion to end. Is NULL for promotions that you want active indefinitely. Format: Y-m-d |
||||||
|
MaximumOrdersNumber |
Optional(Int) |
||||||
|
|
Avangate stops offering the discount when the promotion reaches the maximum number of orders. Can be NULL if you want the promotion to apply to an unlimited number of orders. |
||||||
|
MaximumQuantity |
Optional(Int) |
||||||
|
|
Discount only applies to a specific number of products, smaller than the maximum quantity you defined. Can be NULL if you want the promotion to apply to an unlimited number of units. Any extra quantity added to the cart will be sold at full price. |
||||||
|
InstantDiscount |
Optional(Boolean) |
||||||
|
|
Selecting the instant discount option will auto-apply the discount for ALL the selected products for all shoppers, without the need to enter the discount coupon. |
||||||
Coupon |
Optional(Object) |
|||||||
|
Type |
Optional(String) |
||||||
|
|
|
||||||
|
Code/Codes |
Optional(String/Array) |
||||||
|
|
Varies according to type. Send:
|
||||||
Enabled |
Optional(Boolean) |
|||||||
|
TRUE FALSE |
|||||||
ChannelType |
Optional(String) |
|||||||
|
Possible values:
|
|||||||
Type |
Optional(String) |
|||||||
|
REGULAR |
|||||||
Discount |
Optional(Object) |
|||||||
|
Type |
Optional(String) |
||||||
|
|
Discount type:
|
||||||
|
Value / Values |
Optional (Int / Array of objects) |
||||||
|
|
|
||||||
|
|
Value |
Optional(Object) |
|||||
|
|
|
Currency |
Optional (String) |
||||
|
|
|
|
ISO currency code |
||||
|
|
|
Amount |
Optional (Int) |
||||
|
|
|
|
Discount amount in corresponding currency. |
||||
|
DefaultCurrency |
Optional(String) |
||||||
|
|
ISO code |
||||||
Products |
Optional(Object) |
|||||||
|
Code |
Optional(Int) |
||||||
|
|
Unique product code that you control. |
||||||
|
PricingConfigurationCode |
Optional(String) |
||||||
|
|
Unique system generated pricing configuration code. |
||||||
|
PricingOptionCodes |
Array of strings |
||||||
|
|
Array of pricing option codes controlled by you. |
||||||
PriceThreshold |
Object |
|||||||
|
Limits discount use only when total order value (taxes included) exceeds the threshold you configure. |
|||||||
|
Amount |
Decimal |
||||||
|
|
The minimum threshold you defined for the default currency. |
||||||
|
Currency |
String |
||||||
|
|
Currency code available for the default currency of custom threshold settings. |
||||||
Translations |
Optional(Array of objects) |
|||||||
|
PromotionTranslation |
Optional(Object) |
||||||
|
|
Name |
Optional(String) |
|||||
|
|
|
Localized name corresponding to translated language. Name: Le product Language: FR |
|||||
|
|
Language |
Optional(String) |
|||||
|
|
|
||||||
Sources |
StringArray |
|||||||
|
Array of strings defining the sale source through the SRC parameter. |
|||||||
PublishToAffiliatesNetwork |
Optional(Int) |
|||||||
|
||||||||
ApplyRecurring |
Optional(String) |
|||||||
|
|
|||||||
RecurringChargesNumber |
Optional(Int) |
|||||||
|
Offer discounts for a number of recurring billing charges beyond the initial purchase. |
Response
Parameters | Type/Description |
---|---|
Promotion | Object |
Request
<?php
class Client
{
protected static $merchantCode;
protected static $loginDate;
protected static $hash;
protected static $baseUrl;
protected static $callCount = 0;
protected static $sessionId = '';
protected static $client;
public static function setCredentials($code, $key)
{
static::$merchantCode = $code;
static::$loginDate = gmdate('Y-m-d H:i:s');
static::$hash = hash_hmac('md5', strlen($code) . $code . strlen(static::$loginDate) . static::$loginDate, $key);
static::$sessionId = static::login();
}
public static function setBaseUrl($url)
{
static::$baseUrl = $url;
}
public static function login()
{
$client = static::getClient();
return $client->login(static::$merchantCode, static::$loginDate, static::$hash);
}
public static function __callStatic($name, $arguments = array())
{
$client = static::getClient();
array_unshift($arguments, static::$sessionId);
$response = call_user_func_array(array($client, $name), $arguments);
return $response;
}
protected static function getClient()
{
$opts = array(
'http'=> ['user_agent' => 'PHPSoapClient'],
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
],
);
if (null === static::$client) {
static::$client = new \SoapClient(static::$baseUrl . '?wsdl', [
'location' => static::$baseUrl,
'cache_wsdl' => WSDL_CACHE_NONE,
'stream_context' => stream_context_create($opts),
]);
}
return static::$client;
}
}
$promotionObject = new stdClass;
$promotionObject->Name = 'YOUR_PROMOTION_TITLE';
$promotionObject->Description = 'YOUR_PROMOTION_DESCRIPTION';
$promotionObject->StartDate = date('Y-m-d', strtotime('1 month ago'));
$promotionObject->EndDate = date('Y-m-d', strtotime('+1 month'));
$promotionObject->Type = 'REGULAR';
$promotionObject->Enabled = 1;
$promotionObject->MaximumOrdersNumber = 0;
$promotionObject->MaximumQuantity = 0;
$promotionObject->InstantDiscount = false;
$promotionObject->ChannelType = 'ECOMMERCE';
$promotionObject->ApplyRecurring = 'NONE';
$promotionObject->RecurringChargesNumber = 3;
$promotionObject->PublishToAffiliatesNetwork = 0;
$promotionObject->InstantDiscount = 0;
$couponObject = new stdClass;
$couponObject->Type = 'SINGLE';
$couponObject->Code = 'single_code';
$promotionObject->Coupon = $couponObject;
$discountObj = new stdClass;
$discountObj->Type = 'PERCENT';
$discountObj->Value = 80;
$promotionObject->Discount = $discountObj;
$promotionObject->Products = [$productsObj1, $productsObj2, $productsObj3];
$promotionObject->Translations = [$translation1, $translation2];
Client::setBaseUrl('https://api.avangate.com/soap/3.1/');
Client::setCredentials('YOUR_MERCHANT_CODE', 'YOUR_SECRET_KEY');
Client::login();
$response = Client::addPromotion($promotionObject);
var_dump($response);