Skip to main content

Add special price promotion

Overview

Use the AddSpecialPricePromotion method to create a promotion with a special price.

Request parameters

Parameters Type Required Description
Promotion Object Required Contains details of the promotion.
PriceMatrix Array of Objects Required Only for this type of promotion. It is generated by getPriceMatrix and used to set promotion special prices.
Coupon Object Required Type of coupon applied to the promotion.

Request sample

<?php

require('PATH_TO_AUTH');

$promotionObject = new stdClass;
$promotionObject->Name = 'YOUR_PROMOTION_TITLE';
$promotionObject->Description = 'YOUR_PROMOTION_DESCRIPTION';
$promotionObject->DefaultCurrency = "EUR";
$promotionObject->StartDate = date('Y-m-d', strtotime('1 month ago'));
$promotionObject->EndDate = date('Y-m-d', strtotime('+1 month'));
$promotionObject->Type = 'SPECIAL_PRICE';
$promotionObject->Enabled = 1;
$promotionObject->MaximumOrdersNumber = 0;
$promotionObject->MaximumQuantity = 0;
$promotionObject->InstantDiscount = false;
$promotionObject->ApplyRecurring = 'NONE';
$promotionObject->RecurringChargesNumber = 3;
$promotionObject->InstantDiscount = 0;

$couponObject = new stdClass;
$couponObject->Type = 'SINGLE';
$couponObject->Code = 'single_code';
$promotionObject->Coupon = $couponObject;

$productsObj1 = new stdClass;
$productsObj1->Code = 'test';
$promotionObject->Products = [$productsObj1];


$priceMatrixDefinition1 = new stdClass;
$priceMatrixDefinition1->ProductCode = "test";
$priceMatrixDefinition1->PricingConfigurationCode = "738C6A2049";
$priceMatrixDefinition1->OptionHash = "708e43960c4edc42f14cf388bcb24bde";

$option1 = new stdClass;
$option1->GroupName = "Units";
$option1->OptionText = "1 - maximum";

$price1 = new stdClass;
$price1->Value = 10;
$price1->Currency = "USD";
$price2 = new stdClass;
$price2->Value = 15;
$price2->Currency = "EUR";

$priceMatrixDefinition1->Options = [$option1];
$priceMatrixDefinition1->Prices = [$price1, $price2];

$promotionObject->PriceMatrix = [$priceMatrixDefinition1];


$jsonRpcRequest = array (
'jsonrpc' => '2.0',
'id' => $i++,
'method' => 'addPromotion',
'params' => array($sessionID, $promotionObject),
);

$result = callRPC((object)$jsonRpcRequest, $host);
var_dump($result);

Response

{
  "jsonrpc": "2.0",
  "id": 2,
  "result": {
    "Code": "M99QQ7Q97A",
    "Name": "Promo percentage REST",
    "Description": "Promo description1",
    "StartDate": "2019-11-30",
    "EndDate": "2100-12-31",
    "MaximumOrdersNumber": -1,
    "MaximumQuantity": "1",
    "InstantDiscount": false,
    "Coupon": {
      "Type": "MULTIPLE",
      "Codes": [
        "code1",
        "code2"
      ]
    },
    "Enabled": true,
    "Type": "SPECIAL_PRICE",
    "Products": [
      {
        "Code": "test",
        "PricingOptionCodes": null,
        "PricingConfigurationCode": null
      }
    ],
    "Translations": [
      {
        "Name": "Promo percentage REST",
        "Language": "EN"
      }
    ],
    "Sources": [],
    "ApplyRecurring": "NONE",
    "RecurringChargesNumber": "0",
    "DefaultCurrency": "EUR",
    "PriceMatrix": [
      {
        "ProductCode": "test",
        "PricingConfigurationCode": "738C6A2049",
        "OptionHash": "708e43960c4edc42f14cf388bcb24bde",
        "Options": [
          {
            "GroupName": "Units",
            "OptionText": "1 - maximum"
          }
        ],
        "Prices": [
          {
            "Value": 31.15600000000014,
            "Currency": "CAD"
          },
          {
            "Value": 20,
            "Currency": "EUR"
          },
          {
            "Value": 40,
            "Currency": "USD"
          },
          {
            "Value": 1587.5251590697817,
            "Currency": "ARS"
          },
          {
            "Value": 18541.128586270122,
            "Currency": "CLP"
          },
          {
            "Value": 18.132399999999887,
            "Currency": "GBP"
          },
          {
            "Value": 2447.1999999999794,
            "Currency": "JPY"
          },
          {
            "Value": 499.51800000000384,
            "Currency": "MXN"
          },
          {
            "Value": 97.536,
            "Currency": "RON"
          },
          {
            "Value": 1846.0500000000052,
            "Currency": "RUB"
          },
          {
            "Value": 601.8285443739301,
            "Currency": "UAH"
          },
          {
            "Value": 384.3740000000019,
            "Currency": "ZAR"
          }
        ]
      }
    ]
  }
}

Retrieve partner information

Overview

Access partner details using the unique codes set to identify them.

Parameters

Parameters Type/Description
sessionID Required (string)
  Session identifier, output by the Login method. An exception will be thrown if the values are incorrect.
partnerCode Required (string)
  The unique partner code.

Response

Parameter Type/Description
Partner Object
  Partner information object.

Request

<?php

require('PATH_TO_AUTH'); // Authentication example: https://knowledgecenter.avangate.com/Integration/Channel_Manager_API/SOAP/02Authentication

$partnerCode = 'YOUR_PARTNER_CODE'; // Partner code corresponding to the partner you want to get information for

try {
    $PartnerDetails= $client->getPartnerByCode($sessionID, $partnerCode);
} catch (SoapFault $e) {
    echo "Partner: " . $e->getMessage();
    exit;
}
var_dump ("Partner", $PartnerDetails);

?>

Errors

Error Description

INVALID_PARTNER

Partner code is mandatory.

INVALID_PARTNER

Partner code provided is not associated with an active partner account in the Avangate system.

Cancel subscription pause

Overview

Use the cancelRenewalPause method to cancel a subscription's pause and change its status.

Request Parameters

Parameters Required Type/Description
merchantCode Required String. Unique merchant ID code that can be found in the Merchant Control Panel.
SubscriptionRef Required String. The system-generated reference code of the subscription.

Request Example

<?php
 
$host = 'https://api.2checkout.com/rpc/6.0/';
 
$merchantCode = "22322"; // MERCHANT CODE
$key = "q0^H5i?q3=)x9NP02W3q"; // MERCHANT SECRET KEY
 
$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; // counter for api calls
// call login
$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);
var_dump("session id:" . $sessionID);
 
// call api methods below
 
 
$SubscriptionRef = 'FA27DD5072';
 
$jsonRpcRequest = array (
    'jsonrpc' => '2.0',
    'method' => 'cancelRenewalPause',
    'params' => array($sessionID, $SubscriptionRef),
    'id' => $i++
);
var_dump ("cancelRenewalPause", callRPC((Object)$jsonRpcRequest, $host));
print ("If TRUE pause is canceled");
 
 
/* $jsonRpcRequest = array (
    'jsonrpc' => '2.0',
    'method' => 'getRenewalPause',
    'params' => array($sessionID, $SubscriptionRef),
    'id' => $i++
);
var_dump ("getRenewalPause", callRPC((Object)$jsonRpcRequest, $host));
*/
function callRPC($Request, $hostUrl, $Debug = false) {
    $curl = curl_init($hostUrl);
    curl_setopt( $curl, CURLOPT_POST, 1);
    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);
 
    curl_setopt( $curl, CURLOPT_COOKIE, "XDEBUG_SESSION=PHPSTORM");
 
    if (stristr($hostUrl, 'sandboxdev') || stristr($hostUrl, 'git-sb')) {
        curl_setopt( $curl, CURLOPT_PROXY, 'localhost:3128');
        //  curl_setopt( $curl, CURLOPT_PROXY, 'proxy.avangate.local:8080');
        //  curl_setopt( $curl, CURLOPT_PROXYUSERPWD, 'andrei.avramica:pw'); // for authenticated proxies
    }
 
    $ResponseString = curl_exec ($curl);
 
    if (!empty($ResponseString)) {
        $Response = json_decode ($ResponseString,false);
        if (isset($Response->error) && !is_null($Response->error)) {
            var_dump($Response->error) ;
            return null;
        }
 
        return $Response->result;
    } else {
        return null;
    }
}

Response Parameters

Parameters Type/Description
SubscriptionRef

Boolean

  • TRUE - if the call was successful and a pause was scheduled; 
  • FALSE - if the pause mechanism is not enabled for the merchant OR any of the eligibility conditions were not met OR pause is not enabled for the product OR the maximum pause duration for the product was exceeded. In this case, the system also throws the following message: "The subscription is not eligible for pause."
   

Response Example

{
    “StartDate”: “2020-02-19 22:20:30",
    “ResumeDate”: “2020-03-01 18:00:00",
    “PauseReason”: “vacation leave”
} 

Next renewal price

Overview

Retrieve the costs of the next subscription renewal.

Attributes

Parameters Type/Description

NetPrice

Double

 

Price without taxes

NetCurrency

String

 

Currency for the price without taxes. The currency ISO code used for the payment - ISO 4217.

FinalPrice

Double

 

Price with taxes

FinalCurrency

String

 

Currency used for prices with taxes. The currency ISO code used for the payment - ISO 4217.

 

Retrieve a subscription

Overview

Extract information on a single subscription. Use the getSubscription method to retrieve details about a subscription.

Subscriptions can be retrieved starting with 5 minutes after their orders are generated in the 2Checkout system. 

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.

Response

Parameters Type/Description

Subscription

Object

Request

<?php

require ('PATH_TO_AUTH');

$subscriptionReference = 'YOUR_SUBSCRIPTION_REFERENCE';

$jsonRpcRequest = array (
'method' => 'getSubscription',
'params' => array($sessionID, $subscriptionReference),
'id' => $i++,
'jsonrpc' => '2.0');

var_dump (callRPC((Object)$jsonRpcRequest, $host, true));

Delay subscription start

Overview

In scenarios in which you're responsible for fulfilling orders, you can control the moment when 2Checkout generates subscriptions. Synchronize the subscription start date with the moment when you confirm fulfillment in the 2Checkout system.

By default, the lifecycle of subscriptions starts when 2Checkout receives the payment confirmation.

Availability

All 2Checkout accounts.

Requirements

Custom subscription start dates are available only for products:

  • For which subscriptions are generated.
  • In scenarios in which you're responsible for the fulfillment (delivery made by you).

Set-up

To set up a subscription start date for one of your offerings:

  1. Log in to your Merchant Control Panel.
  2. Navigate to Setup → Products, and search to identify the product for which you want to set a subscription start date other than the default, and click the Edit button.

delay subscription start_edit.png

3. Select the Fulfillment tab and select the Fulfillment made by you option.

4. Check the Start subscription after fulfillment option. If unchecked, the subscription starts on payment confirmation date.

delay subscription start_fulfillment.png

The new setting comes into effect only for new orders placed by your customers after you enable this option. You will need to confirm fulfillment yourself, either manually, or through IDN. Subscriptions sold to customers for specific products will only start when fulfillment confirmation is received.

Customer data 

2Checkout generates customer data automatically along with subscriptions. In case you use either the 2Checkout customer reference or the External customer reference during the purchase process to sell a subscription to an existing customer, 2Checkout assigns the subscription to the existing customer entity.

Product group

Overview

Use the ProductGroup object to create/add and update/edit product groups. 

Parameters 

ProductGroup

Object

Name

Required (string)

 

The name of the product group.

Code Required (string)
  Unique, system-generated identifier assigned to product groups. 

TemplateName

Required (string)

 

Leave empty to assign the Default Template to the product.

 

Or use the name of an active shopping cart template.

Description

Required (string)

 

The description of the product group.

 

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.

 

Update a subscription plan/product

Overview

Use the updateProduct method to update the configuration of a subscription plan/product you already configured for your account. 

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.

Product

Required (object)

 

Use this object to configure your subscription plans/products.

 

You can update/edit all parameters, except the following:

  • AvangateID
  • ProductType

Exceptions

When updating a subscription plan/product, you also update its PricingConfigurations. However, you cannot modify:

  • The pricing configuration CODE.
  • The PricingSchema from DYNAMIC to FLAT or vice versa.

Request

<?php

require ('PATH_TO_AUTH');

$ProductCode = 'NewProdCodeAPI12345';

$jsonRpcRequest = array (
'jsonrpc' => '2.0',
'id' => $i++,
'method' => 'getProductByCode',
'params' => array($sessionID, $ProductCode)
);

$myProduct = callRPC($jsonRpcRequest, $host);

$myProduct->ProductName = 'Edited_From_API_Again';

var_dump ($myProduct);

$jsonRpcRequest = array (
'jsonrpc' => '2.0',
'id' => $i++,
'method' => 'updateProduct',
'params' => array($sessionID, $myProduct)
);

$updatedProduct = callRPC($jsonRpcRequest, $host);
var_dump ($updatedProduct);

?>

Response

bool(true)

Retrieve a price option group

Overview

Use the getPriceOptionGroup method to extract information about a specific price option group that you configured.

Parameters

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.

GroupCode

Required (string)

 

The code that the Avangate system generates or that you set for the product pricing options group.

Response

PriceOptionGroup

Array of objects

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 = "YOURCODE123"; //your account's merchant code available in the 'System settings' area of the cPanel: https://secure.avangate.com/cpanel/account_settings.php
$key          = "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;
}

$GroupCode = 'USERS';

try {
    $existentPriceOptionGroup = $client->getPriceOptionGroup($sessionID, $GroupCode);
}

catch (SoapFault $e) {
    echo "existentPriceOptionGroup: " . $e->getMessage();
    exit;
}

var_dump("existentPriceOptionGroup", $existentPriceOptionGroup);

?>

Need help?

Do you have a question? If you didn’t find the answer you are looking for in our documentation, you can contact our Support teams for more information. If you have a technical issue or question, please contact us. We are happy to help.

Not yet a Verifone customer?

We’ll help you choose the right payment solution for your business, wherever you want to sell, in-person or online. Our team of experts will happily discuss your needs.

Verifone logo