Skip to main content

Remove products from a promotion

Overview

Use deletePromotionProducts via JSON-RPC API 4.0 to remove products from 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 products from.

promotionProducts

Required (object)

 

Code

Required (string)

 

 

System generated product code.

 

pricingConfigurationCode

Required (string)

 

 

System generated pricing configuration code.

 

pricingOptionCodes

Required (array of strings)

 

 

Pricing option codes that you control.

Response

Parameter Type/Description
status Boolean
  True or False

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 the first product to remove from the promotion
$newProduct1 = new stdClass;
$newProduct1->Code = '';
$newProduct1->PricingConfigurationCode = '';
$newProduct1->PricingOptionCodes = ['',''];

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

$productPromotion = [$newProduct1, $newProduct2];

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

Place an order with PayPal

Overview

Use the placeOrder method to create an order and collect the payment from PayPal.

Requirements

You're required to include the following text when using the 2Checkout API and to make it visible for your customers in the ordering interface. 

Order processed by 2Checkout, authorized reseller and merchant of the products and services offered within this store. 

Currency support

Check with 2Checkout support for a list of currencies available for PayPal. 

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 PayPal rather than PayPal Express, use PAYPAL as the type of the PaymentDetails object and send the shopper email and a return URL as part of the PaymentMethod object. See code sample. 

Workflow

  1. Create the order object. Use PAYPAL as the type of the PaymentDetails object and send the shopper email and a return URL as part of the PaymentMethod object. Place the order.
  2. Once you place the order, 2Checkout logs it into the system. At this point in time, the status of the order is PENDING. 2Checkout responds with the Order information object.
  3. Redirect shoppers to the RedirectURL from the Order information object you receive as response from 2Checkout.
  4. Once shoppers log in to their PayPal account and complete the transaction, they're redirected to the ReturnURL you set in the order object. 2Checkout also authorizes the order and updates the status to AUTHRECEIVED. 

Response

Parameter Type/Description

Order information

Object

Request


<?php
 
//The following script let's you place an new order with Credit/Debit cards as the payment method
 
function callRPC($Request, $hostUrl, $Debug = true) {
    $curl = curl_init($hostUrl);
    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, 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)) {
        $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.0/';
 
$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);
 
$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
// call login
$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);
 
var_dump($sessionID);
$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->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->BillingDetails = new stdClass();
$Order->BillingDetails->FirstName = 'FirstName';
$Order->BillingDetails->LastName = 'LastName';
$Order->BillingDetails->CountryCode = 'us';
$Order->BillingDetails->State = 'California';
$Order->BillingDetails->City = 'LA';
$Order->BillingDetails->Address1 = 'Address example';
$Order->BillingDetails->Address2 = NULL;
$Order->BillingDetails->Zip = '90210';
$Order->BillingDetails->Email = 'email@avangate.com';
$Order->BillingDetails->Phone = NULL;
$Order->BillingDetails->Company = NULL;
$Order->DeliveryDetails = NULL;
$Order->PaymentDetails = new stdClass ();
$Order->PaymentDetails->Type = 'PAYPAL';
$Order->PaymentDetails->Currency = 'usd';
$Order->PaymentDetails->PaymentMethod = new stdClass ();
$Order->PaymentDetails->CustomerIP = '10.10.10.10';
$Order->PaymentDetails->PaymentMethod->RecurringEnabled = true;
$Order->PaymentDetails->PaymentMethod->Email = 'email@avangate.com';
$Order->PaymentDetails->PaymentMethod->ReturnURL = 'http://YourReturnURL.com';
$Order->Promotions = NULL;
$Order->AdditionalFields = NULL;
$Order->LocalTime = NULL;
$Order->GiftDetails = NULL;

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

$APIOrderFullInfo = callRPC((Object)$jsonRpcRequest, $host);
    
$url = $APIOrderFullInfo->PaymentDetails->PaymentMethod->RedirectURL;

header ("Location: $url");

Unassign a PricingOption Group

Overview

Use the unassignPricingConfigurationOptionGroup method to remove a PricingOption Group from a PricingConfiguration.

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.

PricingConfigurationCode

Required (string)

 

Unique, system-generated pricing configuration identifier.  

PriceOptionsGroupAssigned

Required (Object)

 

Details below.

 

PriceOptionsGroupAssigned

Object

Code

Required (string)

 

PricingOption Group identifier.

Required

Required (Object)

 

True or false depending on whether the pricing options group is required during the purchase process or not.

Response

bool(true)

Request

<?php

$host   = "https://api.avangate.com";
$client = new SoapClient($host . "/soap/3.0/?wsdl", array(
    'location' => $host . "/soap/3.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;
}
 
$PricingConfigurationCode = '54DCBC3DC8';
$PriceOptionsGroupAssigned = new stdClass();
$PriceOptionsGroupAssigned->Code = 'STORAGE';
$PriceOptionsGroupAssigned->Required = false;
 
 
try {
    $UnassignedOption = $client-> unassignPricingConfigurationOptionGroup ($sessionID, $PricingConfigurationCode, $PriceOptionsGroupAssigned);
}

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

var_dump("Options", $UnassignedOption);
 
 
?>

 

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

Subscription

Array of objects

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;
}
$CustomerReference = 260015052;
try {
    $ListofSubscriptions = $client->getCustomerSubscriptions($sessionID, $CustomerReference);
}
catch (SoapFault $e) {
    echo "ListofSubscriptions: " . $e->getMessage();
    exit;
}
var_dump("ListofSubscriptions", $ListofSubscriptions);

Unassign a product group

Response

bool(true)

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

$ProductCode = 'AAA4643116';
$Code = "Code_12345AB";
try {
    $AssignedProductGroup = $client->unassignProductGroup($sessionID, $ProductCode, $Code);
}

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

var_dump("AssignedProductGroup", $AssignedProductGroup);

?>

 

SSO by customer reference

Overview

Use the getSingleSignOnByCustomer method to create Single Sign-On links into 2Checkout myAccount based on customer references (IDs). Use either the Avangate Customer Reference or the External Customer Reference to identify specific customers.

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.

idCustomer

Required (string)

 

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

customerType

Required (string)

 

Possible values:

  • ExternalCustomerReference
  • AvangateCustomerReference

page

Optional (string)

 

The specific myAccount page where you redirect the customer.

Possible values:

my_subscription - redirect shoppers to the subscription's page of myAccount based on the SubscriptionReference you provide.

my_products - redirects shoppers to the myAccount page designed to list all products purchased from 2Checkout.

https://store.YourCustomDomain.com/m...t/my_products/?

user_data - redirects shoppers to the Personal Information page in myAccount

https://store.YourCustomDomain.com/m...unt/user_data/?

order_lookup - redirects shoppers to the Order Lookup area of myAccount:

https://store.YourCustomDomain.com/m.../order_lookup/

faq - redirects shoppers to the Support page of myAccount

https://secure. YourCustomDomain.com/support/

payment_methods – redirect shoppers to the Payment Methods area of myAccount:

https://store.YourCustomDomain.com/m...yment_methods/

Do not include PAGE in the URL to redirect shoppers to myAccount homepage

https://store.YourCustomDomain.com/myaccount/?

 

request

Optional (string)

 

Needed for 'my_subscription'

Request[]=code=123D40F123 redirects customers to the page for the subscription with the 123D40F123 SubscriptionReference value.

 

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 string generated is the complete single sign-on URL pointing to 2Checkout myAccount, containing the unique URL. Shoppers using it log into their 2Checkout myAccount automatically.

Request

<?php
require('PATH_TO_AUTH');

$idCustomer = '352365983';
$customerType = 'AvangateCustomerReference';
$page = 'my_license';
$request = null;
$validityTime = 50;
$validationIp = null;
$languageCode = 'en';

$jsonRpcRequest = [
    'method' => 'getSingleSignOnByCustomer',
    'params' => [
        $sessionID,
        $idCustomer,
        $customerType,
        $page,
        $request,
        $validityTime,
        $validationIp,
        $languageCode // optional
    ],
    'id' => $i++,
    'jsonrpc' => '2.0',
];

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

Place an order with iDEAL

Overview

Use the placeOrder method to create orders and collect payments from iDEAL.

Requirements

Only shoppers in the Netherlands can select iDEAL as a payment option and choose their bank. You're required to include the following text when using 2Checkout API and to make it visible for your customers in the ordering interface.

Order processed by 2Checkout, authorized reseller and merchant of the products and services offered within this store. 

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 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 a successful payment.
  • CancelURL - URL to which customers are directed 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

    Order information

    Object

    Request

    
    <?php
    
    // authentication script: https://knowledgecenter.2checkout.com/Integration/SOAP_API/API_4.0/02Authentication
    
    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->BillingDetails = new stdClass();
    $Order->BillingDetails->FirstName = 'FirstName';
    $Order->BillingDetails->LastName = 'LastName';
    $Order->BillingDetails->CountryCode = 'NL';
    $Order->BillingDetails->State = 'State Example';
    $Order->BillingDetails->City = 'City Example';
    $Order->BillingDetails->Address1 = 'Address example';
    $Order->BillingDetails->Address2 = NULL;
    $Order->BillingDetails->Zip = '12345';
    $Order->BillingDetails->Email = 'email@address.com';
    $Order->BillingDetails->Phone = NULL;
    $Order->BillingDetails->Company = 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 = 'YOUR_RETURN_URL';
    $Order->PaymentDetails->PaymentMethod->CancelURL= 'YOUR_CANCEL_URL';
    $Order->PaymentDetails->PaymentMethod->BankCode='BANK_CODE'; // 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);
    ?>
    

     

    Unassign a product group

    Response

    bool(true)
    

    Request

    <?php
    
    $host   = "https://api.avangate.com";
    $client = new SoapClient($host . "/soap/3.0/?wsdl", array(
        'location' => $host . "/soap/3.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;
    }
    
    $ProductCode = 'AAA4643116';
    $Code = "Code_12345AB";
    try {
        $AssignedProductGroup = $client->unassignProductGroup($sessionID, $ProductCode, $Code);
    }
    
    catch (SoapFault $e) {
        echo "AssignedProductGroup: " . $e->getMessage();
        exit;
    }
    
    var_dump("AssignedProductGroup", $AssignedProductGroup);
    
    ?>
    

     

    Retrieve PayPal redirect URL

    Overview

    Use the getPayPalExpressCheckoutRedirectURL method to retrieve the RedirectURL by sending an Order object with PAYPAL_EXPRESS payment method.

    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.

    Order

    Required (Object)

     

    Object designed to collect all data necessary for an order, including billing, product/subscription plan and payment details.

     

    Use PAYPAL_EXPRESS as the payment method.

    Response

    Parameters Type/Description

    PayPalExpressCheckoutRedirectURL

    String

    Request

     <?php
    //Use the following 2 scripts:
    //The place_order_api_json_paypal_express.php
    // And the place_order_api_json_paypal_express_response that you can find below
    
    require ('PATH_TO_AUTH');
    
    $NewOrder = new stdClass();
    $NewOrder->Language = 'fr';
    //$NewOrder->LocalTime = date('Y-m-d G:i:s');
    $NewOrder->CustomerReference = 'APITEST';//uniqid('TESTCUSTOMER:');
    
    $Product = new stdClass();
    $Product->Code = 'my_subscription_1';
    $Product->Quantity = 1;
    $NewOrder->Items[] = $Product;
    $NewOrder->Currency = 'EUR';
    $Payment = new stdClass();
    $Payment->Type = 'PAYPAL_EXPRESS';
    $Payment->Currency = 'EUR';
    $Payment->CustomerIP = '91.220.121.21';
    $PayPalExpress = new stdClass();
    $PayPalExpress->Email='customer@email.com';
    $PayPalExpress->ReturnURL = 'http://' . $_SERVER['HTTP_HOST'] . '/api/place_order_api_json_paypal_express_response.php';
    $PayPalExpress->CancelURL = 'http://' . $_SERVER['HTTP_HOST'] . '/api/place_order_api_json_paypal_express_response.php' . '?cancel=true';
    $Payment->PaymentMethod = $PayPalExpress;    
    $NewOrder->PaymentDetails = $Payment;
    
    // Call the method for retrieving Express Checkout redirect URL
    $jsonRpcRequest = new stdClass();
    $jsonRpcRequest->jsonrpc = '2.0';
    $jsonRpcRequest->method = 'getPayPalExpressCheckoutRedirectURL';
    $jsonRpcRequest->params = array($sessionID, $NewOrder);
    $jsonRpcRequest->id = $i++;
    $redirectUrl = callRPC($jsonRpcRequest, $host);
    header('Location:' . $redirectUrl);
    die();
    
    
    // This is the start of the second script place_order_api_json_paypal_express_response.php
    
    <?php
    var_dump($_REQUEST);
    if (isset($_GET['billingDetails'])) {
        $billingDetails = base64_decode($_GET['billingDetails']);
        parse_str($billingDetails, $billingDetailsArray);
    }
    if (isset($_GET['deliveryDetails'])) {
        $deliveryDetails = base64_decode($_GET['deliveryDetails']);
        parse_str($deliveryDetails, $deliveryDetailsArray);
    }
    if (isset($_GET['token'])) {
        $token = $_GET['token'];
    }
    if (!empty($_GET['cancel']) && $_GET['cancel'] == true) {
      echo 'canceled';
      die();
    } else {
      echo 'success!';
    }
    
    
    /*************************************************************/
    
    function callRPC($Request, $hostUrl, $Debug = true) {
        $curl = curl_init($hostUrl);
        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, 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)) {
            $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.0/';
    
    $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; // counter for api calls
    // Call the login method for authentication
    $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);
    $NewOrder = new stdClass();
    $NewOrder->Language = 'fr';
    $NewOrder->CustomerReference = 'APITEST';//uniqid('TESTCUSTOMER:');
    $Product = new stdClass();
    $Product->Code = 'my_subscription_1';
    $Product->Quantity = 1;
    $NewOrder->Items[] = $Product;
    $Billing = new stdClass();
    $Billing->Country = empty($billingDetailsArray['Country']) ? '' : $billingDetailsArray['Country'];
    $Billing->City = empty($billingDetailsArray['City']) ? '' : $billingDetailsArray['City'];
    $Billing->State = empty($billingDetailsArray['State']) ? '' : $billingDetailsArray['State'];
    $Billing->PostalCode = empty($billingDetailsArray['PostalCode']) ? '' : $billingDetailsArray['PostalCode'];
    $Billing->Email = empty($billingDetailsArray['Email']) ? '' : $billingDetailsArray['Email'];
    $Billing->FirstName = empty($billingDetailsArray['FirstName']) ? '' : $billingDetailsArray['FirstName'];
    $Billing->LastName = empty($billingDetailsArray['LastName']) ? '' : $billingDetailsArray['LastName'];
    $Billing->Address = empty($billingDetailsArray['Address']) ? '' : $billingDetailsArray['Address'];
    $NewOrder->BillingDetails = $Billing;
    $Delivery = new stdClass();
    $Delivery->Country = empty($deliveryDetailsArray['Country']) ? '' : $deliveryDetailsArray['Country'];
    $Delivery->City = empty($deliveryDetailsArray['City']) ? '' : $deliveryDetailsArray['City'];
    $Delivery->State = empty($deliveryDetailsArray['State']) ? '' : $deliveryDetailsArray['State'];
    $Delivery->FirstName = empty($deliveryDetailsArray['FirstName']) ? '' : $deliveryDetailsArray['FirstName'];
    $Delivery->LastName = empty($deliveryDetailsArray['LastName']) ? '' : $deliveryDetailsArray['LastName'];
    $Delivery->Address = empty($deliveryDetailsArray['Address']) ? '' : $deliveryDetailsArray['Address'];
    $Delivery->PostalCode = empty($deliveryDetailsArray['PostalCode']) ? '' : $deliveryDetailsArray['PostalCode'];
    $NewOrder->DeliveryDetails = $Delivery;
    $Payment = new stdClass();
    $Payment->Type = 'PAYPAL_EXPRESS';
    $Payment->Currency = 'EUR'; // for sku
    $Payment->CustomerIP = '91.220.121.21';
    $PayPal = new stdClass();
    $PayPal->Email='customer@email.com';
    $PayPal->Token = $token;
    $PayPal->ReturnURL = 'http://' . $_SERVER['HTTP_HOST'] . '/api/place_order_api_json_paypal_express_response.php1';
    $PayPal->CancelURL = 'http://' . $_SERVER['HTTP_HOST'] . '/api/place_order_api_json_paypal_express_response.php1' . '?cancel=true';
    $Payment->PaymentMethod = $PayPal;
    $NewOrder->PaymentDetails = $Payment;
    $OrderField = new stdClass();
    $OrderField->Code = 'ED5310';
    $OrderField->Value = 'Value1';
    
    // Call the method for placing the order
    $jsonRpcRequest = new stdClass();
    $jsonRpcRequest->jsonrpc = '2.0';
    $jsonRpcRequest->method = 'placeOrder';
    $jsonRpcRequest->params = array($sessionID, $NewOrder);
    $jsonRpcRequest->id = $i++;
    $APIOrderFullInfo = callRPC($jsonRpcRequest, $host);
    
    var_dump($APIOrderFullInfo);
    

    Retrieve price based on specific options

    Overview

    Use getPrice to extract cost information for a product/subscription plan, based on a specific list of options. 

    Parameters

    Parameters Type/Description

    Item

    Required (Object)

    Details below.

     

    Code

    Required (string)

     

     

    Unique product identifier your control. Max length 256 characters.

     

    Quantity

    Required (String)

     

     

    Number of units.

     

    PriceOptions

    Optional (array of objects)

     

     

    Array of price option groups.

                    Options Optional (array of objects)
        Array of pricing options.
                                    Value Optional (string)
        Pricing option code.

    Billing details

    Optional (Object)

     

    Details below. Can be null. 

     

    FirstName

    Optional (string)

     

     

    Shopper name.

     

    LastName

    Optional (string)

     

     

    Shopper surname.

     

    CountryCode

    Optional (string)

     

     

    Shopper country. ISO 3166 two-letter code. Include CountryCode in your request in combination with a null value for Currency, to receive the price in the default currency of the country you set. 

     

    State

    Optional (string) – Required for US, Brazil, and Romania

     

     

    The state in the shopper's country. Mandatory when you set the Billing Country to the US, Brazil, and Romania. Use case insensitive utf8 strings for the full name, or just the two-letter code.

     

    City

    Optional (string)

     

     

    Shopper city.

     

    Address1

    Optional (string)

     

     

    Shopper address.

     

    Address2

    Optional (string)

     

     

    Shopper address.

     

    Zip

    Optional (string)

     

     

    ZIP/ Postal code.

     

    Email

    Optional (string)

     

     

    Shopper email address.

     

    Phone

    Optional (string)

     

     

    Shopper phone number. Mandatory when you set Brazil as the Billing Country. Can be NULL.

     

    Company

    Optional (string)

     

     

    Company name. Can be null for end users. When present, you also need to provide the FiscalCode.

     

    FiscalCode

    Optional (string) – Required for Brazil

     

     

    • For companies, it needs to be the VAT ID. 2Checkout will validate the value provided and throw an error if the VAT ID is invalid/incorrect when calling setPaymentDetails. When present, you also need to provide the Company name.

    • Mandatory when you set Brazil as the Billing Country. For Brazilian customers, it represents the Fiscal Code (CPF/CNPJ).

    • Can be NULL for end users.

    Currency

    Required (string)

     

    The currency ISO code for the payment - ISO 4217. Example: “usd.”

    CouponCode

    Optional (string)

     

    Promotion coupon/voucher.

    PayType

    Optional (string)

     

    The payment method:

    • CC (credit/debit card - including local Brazilian cards).
    • ENCRYPTED_PAYMENT_DATA (client-side encryption)
    • PAYPAL
    • PAYPAL_EXPRESS
    • TEST (for test orders).
    • PREVIOUS_ORDER (place new orders using the reference of a previous order).
    • EXISTING_PAYMENT_DATA  (use a card one of your customers already used to purchase from your account).
    • WIRE – the placeOrder response includes Wire payment details.
    • CHECK – the placeOrder response includes Check payment details.
    • PURCHASEORDER - use for orders with POs.
    • FREE – for 0 value orders for which you’re not requiring customers to provide payment details.

    Response

    Parameters Type/Description
    ItemPrice

    Object

    Details below.

    UnitNetPrice

    Float

     

    The value per product unit, excluding sales tax/VAT expressed in the payment currency.

    UnitGrossPrice

    Float

     

    Total value per product unit, including sales tax/VAT expressed in the payment currency. UnitGrossPrice does not reflect any discounts.

    UnitVAT

    Integer

     

    Sales tax/VAT per product unit expressed in the payment currency.

    UnitDiscount

    Integer

     

    Value of the discount per product unit expressed in the payment currency.

    UnitNetDiscountedPrice

    Float

     

    The value per product unit, expressed in the payment currency, excluding sales tax/VAT, from which 2Checkout deducts the unit discount.

    UnitGrossDiscountedPrice

    Float

     

    Total costs shoppers incur per product unit, expressed in the payment currency. This value includes sales tax/VAT, 2Checkout and affiliate commissions, but 2Checkout deducts the value of any discounts.

    UnitAffiliateCommission

    Integer

     

    Value of the affiliate commission per product unit calculated expressed in the payment currency.

     

    2Checkout deducts discounts from the costs incurred by shoppers before calculating affiliate commissions.

     

    2Checkout does not take into account shipping costs when calculating affiliate commissions.

     

    NULL when 2Checkout does not apply an affiliate commission.

    VATPercent Integer
      VAT percentage applied to purchase.
    HandlingFeeNetPrice Integer
      Handling fee applied to your NET price configuration.
    HandlingFeeGrossPrice Integer
      Handling fee applied to your GROSS price configuration.
    AffiliateCommission Optional (double)
      Value of the affiliate commission for the order calculated from the NetDiscountedPrice expressed in the payment currency. Or NULL. 2Checkout does not take into account shipping costs when calculating affiliate commissions.
    Currency Optional (string)
      The currency ISO code for the payment - ISO 4217. Example: “usd.” Use null as value when you include CountryCode in your request, to receive the price in the default currency of the country you set. 
    Discount Optional (double)
      Value of the discounts for an order expressed in the payment currency.
    GrossDiscountedPrice Optional (double)
      Total costs shoppers incurexpressed in the payment currencyThis value includes sales tax/VAT, 2Checkout, and affiliate commissions, but 2Checkout deducts the value of any discounts.
    GrossPrice Optional (double)
      Total order value, including sales tax/VAT expressed in the payment currency. GrossPrice does not reflect any discounts.
    NetDiscountedPrice Optional (double)
      The NetPrice order value excluding sales tax/VAT, from which 2Checkout deducts discounts. NetDiscountedPriceis expressed in the payment currency.
    NetPrice Optional (double)
      Order value excluding sales tax/VAT expressed in the payment currency.
    VAT Optional (double)
      Value of sales tax/VAT expressed in the payment currency.

    Request

    <?php
    
    require ('PATH_TO_AUTH');
    
    $CartItem = new stdClass();
    
    $CartItem->Code = 'my_subscription_1';
    $CartItem->Quantity = 1;
    
    $CartItem->PriceOptions = array();
    $CartItem->PriceOptions[0] = new stdClass();
     
    $CartItem->PriceOptions[0]->Options = array();
    $CartItem->PriceOptions[0]->Options[0] = new stdClass();
    $CartItem->PriceOptions[0]->Options[0]->Value ="myPriceOptionCode";
    
    /* $CartItem->Trial = new stdClass();
    $CartItem->Trial->Period = 8;
    $CartItem->Trial->Price = 0; */
    
    $BillingDetails = NULL;
    $Currency = 'USD';
    $CouponCode = '123';
    $PayType = 'CC';
    
    
    $jsonRpcRequest = array (
    'method' => 'getPrice',
    'params' => array($sessionID, $CartItem, $BillingDetails, $Currency, $CouponCode, $PayType),
    '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