Add product
Request parameters
Parameter
Type / Description
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 = 'addProduct';
public const ADDITIONAL_OPTIONS = null;
//array or JSON
public const PAYLOAD = <<<JSON
{
"AvangateId": null,
"Enabled": true,
"GeneratesSubscription": true,
"GiftOption": false,
"LongDescription": "Some long description",
"ProductCode": "API_Imported_Product_1",
"ProductGroupCode": "9652CDA441",
"TaxCategory": "5db74b57-98a5-4fc1-b559-aee8eba3f046",
"Tangible": 0,
"Fulfillment": "",
"Platforms": [\
{\
"Category": "Mobile",\
"IdPlatform": "23",\
"PlatformName": "Android"\
},\
{\
"Category": "Mobile",\
"IdPlatform": "20",\
"PlatformName": "iPhone"\
},\
{\
"Category": "Desktop",\
"IdPlatform": "32",\
"PlatformName": "Windows 10"\
}\
],
"Prices": [],
"PricingConfigurations": [\
{\
"BillingCountries": [],\
"Code": "54DCBC3DC8",\
"Default": true,\
"DefaultCurrency": "USD",\
"Name": "2Checkout Subscription's Price Configuration Marius",\
"PriceOptions": [\
{\
"Code": "SUPPORT",\
"Required": true\
},\
{\
"Code": "USERS",\
"Required": true\
},\
{\
"Code": "BACKUP",\
"Required": false\
}\
],\
"PriceType": "NET",\
"Prices": {\
"Regular": [\
{\
"Amount": 99,\
"Currency": "USD",\
"MaxQuantity": "99999",\
"MinQuantity": "1",\
"OptionCodes": []\
},\
{\
"Amount": 0,\
"Currency": "EUR",\
"MaxQuantity": "99999",\
"MinQuantity": "1",\
"OptionCodes": []\
}\
],\
"Renewal": []\
},\
"PricingSchema": "DYNAMIC"\
}\
],
"ProductCategory": "Audio & Video",
"ProductImages": [\
{\
"Default": true,\
"URL": "https://store.avancart.com/images/merchant/ef0b9a69f90b1ab0228784ccc7d52136/products/box-2.jpg"\
}\
],
"ProductName": "Product Name 01",
"ProductType": "REGULAR",
"ProductVersion": "1.0",
"PurchaseMultipleUnits": true,
"ShortDescription": "some short description",
"SubscriptionInformation": {
"BillingCycle": "1",
"BillingCycleUnits": "M",
"BundleRenewalManagement": "GLOBAL",
"ContractPeriod": {
"Action": "RESTART",
"EmailsDuringContract": true,
"IsUnlimited": true,
"Period": -1,
"PeriodUnits": "D"
},
"DeprecatedProducts": [],
"GracePeriod": {
"IsUnlimited": false,
"Period": "7",
"PeriodUnits": "D",
"Type": "CUSTOM"
},
"IsOneTimeFee": false,
"RenewalEmails": {
"Settings": {
"AutomaticRenewal": {
"After15Days": false,
"After5Days": false,
"Before15Days": false,
"Before1Day": false,
"Before30Days": false,
"Before7Days": true,
"OnExpirationDate": true
},
"ManualRenewal": {
"After15Days": false,
"After5Days": false,
"Before15Days": false,
"Before1Day": false,
"Before30Days": false,
"Before7Days": true,
"OnExpirationDate": true
}
},
"Type": "CUSTOM"
},
"UsageBilling": 0
},
"SystemRequirements": "",
"Translations": [\
{\
"Description": "some description",\
"Language": "ZH",\
"LongDescription": "some long description",\
"Name": "some name",\
"SystemRequirements": "",\
"TrialUrl": "url",\
"TrialDescription": "TrialDescription"\
}\
],
"TrialDescription": "",
"TrialUrl": ""
}
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, $payload]);
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
Last updated
Was this helpful?