Skip to main content

Retrieve customer

Overview

Use the getCustomerInformation method to retrieve 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.

CustomerReference

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 CustomerReference. If you include it, it needs to belong to the same customer as the CustomerReference.

Response

Parameters Type/Description

Customer

Object

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

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

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

Create fixed discount

Overview

Use setPromotionDiscount to set a fixed promotion discount.

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 set the discount for.

promotionDiscount

Required(Object)

 

Type

Required (String)

 

 

Discount type:

  • PERCENT, use in combination with Value
  • FIXED, use in combination with Values and DefaultCurrency

 

Value / Values

Required (Int / Array of objects)

 

 

  • Value = Int, determines the discount percentage from 0 to 100
  • Values = Array of Value objects

 

 

Value

Required (Object)

 

 

 

Currency

Required (String)

 

 

 

 

Discount currency ISO code (ISO 4217).

 

 

 

Amount

Required (Int)

 

 

 

 

Discount amount in corresponding currency.

 

DefaultCurrency

Required (String)

 

 

Default discount currency ISO code (ISO 4217).

Response

Parameter Type/Description
promotionDiscount Object

Request

<?php
declare(strict_types=1);

class Configuration
{
    public const MERCHANT_CODE = '';
    public const MERCHANT_KEY = '';
    public const URL = 'http://api.2checkout.com/soap/6.0';
    public const ACTION = 'setPromotionDiscount';
    public const ADDITIONAL_OPTIONS = null;
    public const PROMOTION_CODE = "AB3WMME0UA";
    //array or JSON
    public const PAYLOAD = <<<JSON
{
  "Type": "FIXED",
  "DefaultCurrency": "USD",
  "Values": [
    {
        "Currency": "USD",
        "Amount": 10
    },
    {
        "Currency": "EUR",
        "Amount": 10
    }
  ]
}
JSON;
}

class Client
{
    public function call(
        string $url = Configuration::URL,
        $payload = Configuration::PAYLOAD,
        string $action = Configuration::ACTION,
        string $promotionCode = Configuration::PROMOTION_CODE
    ): ?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, $promotionCode, $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;
        $hash = hash_hmac('md5', $string, $key);
        $client->__setCookie('XDEBUG_SESSION', 'PHPSTORM');

        return $client->login($merchantCode, $date, $hash);
    }
}

try {
    $client = new Client();
    var_dump($client->call());
} catch (Exception $ex) {
    var_dump($ex);
}

LCN triggers

Set LCN triggers and contents 

In your Merchant Control Panel account, navigate to Dashboard → Integrations → Webhooks and API and click on the LCN Settings tab. In the General LCN Settings section, under Triggers, select the events for which 2Checkout sends notifications.

License Change Notification (LCN) provides automatic notifications for orders from the 2Checkout system, based on the below list of triggers you control.

LCN Triggers 

Here's a list of the events for which you can trigger notifications. from Merchant Control Panel. You can set the triggers (when the notification will be sent) and what tags (parameters) will be included in the response from Merchant Control Panel. Find further information on LCN parameters here.

LCN Triggers Dispatch reason codes and labels Subscription status Actions that trigger LCN

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Licenses changes

LICENCE_CHANGE - Licence change

LICENCE_GP_CHANGE - Licence grace period change

LICENCE_PENDING_ACTIVATION - Licence pending activation

 

 

 

 

ACTIVE & auto-renewal

When:

  • updating Subscription info to change expiration date and recurring enabled/disabled
  • updating End User details
  • updating Subscription details: canceling/reactivating the subscription

 

 

 

ACTIVE & non-recurring

When:

  • updating Subscription details: cancel subscription
  • updating End User details

 

 

 

ACTIVE & manual payment

When:

  • updating Subscription details to cancel/reactivate subscription
  • updating End User details

 

 

DISABLED & non-recurring

When:

  • updating Subscription details to reactivate/cancel the subscription
  • updating End user details

 

 

PENDING ACTIVATION & auto-recurring

When:

  • updating Subscription details to reactivate/cancel the subscription
  • updating Subscription info to disable automatic billing
  • updating End User details

 

 

 

 

 

 

Licenses expirations (including past due notifications)

LICENCE_EXPIRATION - Licence expiration

LICENCE_PASTDUE - Licence past due


 

 

 

 

 

EXPIRED or PAST DUE & auto-recurring

When:

  • updating Subscription details to cancel subscription
  • updating Subscription info to extend billing cycle expiration
  • updating Subscription info to stop automatic billing cycle
  • updating End User details

 

 

 

 

EXPIRED/PAST DUE & manual payment

When:

  • updating Subscription details: cancel/reactivate subscription
  • updating Subscription info: extend billing cycle expiration
  • updating Subscription info to stop automatic billing cycle
  • updating End User details

 

Licenses payment method changes

LICENCE_CHANGE - Licence change

 

ACTIVE & auto-renewal subscription

  • when updating Subscription info to change credit card details

 

Licenses when a Churn Prevention Campaign was accepted

LICENCE_CPC_ACCEPTED - Churn Prevention Campaign was accepted ACTIVE

When:

  • accepting a discount proposed through a churn prevention campaign
  • accepting a discount for enabling autorenewal

*For both situations, the LCN will contain the updated renewal price.

Licenses changed via import LICENCE_CHANGE - Licence change ACTIVE

When:

  • importing a subscription from CSV
Scheduled cancellation event has been registered SCHEDULED_FOR_CANCELATION_ON_DEMAND - Scheduled cancellation event has been registered ACTIVE

When:

  • a shopper with a German billing address requested subscription cancelation
Scheduled cancellation event has been reverted REVERT_CANCELATION_ON_DEMAND - Scheduled cancellation event has been reverted ACTIVE When:
  •  a shopper with a German billing address has requested subscription cancelation, and then reverted the cancelation request
Scheduled cancellation actually has taken place CANCELATION_ON_DEMAND - Scheduled cancellation actually has taken place DISABLED When:
  • the subscription is canceled 28 days after a shopper with a German billing address requested subscription cancelation

LCN triggers - API calls

Triggers API calls that trigger LCN API calls that do not trigger LCN

 

 

 

 

 

License changes

  • convertTrial
  • enableSubscription
  • disableSubscription
  • setSubscriptionGracePeriod
  • enableRecurringBilling
  • disableRecurringBilling
  • renewSubscription
  • setSubscriptionUpgrade
  • extendSubscription
  • updateSubscriptionEndUser
  • copyPaymentInfo (on APIv6)
  • setSubscriptionCustomer
  • setCustomRenewalPrice
  • externalCustomerRef

 

Time to go beyond payments

For online businesses today, accepting payments online is a core requirement. However, lured by low-cost offers from payment processors, decisions are based solely on price, rather than examining the actual needs of a growing business beyond the first year. Companies are spending upwards of 11% of revenue in addition to their payment processor investment because key business features are missing - for rapid product launch, experimentation, and a focus on conversion metrics.

Watch this webinar and learn from Raj Badarinath, Senior Director Marketing at 2Checkout, why your payment processor isn't enough, why you're continuously "hitting the payments wall", and why your revenue is shrinking instead of growing.

Watch this webinar to discover:

  • Accepting payments online isn't enough for emerging and growing companies
  • Payments are critical, but only part of the puzzle
  • The graduation path to true online revenue success

Selling digital goods and services to a global audience needs a combination of smarter payments, commerce, and distribution. It's time to Go Beyond Payments!

Join Our Webinar

 

One click (1-click) purchase

Overview

2Checkout supports 1-click purchases for returning customers who paid for their previous orders with:

  • Credit/Debit cards
  • PayPal
  • iDEAL
  • Alipay
  • UnionPay

How does this work?

  1. Identify returning customers.
  2. Access data on the previous purchases of returning customers.
  3. Validate previous order references for 1-click purchase scenarios using the isValidOrderReference method (explained below).
  4. Place a new order using a valid previous order reference as the payment method.
  5. 2Checkout charges returning customers using their payment-on-file information, either a card or their PayPal account.

Requirements

  • Use only references to previous orders with one of the following statuses AUTHRECEIVED or COMPLETE.
  • The email address of the BillingDetails object is mandatory and it needs to match the email address used as a part of the billing details of the initial order whose reference you're now using to place a new order. 2Checkout checks whether the email addresses are identical, and throws an error if they're not, blocking the order placement process.

     
    You have the possibility of providing only the email address of the shopper, and can ignore the rest of the required customer billing information. This way the rest of the billing information will be pre-filled from the order used as payment reference. If you enter any billing details in addition to the email address, you'll have to provide all information required in the BillingDetails object.

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.
Order Required (Object)
  Object designed to collect all data necessary for an order, including billing, product/subscription plan and payment details.

Response

Parameters Type/Description
Order information Object
  Object containing order information.

Validate previous order reference

<?php
require('PATH_TO_AUTH');
$orderReference = '670174996';
try {
    $validOrderRef = $client->isValidOrderReference($sessionID, $orderReference);
}
catch (SoapFault $e) {
    echo "validOrderRef: " . $e->getMessage();
    exit;
}
var_dump("validOrderRef", $validOrderRef);
try {
    $existentOrder = $client->getOrder($sessionID, $orderReference);
}
catch (SoapFault $e) {
    echo "existentOrder: " . $e->getMessage();
    exit;
}

Place an order using previous order reference 

<?php
require('PATH_TO_AUTH');
$oldOrderExistent = callRPC((Object)$jsonRpcRequest, $host, true);
$Order = new stdClass();
$Order->RefNo = NULL;
$Order->Currency = 'usd';
$Order->Country = 'US';
$Order->Language = 'en';
$Order->CustomerIP = '91.220.121.21';
$Order->ExternalReference = NULL;
$Order->Source = NULL;
$Order->Affiliate = new stdClass();
$Order->Affiliate->AffiliateCode = 'Partner123'
$Order->Affiliate->AffiliateSource = 'MobilePlatform'
$Order->CustomerReference = NULL;
$Order->Items = array();
$Order->Items[0] = new stdClass();
$Order->Items[0]->Code = 'my_subscription_1';
$Order->Items[0]->Quantity = 1;
$Order->Items[0]->PriceOptions = NULL;
$Order->Items[0]->SKU = NULL;
$Order->Items[0]->Price = NULL;
$Order->Items[0]->CrossSell = NULL;
$Order->Items[0]->Trial = false;
$Order->BillingDetails = new stdClass();
$Order->BillingDetails->Email = $oldOrderExistent->BillingDetails->Email;;
$Order->DeliveryDetails = NULL;
$Order->PaymentDetails = new stdClass ();
$Order->PaymentDetails->Type = 'PREVIOUS_ORDER';
$Order->PaymentDetails->Currency = 'usd';
$Order->PaymentDetails->PaymentMethod = new stdClass ();
$Order->PaymentDetails->CustomerIP = '10.10.10.10';
$Order->PaymentDetails->PaymentMethod->RecurringEnabled = true;
$Order->PaymentDetails->PaymentMethod->RefNo = $orderReference;
$Order->Promotions = NULL;
$Order->AdditionalFields = NULL;
$Order->LocalTime = NULL;
$Order->GiftDetails = NULL;
try {
    $newOrderPaidWithPreviousRef = $client->placeOrder($sessionID, $Order);
}
catch (SoapFault $e) {
    echo "newOrderPaidWithPreviousRef: " . $e->getMessage();
    exit;
}
var_dump("newOrderPaidWithPreviousRef", $newOrderPaidWithPreviousRef);
?>

Delay Payment Capture

Overview

Use this setup to force a delay between the moment of authorization and the actual payment capture. Add a buffer period between the moment the payment is authorized and the actual completion date of the order, so you can check if you have enough stock for the products you’re selling or do additional background checks on the customers that place orders, to identify potential fraudulent purchases.

Availability

Capture delay is a set-up available only on request. Contact 2Checkout for more information.

Workflow

The recommended capture delay interval is 48 hours after payment authorization. Capture delay is valid for a period of up to 7 days from the authorization of the payment. After 7 days, the authorization expires, and the amount will be reversed back to customers by their bank.

Tangible products (catalog or dynamic) with catalog shipping

Payment Capture Interval Tangible products (catalog or dynamic)
0h New purchase and Upgrade Renewal for catalog products with catalog shipping Renewal for dynamic products with catalog shipping
Instant authorization, wait for mark shipped/fulfillment, then capture Instant authorization, wait for mark shipped/fulfillment, then capture

 

Instant authorization and capture

48h Instant authorization, wait for mark shipped/fulfillment, if 48h passed, then capture Instant authorization, wait for mark shipped/fulfillment, if 48h passed, then capture Instant authorization, wait for mark shipped/fulfillment, if 48h passed, then capture

Intangible and dynamic products with dynamic shipping 

Payment Capture Interval Intangible and dynamic products
0h

New purchase and Upgrade

Renewal

Instant authorization and capture

Instant authorization and capture

48h

Instant authorization, wait for 48h, then capture

Instant authorization, wait for 48h, then capture

Payment methods

Capture delay can be applied to new purchases, renewals (only for the first billing cycle), and upgrades paid by credit cards.

Use cases

The capture delay feature works differently depending on the products/services that are ordered. 
 

1. If you have a capture delay of 48 hours set on your account and you have incoming orders for catalog or dynamic products, but without using a catalog shipping method, the payment capture takes place at the end of the delay period. This happens even if all other conditions to mark the order as complete were met.

2. If you have a capture delay of 48 hours set on your account and you have incoming orders for catalog or dynamic product with a catalog shipping method, the payment capture is delayed until:

  • You (merchant) mark the order as fulfilled AND
  • The end of the delay interval has been reached (48 hours) although all other conditions to mark the order as complete were met

3. If the end of the delay interval was not reached (48 hours), then the capture continues to be delayed until the end of the interval is reached, regardless of the order having been marked as shipped.

4. If the end of the delay interval was not reached (48 hours), the capture of the payment takes place immediately after the order is marked as fulfilled/shipped.

5. If the end of the delay interval was reached but the order is not marked as shipped, the payment will not be captured, and the funds will be reversed back to the shopper.

 

 

Set test orders in InLine Cart

Overview

Set the test mode in order to use card-based payment methods and eCheck/ACH using test cards and test cardholder names.

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 theTwoCoInlineCart.products.add({code, quantity, options})method to prepare your catalog product.
  4. In order to test mode useTwoCoInlineCart.cart.setTest(true).
  5. Use theTwoCoInlineCart.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.setTest(true);
  TwoCoInlineCart.cart.checkout();
});

Demo

After adding the products to the InLine cart using the above method for testing purposes, your cart should look like this:

Test cards

Card type Card number
VISA 4111111111111111
MasterCard 5555555555554444
AMEX 378282246310005
Discover 6011111111111117
JCB 3566111111111113

 

Use case. To achieve the desired result use the corresponding cardholder names. Cardholder name
Successful authorization for the initial transaction and all recurring charges. John Doe
Successful authorization for the initial transaction and manual renewal transactions but recurring charges fail to authorize with the Insufficient Funds error message. Mike Doe
Successful authorization for the initial transaction and manual renewal transactions but recurring charges fail to authorize with the Stolen Card error message. Jenny Doe
Insufficient funds Mona Doe
Try again later Mark Doe
Stolen card Red Doe
Authentication failed Joy Doe
Expired card Angela Doe
Invalid card number Adrian Doe
Invalid CVV Jack Doe

Remove sources

Overview

Use the deletePromotionSources method 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

require ('PATH_TO_AUTH');

// Promotion code corresponding to the promotion you want to remove sources from
$promotionCode = '';

// Sources array with the source values 
$sources = ['source1', 'source2'];

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

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. 2Checkout 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

Parameter Type/Description

Boolean

true or false depending on whether the changes were successful or not.

Request


<?php
 
require('PATH_TO_AUTH');

$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 2.0';
$EndUser->Language = 'en';
$EndUser->LastName = 'Avangate';
$EndUser->Phone = '1234567890';
$EndUser->State = 'California';
$EndUser->Zip = '90210';
$EndUser->Fax = null;

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

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

Add promotion sources

Overview

Use the addPromotionSources method 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 add products to.

promotionSources

Required (string array)

 

Array of strings defining the promotion sources.

Response

Parameter Type/Description

promotionSources

String array

 

Array of strings defining the promotion sources.

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

// Promotion code corresponding to the promotion you want to add sources to
$promotionCode = '';

// Sources array with the source values 
$sources = ['source1', 'source2'];

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

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