Skip to main content

Update a 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. Avangate 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 Bank transfers

Overview

Place an order using catalog products, and collect the payment using Wire transfers.

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

 Request

<?php

require ('PATH_TO_AUTH');

$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->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 = '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 = 'john.doe@2checkout.com';
$Order->BillingDetails->Phone = NULL;
$Order->BillingDetails->Company = NULL;
$Order->DeliveryDetails = NULL;
$Order->PaymentDetails = new stdClass ();
$Order->PaymentDetails->Type = 'WIRE';
$Order->PaymentDetails->Currency = 'usd';
$Order->PaymentDetails->PaymentMethod = new stdClass ();

$Order->AdditionalFields = NULL;
$Order->LocalTime = NULL;
$Order->GiftDetails = NULL;

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

$order = callRPC($jsonRpcRequest, $host);

Update pricing configuration

Overview

Use the updatePricingConfiguration method to update/edit an existing pricing configuration.

Parameters

Parameters Type/Description

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.

PricingConfiguration

Required (object)

 

Use this object to update/edit an existing pricing configuration for your account.

ProductCode

Required (string)

 

The unique product code that you control not the system-generated product identifier.

You cannot modify:

  • The pricing configuration CODE.
  • The PricingSchema from DYNAMIC to FLAT or vice versa.
  • The intervals of an existing pricing configuration (MinQuantity and MaxQuantity). 

Response

bool(true)

Request

<?php

require ('PATH_TO_AUTH');

$ProductCode = 'YOUR_PRODUCT_CODE';

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

$existingPricingConfig = callRPC((Object)$jsonRpcRequest, $host);
var_dump ($existingPricingConfig );
die;
$existingPricingConfig[1]->Prices->Regular[0]->Currency = 'USD';
$existingPricingConfig[1]->Prices->Regular[0]->Amount = 99;
$newPriceConfig = $existingPricingConfig[1];

$jsonRpcRequest = array (
'jsonrpc' => '2.0',
'id' => $i++,
'method' => 'updatePricingConfiguration',
'params' => array($sessionID, $newPriceConfig, $ProductCode) //Use product ID and not product code for API versions smaller than 2.5
);

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

?>

Create a product group

Overview

Use the addProductGroup method to create product groups for your account:

  • Send null for product group Code. 2Checkout ignores any values you send for Code and generates identifiers itself. 
  • Use unique product group names. 
  • 2Checkout throws an exception if you send a blank product group.
  • If you send only the name of the product group 2Checkout creates the new product group entity. 

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 create product groups. Send null for the Code. 2Checkout generates unique product group code identifiers. 

Response

bool(true)

Request

<?php

require ('PATH_TO_AUTH');

$ProductGroup = new stdClass();
$ProductGroup->Name = 'New Product Group from API';
$ProductGroup->Code = null;//Send null for the Code. 2Checkout generates unique product group code identifiers.
$ProductGroup->TemplateName = 'Default Template';//'001 - Two Column Billing'; //the name of the cart template you want to associate with the product group
$ProductGroup->Description = 'This is a generic description';
$ProductGroup->Enabled = true;

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

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

?>

Retrieve active promotions in cart

Overview

Use this method to list all promotions applied to products added to the cart.

Requirements

This method requires you to set a specific partner using setPartner.

Parameters

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

Response

Parameter Type/Description

Promotion

Array of objects

 

Details below

 

Name

String

 

 

Promotion name

 

Description

String

 

 

Promotion description

 

StartDate

String

 

 

Promotion start date. NULL for promotions that start immediately after they're created.

 

EndDate

String

 

 

Ending date. The date when you set the promotion to end. Is NULL for promotions that you want active indefinitely.

 

MaximumOrdersNumber

Int

 

 

When the maximum number of orders is reached the promotion stops. NULL if you want the promotion to apply to an unlimited number of orders.

 

MaximumQuantity

Int

 

 

Discount only applies to a specific number of products, smaller than the maximum defined quantity. NULL if you want the promotion to apply to an unlimited number units. Any extra quantity added to the cart will be sold at full price.

 

InstantDiscount

Boolean

 

 

Selecting the instant discount option auto-applies the discount for ALL the selected products for all shoppers, without the need to enter the discount coupon.

 

Coupon

String

 

 

Promotion coupon/voucher.

 

DiscountLabel

String

 

 

Set discounts as percentage from the product price or as a fixed amount in the chosen currency.

Request

<?php

require ('PATH_TO_AUTH');  // Authentication example: https://knowledgecenter.avangate.com/Integration/Channel_Manager_API/JSON-RPC/02Authentication
require ('PATH_TO_setPartner'); // setPartner example: https://knowledgecenter.avangate.com/Integration/Channel_Manager_API/JSON-RPC/06Reference/Partner/00Set_partner

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

Errors

Error Description

EMPTY_CART

The shopping cart is empty.

NO_PROMOTIONS

There are no promotions applied to the current shopping cart.

 

One click (1-click) subscription upgrade

Detailed 1-click subscription upgrade flow

Identify returning customers

You particularly need either the Avangate customer reference or the external customer reference you control.

Use customer information

getCustomerSubscriptions 

 

If customers log into your system and you’ve mapped unique identifiers into the Avangate platform you can easily extract their subscription information.

 

Use subscription information

searchSubscriptions 

 

You can also use subscription information to extract customer references, based on a set of filters. Validate the status of the subscription (needs to be Active or Past Due).

  • Customer email
  • Delivered codes/activation keys
  • Avangate customer reference
  • External customer reference
  • Subscription status
  • Recurring billing status
  • Product code
  • Customer country
  • Purchased date
  • Expiration/Renewal deadline
  • Subscription type

 

Validate upgrade options and costs

getProductUpgradeOptions

 

 

getProductUpgradeOptionsPrice

Retrieve the possible upgrade options for a subscription.

 

 

Retrieve information about the costs a customer incurs when upgrading a specific subscription

Create the manual upgrade link

To build custom upgrade links you need the following two elements:

1. The main upgrade path: https://secure.avangate.com/order/upgrade.php? or https://YourStore.com/order/upgrade.php? if you use a custom domain with Avangate. 

2. The unique subscription identifier from the Avangate system: LICENSE=1234567.

The simplest upgrade link you can build is https://secure.avangate.com/order/upgrade.php?LICENSE=1234567

Attach the payment token to the manual Upgrade link

getSingleSignOnInCart

 

Avangate 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 Avangate system.

 

Example


<?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 = "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          = date('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;
}
 
$SubscriptionSearch = new stdClass();
$SubscriptionSearch->CustomerEmail  = null;
$SubscriptionSearch->DeliveredCode = '___TEST___CODE____123';
$SubscriptionSearch->AvangateCustomerReference = '449686020';
$SubscriptionSearch->ExternalCustomerReference = null;
$SubscriptionSearch->Aggregate = false;
$SubscriptionSearch->SubscriptionEnabled = null; //true false null
$SubscriptionSearch->RecurringEnabled = null; // true - autorenewal, false - manual renewal, null = both(default) 
$SubscriptionSearch->ProductCodes = null; //array('Product_Code1', 'Product_Code2');
$SubscriptionSearch->CountryCodes = null;//array ('au')
$SubscriptionSearch->PurchasedAfter = null;
$SubscriptionSearch->PurchasedBefore = null;
$SubscriptionSearch->ExpireAfter = null;
$SubscriptionSearch->ExpireBefore = null;
$SubscriptionSearch->RenewedAfter = null;
$SubscriptionSearch->RenewedBefore = null;
$SubscriptionSearch->NotificationAfter = null;
$SubscriptionSearch->NotificationBefore = null;
$SubscriptionSearch->LifetimeSubscription = null;
$SubscriptionSearch->Type = 'regular'; //'trial', 'regular', 'regularfromtrial'
$SubscriptionSearch->TestSubscription = null; // true, false, null = both(default) 
$SubscriptionSearch->Page = 1;
$SubscriptionSearch->Limit = 10;
try {
    $allsubscriptions = $client->searchSubscriptions($sessionID, $SubscriptionSearch);
}
catch (SoapFault $e) {
    echo "allsubscriptions: " . $e->getMessage();
    exit;
}
$subscriptionReference = $allsubscriptions[0]->SubscriptionReference;
//retrieve all the upgrade options for a subscription
try {
    $optionsforUpgrade = $client->getProductUpgradeOptions($sessionID, $subscriptionReference);
}
catch (SoapFault $e) {
    echo "optionsforUpgrade: " . $e->getMessage();
    exit;
}
//retrieve information about the costs a customer incurs when upgrading a specific subscription
$productCode = $optionsforUpgrade[1]->ProductInfo->ProductCode;
$Currency = 'usd';
$Options = 'emailsupport'.';'.'oneuser1';
try {
    $upgradeOptions = $client->getProductUpgradeOptionsPrice($sessionID, $subscriptionReference, $productCode, $Currency, $Options);
}
catch (SoapFault $e) {
    echo "upgradeOptions: " . $e->getMessage();
    exit;
}
var_dump("upgradeOptions", $upgradeOptions);
try {
    $upgradadebleProduct = $client->getProductByCode($sessionID, $productCode);
}
catch (SoapFault $e) {
    echo "upgradadebleProduct: " . $e->getMessage();
    exit;
}
$upgradadebleProductID = $upgradadebleProduct->AvangateId;
$Options = 'emailsupport'.','.'oneuser1';//Replace the ; separator with , for use with query strings
 
//$upgradelink = "https://secure.avangate.com/order/upgrade.php?LICENSE=".$subscriptionReference; //This is the simplest upgrade link you can build and use to generate a tokenized upgrade checkout URL
$upgradelink = "https://store.avancart.com/order/upgrade.php?LICENSE=".$subscriptionReference."&UPGRADEPROD=".$upgradadebleProductID."&UPGRADEOPT=".$Options; //make sure to use your custom domain or secure.avangate.com otherwise
$IdCustomer = $allsubscriptions[0]->AvangateCustomerReference;
$CustomerType = 'AvangateCustomerReference';
$Url = $upgradelink;
$ValidityTime = 10;
$ValidationIp = null;
try {
    $upgradeSSOURL = $client->getSingleSignOnInCart($sessionID, $IdCustomer, $CustomerType, $Url, $ValidityTime, $ValidationIp);
}
catch (SoapFault $e) {
    echo "ssoLINK: " . $e->getMessage();
    exit;
}
header("Location: $upgradeSSOURL");


Order session contents

Overview

Retrieve the current cart session content, and learn insights about your customers actions in cart.

You can obtain the VAT or sales TAX based on current cart items, prefill the customer information based on the subscription reference, or get the price applied in cart by using the API method from below.

 

Retrieve assigned additional fields

Overview

Use the getAssignedAdditionalFields method to extract information about the additional fields assigned to a specific product.

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.

productCode

Required (string)

 

The editable code that you control at product-level, not the unique, system-generated product ID.

Response

Parameters Type/Description

AdditionalField

Array of objects

Request

<?php

require ('PATH_TO_AUTH');

$ProductCode = 'YOUR_PRODUCT_CODE';

try {
    $AssignedAdditionalField = $client->getAssignedAdditionalFields($sessionID, $ProductCode);
}

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

var_dump("AssignedAdditionalField", $AssignedAdditionalField);


Retrieve a product’s campaigns

Overview

Use the getProductCrossSellCampaigns method to extract information on all cross-sell campaigns triggered by the same primary product.

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.

ProductCode

Required (string)

 

The code of the primary product triggering cross-sell campaign that you can define for each of your offerings.

Response

Parameters Type/Description

CrossSellCampaign

Object

Request

<?php

require ('PATH_TO_AUTH');

$ProductCode = 'subscr1';

$jsonRpcRequest = new stdClass();
$jsonRpcRequest->jsonrpc = '2.0';
$jsonRpcRequest->method = 'getProductCrossSellCampaigns';
$jsonRpcRequest->params = array($sessionID, $ProductCode);
$jsonRpcRequest->id = $i++;

var_dump(" \n Cross-sell campaigns: \n", callRPC($jsonRpcRequest, $host));


Retrieve VAT or sales tax

Overview

  1. Populate the Order object with information. Avangate needs the BillingDetails (object) information to calculate taxes. 
  2. Use the getContents method to get info on all the products added to cart by the shopper in the current session.
  3. The output of the getContents method is the Order session content object.
  4. Under the Price, access information including for each product purchased. Find value added tax and sales tax details under the VAT parameter. 
  5. Tax information is also available for the entire order object. Find value added tax and sales tax details under the VAT parameter.
  6. Calculate the VAT/sales tax rates using the VAT and NetPrice values. 

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.

Response

OrderContents

Object

Request


<?php
$host   = "https://api.avangate.com";
$client = new SoapClient($host . "/soap/6.0/?wsdl", array(
    'location' => $host . "/soap/6.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          = date('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;
}
 
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->Items[0]->Promotion = 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 = 'customer@email.com';
$Order->BillingDetails->Phone = NULL;
$Order->BillingDetails->Company = NULL;
$Order->DeliveryDetails = NULL;
$Order->PaymentDetails = new stdClass ();
$Order->PaymentDetails->Type = 'CC';
$Order->PaymentDetails->Currency = 'usd';
$Order->PaymentDetails->PaymentMethod = new stdClass ();
$Order->PaymentDetails->CustomerIP = '10.10.10.10';
$Order->PaymentDetails->PaymentMethod->RecurringEnabled = true;
$Order->PaymentDetails->PaymentMethod->CardNumber = "4111111111111111";
$Order->PaymentDetails->PaymentMethod->CardType = 'visa';
$Order->PaymentDetails->PaymentMethod->ExpirationYear = '2019';
$Order->PaymentDetails->PaymentMethod->ExpirationMonth = '12';
$Order->PaymentDetails->PaymentMethod->HolderName = 'John';
$Order->PaymentDetails->PaymentMethod->CCID = '123';
$Order->Promotions = NULL;
$Order->AdditionalFields = NULL;
$Order->LocalTime = NULL;
$Order->GiftDetails = NULL;
try {
    $CartContents = $client->getContents    ($sessionID, $Order);
}
catch (SoapFault $e) {
    echo "CartContents: " . $e->getMessage();
    exit;
}
var_dump("CartContents", $CartContents);
?>

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