Skip to main content

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);

?>

ConvertPlus renewal flow

Overview

Enable your customers to order on-demand renewals for their subscriptions using custom Buy-Links on ConvertPlus ordering flow.

 

Recommended resources

Availability

ConvertPlus renewal flow is available only to 2Checkout merchants that have activated ConvertPlus in their accounts. Contact 2Checkout for activation.

Requirements

Custom on-demand renewals buy links can be generated manually, and they work for active and past-due subscriptions (excluding trials and non-recurring/lifetime subscriptions). They can also be set from the Subscription page in Control Panel (Orders and customers à Subscriptions à Edit subscription details à Renew subscription).

Subscriptions can be renewed automatically ahead of their expiry deadline with 90 to 3000 days. The default platform renewal option is 370 days. Contact 2Checkout directly if you wish to customize this limitation.

Scenarios covered

  1. Renew Subscription A belonging to Product A (source product) keeping it under Product A (target product).
  2. Renew Subscription A belonging to Product A (source product) and moving/upgrading the customer to Product B (target product).

Workflow

Use this feature to enable your customers to renew their active and past-due subscriptions on demand, bypassing the upcoming renewal operation scheduled in the 2Checkout system.

Custom on-demand subscription renewals are performed:

  1. From the moment when the items were scheduled to renew/expire. For example, let's assume that Subscription A (a monthly subscription), scheduled to expire June 30th, 2019, is renewed through the use of an on-demand link with a period of 10 days on June 22nd. Subscription A's lifetime will be prolonged with 10 days starting with June 30th, and the renewal/expiry deadline moved to July 10th. Moving forward, Subscription A will be renewed a month after the July 10threnewal, per its monthly renewal cycle.
  2. By overriding the subscription billing cycle settings. However, following the custom on-demand renewal, the subscription will be governed by the renewal settings and pricing configuration of the product it's associated with.

Create a custom renewal link

Use the following parameters to generate ConvertPlus renewal links.

Parameter Required Description

merchant

Required

Your merchant identification code. The merchant code is available in Settings à Edit system settings, under the System settings tab.

subscription

Required

Unique system-generated identifier of your subscriptions. The subscription reference is available on Orders and customers à Subscriptions à Edit subscription details.

prod Optional

Identifier of the product used in the renewal process. The product code is available on Setup à Products à  Column code in the product listing.

By default, the renewal process uses the product from the original order. Use a different product code to renew a subscription to a different target product.

Note: When included in renewal links, this parameter needs to be signed as well.

qty Optional The number of units (quantity) for the renewed product. 
opt Optional

Control the pricing option used in the renewal process.

  • 1 product with 1 price option with 1 value (includes scale option type)
    • prod=code1&opt=gr1:val1
  • 1 product with 1 price option with multiple values
    • prod=code1&opt=gr1:val1;val2
language Optional Control the language used in the renewal process. Available values for language codes are displayed in this article.
recurrence Optional The interval of time that will be added to the subscription lifetime starting with the current renewal/expiry deadline. For example 10:day

Examples

Renew the subscription with the same product and a specific pricing option

For this example, let's assume that we need a custom on-demand renewal link for Subscription A (monthly subscription expiring on June 30th, 2019 with the reference 9E0BAD7B5C) associated with Product A with the code product_a.

Use the following parameters to generate the renewal link:

  • merchant=2COTEST
  • subscription=9E0BAD7B5C
  • prod=product_a
  • opt=group_name:option_value

The resulting renewal link is:

https://secure.2checkout.com/checkout/renew/?merchant=2COTEST&subscription=9E0BAD7B5C&prod=product_a&opt=group_name:option_value

Renew a subscription with a different product

For this example, let's assume that we need a custom on-demand renewal link for Subscription A (monthly subscription expiring on June 30th, 2019 with the reference 9E0BAD7B5C) associated with Product A with the code product_a. In the renewal process, the customer will also be upgraded from Product A to Product B (code product_b).

Use the following parameters to generate the renewal link:

  • merchant=2COTEST
  • subscription=9E0BAD7B5C
  • prod=product_b

The resulting renewal link is:

https://secure.2checkout.com/checkout/renew/?merchant=2COTEST&subscription=9E0BAD7B5C&prod=product_b

Domain use

  1. secure.2checkout.com domain - If your account is using the 2Checkout's secure.2checkout.com domain, then this is what you need to include in your custom on-demand renewal links served to your customers, namely https://secure.2checkout.com/renewal/?.
  2. Custom domains such as store.YourDomain.com - If your account is using a custom domain such as store.YourDomain.com, then this is what you need to include in your custom on-demand renewal links served to your customers, namely https://store.YourDomain.com /renewal/?

Control the ordering experience 

You can control some aspects of the ordering experience for customers using early renewal links, by appending the following parameters to the buy link created.

Parameter Required/Optional Description
order-ext-ref Optional Use this parameter to set an external reference to the order.

src

Optional

Control the order source identifier.

You can track the source page by entering the following parameters: 

src=prodpage for the product page or src=dldpage for the link on the download page 
(dldpage and prodpage are example strings only, you can use any combination).

coupon

Optional

Promotion coupon code discounting the price of a product added to checkout. You can send multiple values separated by a semicolon when standalone coupons discount different products added to checkout. 
For example [...]&coupon=voucher1;voucher2[...]
style

Optional

Control the cart template used during the renewal process.

Each template defined in the Interface Templates area of the Control Panel has a unique identifier associated which is visible in the browser address bar when previewing the shopping cart.

Upsell settings object

Overview

Use the UpSellSettings object to update the merchant's displayType via SOAP API 6.0. The 2Checkout Public API supports upsell campaigns which means you can invite your customers to purchase upgrades or add-ons from your own product catalog.

Parameters

Parameter Type Description
UpsellingDisplayType String Set upsell settings display type. Can be overlay, interstitial.

 

 

 

Update a customer

Overview

Use the updateCustomerInformation method to update the details of a customer entity from the Avangate system.

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.

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 = 'EXTERNAL_CUSTOMER_REFERENCE'; //Optional, but if you include it it needs to belong to the same customer as the internal Avangate customer reference

$jsonRpcRequest = array (
'method' => 'getCustomerInformation',
'params' => array($sessionID, $customerReference, $externalCustomerReference),
'id' => $i++,
'jsonrpc' => '2.0');

$existingCustomer = callRPC((Object)$jsonRpcRequest, $host, true);
$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.

$jsonRpcRequest = array (
'method' => 'updateCustomerInformation',
'params' => array($sessionID, $existingCustomer, $UpdateEndUserSubscriptions),
'id' => $i++,
'jsonrpc' => '2.0');

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

Update upsell settings

Overview

Use the updateDisplayType method to change the upselling display type for your campaigns between the values "overlay" or "interstitial".

Request parameters

Parameter Type Required/Optional 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.
UpsellingDisplayType String Required Change the upselling display type for your campaigns between the values "overlay" or "interstitial".

Response

The updateDisplayType method will return the  UpsellingDisplayType value after the update.

Request sample

<?php 

          require ('PATH_TO_AUTH'); 

          $textObj = new stdClass(); 
          $textObj->UpsellingDisplayType = "interstitial"; 

          try { 

            $upSellSettingsResponse = $client->updateDisplayType($sessionID, $textObj); 

          } catch (SoapFault $e) { 

            echo  $e->getMessage(); 

          } 

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