Skip to main content

Remove coupon

Overview

Use the deletePromotionCoupon method to remove single or multiple coupons from a promotion.

Parameters

Parameter Type/Description

promotionCode

Required (string)

 

The code corresponding to the promotion that you want to remove coupons from.

promotionCoupon

Required (object)

 

type

Required (string)

 

 

Coupon type. Available values:

  • SINGLE, use in conjunction with Code
  • MULTIPLE, use in conjunction with Codes

 

Code/Codes

Required (string/array of strings)

 

 

Coupon code (for SINGLE) or array of coupon codes (for MULTIPLE).

Response

Parameter Type/Description
promotionCoupon Object

Request

<?php

require ('PATH_TO_AUTH');

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

// Define single coupon object
$promotionCoupon = new stdClass;
$promotionCoupon->Type = 'SINGLE';
$promotionCoupon->Code = 'YOUR_CODE_HERE';

// Define multiple coupon object
$promotionCoupon = new stdClass;
$promotionCoupon->Type = 'MULTIPLE';
$promotionCoupon->Codes = ['YOUR_CODE_1', 'YOUR_CODE_2'];

try {
    $updatedPromotion = $client->addPromotionCoupon ($sessionID, $promotionCode, $promotionCoupon);
}

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

var_dump("UpdatedPromotion", $updatedPromotion);

 

Assign order/product additional fields

Overview

Use the assignAdditionalField method to update additional fields 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.

FieldCode

Required (string)

 

Field identifier. Alpha-numeric chars, underscores and dashes.

Required

Boolean

 

True or False depending on whether you want make the field mandatory or not.

ProductCode

Required (string)

 

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

Request

<?php

require ('PATH_TO_AUTH');

$ProductCode = 'YOUR_PRODUCT_CODE';
$FieldCode = 'YOUR_FIELD_CODE';
$Required = true;

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

?>

Response

bool(true)

Change time zones in the 2Checkout system

Overview

The 2Checkout platform supports time zones and Daylight Saving Time corrections when reporting the date and time. Time zone support enables you to gain better insight into the performance of your business operations correlating it with your preferred time zone, or the one that best matches your geographical location.

2Checkout date-time stamps:

  • GMT+02:00 by default;
  • The time zone you set using Account settings.

The 2Checkout platform enables you to control the Time zone for:

  • The Control Panel
  • The 2Checkout API

Note: The Time zones set for the Control Panel and for the API can coincide, but at the same time they can be different, since they work independent of one another. For example, you can set GMT-8 if you're on Pacific Time for the Control Panel, and GMT-6 for Central America for the API.

Impact

Changing the Time zones in the 2Checkout platform impacts the way in which the system reports:

  • the date and time of orders placed by your customers and partners;
  • when placing partner orders;
  • subscriptions generated by the system;
  • changes happening through the lifetime of subscriptions;
  • delivery confirmations;
  • refunds.

Note: 2Checkout corrects for Daylight Saving Time. The date and time information can vary through the inclusion of Daylight Savings depending on your country and the period of the year.

In addition, date and time info sent through IPN (Instant Payment Notification) and LCN (License Change Notification) will also adapt to reflect the time zone you opt to use for the 2Checkout API.

Exceptions

  1. Accounting area - All Accounting data recorded and provided by the 2Checkout platform uses the system's default GMT+02:00 time zone and cannot be changed. The accounting reports, emails you receive from 2Checkout, the Accounting area in the Control Panel, invoices, Product overview, Orders overview and Products report will display the GMT+02:00 time zone of 2Checkout's system.
  2. Bonus programs for 2Checkout affiliates use the default GMT+02:00 time zone.
  3. The 2Checkout sales reports use default GMT+02:00 time zone.
  4. Parts of the 2Checkout API not related to IPN and LCN.

Time zone setup

To set up or change time zones in the 2Checkout platform for your account, navigate to Account settings, and in the System settings area, click on the Edit system settings button at the bottom of the page.

By default, the Control Panel uses the (GMT+02:00) Athens, Bucharest, Istanbul time zone to display the date, to which Daylight Saving might apply, depending on country and period of the year. Using the dropdown menus, you can change the Control Panel display time zones in order & customers related areas (Order Search, Customers, Delivery Confirmations, Place Partner Order and Partner Refunds) and the time zoned used in the 2Checkout APIs for IPN (Instant Payment Notification) and LCN (License Change Notification).

Displaying time zone details

When you select a time zone it is displayed throughout the Control Panel, but Daylight Saving Time corrections will only be made for the actual date and time.

This means that if you select GMT + 01:00, when the associated offset increases to GMT + 02:00 because of Daylight Savings, the date and time reported by the system will change accordingly, even though GMT + 01:00 will appear per your settings.

Orders search for both eStore orders and Partner orders enable you to swap the report time zone between the 2Checkout default and the custom time zone you selected.

The same is valid for the Subscriptions ManagementCustomers and the Partner Refunds report.

The time zone is also displayed on the Dashboard (home page of the Control Panel) under the Latest orders area. In addition, when editing the details of a subscription, time zone information will also be displayed.

2Checkout API time zones

2Checkout sends out datetime stamps in the following situations:

  • By default for every LCN (License Change Notification). This behavior cannot be switched off.
  • For IPN (Instant Payment Notification) but only if under IPN settings you check the TIMEZONE_OFFSET option in the notification details area.

LCN - TIMEZONE_OFFSET: The time zone you selected or the default GMT+02:00 time zone of the 2Checkout system.

IPN - TIMEZONE_OFFSET: The time zone you selected or the default GMT+02:00 time zone of the 2Checkout system.

IDN_DATE - If you changed the time zone for the 2Checkout API by editing system settings under Account settings, then the IDN_DATE will be calculated according to your custom configuration. 2Checkout will use your custom set time zone for the IDN_DATE when calculating the HASH, and it's important that you also use the same datetime stamp, also per the custom time zone.

IRN_DATE - If you changed the time zone for the 2Checkout API by editing system settings under Account settings, then the IRN_DATE will be calculated according to your custom configuration. 2Checkout will use your custom set time zone for the IRN_DATE when calculating the HASH, and it's important that you also use the same datetime stamp, also per the custom time zone.

Electronic delivery - TIMEZONE: The time zone you selected or the default GMT+02:00 time zone of the 2Checkout system.

FAQ

Will changing the time zone prolong or shorten the lifetime of subscriptions sold?

No. Changing the time zone has no impact on the lifecycle of subscriptions you already sold and are used by your customers. Only the datetime stamps reported by the 2Checkout system vary when swapping one time zone for another. Similarly, changing time zones will not impact renewals or expiration deadlines, for example.

Some orders just placed appear with datetime stamps in the future or in the past. How is this possible?

Such discrepancies occur only in scenarios in which you opted to set a time zone different than the one specific to your geographical location.

If you're based in the UK but use (GMT+01:00) Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna instead of (GMT+00:00) Greenwich Mean Time : Dublin, Edinburgh, Lisbon, London, then orders your customers place between 11:00 PM and 12:00 AM (UK time) are reported as being placed the next day.

Similarly, if you're based in the UK but instead of using (GMT+00:00) Greenwich Mean Time : Dublin, Edinburgh, Lisbon, London, you change the time zone settings in the 2Checkout Control Panel to (GMT-06:00) Central Time (US & Canada), orders your customers place after 12:00 AM are reported as being placed the previous day.

Available time zones

  • (GMT-11:00) Midway Island, Samoa
  • (GMT-10:00) Hawaii
  • (GMT-09:00) Alaska
  • (GMT-08:00) Tijuana, Baja California
  • (GMT-08:00) Pacific Time (US & Canada)
  • (GMT-07:00) Mountain Time (US & Canada)
  • (GMT-07:00) Chihuahua, La Paz, Mazatlan - Old
  • (GMT-07:00) Chihuahua, La Paz, Mazatlan - New
  • (GMT-07:00) Arizona
  • (GMT-06:00) Saskatchewan
  • (GMT-06:00) Guadalajara, Mexico City, Monterrey - Old
  • (GMT-06:00) Guadalajara, Mexico City, Monterrey - New
  • (GMT-06:00) Central Time (US & Canada)
  • (GMT-06:00) Central America
  • (GMT-05:00) Indiana (East)
  • (GMT-05:00) Eastern Time (US & Canada)
  • (GMT-05:00) Bogota, Lima, Quito, Rio Branco
  • (GMT-04:30) Caracas
  • (GMT-04:00) Santiago
  • (GMT-04:00) Manaus
  • (GMT-04:00) La Paz
  • (GMT-04:00) Atlantic Time (Canada)
  • (GMT-03:30) Newfoundland
  • (GMT-03:00) Montevideo
  • (GMT-03:00) Greenland
  • (GMT-03:00) Georgetown
  • (GMT-03:00) Buenos Aires
  • (GMT-03:00) Brasilia
  • (GMT-02:00) Mid-Atlantic
  • (GMT-01:00) Cape Verde Is.
  • (GMT-01:00) Azores
  • UTC (this option will only appear in the drop down menu for the 2Checkout API time zone selection)
  • (GMT+00:00) Casablanca
  • (GMT+00:00) Greenwich Mean Time : Dublin, Edinburgh, Lisbon, London
  • (GMT+00:00) Monrovia, Reykjavik
  • (GMT+01:00) Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna
  • (GMT+01:00) Belgrade, Bratislava, Budapest, Ljubljana, Prague
  • (GMT+01:00) Brussels, Copenhagen, Madrid, Paris
  • (GMT+01:00) Sarajevo, Skopje, Warsaw, Zagreb
  • (GMT+01:00) West Central Africa
  • (GMT+02:00) Amman
  • (GMT+02:00) Athens, Bucharest, Istanbul
  • (GMT+02:00) Beirut
  • (GMT+02:00) Cairo
  • (GMT+02:00) Harare, Pretoria
  • (GMT+02:00) Helsinki, Kyiv, Riga, Sofia, Tallinn, Vilnius
  • (GMT+02:00) Jerusalem
  • (GMT+02:00) Minsk
  • (GMT+02:00) Windhoek
  • (GMT+03:00) Baghdad
  • (GMT+03:00) Kuwait, Riyadh
  • (GMT+03:00) Moscow, St. Petersburg, Volgograd
  • (GMT+03:00) Nairobi
  • (GMT+03:00) Tbilisi
  • (GMT+03:30) Tehran
  • (GMT+04:00) Abu Dhabi, Muscat
  • (GMT+04:00) Baku
  • (GMT+04:00) Caucasus Standard Time
  • (GMT+04:00) Port Louis
  • (GMT+04:00) Yerevan
  • (GMT+04:30) Kabul
  • (GMT+05:00) Ekaterinburg
  • (GMT+05:00) Islamabad, Karachi
  • (GMT+05:00) Tashkent
  • (GMT+05:30) Chennai, Kolkata, Mumbai, New Delhi
  • (GMT+05:30) Sri Jayawardenepura
  • (GMT+05:45) Kathmandu
  • (GMT+06:00) Almaty, Novosibirsk
  • (GMT+06:00) Astana, Dhaka
  • (GMT+06:30) Yangon (Rangoon)
  • (GMT+07:00) Bangkok, Hanoi, Jakarta
  • (GMT+07:00) Krasnoyarsk
  • (GMT+08:00) Beijing, Chongqing, Hong Kong, Urumqi
  • (GMT+08:00) Irkutsk, Ulaan Bataar
  • (GMT+08:00) Kuala Lumpur, Singapore
  • (GMT+08:00) Perth
  • (GMT+08:00) Taipei
  • (GMT+09:00) Osaka, Sapporo, Tokyo
  • (GMT+09:00) Seoul
  • (GMT+09:00) Yakutsk
  • (GMT+09:30) Adelaide
  • (GMT+09:30) Darwin
  • (GMT+10:00) Brisbane
  • (GMT+10:00) Canberra, Melbourne, Sydney
  • (GMT+10:00) Guam, Port Moresby
  • (GMT+10:00) Hobart
  • (GMT+10:00) Vladivostok
  • (GMT+11:00) Magadan, Solomon Is., New Caledonia
  • (GMT+12:00) Auckland, Wellington
  • (GMT+12:00) Fiji, Kamchatka, Marshall Is.
  • (GMT+13:00) Nuku'alofa

Update order/product additional fields

Overview

Use the updateAdditionalField method to update additional fields 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.

AdditionalField

Object

 

Additional field object.

Response

bool(true)

Request

<?php

require ('PATH_TO_AUTH');

$AdditionalField                             = new stdClass();
$AdditionalField->Label                      = 'Do you agree with the new newsletter policy 2015?';
$AdditionalField->Type                       = 'LISTBOX';
$AdditionalField->Code                       = 'NewsletterPolicy1234576';
$AdditionalField->ApplyTo                    = 'ORDER';
$AdditionalField->Values                     = array();
$AdditionalField->Values[0]                  = 'YES';
$AdditionalField->Values[1]                  = 'NO';
$AdditionalField->ValidationRule             = null;
$AdditionalField->Translations               = array();
$AdditionalField->Translations[0]            = new stdClass();
$AdditionalField->Translations[0]->Label     = "Êtes-vous d'accord avec la politique de la newsletter?";
$AdditionalField->Translations[0]->Values    = array();
$AdditionalField->Translations[0]->Values[0] = 'Oui';
$AdditionalField->Translations[0]->Values[1] = 'Non';
$AdditionalField->Translations[0]->Language  = 'fr';
$AdditionalField->Translations[1]            = new stdClass();
$AdditionalField->Translations[1]->Label     = 'Haben Sie mit dem Newsletter Politik zu?';
$AdditionalField->Translations[1]->Values    = array();
$AdditionalField->Translations[1]->Values[0] = 'Ja';
$AdditionalField->Translations[1]->Values[1] = 'Nein';
$AdditionalField->Translations[1]->Language  = 'de';

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

?>

 

VAT ID support for Express PayPal Checkout

Overview

VAT-registered business customers based in the European Union can now use the PayPal Express Checkout flow to pay for their orders being charged according to the VAT ID they provide.

After customers confirm the payment with PayPal, 2Checkout redirects them to the shopping cart and allows them to enter their VAT ID before placing the order.

Availability

This feature is available for all 2Checkout accounts and applies to the PayPal Express Checkout purchase flow.

Usage

Buy links generated on the Express Checkout purchase flow include DESIGN_TYPE=2 by default for new 2Checkout accounts.

Existing 2Checkout customers can easily leverage this enhancement by altering the DESIGN_TYPE parameter within the buy links from DESIGN_TYPE=1 to DESIGN_TYPE=2.

Using DESIGN_TYPE=1 does not enable VAT ID support.

Purchase flow

1. Shoppers reach the shopping cart, select PayPal as their payment method and proceed to checkout.

 

2. They log in to their PayPal account

3. PayPal asks them to confirm the payment

4. Shoppers return to the shopping cart to confirm the billing and delivery data and enter their VAT ID.

5. They place the order.

Pricing configuration

Overview

Use this object to add/create and update/edit pricing configurations for your account. You can assign one or multiple price option groups to pricing configurations.

You identify a pricing configuration using its unique identifier: Code.

Parameters

Parameters Type/Description

Name

String

 

Pricing configuration name.

Default

Boolean

 

True for the default pricing configuration

BillingCountries

Array of strings

 

ISO codes of the countries assigned to the pricing configuration.

Empty unless a pricing configuration has specific countries assigned.

PricingSchema

String

 

DYNAMIC – With a base price

FLAT – Without a base price

PriceType

String

 

Possible values:

• NET

• GROSS

DefaultCurrency

String

 

The ISO code of the default currency for the pricing configuration

Prices

Object

 

Details below.

 

Regular

Array of objects

 

 

Details below.

 

 

Amount

Int

 

 

 

The price of the product. Use -1 to delete it.

 

 

Currency

String

 

 

 

ISO code of the currency for the product price.

 

 

MinQuantity

Int

 

 

 

The minimum quantity of volume discounts. Default is 1.

 

 

MaxQuantity

Int

 

 

 

The maximum quantity of volume discounts. Default is 99999.

 

 

OptionCodes

Array of objects

 

 

 

Details below.

 

 

 

Code

String

 

 

 

 

System generated pricing options group code (you can also configure it) that the 2Checkout system uses to calculate product prices for pricing configurations without a base price.

 

 

 

Options

StringArray

 

 

 

 

The pricing options group option code you configured that the 2Checkout system uses to calculate product prices for pricing configurations without a base price.

 

Renewal

Array of objects

 

 

Details below.

 

 

Amount

Int

 

 

 

The price of the product. Use -1 to delete it.

 

 

Currency

String

 

 

 

ISO code of the currency for the product price.

 

 

MinQuantity

Int

 

 

 

The minimum quantity of volume discounts. Default is 1.

 

 

MaxQuantity

Int

 

 

 

The maximum quantity of volume discounts. Default is 99999.

 

 

OptionCodes

Array of objects

 

 

 

Details below.

PriceOptions

Array of objects

 

Details below.

 

Code

String

 

 

System generated pricing options group code (you can also configure it) that the 2Checkout system uses to calculate product prices for pricing configurations without a base price.

 

Required

Boolean

 

 

true – you set the price options group as required during the purchase process.

false - you did not set the price options group as required during the purchase process.

 

Retrieve a price option group

Overview

Use the getPriceOptionGroup method to extract information about a specific price option group that you configured.

Parameters

Parameters Type/Description

ProductGroup

Object

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.

groupCode

Required (string)

 

The code that the 2Checkout system generated or that you set for the product pricing options group.

Response

Parameters Type/Description

PriceOptionGroup

Array of objects

Request

<?php

require ('PATH_TO_AUTH');

$groupCode = 'USERS';

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

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

 

Retrieve cross-sell campaign texts

Overview

Use the getCrossSellTexts method to extract information on all cross-sell campaigns texts.

Parameters

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.

LanguageCode

Required (string)

 

ISO language code. (ISO 639-1 two-letter code).

Response

Title

String

 

Cross-selling message title. Set here.

Description

String

 

Cross-selling message description. Set here.

Language

String

 

ISO language code. (ISO 639-1 two-letter code).

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 = "YOURCODE123"; //your account's merchant code available in the 'System settings' area of the cPanel: https://secure.avangate.com/cpanel/account_settings.php
$key          = "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;
}

$LanguageCode = 'de'; //returns title and description texts you set under https://secure.avangate.com/cpanel/network_cross_selling_settings.php

try {
    $CrossSellCampaignsTexts = $client->getCrossSellTexts($sessionID, $LanguageCode);
}

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

var_dump("CrossSellCampaignsTexts", $CrossSellCampaignsTexts);
?>

Retrieve assigned price option groups

Overview

Use the getAssignedPriceOptionGroups method to extract information about the price option groups you assigned to one of your products.

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.
ProductCode Required (string)
  The editable code that you control at product-level, not the unique, system-generated product ID.

Response

Parameters Type/Description
PriceOptionGroup Array of objects

Request

<?php

$host   = "https://api.avangate.com";
$client = new SoapClient($host . "/soap/5.0/?wsdl", array(
    'location' => $host . "/soap/5.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.avangate.com/cpanel/account_settings.php
$key          = "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;
}

$ProductCode = 'AAA4643199';

try {
    $AssignedPriceOptionGroups = $client->getAssignedPriceOptionGroups($sessionID, $ProductCode);
}

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

var_dump("AssignedPriceOptionGroups", $AssignedPriceOptionGroups);

?>

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


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 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->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 = 'TEST';
$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;
$jsonRpcRequest = array (
'method' => 'getContents',
'params' => array($sessionID, $Order),
'id' => $i++,
'jsonrpc' => '2.0'
);
echo '<BR>';
echo 'The content of the current session:';
echo '<BR>';
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