Skip to main content

Handle Connection Errors

Overview

If you want to catch and handle any errors encountered during the iFrame mounting process use the mountAsync method.

Use case

  1. Create a form with id="payment-form":

    <form type="post" id="payment-form">
     <div class="form-group">
       <label for="name" class="label control-label">Name</label>
       <input type="text" id="name" class="field form-control">
     </div>
     <button class="btn btn-primary" type="submit">Generate token</button>
    </form>
  2. Inside the form add an element with id="card-element". The form should now look like this:

    <form type="post" id="payment-form">
     <div class="form-group">
       <label for="name" class="label control-label">Name</label>
       <input type="text" id="name" class="field form-control">
     </div>
     <div id="card-element">
       <!-- A TCO IFRAME will be inserted here. -->
     </div>
     <button class="btn btn-primary" type="submit">Generate token</button>
    </form>
  3. Include the 2Pay.js drop-in payment client JavaScript.

    <script type="text/javascript" src="https://2pay-js.2checkout.com/v1/2pay.js"></script>
  4. Add the following configuration JavaScript to load the client and create the component.

    window.addEventListener('load', function() {
     // Initialize the JS Payments SDK client.
     let jsPaymentClient = new  TwoPayClient('YOUR_MERCHANT_CODE');
     
     // Create the component that will hold the card fields.
     let component = jsPaymentClient.components.create('card');
  5. Use the mountAsync method to catch any mounting errors and retry if needed.

    // Use mountAsync() to catch errors and retry if needed
    component.mountAsync('#card-element')
        .then(() => {
            console.log('Card component mounted successfully');
        })
        .catch((error) => {
            console.error('Mount failed, retrying after cleanup:', error);
            // Clean up the failed mount
            component.unmount();
    
            // Retry mounting
            component.mountAsync('#card-element')
                .then(() => {
                    console.log('Card component mounted successfully on retry');
                })
                .catch((retryError) => {
                    console.error('Retry failed:', retryError);
                });
        });

Demo

Place upgrade orders with InLine Cart

Overview

Upgrades a current subscription using the inline checkout.

 
The Checkout form will be prefilled with subscription's billing data.

Use case

  1. Add an HTML link or button in your page like the one below.
  2. Create a JavaScript click handler to execute the Inline Client desired methods.
  3. Use the TwoCoInlineCart.products.add({code, quantity, options}) method to prepare your catalog product.
  4. Set the license code as the subscription reference on the cart TwoCoInlineCart.cart.setSubscription('IMKNNVEY13').

     
    Make sure your parent subscription has upgrades available in Control Panel, for your current product.
  5. Set the upgrade flag on the cart TwoCoInlineCart.cart.setUpgrade(true).
  6. Use the TwoCoInlineCart.cart.checkout() method to show the cart on your page.

Sample request

HTML

<a href="#" class="btn btn-success" id="buy-button">Buy now!</a>

Javascript

window.document.getElementById('buy-button').addEventListener('click', function() {
  TwoCoInlineCart.products.add({
    code: "74B8E17CC0"
  });
  TwoCoInlineCart.cart.setSubscription('IMKNNVEY13');
  TwoCoInlineCart.billing.setEmail('john.doe@company.com');
  TwoCoInlineCart.cart.setUpgrade(true);
  TwoCoInlineCart.cart.checkout();
});

Upgrade partner subscription

Parameters

Parameters     Type/Description
sessionID     Required (String)
      Session identifier, output of the Login method. An exception is thrown for incorrect values.
Items     Object (Required)
  SubscriptionReference   String (Required)
      The 2Checkout unique subscription code.
  UpgradeProductCode   String (Required)
      Unique product identifier code of the product you wish the subscription to be upgraded to. 
  Quantity   String (Required)
      Defines the amount of product units to be renwed.
  PricingOptions   Object (Required)
    Code The 2Checkout unique pricing code.
ExtraDiscount     Object (Optional)
  Value   String
      Extra discount you offer to partner orders. 
  Type   String
      Possible values: FIXED or PERCENT.
ExtraMargin     Object (Optional)
  Value   String
      Extra margin you offer to partner orders.
  Type   String
      Possible values: FIXED or PERCENT.
ExternalReferenceNumber     String (optional)
      Set external reference identifiers for orders. Maximum 100 characters. 
Comment     String (Optional)
      Set comments on orders as needed.

Request

<?php
declare(strict_types=1);
class Configuration
{
    public const MERCHANT_CODE = 'MERCHANT';
    public const MERCHANT_KEY = 'SECRET_KEY';
    public const URL = 'http://api.avangate.local/rpc/6.0';
    public const ACTION = 'upgradePartnerSubscriptions';
    
    public const PAYLOAD =  <<<JSON
{
    "Items": [
        {
            "SubscriptionReference": "XYZ23GHUJK",
            "UpgradeProductCode": "AVANGATE",
            "Quantity": 5,
            "PricingOptions": [
                {
                    "Code": "option30p"
                },
                {
                    "Code": "option20p"
                }
            ]
        }
    ],
    "ExtraDiscount": {
        "Value": 10,
        "Type": "FIXED"
    },
    "ExtraMargin": {
        "Value": 10,
        "Type": "PERCENT"
    },
    "ExternalReferenceNumber": "EXT-007",
    "Comment": "API partner order for upgrade"
}
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;
        $algo = 'sha256';
        $hash = hash_hmac($algo, $string, $key);

        return compact('merchantCode', 'date', 'hash', 'algo');
    }

    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];
        }
        $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,
            ['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);

Retrieve partner subscription upgrade price

Parameters

Parameters     Type/Description
sessionID     Required (String)
      Session identifier, output of the Login method. An exception is thrown for incorrect values.
Items     Object (Required)
  SubscriptionReference   String (Required)
      The 2Checkout unique subscription code.
  UpgradeProductCode   String (Required)
      Unique product identifier code of the product you wish the subscription to be upgraded to. 
  Quantity   String (Required)
      Defines the amount of product units to be renwed.
  PricingOptions   Object (Required)
    Code The 2Checkout unique pricing code.
ExtraDiscount     Object (Optional)
  Value   String
      Extra discount you offer to partner orders. 
  Type   String
      Possible values: FIXED or PERCENT.
ExtraMargin     Object (Optional)
  Value   String
      Extra margin you offer to partner orders.
  Type   String
      Possible values: FIXED or PERCENT.

Request

<?php
declare(strict_types=1);
class Configuration
{
    public const MERCHANT_CODE = 'MERCHANT';
    public const MERCHANT_KEY = 'SECRET_KEY';
    public const URL = 'http://api.avangate.local/rpc/6.0';
    public const ACTION = 'getPartnerSubscriptionsUpgradePrice';
    
    public const PAYLOAD =  <<<JSON
{
    "Items": [
        {
            "SubscriptionReference": "XYZ23GHUJK",
            "UpgradeProductCode": "Avangate",
            "Quantity": 5,
            "PricingOptions": [
                {
                    "Code": "option30p"
                },
                {
                    "Code": "option20p"
                }
            ]
        }
    ],
    "ExtraDiscount": {
        "Value": 10,
        "Type": "FIXED"
    },
    "ExtraMargin": {
        "Value": 10,
        "Type": "PERCENT"
    }
}
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;
        $algo = 'sha256';
        $hash = hash_hmac($algo, $string, $key);

        return compact('merchantCode', 'date', 'hash', 'algo');
    }

    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];
        }
        $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,
            ['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);

Renew partner subscription

Parameters

Parameters     Type/Description
sessionID     Required (String)
      Session identifier, output of the Login method. An exception is thrown for incorrect values.
Items     Object (Required)
  SubscriptionReference   String (Required)
      The 2Checkout unique subscription code.
  Quantity   String (Required)
      Defines the amount of product units to be renwed.
  PricingOptions   Object (Required)
    Code The 2Checkout unique pricing code.
ExtraDiscount     Object (Optional)
  Value   String
      Extra discount you offer to partner orders. 
  Type   String
      Possible values: FIXED or PERCENT.
ExtraMargin     Object (Optional)
  Value   String
      Extra margin you offer to partner orders.
  Type   String
      Possible values: FIXED or PERCENT.
ExternalReferenceNumber     String (optional)
      Set external reference identifiers for orders. Maximum 100 characters. 
Comment     String (Optional)
      Set comments on orders as needed.

Request

<?php
declare(strict_types=1);
class Configuration
{
    public const MERCHANT_CODE = 'MERCHANT';
    public const MERCHANT_KEY = 'SECRET_KEY';
    public const URL = 'http://api.avangate.local/rpc/6.0';
    public const ACTION = 'renewPartnerSubscriptions';
    
    public const PAYLOAD =  <<<JSON
{
    "Items": [
        {
            "SubscriptionReference": "XYZ23GHUJK",
            "Quantity": 5,
            "PricingOptions": [
                {
                    "Code": "option30p"
                },
                {
                    "Code": "option20p"
                }
            ]
        }
    ],
    "ExtraDiscount": {
        "Value": 10,
        "Type": "FIXED"
    },
    "ExtraMargin": {
        "Value": 10,
        "Type": "PERCENT"
    },
    "ExternalReferenceNumber": "EXT-007",
    "Comment": "API partner order for renewal"
}
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;
        $algo = 'sha256';
        $hash = hash_hmac($algo, $string, $key);

        return compact('merchantCode', 'date', 'hash', 'algo');
    }

    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];
        }
        $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,
            ['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);

Retrieve partner subscription renewal price

Parameters

Parameters     Type/Description
sessionID     Required (String)
      Session identifier, output of the Login method. An exception is thrown for incorrect values.
Items     Object (Required)
  SubscriptionReference   String (Required)
      The 2Checkout unique subscription code.
  Quantity   String (Required)
      Defines the amount of product units to be renwed.
  PricingOptions   Object (Required)
    Code The 2Checkout unique pricing code.
ExtraDiscount     Object (Optional)
  Value   String
      Extra discount you offer to partner orders. 
  Type   String
      Possible values: FIXED or PERCENT.
ExtraMargin     Object (Optional)
  Value   String
      Extra margin you offer to partner orders.
  Type   String
      Possible values: FIXED or PERCENT.

Request

<?php
declare(strict_types=1);
class Configuration
{
    public const MERCHANT_CODE = 'MERCHANT';
    public const MERCHANT_KEY = 'SECRET_KEY';
    public const URL = 'http://api.avangate.local/rpc/6.0';
    public const ACTION = 'getPartnerSubscriptionsRenewalPrice';
    
    public const PAYLOAD =  <<<JSON
{
    "Items": [
        {
            "SubscriptionReference": "XYZ23GHUJK",
            "Quantity": 5,
            "PricingOptions": [
                {
                    "Code": "option30p"
                },
                {
                    "Code": "option20p"
                }
            ]
        }
    ],
    "ExtraDiscount": {
        "Value": 10,
        "Type": "FIXED"
    },
    "ExtraMargin": {
        "Value": 10,
        "Type": "PERCENT"
    }
}
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;
        $algo = 'sha256';
        $hash = hash_hmac($algo, $string, $key);

        return compact('merchantCode', 'date', 'hash', 'algo');
    }

    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];
        }
        $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,
            ['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);

 

Renewal Performance Report 

Overview 

The renewal performance report provides a comprehensive view of how subscription renewals and expirations occur within a specific period, enabling you to measure retention performance accurately, understand churn drivers, and identify potential churn-risk behaviors. 

The report includes key productivity metrics, such as renewal rate, cancellation rate, and disabling auto-renewal events, alongside visual breakdowns of subscription status changes over time. 

This report supports data-driven analysis of the subscription lifecycle.  

Benefits

Subscription businesses need clear indicators of subscriber engagement and churn potential. The renewal performance report enables you to: 

  • Track how many subscriptions are renewed vs. expired in a selected interval 

  • Monitor customer behaviors related to automated and manual renewals 

  • Detect early churn risk through auto-renewal disablement patterns 

  • Understand the distribution of subscription outcomes over time for effective strategy planning 

Report components 

Filters 

Configure the following filters to tailor the report output: 

  • Subscription expiration date range - choose the interval for which expiring subscriptions’ renewals should be evaluated 

expiration date

  • Initial purchase date - restrict reporting to subscriptions created within the specified interval 

initial purchase date

  • Product - contains product name and product code grouped, enabling precise filtering of the results to one or more products 

  • Billing country - view metrics for subscriptions based on country 

  • Billing cycle length - filter results by subscription term duration. Billing cycle lengths in this report reflect the effective subscription duration after pricing options or lifecycle changes are applied. They are categories, not precise durations. For example, 33 days will be counted as 1M.

billing cycle length

  • Payment method - filter results by payment method (examples: Visa, Carte Bleue, PayPal, etc.) 

payment method

  • Renewal type - segment results by automatic or manual renewal 

renewal type

  • Partner/test subscription flags - include or exclude partner/test subscriptions from the analysis 

partner subscription

Metric cards

At the top of the report, three metric cards display key performance indicators that provide a high-level subscription health status during the reporting period.

  • Renewal Rate - percentage of subscriptions that are renewed successfully out of all subscriptions expiring in the selected period. 

renewal rate

  • Cancellation Rate - percentage of subscriptions that don't renew and become expired or disabled.

cancellation rate

  • Disabling auto-renewal events - percentage of active subscriptions for which auto-renewal is turned off before the renewal date, indicating potential churn risk. 

disable

Each card shows absolute counts, percentage values, and comparisons to previous intervals or the same period in prior years to track trend movements. 

Renewal & expiration events chart

A stacked bar chart displays: 

  • Daily/weekly/monthly counts of subscription renewal status events throughout the reporting interval 

  • Each colored segment corresponds to one subscription renewal status category 

  • Provides a visual timeline of how renewals and expirations occurred 

chart

Subscription renewal statuses

Each bar in the renewal and expiration events chart corresponds to these renewal statuses: 

  • Automatically renewed - subscriptions that successfully renewed via auto-billing around their scheduled renewal date 

  • Manually renewed - subscriptions that were renewed through manual customer action 

  • Active but unrenewed - subscriptions with expiration dates within the selected period where renewal hasn’t occurred yet 

  • Disabled - subscriptions deactivated before renewal through a disable action 

  • Expired - subscriptions whose grace period expired without renewal and are now inactive 

  • Past due - subscriptions past the expiration date but still in grace period; payment retries may still recover renewal in case of auto-renewing subscriptions, or shopper action may still trigger manual renewal 

How to interpret the report 

  • High renewal rate signals strong subscriber engagement and product satisfaction 

  • Rising cancellation or disabling events at scale may uncover issues with pricing, value perception, or communication 

  • Active but unrenewed subscriptions suggest timing effects where renewals may still occur 

  • Past due volume helps evaluate payment processing performance and retry effectiveness 

Update order reseller information

Overview

Use this method to update the reseller information defined for a specific order.

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.
PartnerCode Required (string)
  Unique identifier that you need to specify when creating a partner in the Control Panel. You can find it under the General Information area when editing partner details
ResellerCode Required (string)
  Unique, system generated reseller identifier.
OrderRefNo Required (string)
  The unique, system-generated identifier of a partner order.

Request

<?php

declare(strict_types=1);

class Configuration
{
    public const MERCHANT_CODE = 'MERCHANT';
    public const MERCHANT_KEY = 'SECRET_KEY';
    public const URL = 'https://api.2checkout.com/soap/6.0';
    public const ACTION = 'updateOrderReseller';
    //array or JSON
    public const PAYLOAD = <<<JSON
{
    "PartnerCode": "Test Avangate",
    "ResellerCode": "DB6F1A946E",
    "OrderRefNo": 731522351
}
JSON;

}
class Client
{
    public function call(
        string $url = Configuration::URL,
        $payload = Configuration::PAYLOAD,
        string $action = Configuration::ACTION
    ): ?object {
        if (is_array($payload)) {
            $payload = json_encode($payload);
        }
        if (!empty($payload)) {
            // SoapClient works with objects(StdClass)
            $payload = json_decode($payload);
        }
        $soapClient = $this->getClient($url);
        $sessionId = $this->getSession($soapClient);
        $args = array_filter([$sessionId, $payload]);
        return $soapClient->$action(...$args);
    }

    public function getClient(string $url): SoapClient
    {
        return new SoapClient(
            $url.'?wsdl',
            [
                'location' => $url,
                'cache_wsdl' => WSDL_CACHE_NONE,
            ]
        );
    }

    public function getSession(SoapClient $client)
    {
        $date = gmdate('Y-m-d H:i:s');
        $merchantCode = Configuration::MERCHANT_CODE;
        $key = Configuration::MERCHANT_KEY;
        $string = strlen($merchantCode).$merchantCode.strlen($date).$date;
        $algo = 'sha256';
        $hash = hash_hmac($algo, $string, $key);
        $client->__setCookie('XDEBUG_SESSION', 'PHPSTORM');
        return $client->login($merchantCode, $date, $hash, $algo);
    }
}
try {
    $client = new Client();
    var_dump($client->call());
} catch (Exception $ex) {
    var_dump($ex);
}

Errors 

Error  Description
Missing required parameter: PartnerCode Add the PartnerCode parameter.
Missing required parameter: ResellerCode Add the ResellerCode parameter.
Missing required parameter: OrderRefNo Add the OrderRefNo parameter.
INVALID_ID_SALE Invalid order reference.

Retrieve partner reseller list

Overview

Use this method to retrieve a list of resellers defined and stored for one of your partners.

Parameters

Parameters 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.
partnerCode Required (string)
  Unique identifier that you need to specify when creating a partner in the Control Panel. You can find it under the General Information area when editing partner details. 
searchBy Array (optional)
  Control the pagination of results using the parameters Page and Limit. If they are not provided, the default values will be displayed: Page 1, Limit 10. 

Request

<?php
declare(strict_types=1);
class Configuration
{
    public const MERCHANT_CODE = 'MERCHANT';
    public const MERCHANT_KEY = 'SECRET_KEY';
    public const URL = 'https://api.2checkout.com/soap/6.0';
    public const ACTION = 'getPartnerResellers';

    public const PAYLOAD = <<<JSON
{
    "PartnerCode": "Test Avangate",
    "SearchBy": {
        "Page": 1,
        "Limit": 150
    }
}
JSON;

}
class Client
{
    public function call(
        string $url = Configuration::URL,
        $payload = Configuration::PAYLOAD,
        string $action = Configuration::ACTION
    ): ?object {
        if (is_array($payload)) {
            $payload = json_encode($payload);
        }
        if (!empty($payload)) {
            // SoapClient works with objects(StdClass)
            $payload = json_decode($payload);
        }
        $soapClient = $this->getClient($url);
        $sessionId = $this->getSession($soapClient);
        $args = array_filter([$sessionId, $payload]);
        return $soapClient->$action(...$args);
    }

    public function getClient(string $url): SoapClient
    {
        return new SoapClient(
            $url.'?wsdl',
            [
                'location' => $url,
                'cache_wsdl' => WSDL_CACHE_NONE,
            ]
        );
    }

    public function getSession(SoapClient $client)
    {
        $date = gmdate('Y-m-d H:i:s');
        $merchantCode = Configuration::MERCHANT_CODE;
        $key = Configuration::MERCHANT_KEY;
        $string = strlen($merchantCode).$merchantCode.strlen($date).$date;
        $algo = 'sha256';
        $hash = hash_hmac($algo, $string, $key);
        $client->__setCookie('XDEBUG_SESSION', 'PHPSTORM');
        return $client->login($merchantCode, $date, $hash, $algo);
    }
}
try {
    $client = new Client();
    var_dump($client->call());
} catch (Exception $ex) {
    var_dump($ex);
}

Response

Parameter Type/Description
Reseller Array of reseller objects.

Errors

Error Description
MISSING_PARAMETER Add the PartnerCode paramater in the request before calling this method.

 

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