Product group
Overview
Use the ProductGroup object to create/add and update/edit product groups.
Parameters
Parameters | Type/Description |
---|---|
Name |
Required (string) |
|
The name of the product group. |
TemplateName |
Optional (string) |
|
Leave empty to assign the Default Template to the product.
Or use the name of an active shopping cart template. |
Description |
Optional (string) |
|
The description of the product group. |
Values accepted for EXPORT_TIMEZONE_REGION in ISE
Overview
The list below contains the values accepted in the EXPORT_TIMEZONE_REGION parameter for Instant Order Search Export (ISE). Find more about ISE here.
Column "Timezone region value" holds the strings allowed in the ISE service, as a value for the EXPORT_TIMEZONE_REGION parameter. Use column "Offset hour from UTC" to check the difference in timezone between each region and UTC (Coordinated Universal Time). Column "Country / State timezone" references the country / state / capital from each respective timezone region.
Timezone region value | Offset hour from UTC | Country / State timezone |
---|---|---|
Pacific/Midway | -11:00 | Midway Island |
Pacific/Honolulu | -10:00 | Hawaii |
America/Anchorage | -09:00 | Alaska |
America/Tijuana | -08:00 | Tijuana |
America/Los_Angeles | -08:00 | Pacific Time (US & Canada) |
America/Denver | -07:00 | Mountain Time (US & Canada) |
America/Chihuahua | -07:00 | Chihuahua |
America/Chihuahua | -07:00 | Chihuahua |
America/Phoenix | -07:00 | Arizona |
America/Regina | -06:00 | Saskatchewan |
America/Mexico_City | -06:00 | Guadalajara |
America/Mexico_City | -06:00 | Guadalajara |
America/Chicago | -06:00 | Central Time (US & Canada) |
America/Managua | -06:00 | Central America |
America/Indiana/Knox | -05:00 | Indiana (East) |
America/New_York | -05:00 | Eastern Time (US & Canada) |
America/Bogota | -05:00 | Bogota |
America/Caracas | -04:30 | Caracas |
America/Santiago | -04:00 | Santiago |
America/Manaus | -04:00 | Manaus |
America/La_Paz | -04:00 | La Paz |
America/Halifax | -04:00 | Atlantic Time (Canada) |
America/St_Johns | -03:30 | Newfoundland |
America/Montevideo | -03:00 | Montevideo |
America/Godthab | -03:00 | Greenland |
America/Guyana | -03:00 | Georgetown |
America/Argentina/Buenos_Aires | -03:00 | Buenos Aires |
America/Sao_Paulo | -03:00 | Brasilia |
Atlantic/South_Georgia | -02:00 | Mid-Atlantic |
Atlantic/Cape_Verde | -01:00 | Cape Verde Is. |
Atlantic/Azores | -01:00 | Azores |
Africa/Casablanca | +00:00 | Casablanca |
Europe/London | +00:00 | Greenwich Mean Time : Dublin |
Africa/Monrovia | +00:00 | Monrovia |
Europe/Amsterdam | +01:00 | Amsterdam |
Europe/Belgrade | +01:00 | Belgrade |
Europe/Brussels | +01:00 | Brussels |
Europe/Sarajevo | +01:00 | Sarajevo |
Africa/Porto-Novo | +01:00 | West Central Africa |
Asia/Amman | +02:00 | Amman |
Europe/Bucharest | +02:00 | Athens |
Asia/Beirut | +02:00 | Beirut |
Africa/Cairo | +02:00 | Cairo |
Africa/Harare | +02:00 | Harare |
Europe/Helsinki | +02:00 | Helsinki |
Asia/Jerusalem | +02:00 | Jerusalem |
Europe/Minsk | +02:00 | Minsk |
Africa/Windhoek | +02:00 | Windhoek |
Asia/Baghdad | +03:00 | Baghdad |
Asia/Kuwait | +03:00 | Kuwait |
Europe/Moscow | +03:00 | Moscow |
Africa/Nairobi | +03:00 | Nairobi |
Asia/Tbilisi | +03:00 | Tbilisi |
Asia/Tehran | +03:30 | Tehran |
Asia/Muscat | +04:00 | Abu Dhabi |
Asia/Baku | +04:00 | Baku |
Asia/Baku | +04:00 | Caucasus Standard Time |
Indian/Mauritius | +04:00 | Port Louis |
Asia/Yerevan | +04:00 | Yerevan |
Asia/Kabul | +04:30 | Kabul |
Asia/Yekaterinburg | +05:00 | Ekaterinburg |
Asia/Karachi | +05:00 | Islamabad |
Asia/Tashkent | +05:00 | Tashkent |
Asia/Kolkata | +05:30 | Chennai |
Asia/Colombo | +05:30 | Sri Jayawardenepura |
Asia/Kathmandu | +05:45 | Kathmandu |
Asia/Almaty | +06:00 | Almaty |
Asia/Dhaka | +06:00 | Astana |
Asia/Rangoon | +06:30 | Yangon (Rangoon) |
Asia/Bangkok | +07:00 | Bangkok |
Asia/Krasnoyarsk | +07:00 | Krasnoyarsk |
Asia/Hong_Kong | +08:00 | Beijing |
Asia/Irkutsk | +08:00 | Irkutsk |
Asia/Kuala_Lumpur | +08:00 | Kuala Lumpur |
Australia/Perth | +08:00 | Perth |
Asia/Taipei | +08:00 | Taipei |
Asia/Tokyo | +09:00 | Osaka |
Asia/Seoul | +09:00 | Seoul |
Asia/Yakutsk | +09:00 | Yakutsk |
Australia/Adelaide | +09:30 | Adelaide |
Australia/Darwin | +09:30 | Darwin |
Australia/Brisbane | +10:00 | Brisbane |
Australia/Canberra | +10:00 | Canberra |
Pacific/Guam | +10:00 | Guam |
Australia/Hobart | +10:00 | Hobart |
Asia/Vladivostok | +10:00 | Vladivostok |
Asia/Magadan | +11:00 | Magadan |
Pacific/Auckland | +12:00 | Auckland |
Pacific/Fiji | +12:00 | Fiji |
Retrieve product information by code
Overview
Extract information about a product from the Avangate system using its unique ID and the code of the pricing list to which it is assigned to.
Requirements
Parameters
Parameter | Type/Description |
---|---|
sessionID | Required (string) |
Session identifier, which is the output of the Login method. An exception will be thrown if the values are incorrect. | |
productCode | Required (string) |
The unique product identifier from your system. | |
pricingListCode | Required (string) |
The unique identifier of the pricing list. |
Response
Parameter | Type/Description |
---|---|
ProductInfo | Complet object |
Complex object containing arrays of SimpleProduct and PriceOptions objects. |
Request
<?php
require('PATH_TO_AUTH'); // Authentication example: https://knowledgecenter.avangate.com/Integration/Channel_Manager_API/SOAP/02Authentication
require('PATH_TO_setPartner'); // setPartner example: https://knowledgecenter.avangate.com/Integration/Channel_Manager_API/SOAP/06Reference/Partner/00Set_partner
$productCode = 'YOUR_PRODUCT_CODE';
$pricingListCode = 'YOUR_PRICING_LIST_CODE';
try {
$ProductbyCODE= $client->getProductByCode ($sessionID, $productCode, $pricingListCode);
} catch (SoapFault $e) {
echo "ProductInfo: " . $e->getMessage();
exit;
}
var_dump ("ProductInfo", $ProductbyCODE);
Errors
Error | Description |
---|---|
INVALID_PARTNER |
No partner is set. |
INVALID_PRODUCT |
Provide a valid product ID. |
INVALID_PRICING_LIST_CODE |
Provide a valid pricing list code. |
PARTNER_PRICING_LISTS_NOT_FOUND |
There are no pricing lists with the provided code. |
PRODUCT_NOT_FOUND |
There is no product with this ID in the given pricing list. |
Place a renewal order
Overview
Renew a subscription and collect recurring revenue using the 2Checkout Subscription Reference. You can renew subscriptions for both catalog and dynamic products.
For more details about how to be PCI compliant before accepting CC payments, see this page.
Requirements
To place a renewal order, you need to provide a valid subscription reference number.
Payment methods
You can place renewal orders using the following payment methods:
- Credit cards
- PayPal
- WeChat Pay
- iDEAL
- Purchase Order
- Wire
Use the PaymentDetails object to change the payment method used in the ordering process.
Parameters
Parameters | Type/Description |
---|---|
sessionID |
Required (string) |
|
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. |
Required (Object) |
|
|
Object designed to collect all data necessary for an order, including billing, product/subscription plan and payment details. To place an order with PayPal rather than PayPal Express, use PAYPAL as the type of the PaymentDetails object and send the shopper email and a return URL as part of the PaymentMethod object. See code sample. |
SubscriptionReference |
Required (String) 2Checkout generated subscription reference number. E.q. A8C5671BFE. |
Response
Parameters | Type/Description |
---|---|
Object |
Request
<?php
require ('PATH_TO_AUTH');
$Order = new stdClass();
$Order->Currency = 'USD';
$Order->Language = "EN";
$Order->Country = 'US';
$Order->CustomerIP = '91.220.121.21';
$Order->Source = "sourceAPI.net";
$Order->LocalTime = date('Y-m-d H:i:s');
$Order->Items = array();
/**/
$Order->Items[0]->RenewalInformation = new stdClass();
$Order->Items[0]->RenewalInformation->SubscriptionReference = 'A8C5671BFE'; //subscription used in the renewal process
$Order->Items[0]->Price = new stdClass();
$Order->Items[0]->Price->Type = 'CUSTOM';
$Order->Items[0]->Price->Amount = '10';
$Order->Items[0]->PriceOptions = array('uniqscale1=4');//
$Order->MachineId = "MachineID";
$Order->BillingDetails = new stdClass();
$Order->BillingDetails->Address1 = 'Bil1ing address';
$Order->BillingDetails->Address2 = 'Billing address 2';
$Order->BillingDetails->City = 'Billing City';
$Order->BillingDetails->State = 'Billing State';
$Order->BillingDetails->CountryCode = 'US';
$Order->BillingDetails->Phone = 1231232123;
$Order->BillingDetails->Email = 'customer_details@test.com';
$Order->BillingDetails->FirstName = 'First';
$Order->BillingDetails->LastName = 'Customer';
$Order->BillingDetails->Company = 'Billing Company';
$Order->BillingDetails->Zip = '55104';
$Order->DeliveryDetails = new stdClass();
$Order->DeliveryDetails->Address1 = 'Bil1ing address';
$Order->DeliveryDetails->Address2 = 'Billing address 2';
$Order->DeliveryDetails->City = 'Billing City';
$Order->DeliveryDetails->State = 'Billing State';
$Order->DeliveryDetails->CountryCode = 'US';
$Order->DeliveryDetails->Phone = '12345';
$Order->DeliveryDetails->Email = 'customer_details@test.com';
$Order->DeliveryDetails->FirstName = 'First';
$Order->DeliveryDetails->LastName = 'Customer';
$Order->DeliveryDetails->Zip = "55104";
$Order->PaymentDetails = new stdClass();
$Order->PaymentDetails->Type = "CC";
$Order->PaymentDetails->Currency = $currency;
$Order->PaymentDetails->PaymentMethod = new stdClass();
/**/
$Order->PaymentDetails->PaymentMethod->CardNumber = "4111111111111111";
$Order->PaymentDetails->PaymentMethod->CardType = "VISA";
$Order->PaymentDetails->PaymentMethod->ExpirationYear = "2019";
$Order->PaymentDetails->PaymentMethod->ExpirationMonth = "12";
$Order->PaymentDetails->PaymentMethod->CCID = "123";
$Order->PaymentDetails->PaymentMethod->HolderName = "John Doe";
$Order->PaymentDetails->PaymentMethod->RecurringEnabled = TRUE;
$Order->PaymentDetails->PaymentMethod->HolderNameTime = 1;
$Order->PaymentDetails->PaymentMethod->CardNumberTime = 1;
/**/
try {
$newOrder = $client->placeOrder($sessionID, $Order);
}
catch (SoapFault $e) {
echo "newOrder: " . $e->getMessage();
exit;
}
var_dump("newOrder", $Order);
Subscription end user update
Overview
Use the updateSubscriptionEndUser method to update the details of a subscription’s end user. This method changes per-subscription end user data and not customer details.
Parameters
Parameters | Type/Description |
---|---|
sessionID |
Required (string) |
|
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. |
SubscriptionReference |
Required (string) |
Unique, system-generated subscription identifier. |
|
EndUser |
Required (Object) |
Use this object to update end user information. |
Response
Parameters | Type/Description |
---|---|
Boolean |
true or false depending on whether the changes were successful or not. |
Request
<?php
$host = "https://api.2checkout.com";
$client = new SoapClient($host . "/soap/4.0/?wsdl", array(
'location' => $host . "/soap/4.0/",
"stream_context" => stream_context_create(array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false
)
))
));
function hmac($key, $data)
{
$b = 64; // byte length for md5
if (strlen($key) > $b) {
$key = pack("H*", md5($key));
}
$key = str_pad($key, $b, chr(0x00));
$ipad = str_pad('', $b, chr(0x36));
$opad = str_pad('', $b, chr(0x5c));
$k_ipad = $key ^ $ipad;
$k_opad = $key ^ $opad;
return md5($k_opad . pack("H*", md5($k_ipad . $data)));
}
$merchantCode = "YOUR_MERCHANT_CODE";// your account's merchant code available in the 'System settings' area of the cPanel: https://secure.2checkout.com/cpanel/account_settings.php
$key = "YOUR_SECRET_KEY";// your account's secret key available in the 'System settings' area of the cPanel: https://secure.2checkout.com/cpanel/account_settings.php
$now = gmdate('Y-m-d H:i:s'); //date_default_timezone_set('UTC')
$string = strlen($merchantCode) . $merchantCode . strlen($now) . $now;
$hash = hmac($key, $string);
try {
$sessionID = $client->login($merchantCode, $now, $hash);
}
catch (SoapFault $e) {
echo "Authentication: " . $e->getMessage();
exit;
}
$subscriptionreference = '8F749B63E7';
$EndUser = new stdClass ();
$EndUser->Address1 = 'Address line 1';
$EndUser->Address2 = 'Address line 2';
$EndUser->City = 'LA';
$EndUser->Company = 'Company Name';
$EndUser->CountryCode = 'us';
$EndUser->Email = 'customerAPI@2checkout.com';
$EndUser->FirstName = 'New Customer';
$EndUser->Language = 'en';
$EndUser->LastName = '2Checkout';
$EndUser->Phone = '1234567890';
$EndUser->State = 'California';
$EndUser->Zip = '90210';
$EndUser->Fax = null;
try {
$newEndUser = $client->updateSubscriptionEndUser($sessionID, $subscriptionreference, $EndUser);
}
catch (SoapFault $e) {
echo "newEndUser: " . $e->getMessage();
exit;
}
var_dump("newEndUser", $newEndUser);
Enable recurring billing
Overview
Use the enableRecurringBilling method to switch on the automatic renewal system for a subscription that's manually renewable.
Parameters
Parameters |
Type/Description |
sessionID |
Required (string) |
|
Session identifier, the output of the Login method. Include sessionID into all your requests. Avangate throws an exception if the values are incorrect. The sessionID expires in 10 minutes. |
SubscriptionReference |
Required (string) |
Unique, system-generated subscription identifier. |
Response
Boolean |
true or false depending on whether the changes were successful or not. |
Request
<?php
$host = "https://api.avangate.com";
$client = new SoapClient($host . "/soap/4.0/?wsdl", array(
'location' => $host . "/soap/4.0/",
"stream_context" => stream_context_create(array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false
)
))
));
function hmac($key, $data)
{
$b = 64; // byte length for md5
if (strlen($key) > $b) {
$key = pack("H*", md5($key));
}
$key = str_pad($key, $b, chr(0x00));
$ipad = str_pad('', $b, chr(0x36));
$opad = str_pad('', $b, chr(0x5c));
$k_ipad = $key ^ $ipad;
$k_opad = $key ^ $opad;
return md5($k_opad . pack("H*", md5($k_ipad . $data)));
}
$merchantCode = "YOUR_MERCHANT_CODE";// your account's merchant code available in the 'System settings' area of the cPanel: https://secure.avangate.com/cpanel/account_settings.php
$key = "YOUR_SECRET_KEY";// your account's secret key available in the 'System settings' area of the cPanel: https://secure.avangate.com/cpanel/account_settings.php
$now = gmdate('Y-m-d H:i:s'); //date_default_timezone_set('UTC')
$string = strlen($merchantCode) . $merchantCode . strlen($now) . $now;
$hash = hmac($key, $string);
try {
$sessionID = $client->login($merchantCode, $now, $hash);
}
catch (SoapFault $e) {
echo "Authentication: " . $e->getMessage();
exit;
}
$SubscriptionReferenceTest = '48F5AC7011';
try {
$enabledSubscriptionRecurring = $client->enableRecurringBilling($sessionID, $SubscriptionReferenceTest);
}
catch (SoapFault $e) {
echo "enabledSubscriptionRecurring: " . $e->getMessage();
exit;
}
var_dump("enabledSubscriptionRecurring", $enabledSubscriptionRecurring);
Pricing options
Overview
Use this object to add/create and edit/update price options for your account.
Parameters
Parameters | Type/Description | |||
---|---|---|---|---|
PriceOptionsGroup |
Object |
|||
Name |
String |
|||
|
Price option group name. Use this parameter when adding a new price options group. To edit the name of a price option group use the Name parameter under the Translations object. |
|||
Description |
String |
|||
|
Pricing option group description. |
|||
Translations |
Array of objects |
|||
|
Details below. |
|||
|
Name |
String |
||
|
|
Product pricing options group name, localized under Options. |
||
|
Description |
String |
||
|
|
Product pricing options group description, localized under Options. |
||
|
Language |
String |
||
|
|
ISO language code. (ISO 639-1 two-letter code). |
||
Code |
String |
|||
|
Unique code that The 2Checkout system generates or set for each pricing options group. |
|||
Type |
String |
|||
|
The type of the pricing options group. Possible values: · RADIO · CHECKBOX · INTERVAL · COMBO |
|||
Options |
Array of objects |
|||
|
Details below. |
|||
|
Name |
String |
||
|
|
Pricing option child name. |
||
|
Description |
String |
||
|
|
Pricing option child description. |
||
|
Translations |
Array of objects |
||
|
|
Details above. |
||
|
|
Name |
String |
|
|
|
|
Localized product pricing options group name under PriceOptionGroup. Localized pricing option child name under Options. |
|
|
|
Description |
String |
|
|
|
|
Localized product pricing options group description under PriceOptionGroup. Localized pricing option child description under Options. |
|
|
|
Language |
String |
|
|
|
|
ISO language code. (ISO 639-1 two-letter code). |
|
|
Value |
String |
||
|
|
The code you set or that the 2Checkout system generated for each pricing option child inside a pricing options group parent. |
||
|
ScaleMin |
Int |
||
|
|
The minimum value of a scale interval set for each pricing option child inside a pricing options group parent of the type INTERVAL. |
||
|
ScaleMax |
Int |
||
|
|
The maximum value of a scale interval set for each pricing option child inside a pricing options group parent of the type INTERVAL. |
||
|
SubscriptionImpact |
Object |
||
|
|
Details below. |
||
|
Months |
String |
||
|
|
The value in months the 2Checkout system adds or subtracts from the initial billing cycle of a subscription. |
||
|
Impact |
String |
||
|
|
Possible values: · ADD · SUBTRACT · LIFETIME |
||
|
PriceImpact |
Object |
||
|
|
Details below. |
||
|
|
ImpactOn |
String |
|
|
|
|
Possible values:
|
|
|
|
Impact |
String |
|
|
|
|
Impact on price per unit:
|
|
|
|
Percent |
String |
|
|
|
|
The value of the percentage out of the price per product unit, when you use PERCENT for Method. |
|
|
|
Method |
String |
|
|
|
|
Possible values: · PERCENT · FIXED |
|
|
|
Amounts |
Array of objects. |
|
|
|
|
Details below. |
|
|
|
|
Currency |
String |
|
|
|
|
Currency ISO code - ISO 4217. |
|
|
|
Amount |
String |
|
|
|
|
The amount defined for each specific currency active for your account, when you use FIXED for Method. |
|
Default |
Boolean |
||
|
|
TRUE for preselected options. Missing for options that are not preselected. |
Retrieve installments
Overview
Use the getInstallments method to retrieve information about the number of installments available for a specific selection of products/services.
Supported payment methods
Credit/Debit cards: local Visa and MasterCard in Brazil and Turkey.
Parameters
Parameters | Type/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. |
Object / Required | |
|
An object designed to collect all data necessary for an order, including billing, product/subscription plan, and payment details. |
Response
Parameters | Type/Description | |
---|---|---|
InstallmentsOption |
Array of objects |
|
|
Details below. |
|
|
Number |
Int |
|
|
The number of installments. |
|
Amount |
Double |
|
|
Standalone installment value. (Total order value/Number of installments) |
|
Currency |
String |
|
|
Order currency. |
Request
class Configuration
{
public const MERCHANT_CODE = '';
public const MERCHANT_KEY = '';
public const URL = 'http://api.avangate.local/rpc/6.0';
public const ACTION = 'getInstallments';
public const ADDITIONAL_OPTIONS = null;
//array or JSON
public const PAYLOAD = <<<JSON
{
"Amount" : 500,
"Country": "BR",
"Currency": "BRL",
"FiscalCode" :"345.675.677-7",
"EesToken": ["c49702ea-b0c5-4d39-9f5b-ba43ccf26785"]
}
JSON;
}
class Client
{
private const LOGIN_METHOD = 'login';
private $calls = 1;
private $sessionId;
private function generateAuth(): array
{
$merchantCode = Configuration::MERCHANT_CODE;
$key = Configuration::MERCHANT_KEY;
$date = gmdate('Y-m-d H:i:s');
$string = strlen($merchantCode) . $merchantCode . strlen($date) . $date;
$hash = hash_hmac('md5', $string, $key);
return compact('merchantCode', 'date', 'hash');
}
public function login(string $url)
{
$payload = $this->generateAuth();
$response = $this->call($url, array_values($payload), self::LOGIN_METHOD);
$this->sessionId = $response['result'];
}
public function call(
string $url = Configuration::URL,
$payload = Configuration::PAYLOAD,
string $action = Configuration::ACTION
): ?array {
if (empty($this->sessionId) && $action !== self::LOGIN_METHOD) {
$this->login($url);
}
if (is_string($payload)) {
$payload = json_decode($payload, true);
}
if (!empty($this->sessionId)) {
$payload = [$this->sessionId, $payload, Configuration::ADDITIONAL_OPTIONS];
}
$payload = array_filter($payload);
$request = json_encode([
'jsonrpc' => '2.0',
'method' => $action,
'params' => $payload,
'id' => $this->calls++,
]);
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($curl, CURLOPT_SSLVERSION, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Accept: application/json', 'Cookie: XDEBUG_SESSION=PHPSTORM'));
curl_setopt($curl, CURLOPT_POSTFIELDS, $request);
$response = curl_exec($curl);
if(empty($response)) {
die('Server unavailable');
}
echo $response . '</br>';
return json_decode($response, true);;
}
}
$client = new Client();
$result = $client->call();
var_dump($result);
Update promotion
Overview
Use the updatePromotion method via JSON-RPC API 4.0 to alter the details of an existing promotion.
Parameters
Parameter | Type/Description |
---|---|
sessionID | Required (string) |
Output of the Login method. | |
promotion | Required (object) |
Promotion object that you want to update. |
Response
Parameter | Type/Description |
---|---|
promotion | Updated promotion object. |
Request
<?php
function callRPC($Request, $host, $Debug = true) {
$curl = curl_init($host);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_VERBOSE, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($curl, CURLOPT_SSLVERSION, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Accept: application/json'));
$RequestString = json_encode($Request);
curl_setopt($curl, CURLOPT_POSTFIELDS, $RequestString);
if ($Debug) {
$RequestString;
}
$ResponseString = curl_exec($curl);
if ($Debug) {
$ResponseString;
}
if (!empty($ResponseString)) {
var_dump($ResponseString);
$Response = json_decode($ResponseString);
if (isset($Response->result)) {
return $Response->result;
}
if (!is_null($Response->error)) {
var_dump($Request->method, $Response->error);
}
} else {
return null;
}
}
$host = 'https://api.avangate.com/rpc/3.1/';
$merchantCode = "YOUR_MERCHANT_CODE"; // your account's merchant code available in the 'System settings' area of the cPanel: https://secure.avangate.com/cpanel/account_settings.php
$key = "YOUR_SECRET_KEY"; // your account's secret key available in the 'System settings' area of the cPanel: https://secure.avangate.com/cpanel/account_settings.php
$string = strlen($merchantCode) . $merchantCode . strlen(gmdate('Y-m-d H:i:s')) . gmdate('Y-m-d H:i:s');
$hash = hash_hmac('md5', $string, $key);
$i = 1;
$jsonRpcRequest = new stdClass();
$jsonRpcRequest->jsonrpc = '2.0';
$jsonRpcRequest->method = 'login';
$jsonRpcRequest->params = array($merchantCode, gmdate('Y-m-d H:i:s'), $hash);
$jsonRpcRequest->id = $i++;
$sessionID = callRPC($jsonRpcRequest, $host);
// Retrieve promotion details
$promotionCode = 'PROMOTION_CODE'; // code of the promotion that you want to update
$jsonRpcRequest = array (
'jsonrpc' => '2.0',
'id' => $i++,
'method' => 'getPromotion',
'params' => array($sessionID, $promotionCode)
);
//var_dump (callRPC((Object)$jsonRpcRequest, $host));
// Keep the promotion you want to update in $existingPromotion
$existingPromotion = callRPC((Object)$jsonRpcRequest, $host);
// Set the fields to update
$existingPromotion->Description = 'Updated description';
// Update the promotion
$jsonRpcRequest = array (
'jsonrpc' => '2.0',
'id' => $i++,
'method' => 'updatePromotion',
'params' => array($sessionID, $existingPromotion)
);
var_dump (callRPC((Object)$jsonRpcRequest, $host));