Skip to main content

SOAP Authentication

Overview

Use the login method for the authentication process in the 2Checkout system.

Parameters

Parameters Type/Description

MerchantCode

required (string)

 

Your merchant identifier (received from 2Checkout).

 

Date

required (string)

 

GMT ISO Date format (e.g. 2010-01-01 12:13:14)

 

Hash

required (Object)

 

Calculated HMAC_SHA256 signature based on MerchantCode and Date, using your secret key (see example below).

Response

Parameters

Type/Description

sessionID

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.

Request

To create the HMAC_SHA256 source string use your merchant code (available here) and the date of the request, prefixing them with the length in bytes of each respective value, along with your account’s secret key (for UTF-8 characters the length in bytes might be longer that the string length). For example:

Parameters

Type/Description

MerchantCode

Avangate

 

8AVANGATE

 

Date

2010-05-13 12:12:12

 

192010-05-13 12:12:12

 

HMAC source string

8AVANGATE192010-05-13 12:12:12

 

Secret key

SECRET_KEY

Calculated HMAC_SHA256 signature based on MerchantCode and Date, using your secret key:

bf763db7d333e9c3038698cf59ada3e6

Request example

<?php

$host   = "https://api.2checkout.com";

$merchantCode = "YOURCODE123";
//your account's merchant code available in the 'System settings' area of the cPanel:
//https://secure.2checkout.com/cpanel/account_settings.php

$key          = "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'); //GMT date format)
$algo = "sha256";
$string = strlen($merchantCode) . $merchantCode . strlen($now) . $now;
$hash = hash_hmac($algo, $string, $key);

try {
    $client = new SoapClient($host . "/soap/3.0/?wsdl", array(
        'location' => $host . "/soap/3.0/",
        "stream_context" => stream_context_create(array(
            'ssl' => array(
                'verify_peer' => false,
                'verify_peer_name' => false
            )
        ))
    ));
    $sessionID = $client->login($merchantCode, $now, $hash, $algo);
    echo("Auth token: {$sessionID}" . PHP_EOL);
}
catch (SoapFault $e) {
    echo "Authentication: " . $e->getMessage() . PHP_EOL;
    exit;
}

Manage leads

Overview

Use the markLeads method to mark a lead as used and/or stop follow-ups.

Request Parameters

Parameters Required Type/Description
LeadCode Required String. Unique system-generated identifier.
Used Required

Boolean. With possible values:

TRUE - 

FALSE - 

StopFollowups Required

Boolean. With possible values:

TRUE - 

FALSE - 

Request Example

<?php

require ('PATH_TO_AUTH');

$markLead = [
    'LeadCode' => '60E6C4B574',
    'StopFollowups' => false,
    'Used' => true
];

$jsonRpcRequest = array (
    'method' => 'markLeads',
    'params' => array($sessionID, [$markLead]),
    'id' => $i++,
    'jsonrpc' => '2.0'
);

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

Response Parameters

Response Example

class stdClass#18 (2) {
  public $Response =>
  string(37) "1 leads have been marked successfully"
  public $Errors =>
  array(0) {
  }
}

Remove products

Overview

Use deletePromotionProducts to remove products from an existing promotion.

Parameters

Parameter Type/Description

promotionCode

Required (string)

 

The code corresponding to the promotion that you want to remove products from.

promotionProducts

Required (object)

 

Code

Required (string)

 

 

System generated product code.

 

pricingConfigurationCode

Required (string)

 

 

System generated pricing configuration code.

 

pricingOptionCodes

Required (array of strings)

 

 

Pricing option codes that you control.

Response

Parameter Type/Description
Status Boolean
  True or False

Request

<?php

require ('PATH_TO_AUTH');

// Define the first product to remove from the promotion
$newProduct1 = new stdClass;
$newProduct1->Code = '';
$newProduct1->PricingConfigurationCode = '';
$newProduct1->PricingOptionCodes = ['',''];

// Define another product to remove from the promotion
$newProduct2 = new stdClass;
$newProduct2->Code = '';
$newProduct2->PricingOptionCodes = [''];

$promotionProducts = [$newProduct1, $newProduct2];

try {
    $updatedPromotion = $client->deletePromotionProducts ($promotionCode, $promotionProducts);
}

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

var_dump("UpdatedPromotion", $updatedPromotion);

Update usage

Overview

Use the updateSubscriptionUsage method via SOAP API 6.0 to update a specific usage entry.

Request Parameters

Parameters Type Required Description
merchantCode String Required The system-generated merchant ID.
hash String Required The MD5 hmac key for the request.
sessionID String Required The system-generated code of the session.
UsageReference String Required The system-generated reference code for the usage of the subscription.
SubscriptionReference String Required The system-generated reference code for the subscription.
Units Number Optional  (Optional if Description provided) Number of units used.
Description String Optional (Optional if Units provided) It can be used to store a short merchant comment of the usage being uploaded. This can be anything, from the source of usage (mobile, web, etc.), to why changes occurred, etc. Example: Subscription usage for September.

Request Sample

<?php
require ('PATH_TO_AUTH'); // authentication call
$subscriptionReference = '4A1D733696';
$usageReference = 120010776516;

try {
    $subscriptionUsageRequest = new stdClass();
    $subscriptionUsageRequest->Units = 123;
    $subscriptionUsageRequest->Description = 'Units 123';
    $response = $client->updateSubscriptionUsage($sessionID, $subscriptionReference, $usageReference, $subscriptionUsageRequest);
    var_dump($response);
} catch (SoapFault $ex) {
    $faultname = (isset($ex->faultname)) ? " $faultname" : '';
    echo "[$ex->faultcode]$faultname: $ex->faultstring" . PHP_EOL;
}

exit;

Response 

The updateSubscriptionUsage method via SOAP APIv6 returns the Usage object if successful.

class stdClass#3 (8) {
      public $UsageReference =>
      120011112631
      public $SubscriptionReference =>
      "67F3AD6A32"
      public $OptionCode =>
      "USG_MN"
      public $UsageStart =>
      "2020-07-06 12:00:00"
      public $UsageEnd =>
      "2020-07-07 12:00:00"
      public $Units =>
      69
      public $Description =>
      ""
      public $RenewalOrderReference =>
      0
    }

Error Handling

If unsuccessful, the updateSubscriptionUsage method via SOAP APIv6 will return the error below.

Error message description Error code Error message

 

 

 

 

 

 

Provided parameters lack the required type or format.

MALFORMED_PARAMETER One or more parameters lack the required format: SubscriptionReference must be a string.
MALFORMED_PARAMETER One or more parameters lack the required format: UsageReference must be a positive integer higher than or equal to 1.
PARAMETER_MISSING Please provide at least one of the following parameters: Units, Description.
MALFORMED_PARAMETER One or more parameters lack the required format: Units must be a positive integer higher than or equal to 1.
MALFORMED_PARAMETER One or more parameters lack the required format: Description must be a string.

 

Subscription or usage line are not found.

NOT_FOUND Subscription not found.
Usage line described does not exist.
Usage line is already billed. ALREADY_BILLED Usage was not updated as this usage was already billed.
The renewal process is in progress for this subscription. RENEWAL_IN_PROGRESS There is a renewal in progress for the provided usage line.
The usage was not changed after the update. NOTHING_HAPPENED The usage has not been updated, nothing to change. The provided values are identical to the existing ones.
An unexpected error happens. GENERIC There has been an error updating the usage line. Please try again later.

Delete usage

Overview

Use the deleteSubscriptionUsages method via SOAP API 6.0 to delete one or more usage entries based on the provided criteria.

Request Parameters

Parameters Type Required Description
merchantCode String Required The system-generated merchant ID.
sessionID String Required The system-generated code of the session.
hash String Required The MD5 hmac key for the request.
SubscriptionReference String Required The system-generated reference code of the subscription.
UsageReference Number Optional The system-generated code for usage.
OptionCode String Optional Unique 2Checkout option code.
IntervalStart Number Optional (mandatory if IntervalEnd is provided) Deletes all usages where UsageEnd >= IntervalStart. Format "YYYY-MM-DD". The timezone used is the one on the server.
IntervalEnd Number Optional (mandatory if IntervalStart is provided) Deletes all usages where UsageEnd <= IntervalEnd. Format "YYYY-MM-DD". The timezone used is the one on the server.

Request Sample

<?php
require ('PATH_TO_AUTH'); // authentication call
$subscriptionReferencee = '4A1D733696';
$usageReference = 120010776516;

try {
    $subscriptionUsageRequest = new stdClass();
    $subscriptionUsageRequest->UsageReference = $usageReference;
    $subscriptionUsageRequest->OptionCode = 'Units 123';
    $subscriptionUsageRequest->IntervalStart = '2020-04-09 16:40:00';
    $subscriptionUsageRequest->IntervalEnd = '2020-04-12 15:40:00';
    $response = $client->deleteSubscriptionUsages($sessionID, $subscriptionReference, $subscriptionUsageRequest);
    var_dump($response);
} catch (SoapFault $ex) {
    $faultname = (isset($ex->faultname)) ? " $faultname" : '';
    echo "[$ex->faultcode]$faultname: $ex->faultstring" . PHP_EOL;
}

exit;

Response 

The deleteSubscriptionUsages method via SOAP APIv6 returns NULL when successful.

NULL

Error Handling

The deleteSubscriptionUsages via SOAP APIv6 returns FALSE if:

Error message code Error code Error message description

 

 

 

 

 

 

 

Provided parameters lack the required type or format.

MALFORMED_PARAMETER One or more parameters lack the required format: SubscriptionReference must be a string.
MALFORMED_PARAMETER One or more parameters lack the required format: UsageReference must be a positive integer higher than or equal to 1.
MALFORMED_PARAMETER One or more parameters lack the required format: Units must be a positive integer higher than or equal to 1.
MALFORMED_PARAMETER One or more parameters lack the required format: IntervalStart must be a string.
MALFORMED_PARAMETER One or more parameters lack the required format: IntervalEnd must be a string.

 

The subscription or usage line are not found.

 

NOT_FOUND Subscription not found.
NOT_FOUND Usage line described does not exist.
The usage line is already billed. ALREADY_BILLED Usage was not deleted as this usage was already billed.
The renewal process is in progress for this subscription. RENEWAL_IN_PROGRESS There is a renewal in progress for the provided usage line.
An unexpected error happens. GENERIC There has been an error deleting the usage line. Please try again later.

 

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. Avangate 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.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;
}
$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@avangate.com';
$EndUser->FirstName = 'New Customer';
$EndUser->Language = 'en';
$EndUser->LastName = 'Avangate';
$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);

Retrieve account's time zone

Overview

Use the getTimezone method to retrieve information on the time zone used by your account for the 2Checkout API.

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.

Response

Parameters Type/Description

Timezone

String

 

The time zone you selected or the default GMT+02:00 time zone of the 2Checkout system.

Request

<?php

require ('PATH_TO_AUTH');

try {
    $Timezone = $client->getTimezone($sessionID);
}
catch (SoapFault $e) {
    echo "Timezone: " . $e->getMessage();
    exit;
}
var_dump("Timezone", $Timezone);

API Responses

Overview

This section contains the objects returned as API responses, based on your requests to retrieve information on orders, products, subscriptions, promotions, and others.

 

 

Update customer

Overview

Use the updateCustomerInformation method to update the details of a customer entity from 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.

Customer

Object (required)

Use this object to update customer information.

UpdateEndUserSubscriptions

Optional (boolean)

You can push the changes made on the customer info to the end-user details for all subscriptions belonging to this customer. Set true to have the changes reflected on the end-user details for all subscriptions. If null or false, the changes are made only at the customer level. Default value is false.

Response

Parameters Type/Description

Boolean

true or false depending on whether or not the operation succeeded.

Request

<?php

require ('PATH_TO_AUTH');

$customerReference = CUSTOMER_REFERENCE;
$externalCustomerReference = 'EXT_CUSTOMER_REFERENCE'; //Optional, but if you include it it needs to belong to the same customer as the internal 2Checkout customer reference

try {
    $existingCustomer = $client->getCustomerInformation($sessionID, $customerReference, $externalCustomerReference);
}

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

$existingCustomer->Email = 'newemailaddress@email.com';
$UpdateEndUserSubscriptions = false; // Optional, but if true the changes made on customer info are pushed to all subscriptions from this customer.

try {
    $updatedCustomerInfo = $client->updateCustomerInformation($sessionID, $existingCustomer, $UpdateEndUserSubscriptions);
}
catch (SoapFault $e) {
    echo "updatedCustomerInfo: " . $e->getMessage();
    exit;
}
var_dump("updatedCustomerInfo", $updatedCustomerInfo);

?>

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