Skip to main content

Retrieve a customer’s subscriptions

Overview

Extract all subscriptions belonging to a customer. Use the getCustomerSubscriptions method to retrieve details about the subscriptions belonging to a specific customer.

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.

avangateCustomerReference

Required (int)

 

System-generated customer reference. Required unless you prefer to use ExternalCustomerReference.

externalCustomerReference

Optional (string)

 

External customer reference that you control. Optional when you use AvangateCustomerReference. If you include it, it needs to belong to the same customer as the AvangateCustomerReference.

Response

Parameters Type/Description

Subscription

Array of objects

Request

<?php

require ('PATH_TO_AUTH');

$customerReference = YOUR_CUSTOMER_REFERENCE;

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

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

Retrieve a customer’s subscriptions

Overview

Extract all subscriptions belonging to a customer. Use the getCustomerSubscriptions method to retrieve details about the subscriptions belonging to a specific customer.

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.

avangateCustomerReference

Required (int)

 

System-generated customer reference. Required unless you prefer to use ExternalCustomerReference.

externalCustomerReference

Optional (string)

 

External customer reference that you control. Optional when you use AvangateCustomerReference. If you include it, it needs to belong to the same customer as the AvangateCustomerReference.

Response

Parameters Type/Description

Subscription

Array of objects

Request

<?php

require ('PATH_TO_AUTH');

$CustomerReference = YOUR_CUSTOMER_REFERENCE;

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

Set partner invoice payment details (card payment)

Overview

Configure the details of the payment method that will be used to pay for a partner invoice. Supported payment methods:

  • PayPal
  • Credit / debit cards

Works in conjunction with setProforma and is a prerequisite for payProforma. Call setProforma, then setPaymentDetails and payProforma in this specific order to pay for a partner invoice.

Requirements

This method requires that a specific partner be set using setPartner and that a partner invoice be marked for payment using setProforma.

Parameters

Parameters Type/Description

sessionID

Required (String)

 

Session identifier, output of the Login method. An exception is thrown if the values are incorrect.

paymentDetails

Object

 

Payment details object with the structure detailed below.

 

Type

String

 

 

Possible values:

  • PAYPAL
  • CC

 

Currency

String

 

 

Partner currency ISO code - ISO 4217. This currency governs transactions between you and the partner, and is set in the Commercial Settings page, under Payment information.

Must match the currency of the partner invoice, otherwise an exception is thrown.

If NULL, the system uses the partner invoice currency.

 

PaymentMethod

Object

 

 

Structure below.

 

 

CardNumber

String

 

 

 

Credit / debit card number

 

 

CardType

String

 

 

 

Credit / debit card type:

  • VISA
  • VISAELECTRON
  • MASTERCARD
  • MAESTRO
  • AMEX

 

 

CCID

String

 

 

 

CVC2/CVV2 card identification number.

 

 

ExpirationMonth

String

 

 

 

A valid expiration month must be used, otherwise an exception is thrown. Example: 06 for June.

 

 

ExpirationYear

String

 

 

 

A valid expiration year must be used, otherwise an exception is thrown

 

 

HolderName

String

 

 

 

Card holder name

 

CustomerIP

String

 

 

Partner IP address, needed for security validation.

Response

Parameters Type/Description
Result Boolean
  True or false.

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
require('PATH_TO_setProforma'); // setProforma example: https://knowledgecenter.avangate.com/Integration/Channel_Manager_API/SOAP/06Reference/14Billing/00Capture_card_payment/00Set_partner_invoice

$paymentDetails = new stdClass();

$paymentDetails->Type = 'CC';
$paymentDetails->Curency = 'YOUR_CURRENCY';
$paymentDetails->CustomerIP = 'CUSTOMER_IP';

$paymentDetails->PaymentMethod = new stdClass();
$paymentDetails->PaymentMethod->CardNumber = 'YOUR_CARD_NUMBER';
$paymentDetails->PaymentMethod->CardType = 'YOUR_CARD_TYPE';
$paymentDetails->PaymentMethod->CCID = 'YOUR_CARD_CVV';
$paymentDetails->PaymentMethod->ExpirationMonth = 'CARD_EXPIRATION_MONTH';
$paymentDetails->PaymentMethod->ExpirationYear = 'CARD_EXPIRATION_YEAR';
$paymentDetails->PaymentMethod->HolderName = 'CARDHOLDER_NAME';

try {
    $PaymentDetailsSet= $client->setPaymentDetails($sessionID, $paymentDetails);
} catch (SoapFault $e) {
    Echo "Payment: " . $e->getMessage();
    exit;
}
var_dump ("Payment", $PaymentDetailsSet);

Errors

Error Description

INVALID_PARTNER

No partner is set.

INVALID_PROFORMA

No partner invoice set.

PAYMENT_ERROR

Your currency is not supported. You can only pay in:

PAYMENT_ERROR

You did not set your PaymentMethod property.

PAYMENT_ERROR

Your PaymentMethod property ['.$_prop.'] is not defined.

PAYMENT_ERROR

Your payment type is not supported. We only accept PAYPAL and CC.

PAYMENT_ERROR

We cannot detect the business model

PAYMENT_ERROR

There are no payment methods for this currency

PAYMENT_ERROR

Your payment method is not supported

PAYMENT_ERROR

Invalid credit card

 

IPN Gateway Responses

Overview

This is a list of IPN gateway response statuses for Unfinished orders and their descriptions.  

Order Search Report

The IPN Gateway Response statuses appear on the "Gateway Response" column in the "Order Search" report for unfinished payments. If enabled for your account, you can export the report from your Control Panel account (if the functionality is not enabled for your account, contact 2Checkout) following these steps:

  1. Log in to your Merchant Control Panel.
  2. Navigate to Orders & Customers → Order search
  3. Select the necessary search fields and click on the Search button.

order search report.png

4. After clicking Search, a report will appear under the Search fields. To export this report, click the Export button, as shown in the image below.

order search report export.png

5. Select the 2Checkout Full Options Template from the drop-down menu, and then check the format in which you want to export the report. You can choose between 3 formats: CSV, XLS, XML.

order search report format and template.png

6. After performing the above selection, click on the Export button within the iframe.

7. A report will be generated and you can identify the Gateway response column that captures the reasons for which payments were rejected by the processing gateway.

gateway response column.png

IPN Gateway Response Statuses

Gateway Response Description
Access denied in payment gateway  
Order not pay  
Invalid response  
Call acquirer support call number  
Operation not completed  
Please retry transaction  
Invalid response from gateway  
Already authorized  
Message flow error  
Card type not active or incorrect PIN  
Invalid merchant  
Restricted card  
Authorization declined  
Error - retry  
Password incorrect or card disabled  
Invalid amount  
Amount exceeds card ceiling  
Invalid amount  
No such card  
No such card/issuer  
Re-enter transaction  
Invalid response  
Format error  
Issuer signed off  
Expiry date error  
Card restricted  
Lost card  
Stolen card, pick up  
Insufficient funds  
No chequing account  
No savings account  
Expired card  
Incorrect PIN // Incorrect PIN  
Transaction not permitted on card  
Not permitted to merchant  
Exceeds amount limit  
Restricted card  
Security violation  
Exceeds frequency limit  
PIN tries exceeded // PIN tries exceeded  
Wrong Reference No.  
Reserved  
Network error  
Foreign network error  
Time-out at issuer  
Account verification required  
Authentication failure  
A technical problem occurred, please contact helpdesk  
Router unavailable // Router unavailable  
Violation of law  
Duplicate transmission  
System malfunction  
Authentication failed  
Error in CVC2 or CVC2 Description fields  
Terminal is locked, please try again // Terminal locked  
Our payment system is currently under maintenance, please try later  
Error in amount field  
Error in card expiration date field  
Invalid card number  
Server is not responding //Server is not responding  
No or Invalid response received  
An error occurred during processing. Please retry the operation  
Paypal accept  
Direct Ebanking accept  
Gateway accept  

Retrieve shopping cart contents

Overview

Use this method to get information on the products added to the shopping cart during the current cart session.

Requirements

Parameters

Parameter Type/Description
sessionID Required (String)
  Session identifier, which is the output of the Login method. An exception is thrown if the values are incorrect.

Response

Parameter Type/Description
Contents Object
  Cart contents object.

Request

<?php

require ('PATH_TO_AUTH');  // Authentication example: https://knowledgecenter.avangate.com/Integration/Channel_Manager_API/JSON-RPC/02Authentication
require ('PATH_TO_SET_PARTNER'); // setPartner example: https://knowledgecenter.avangate.com/Integration/Channel_Manager_API/JSON-RPC/06Reference/Partner/00Set_partner
require ('PATH_TO_ADD_PRODUCT'); // addProduct example: https://knowledgecenter.avangate.com/Integration/Channel_Manager_API/JSON-RPC/06Reference/08Place_an_order/00Add_product_to_cart

$jsonRpcRequest = array (
'jsonrpc' => '2.0',
'id' => $i++,
'method' => 'getContents',
'params' => array($sessionID)
);
var_dump (callRPC((Object)$jsonRpcRequest,$host));

Errors

Error Description

EMPTY_CART

The shopping cart is empty.

 

Add products to a promotion

Overview

Use the addPromotionProducts API call via JSON-RPC API 4.0 to add products to an existing promotion.

Parameters

Parameter Type/Description

sessionID

Required (string)

 

Output of the Login method.

promotionCode

Required (string)

 

The code corresponding to the promotion that you want to add products to.

promotionProducts

Required (object)

 

Code

Required (string)

 

 

System generated product code.

 

pricingConfigurationCode

Optional (string)

 

 

System generated pricing configuration code.

 

pricingOptionCodes

Optional (array of strings)

 

 

Pricing option codes that you control.

Response

Parameter Type/Description
promotionProducts 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);

$promotionCode = '';

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

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

$productPromotion = [$newProduct1, $newProduct2];

$jsonRpcRequest = array (
'jsonrpc' => '2.0',
'id' => $i++,
'method' => 'addPromotionProducts',
'params' => array($sessionID, $promotionCode, $productPromotion)
);
var_dump (callRPC($jsonRpcRequest, $host));

Retrieve order fields

Overview

Use the getAdditionalFields method to extract information about additional fields you set up for your account.

Parameters

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

AdditionalFields

Array of orders

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 = "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'); //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;
}

try {
    $AdditionalFields = $client->getAdditionalFields($sessionID);
}

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

var_dump("AdditionalFields", $AdditionalFields);


?>

 

Remove promotion sources

Overview

Use the deletePromotionSources method via SOAP API 4.0 to define new sources for an existing promotion.

Parameters

Parameter Type/Description

sessionID

Required (string)

 

Output of the Login method.

promotionCode

Required (string)

 

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

promotionSources

Required (string array)

 

Array of strings defining the promotion sources to be removed.

Response

Parameter Type/Description

status

Boolean

 

True or false

Request

<?php 

class Client
{
    protected static $merchantCode;
    protected static $loginDate;
    protected static $hash;
    protected static $baseUrl;
    protected static $callCount = 0;
    protected static $sessionId = '';

    protected static $client;

    public static function setCredentials($code, $key)
    {
        static::$merchantCode = $code;
        static::$loginDate = gmdate('Y-m-d H:i:s');
        static::$hash = hash_hmac('md5', strlen($code) . $code . strlen(static::$loginDate) . static::$loginDate, $key);
        static::$sessionId = static::login();
    }

    public static function setBaseUrl($url)
    {
        static::$baseUrl = $url;
    }

    public static function login()
    {
        $client = static::getClient();
        return $client->login(static::$merchantCode, static::$loginDate, static::$hash);
    }

    public static function __callStatic($name, $arguments = array())
    {
        $client = static::getClient();

        array_unshift($arguments, static::$sessionId);
        $response = call_user_func_array(array($client, $name), $arguments);

        return $response;
    }

    protected static function getClient()
    {
        $opts = array(
            'http'=> ['user_agent' => 'PHPSoapClient'],
            'ssl' => [
                'verify_peer' => false,
                'verify_peer_name' => false,
            ],
        );

        if (null === static::$client) {
            static::$client = new \SoapClient(static::$baseUrl . '?wsdl', [
                'location' => static::$baseUrl,
                'cache_wsdl' => WSDL_CACHE_NONE,
                'stream_context' => stream_context_create($opts),
            ]);
        }

        return static::$client;
    }
}

Client::setBaseUrl('https://api.avangate.com/soap/3.1/');
Client::setCredentials('YOUR_MERCHANT_CODE', 'YOUR_SECRET_KEY');
Client::login();

$promotionCode = 'YOUR_PROMOTION_CODE'; // code of the promotion that you want to update
$sources = ['source1', 'source2']; // array of sources to remove from the promotion

$response = Client::deletePromotionSources($promotionCode,$sources); // Set the promotion discount to the existing promotion
var_dump($response);

 

Save prices

Overview

Use the savePrices method to update product prices for a specific pricing configuration.

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.

Prices

BasicPrice Object

 

Details below.

Quantities

Object

 

Details below.

PriceOptions

Required (PriceOptionsAssigned object)

 

Details below.

PricingConfigCode

Required (string)

 

System-generated unique pricing configuration code. Read-only.

type

Require (string)

• REGULAR

• RENEWAL

 

Parameters Type/Description

BasicPrice

Object

Currency

String

 

The currency ISO code used for shipping costs - ISO 4217.

Amount

Float

 

Basic price.

 

Parameters Type/Description

Quantities

Object

MinQuantity

String

 

The minimum quantity of volume discounts. Default is 1.

MaxQuantity

String

 

The maximum quantity of volume discounts. Default is 99999.

 

Parameters Type/Description

PriceOptionsAssigned

Object

Code

String

 

Price option identifier.

Options

Array of strings

 

The pricing options group option code you configured that the 2Checkout system uses to calculate product prices for pricing configurations without a base price.

Response

bool(true)
<?php

require ('PATH_TO_AUTH');

$Prices = array();
$Prices[0] = new stdClass();
$Prices[0]->Currency = 'USD';
$Prices[0]->Amount = 999.99;
$Prices[1] = new stdClass();
$Prices[1]->Currency = 'EUR';
$Prices[1]->Amount = 111.99;
$Quantities = new stdClass();
$Quantities->MinQuantity = 1;
$Quantities->MaxQuantity = 99999;
$PriceOptions = null;
/*
$PriceOptions = array();
$PriceOptions[0] = new stdClass();
$PriceOptions[0]->Code = '04WCPNHWQ5';
$PriceOptions[0]->Options = array();
$PriceOptions[0]->Options[0] = 'loqmhwcpwk';
$PriceOptions[0]->Options[1] = 'n7332ux312';
$PriceOptions[1] = new stdClass();
$PriceOptions[1]->Code = '4CU1OVAGAA';
$PriceOptions[1]->Options = array();
$PriceOptions[1]->Options[0] = 'dvk7hv62jg';
$PriceOptions[1]->Options[1] = 'uf1svzaxcd';
*/
$PricingConfig              = new stdClass();
$PricingConfig->ProductCode = 'NewSubscriptionPlan_Code_12345';
$PricingConfig->Country     = null;
$type                       = 'REGULAR';

try {
    $NewPrice = $client->savePrices($sessionID, $Prices, $Quantities, $PriceOptions, $PricingConfig, $type);
}

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

var_dump("NewPrice", $NewPrice);


?>

 

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

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