Skip to main content

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

/**
 * ProductCode = 'PDOWNFILE'
 * Default currency: EUR
 *
 * Dynamic pricing configuration
 *
 * Send two prices, including the required one for the default currency
 * The method will append the prices for the sent entries, without removing the previous values
 *
 * If the quantities intervals were not defined then they will be set.
 * If the quantities overlap with existing defined intervals, an Exception will be thrown.
 */
 
 
// make call
$Prices = array();
 
$Price = new stdClass(); // BasicPrice object
$Price->Amount = 140;
$Price->Currency = 'USD';
$Prices[] = $Price;
 
$Price = new stdClass(); // BasicPrice object
$Price->Amount = 80;
$Price->Currency = 'EUR';
$Prices[] = $Price;
 
$Quantities = new stdClass(); // QuantityInterval object
$Quantities->MinQuantity = 1;
$Quantities->MaxQuantity = 10;
 
$PriceOptions = array();
 
$PricingConfigurationCode = '5553603382';
$type = 'regular';
 
$jsonRpcRequest = array (
    'jsonrpc' => '2.0',
    'id' => $i++,
    'method' => 'savePrices',
    'params' => array($sessionID, $Prices, $Quantities, $PriceOptions, $PricingConfigurationCode, $type)
);

$response = callRPC((Object)$jsonRpcRequest, $host);
var_dump ($response);
 
// will output:
// bool(true)

 
/**
 * ProductCode = 'PDOWNFILE'
 * Default currency: EUR
 *
 * Flat pricing configuration
 * Has the VOLTAGE pricing option group assigned and marked as required.
 * If prices are sent WITHOUT setting the pricing option group and options will set the price but without setting values for the options prices.
 */
 
// Call the login method for authentication
$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; // counter for api calls
$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);
 
// make call
$Prices = array();
 
$Price = new stdClass(); // BasicPrice object
$Price->Amount = 80;
$Price->Currency = 'EUR';
$Prices[] = $Price;
 
// if PricingOption group is not required, will set price for combination of QuantityInterval - no-pricing-option-value.
$PriceOptions = array();
 
// if PricingOption group is required, then send options by assigning a PriceOptionsAssigned object (group code and options)
// $optionAssigned = new stdClass(); // PriceOptionsAssigned
// $optionAssigned->Code = 'VOLTAGE';
// $optionAssigned->Options = array('220V'); // radio option group
// $PriceOptions = array($optionAssigned);
 
$Quantities = new stdClass(); // QuantityInterval object
$Quantities->MinQuantity = 1;
$Quantities->MaxQuantity = 99999; // default maximum value
 
$PricingConfigurationCode = '54AA62CA31'; // flat pricing configuration
$type = 'regular';
 
$jsonRpcRequest = array (
    'jsonrpc' => '2.0',
    'id' => $i++,
    'method' => 'savePrices',
    'params' => array($sessionID, $Prices, $Quantities, $PriceOptions, $PricingConfigurationCode, $type)
);
 
$response = callRPC((Object)$jsonRpcRequest, $host);
var_dump ($response);
 
 
/**
 * ProductCode = 'PDOWNFILE'
 * Default currency: EUR
 *
 * Flat pricing configuration
 * Has the COLOR and scalenotmandatory pricing option group assigned and marked as required.
 */
// Call the login method for authentication
$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; // counter for api calls
$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);
 
// make call
$Prices = array();
 
$Price = new stdClass(); // BasicPrice object
$Price->Amount = 10;
$Price->Currency = 'EUR';
$Prices[] = $Price;
 
$optionAssigned = new stdClass(); // PriceOptionsAssigned
$optionAssigned->Code = 'COLOR'; // checkbox pricing option group, multiple values are allowed
$optionAssigned->Options = array('cyan', 'magenta');
$PriceOptions = array($optionAssigned);
 
$optionAssigned = new stdClass(); // PriceOptionsAssigned
$optionAssigned->Code = 'scalenotmandatory'; // interval pricing option group
$optionAssigned->Options = array('scalenotmandatory-1-5');
$PriceOptions = array($optionAssigned);
 
$Quantities = new stdClass(); // QuantityInterval object
$Quantities->MinQuantity = 1;
$Quantities->MaxQuantity = 99999; // default maximum value
 
$PriceOptions = array();
 
$PricingConfigurationCode = '54AA62CA31'; // flat pricing configuration
$type = 'regular';
 
$jsonRpcRequest = array (
    'jsonrpc' => '2.0',
    'id' => $i++,
    'method' => 'savePrices',
    'params' => array($sessionID, $Prices, $Quantities, $PriceOptions, $PricingConfigurationCode, $type)
);
 
$response = callRPC((Object)$jsonRpcRequest, $host);
var_dump ($response);
?>

Add/Import subscriptions with credit/debit card data

Overview

Include payment (credit/debit card) information that 2Checkout uses for recurring billing to renew imported subscriptions. Importing subscriptions with payment data is available only to eligible 2Checkout accounts. Contact 2Checkout directly for additional details.

Use the addSubscription method to import a subscription into 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.

SubscriptionImport

Required (Object)

 

Object designed to provide 2Checkout with all the information to create a subscription.

CardPayment

Optional (Object)

 

Object containing card details.

Response

Parameters Type/Description

SubscriptionReference

String

 

Unique, system-generated subscription identifier.

Request

<?php

require ('PATH_TO_AUTH');

$Product = new stdClass ();
$Product->ProductCode = 'my_subscription_1';
$Product->ProductId = 4639321;
$Product->ProductName = '2Checkout Subscription Imported';
$Product->ProductVersion = 1.0;
$Product->ProductQuantity = 3;
$Product->PriceOptionCodes = array();

$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@2Checkout.com';
$EndUser->FirstName = 'Customer';
$EndUser->Language = 'en';
$EndUser->LastName = '2Checkout';
$EndUser->Phone = '1234567890';
$EndUser->State = 'California';
$EndUser->Fax = NULL;
$EndUser->Zip = '90210';

$Subscription = new stdClass();
$Subscription->ExternalSubscriptionReference = '12345678912ImportedSubscription';
$Subscription->SubscriptionCode= NULL;
$Subscription->StartDate = '2013-01-01';
$Subscription->ExpirationDate = '2017-12-30';
$Subscription->Product = $Product;
$Subscription->EndUser = $EndUser;
$Subscription->ExternalCustomerReference = '12354678ExtCustRef';

$PaymentCard = new stdClass ();
$PaymentCard->CardNumber = '4111111111111111' ;
$PaymentCard->CardType = 'VISA';
$PaymentCard->ExpirationYear = '2018';
$PaymentCard->ExpirationMonth = '12';
$PaymentCard->CCID = '123';
$PaymentCard->HolderName = 'John Doe';
$PaymentCard->HolderNameTime = '15';
$PaymentCard->CardNumberTime = '15';
$PaymentCard->AutoRenewal = true;

$jsonRpcRequest = array (
'method' => 'addSubscription',
'params' => array($sessionID, $Subscription, $PaymentCard),
'id' => $i++,
'jsonrpc' => '2.0');

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

Update a subscription and assign it to another customer

Overview

Move a subscription from under a customer to another customer entity.

Use the updateSubscription method. Avangate moves subscription under the customer for which you provide the Avangate customer reference or the External customer reference during the subscription update process.

update_diagram.png

Requirements

To move a subscription from a source customer to a target customer:

  • Use Avangate customer references or External customer references belonging to the target customer. Avangate re-assigns the subscription to the target customer. 
  • Customer references must be valid and associated to the target customer entity under which you move the subscription.

If you provide both the Avangate customer reference and External customer reference they need to belong to the same target customer entity.

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.

Subscription

Required (Object)

 

To only move a subscription from a source customer to a target customer, send only the Avangate customer reference or the External customer reference.

Response

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;
}
$SubscriptionReferenceTest = '0742B179DD';
try {
    $retrievedSubscription = $client->getSubscription($sessionID, $SubscriptionReferenceTest);
}
catch (SoapFault $e) {
    echo "retrievedSubscription: " . $e->getMessage();
    exit;
}
var_dump("retrievedSubscription", $retrievedSubscription);
var_dump ($retrievedSubscription);
$retrievedSubscription->AvangateCustomerReference = 172673064;
try {
    $updatedSubscription = $client->updateSubscription($sessionID, $retrievedSubscription);
}
catch (SoapFault $e) {
    echo "updatedSubscription: " . $e->getMessage();
    exit;
}
var_dump("updatedSubscription", $updatedSubscription);

Update a subscription

Overview

Change specific details about a subscription. Use the updateSubscription method to change specific details about a subscription.

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.

Subscription

Required (Object)

 

You need to include the entire Subscription object keeping its structure unchanged (retrieve it using getSubscription) but you can update only specific parameters enumerated below.

 

EndUser

Object

 

 

End user details.

 

ExpirationDate

String

 

 

Subscription expiration date - If you changed the time zone for the 2Checkout API by editing system settings under Account settings, then 2Checkout calculates the ExpirationDate according to your custom configuration. Note: The default 2Checkout API time zone is GMT+02:00.

You cannot set an expiration date from the past.

 

SubscriptionEnabled

Boolean

 

 

Possible values: TRUE/FALSE

 

RecurringEnabled

Boolean

 

 

Possible values: TRUE/FALSE

 

ExternalCustomerReference

String

 

 

Unique customer alphanumeric (string) identifiers that you control. Use this to 

move a subscription from under a customer to another customer entity. 2Checkout moves subscription under the customer for which you provide the External customer reference during the subscription update process. View example.

 

ProductId

Int

 

 

System-generated unique product ID. Needs to be the ID of an existing product in the 2Checkout system created under your account.

The product ID governs the product to which the subscription is associated with.

Product types must match Regular - Regular or Bundle - Bundle.

IDs must identify products with the renewal system enabled (max billing cycle 36 months).

 

ProductName

String

 

 

The name of the product for identifier used under ProductID.

 

ProductQuantity

Int

 

 

Ordered quantity.

 

PriceOptionCodes

Array

 

 

Array of product options codes. Pricing options codes are case sensitive.

To impact the renewal price, the PriceOptionsCodes need to belong to price options of pricing configurations used for the product with which the subscription is associated.

 

All other parameters of the Subscription object are non-editable.

The 2Checkout system uses the updated subscription information for:

  • Manual and automatic renewals
  • Upgrades
  • Trial conversions

Response

Parameters Type/Description

Boolean

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

Request

<?php

require ('PATH_TO_AUTH');

$subscriptionReferenceTest = 'YOUR_SUBSCRIPTION_REFERENCE';

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

$updatedSubscription = callRPC((Object)$jsonRpcRequest, $host, true);
var_dump ($updatedSubscription);
$updatedSubscription->RecurringEnabled = false;
$updatedSubscription->SubscriptionEnabled = true;
$updatedSubscription->ExpirationDate = '2020-12-12';

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

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

 

Retrieve iDEAL bank information

Overview

Use the getIdealIssuerBanks method to retrieve the information on the 2Checkout list of banks that support iDEAL payments for shoppers in the Netherlands. You will need banking information to place orders, enabling your shoppers to pay using iDEAL. Use the code parameter from the array returned by getIdealIssuerBanks, as a value of the BankCode parameter in the Order object, when you call placeOrder.

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

The method returns an array of objects, containing the bank code and bank name as parameters. The value of the Code parameter is used in the placeOrder call, in the BankCode parameter.

Parameters Type/Description

Code

String

  String contains the SWIFT code of the bank, the plus sign "+", and the first 3 characters from the bank name. E.q.: in the case of Rabobank, code parameter is "RABONL2U+RAB".
Name String
  String contains the full bank name. E.q.: "Rabobank".

Request


<?php

// authentication script: https://knowledgecenter.2checkout.com/Integration/SOAP_API/API_4.0/02Authentication

require ('PATH_TO_AUTH');

try {
    $getIdealBanks = $client->getIdealIssuerBanks($sessionID);
} catch (SoapFault $e) {
    echo "Error getIdealIssuerBanks: " . $e->getMessage() . $e->faultcode;
    exit;
}

$bankCodes=("getIdealIssuerBanks", $getIdealBanks);

?>

 

Partial refund

Overview

Use the issueRefund method to issue a partial refund for an order processed by 2Checkout.

Requirements 

The payment for the refundable order needs to be collected.

You cannot issue a refund for an amount higher than the total order amount.

Request

require ('PATH_TO_AUTH'); // authentication call

$orderReference = "11554831";
$amount = 48.36;
$item = new stdClass();
$item->LineItemReference = "20c7aaa07650e517b8df55db47d053b70f93764e";
$item->Quantity = 1;
$item->Amount = 10.00;
$items = array($item);
$comment = "We hope you are satisfied with the refund process.";
$reason = "Duplicate purchase";

try {
    $refundedOrder = $client->issueRefund($sessionID, $orderReference, $amount, $items, $comment, $reason);
}
catch (SoapFault $e) {
    echo "refundedOrder: " . $e->getMessage();
    exit;
}
var_dump("refundedOrder", $refundedOrder);

Response

Response Type/Description
Boolean

TRUE is the refund was processed successfully

FALSE otherwise

 

Update product group

Overview

Use the updateProductGroup method to create a new product group for your account.

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.

ProductGroup

Required (object)

 

Use this object to update product groups.

Response

bool(true)

Request

<?php

require ('PATH_TO_AUTH');

$ProductGroup = new stdClass();
$ProductGroup->Name = 'New Product Group from API';
$ProductGroup->Code = 'DBA13A4268';
$ProductGroup->TemplateName = 'Default Template'; // the name of the cart template you want to associate with the product group
$ProductGroup->Description = 'This is a generic description';
$ProductGroup->Enabled = false;

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

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

Use iDEAL

Overview

Place an order with catalog products defined in your Control Panel and collect the payment using iDEAL.

Requirements

Shoppers in the Netherlands can purchase using iDEAL. The billing country and the order country code has to be NL.

Supported currencies

  • EUR

Workflow

  1. Use the getIdealIssuerBanks method for retrieving information on the 2Checkout list of banks that support iDEAL payments. More details about this method here.
  2. Shoppers select iDEAL as a payment option in the interface you provide them and select their bank from the list.
  3. Create the order object. Use IDEAL as the type of the PaymentDetails object, and include ReturnURL and CancelURL. The BankCode parameter should be added based on the bank selected by the customer, from the array obtained after calling method getIdealIssuerBanks.
  4. Use the placeOrder method to send the data to 2Checkout.
  5. Once you place the order, 2Checkout logs it into the system. At this point in time, the status of the order is PENDING.
  6. 2Checkout returns an Order object as the output of the placeOrder method. 
  7. Use the PaymentMethod object to create a redirect URL for the shoppers, concatenating the values of the Href and avng8apitoken parameters. Here's an example of the redirect URL:
    https://api.2checkout.com/4.0/scripts/ideal/authorize/?avng8apitoken=f56373d92ed6b153
    
  8. Customers are directed to the iDEAL payment page, where they have to confirm their payment details before finishing the ordering process.
  9. Shoppers are redirected to the RedirectURL from the Order information object. In case the payment fails, shoppers are redirected to the CancelURL. 

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.

To place an order with iDEAL, use IDEAL as the type of the PaymentDetails object and provide the following parameters as part of the PaymentMethod object:

  • ReturnURL - URL to which customers are redirected after successful payment.
  • CancelURL - URL to which customers are redirected after a failed payment attempt.
  • BankCode - information retrieved based on the bank selected by the customer, from the array obtained after calling getIdealIssuerBanks method.

See code sample for more details. 

    Response

    Parameter Type/Description

    Order information

    Object

      Object containing order information.

    Request

    <?php
    
    require ('PATH_TO_AUTH');
    
    $Order = new stdClass();
    $Order->RefNo = NULL;
    $Order->Currency = 'EUR';
    $Order->Country = 'NL';
    $Order->Language = 'en';
    $Order->CustomerIP = '91.220.121.21';
    $Order->ExternalReference = NULL;
    $Order->Source = NULL;
    $Order->AffiliateId = NULL;
    $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->Items[0]->AdditionalFields = NULL;
    $Order->Items[0]->SubscriptionStartDate = NULL; //If empty or null, subscriptions become active when purchase is made.
    $Order->BillingDetails = new stdClass();
    $Order->BillingDetails->FirstName = 'Test Cosmin API';
    $Order->BillingDetails->LastName = 'Cosmin API';
    $Order->BillingDetails->CountryCode = 'NL';
    $Order->BillingDetails->State = 'California';
    $Order->BillingDetails->City = 'LA';
    $Order->BillingDetails->Address1 = 'Address example';
    $Order->BillingDetails->Address2 = NULL;
    $Order->BillingDetails->Zip = '90210';
    $Order->BillingDetails->Email = 'cosmin.deftu@2checkout.com';
    $Order->BillingDetails->Phone = NULL;
    $Order->BillingDetails->Company = NULL;
    $Order->DeliveryDetails = NULL;
    
    $Order->PaymentDetails = new stdClass ();
    $Order->PaymentDetails->Type = 'IDEAL';
    $Order->PaymentDetails->Currency = 'EUR';
    $Order->PaymentDetails->PaymentMethod = new stdClass ();
    $Order->PaymentDetails->CustomerIP = '91.220.121.21';
    $Order->PaymentDetails->PaymentMethod->ReturnURL = 'http://yourreturnurl.com';
    $Order->PaymentDetails->PaymentMethod->CancelURL= 'http://yourcancelurl.com';
    $Order->PaymentDetails->PaymentMethod->BankCode='RABONL2U+RAB'; // value retrieved based on the bank selected by the customer, from the array obtained after calling method getIdealIssuerBanks.
    
    try {
       $newOrder = $client->placeOrder($sessionID, $Order);
    }
    catch (SoapFault $e) {
        echo "newOrder: " . $e->getMessage();
        exit;
    }
    
    $idealredirect= $newOrder->PaymentDetails->PaymentMethod->Authorize->Href."/?avng8apitoken=".$newOrder->PaymentDetails->PaymentMethod->Authorize->Params->avng8apitoken;
    
    header('Location:' . $idealredirect);
    ?>
    

     

    Retrieve customer 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.

    2CheckoutCustomerReference

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

    Response

    Subscription

    Array of objects

    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 = "YOUR_MERCHANT_CODE";// your account's merchant code available in the 'System settings' area of the cPanel: https://secure.2checkout.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.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;
    }
    $CustomerReference = 260015052;
    try {
        $ListofSubscriptions = $client->getCustomerSubscriptions($sessionID, $CustomerReference);
    }
    catch (SoapFault $e) {
        echo "ListofSubscriptions: " . $e->getMessage();
        exit;
    }
    var_dump("ListofSubscriptions", $ListofSubscriptions);
    
    

     

    Single Sign On in cart

    Overview

    Use the getSingleSignOnInCart method. 2Checkout attaches a unique token to links, designed to identify the returning shoppers and support the automatic extraction of payment data and billing information from the 2Checkout system. For example, you can generate single sign-on in cart links for existing customers logged into your website based on their external or 2Checkout customer IDs.

    How does this work?

    When accessing the shopping cart using tokenized payment links:

    • 2Checkout prefills automatically customer billing and delivery details associated with their 2Checkout customer accounts (linked based on their unique customer IDs).
    • 2Checkout presents shoppers with an optimized payment area featuring the credit/debit cards used to make previous purchases/transactions in the 2Checkout system. Customers have the option of selecting one of the payment methods depending on available card-on-file data.

    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

    Required (string)

     

    Unique customer identifiers. Can be either the ExternalCustomerReference you control or the system-generated 2CheckoutCustomerReference.

    customerType

    Required (string)

     

    Possible values:

    • ExternalCustomerReference
    • 2CheckoutCustomerReference

    url

    Required (string)

     

    The shopping cart URL. 2Checkout redirects shoppers to this URL.

     

    Possible values:

     

    Any buy link you generate from the cPanel or using the API. Note: For the time being, payment tokenization does not support Express Payments Checkout or the 2Checkout mobile shopping cart.

    validityTime

    Optional (int)

     

    The time, in seconds, before the single sign-on URL expires. By default, the URL expires after 10 seconds. (optional)

    validationIp

    Optional (string)

     

    The IP address of the shopper, necessary for security purposes. Can be an empty string or a valid IP, or null.

    Response

    Parameters Type/Description

    Single sign-on URL

    String

     

    The generated string is the tokenized time-limited single sign-on URL pointing to 2Checkout shopping cart.

     

    Note: Each SSO link cleans any previous cart sessions. Shoppers using multiple SSO links would purchase only a single product at a time.

     

    If shoppers add multiple products to cart via SSO buy links and then use a non-SSO link, they’ll purchase all items using the same order.

    When you use single sign-on in cart for customers without card on files in the 2Checkout system, the generated tokenized link prefills the billing information but the purchase process requires that shoppers provide payment information, such as a credit or debit card.

    Example: https://store.YourCustomDomain.com/order/checkout.php?PRODS=1112233&logintoken=8b74ac97f8277654563c44da6915b054ba0d21be

     

    Important! You can use the value of the logintoken to retrieve customer information by SSO token.

     

    Request

    <?php
    
    require ('PATH_TO_AUTH');
    
    $idCustomer = '352365983';
    $customerType = '2CheckoutCustomerReference';
    $url = 'https://store.avancart.com/order/checkout.php?PRODS=4639321&QTY=1&CART=1&CARD=2';
    $validityTime = 50;
    $validationIp = null;
    
    $jsonRpcRequest = array (
    'method' => 'getSingleSignOnInCart',
    'params' => array($sessionID, $idCustomer, $customerType, $url, $validityTime, $validationIp),
    '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