Place orders with catalog physical products
Overview
Use the placeOrder method to create an order using physical/tangible products defined in your Control Panel and collect the payment using credit card based payment methods.
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. |
|
Required (Object) |
|
|
|
Object designed to collect all data necessary for an order, including billing, product/subscription plan and payment details. |
Requirements
Add the product code of a tangible/physical product defined in your 2Checkout Control Panel.
When placing orders for physical products, you can provide the shipping method that applies to the purchase in the API call, as part of the DeliveryInformation object.
Response
| Parameters | Type/Description |
|---|---|
|
Object |
|
| Object containing order information. |
Request
<?php
require ('PATH_TO_AUTH');
$Order = new stdClass();
$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 = 'First';
$Order->BillingDetails->LastName = 'Last';
$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@address.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->CCID = '123';
$Order->PaymentDetails->PaymentMethod->HolderName = 'John';
$Order->PaymentDetails->PaymentMethod->CardNumberTime = 83.21; // can be null - high value in seconds is a red flag for fraud attempts.
$Order->PaymentDetails->PaymentMethod->HolderNameTime = 13.35; // can be null - high value in seconds is a red flag for fraud attempts.
$Order->PaymentDetails->PaymentMethod->Vendor3DSReturnURL = "http://www.success.ro";
$Order->PaymentDetails->PaymentMethod->Vendor3DSCancelURL = "http://www.error.ro";
try {
$newOrder = $client->placeOrder($sessionID, $Order);
}
catch (SoapFault $e) {
echo "newOrder: " . $e->getMessage();
exit;
}
var_dump("newOrder", $Order);
Send subscription registration emails
Overview
Use this method to send registration emails for a list of subscriptions.
Requirements
Parameters
| Parameter | Type/Description |
|---|---|
| sessionID | Required (String) |
| Session identifier, output of the Login method. An exception is thrown if the values are incorrect. | |
| subscriptionReferencesList | Required (StringArray) |
| Array of subscription references for which the registration email will be sent. You can send registration emails for a maximum of 50 subscriptions at once. | |
| Required (String) | |
| End user email address. | |
| language | Optional (String) |
|
ISO 639-1 two-letter language code for the language used in email registration messages. You can use all languages active on your account. Default language is English (en). Can be NULL. |
Response
| Parameter | Type/Description |
|---|---|
| result | Boolean |
| True or false |
Request
<?php
require('PATH_TO_AUTH'); // Authentication example: https://knowledgecenter.avangate.com/Integration/Channel_Manager_API/SOAP/02Authentication
require('PATH_TO_setPartner'); // setPartner example: https://knowledgecenter.avangate.com/Integration/Channel_Manager_API/SOAP/06Reference/Partner/00Set_partner
$subscriptionReferencesList = array('REFERENCE_1', 'REFERENCE_2');
$email = 'YOUR_EMAIL_ADDRESS';
$language = 'YOUR_LANGUAGE';
try {
$RegistrationEmail= $client->sendRegistrationEmail ($sessionID, $subscriptionReferencesList, $email, $language);
} catch (SoapFault $e) {
Echo "REmail: " . $e->getMessage();
exit;
}
var_dump ("REmail ", $RegistrationEmail);
Errors
| Error | Description |
|---|---|
|
NOT_FOUND_PARTNER |
A partner must be set first. |
|
INVALID_ORDER |
Order is not yet completed. |
|
EMPTY_SUBSCRIPTION_REFERENCES_LIST |
The subscription references list is empty. |
|
INVALID_SUBSCRIPTION_REFERRENCE |
The subscription reference is invalid. |
|
INVALID_EMAIL |
The email address is invalid. |
|
REGISTRATION_EMAIL_SENDING_FAILED |
Failed to send the registration email. |
Set external order reference
Overview
Use this method to set an external reference for a partner order. This is helpful if you use unique identifiers in your own order management system and you want to mirror the IDs in the 2Checkout system.
Requirements
Use this method before placeOrder.
Parameters
| Parameter | Type/Description |
|---|---|
| sessionID | Required (String) |
| Session identifier, which is the output of the Login method. An exception is thrown if the values are incorrect. | |
| externalRef | Required (String) |
| The unique identifier of an order placed in the Avangate system mirroring the reference you're using to manage order data in your system. |
Response
| Parameter | Type/Description |
|---|---|
| Response | Boolean |
| True or false |
Request
<?php
require ('PATH_TO_AUTH'); // Authentication example: https://knowledgecenter.avangate.com/Integration/Channel_Manager_API/JSON-RPC/02Authentication
require ('PATH_TO_SET_PARTNER'); // setPartner example: https://knowledgecenter.avangate.com/Integration/Channel_Manager_API/JSON-RPC/06Reference/Partner/00Set_partner
require ('PATH_TO_ADD_PRODUCT'); // addProduct example: https://knowledgecenter.avangate.com/Integration/Channel_Manager_API/JSON-RPC/06Reference/08Place_an_order/00Add_product_to_cart
$externalRef = 'NEW_REFERENCE';
$jsonRpcRequest = array (
'jsonrpc' => '2.0',
'id' => $i++,
'method' => 'setExternalRef',
'params' => array($sessionID, $externalRef)
);
var_dump (callRPC((Object)$jsonRpcRequest, $host));
$jsonRpcRequest = array (
'jsonrpc' => '2.0',
'id' => $i++,
'method' => 'placeOrder',
'params' => array($sessionID)
);
var_dump (callRPC((Object)$jsonRpcRequest,$host));
require ('PATH_TO_PLACE_ORDER');
Errors
| Error | Description |
|---|---|
|
INVALID_SOURCE |
The provided external reference is empty. |
Add promotion sources
Overview
Use the addPromotionSources method via SOAP API 4.0 to define new sources for an existing promotion.
Parameters
| Parameter | Type/Description |
|---|---|
|
sessionID |
Required (string) |
|
|
Output of the Login method. |
|
promotionCode |
Required (string) |
|
|
The code corresponding to the promotion that you want to add products to. |
|
promotionSources |
Required (string array) |
|
|
Array of strings defining the promotion sources. |
Response
| Parameter | Type/Description |
|---|---|
|
promotionSources |
String array |
|
|
Array of strings defining the promotion sources. |
Request
<?php
class Client
{
protected static $merchantCode;
protected static $loginDate;
protected static $hash;
protected static $baseUrl;
protected static $callCount = 0;
protected static $sessionId = '';
protected static $client;
public static function setCredentials($code, $key)
{
static::$merchantCode = $code;
static::$loginDate = gmdate('Y-m-d H:i:s');
static::$hash = hash_hmac('md5', strlen($code) . $code . strlen(static::$loginDate) . static::$loginDate, $key);
static::$sessionId = static::login();
}
public static function setBaseUrl($url)
{
static::$baseUrl = $url;
}
public static function login()
{
$client = static::getClient();
return $client->login(static::$merchantCode, static::$loginDate, static::$hash);
}
public static function __callStatic($name, $arguments = array())
{
$client = static::getClient();
array_unshift($arguments, static::$sessionId);
$response = call_user_func_array(array($client, $name), $arguments);
return $response;
}
protected static function getClient()
{
$opts = array(
'http'=> ['user_agent' => 'PHPSoapClient'],
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
],
);
if (null === static::$client) {
static::$client = new \SoapClient(static::$baseUrl . '?wsdl', [
'location' => static::$baseUrl,
'cache_wsdl' => WSDL_CACHE_NONE,
'stream_context' => stream_context_create($opts),
]);
}
return static::$client;
}
}
Client::setBaseUrl('https://api.avangate.com/soap/3.1/');
Client::setCredentials('YOUR_MERCHANT_CODE', 'YOUR_SECRET_KEY');
Client::login();
$promotionCode = 'YOUR_PROMOTION_CODE'; // code of the promotion that you want to update
$sources = ['source1', 'source2']; // array of sources to add to the promotion
$response = Client::addPromotionSources($promotionCode,$sources); // Set the promotion discount to the existing promotion
var_dump($response);
Create a new customer
Overview
Use the createCustomer method to add the details of a customer entity into the 2Checkout system. By default, customer status is Inactive until you assign a specific subscription to the customer. Following that action, customer status reflects the status of the attached subscription(s).
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. |
|
Object |
Response
|
2CheckoutCustomerReference |
Int |
|
|
System-generated customer reference. |
Request
<?php
$host = "https://api.2checkout.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.2checkout.com/cpanel/account_settings.php
$key = "YOUR_SECRET_KEY";// your account's secret key available in the 'System settings' area of the cPanel: https://secure.2checkout.com/cpanel/account_settings.php
$now = gmdate('Y-m-d H:i:s'); //date_default_timezone_set('UTC')
$string = strlen($merchantCode) . $merchantCode . strlen($now) . $now;
$hash = hmac($key, $string);
try {
$sessionID = $client->login($merchantCode, $now, $hash);
}
catch (SoapFault $e) {
echo "Authentication: " . $e->getMessage();
exit;
}
$newCustomer = new stdClass();
$newCustomer->2CheckoutCustomerReference = null;
$newCustomer->ExternalCustomerReference = 'ThisIsATestReference123456';
$newCustomer->FirstName = 'NewCustomer';
$newCustomer->LastName = 'NewCustomerLastName';
$newCustomer->Company = null;
$newCustomer->FiscalCode = null;
$newCustomer->Address1 = 'Address';
$newCustomer->Address2 = null;
$newCustomer->City = 'LA';
$newCustomer->Zip = '90210';
$newCustomer->CountryCode = 'us';
$newCustomer->Phone = null;
$newCustomer->Fax = null;
$newCustomer->Email = 'newcustomer@email.com';
$newCustomer->ExistingCards = null;
$newCustomer->Enabled = null;
$newCustomer->Trial = null;
$newCustomer->Language = 'en';
try {
$newCustomerInfo = $client->createCustomer($sessionID, $newCustomer);
}
catch (SoapFault $e) {
echo "newCustomerInfo: " . $e->getMessage();
exit;
}
var_dump("newCustomerInfo", $newCustomerInfo);
Retrieve VAT or sales tax
Overview
- Populate the Order object with information. Avangate needs the BillingDetails (object) information to calculate taxes.
- Use the getContents method to get info on all the products added to cart by the shopper in the current session.
- The output of the getContents method is the Order session content object.
- Under the Price, access information including for each product purchased. Find value added tax and sales tax details under the VAT parameter.
- Tax information is also available for the entire order object. Find value added tax and sales tax details under the VAT parameter.
- 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. |
|
Required (Object) |
|
|
|
Object designed to collect all data necessary for an order, including billing, product/subscription plan and payment details. |
Response
|
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);
?>
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 |
|---|---|
|
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 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 |
|---|---|
|
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);
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.