Skip to main content

Unassign additional fields

Overview

Use the unassignAdditionalField 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. 2Checkout 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.

ProductCode

Required (string)

 

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

Response

bool(true)

Request

<?php

require ('PATH_TO_AUTH');

$productCode = 'YOUR_PRODUCT_CODE';
$fieldCode = 'YOUR_FIELD_CODE';

$jsonRpcRequest = array(
    'jsonrpc' => '2.0',
    'id' => $i++,
    'method' => 'unassignAdditionalField',
    'params' => array($sessionID,$fieldCode,$productCode)
);

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


Update 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. 2Checkout 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';

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

?>

 

Use Purchase order flow

Overview 

Place an order using catalog products, and collect the payment using the Purchase Order flow.

Requirements

Purchase order flow needs to be enabled on your account. Contact 2Checkout for activation.

You have to send the InternalPONumber and AutoApprove parameters to place a Purchase Order. The company name is mandatory when placing an order via PO.

Currency support 

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

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.

 

Workflow 

  1. The customer is placing the order using Purchase Order as the ordering flow, filling in the internal PO number as mandatory information.
  2. You are able to set the order to auto-approve as soon as the purchase order is submitted. Otherwise, you have to approve/cancel it manually from Control Panel.
  3. After the order is placed, the order confirmation e-mail is sent, including the payment instructions and payment terms agreed.
  4. The order is finalized as soon as the payment is confirmed.
  5. If payment is not received according to the terms, the order is canceled.

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->AffiliateId = NULL;
$Order->CustomerReference = NULL;
$Order->Items = array();
$Order->Items[0] = new stdClass();
$Order->Items[0]->Code = 'my_subscription_1';
$Order->Items[0]->Quantity = 1;
$Order->Items[0]->PriceOptions = NULL;
$Order->Items[0]->SKU = NULL;
$Order->Items[0]->Price = NULL;
$Order->Items[0]->CrossSell = NULL;
$Order->Items[0]->Trial = false;
$Order->Items[0]->AdditionalFields = NULL;
$Order->Items[0]->SubscriptionStartDate = NULL; //If empty or null, subscriptions become active when purchase is made.
$Order->BillingDetails = new stdClass();
$Order->BillingDetails->FirstName = 'Test Cosmin API';
$Order->BillingDetails->LastName = 'Cosmin API';
$Order->BillingDetails->CountryCode = '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 = 'cosmin.deftu@2checkout.com';
$Order->BillingDetails->Phone = NULL;
$Order->BillingDetails->Company = 'ABC Company';
$Order->DeliveryDetails = NULL;


$Order->PaymentDetails = new stdClass ();
$Order->PaymentDetails->Type = 'PURCHASEORDER';
$Order->PaymentDetails->Currency = 'USD';
$Order->PaymentDetails->PaymentMethod = new stdClass();
$Order->PaymentDetails->PaymentMethod->AutoApprove = true;
$Order->PaymentDetails->PaymentMethod->InternalPONumber = 84864848;


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

try {
    $newOrder = $client->placeOrder($sessionID, $Order);
}
catch (SoapFault $e) {
    echo "newOrder: " . $e->getMessage();
    exit;
}

var_dump("newOrder", $newOrder);

 

Retrieve the upgrade price for a subscription

Overview

Use the getProductUpgradeOptionsPrice method to retrieve information about the costs a customer incurs when upgrading a specific subscription. Retrieve information about the costs a customer incurs when upgrading a specific subscription.

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.

SubscriptionReference

Required (string)

 

Unique, system-generated subscription identifier.

ProductCode

Required (string)

 

Unique identifier of the target product for the subscription upgrade process. You control the product code and can set it up in the Control Panel.

Currency

Required (string)

 

ISO 4217 code.

Options

Required (string)

 

Pricing options of the target product for the subscription upgrade process.

 

String - ';' separated list of 'OptionValue' returned by getProductUpgradeOptions function.

If the pricing options groups is "scale" (interval), the Options parameter should be sent like this: [option group unique code] + "=" + value

e.g. Users=7

Response

UpgradePrice

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);
$subscriptionReference = '30E47F8699';
$productCode = 'my_subscription_123';
$Currency = 'usd';
$Options = 'emailsupport;oneuser1';

$jsonRpcRequest = array (
'method' => 'getProductUpgradeOptionsPrice',
'params' => array($sessionID, $subscriptionReference, $productCode, $Currency, $Options),
'id' => $i++,
'jsonrpc' => '2.0');

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

Add a physical dynamic product with dynamic shipping, dynamic taxes, and dynamic coupon

Overview

Use the order promotions object to add a physical dynamic product with dynamic shipping, dynamic taxes, and dynamic coupon (for the PSP business model).

Use case

  1. Add an HTML link or button to your page like the one below.
  2. Create a JavaScript click handler to execute the InLine Client desired methods.
  3. Use the TwoCoInlineCart.setup.setMode('DYNAMIC') method in order to let the cart know you are using dynamic instead of catalog products.
  4. Use the TwoCoInlineCart.cart.setCurrency(currency-code) method to set the currency.
  5. Add your product to the cart by calling the TwoCoInlineCart.products.add({name, quantity, price, options}) method.
  6. You can see below a signature token request payload for this example. A success response contains a JSON with the property “signature“ which needs to be used at the next step to set the signature using the TwoCoInlineCart method.
{
    "merchant": "250535979326",
    "dynamic": "1",
    "currency": "USD",
    "products": [
        {
            "name"    : "A test physical product",
            "quantity": 1,
            "price"   : 20,
            "type"    : 'physical'
        },
        {
            "name"    : "A test shipping",
            "quantity": 1,
            "price"   : 7,
            "type"    : 'shipping'
        },
        {
            "name"    : "A test tax",
            "quantity": 1,
            "price"   : 10,
            "type"    : 'tax'
        },
        {
            "name"    : "A test promotion",
            "quantity": 1,
            "price"   : 5,
            "type"    : 'coupon'
        }
    ]
}

7. Use the TwoCoInlineCart.cart.setSignature('718e810fee34be2bf4b9d4582323aa37580c4011ef694116cca5b0bb7badd2f1') method to set the signature. It is important that you employ TwoCoInlineCart.cart.removeAll() just before the TwoCoInlineCart.products.addMany(products) or TwoCoInlineCart.products.add(product) methods to remove previous products as the signature is based on the products' definition.

 8. Use the TwoCoInlineCart.cart.checkout() method to show the cart on your page.

Sample request

HTML

<a href="#" class="btn btn-success" id="buy-button">Buy now!</a>

JavaScript

window.document.getElementById('buy-button').addEventListener('click', function() {
  TwoCoInlineCart.setup.setMode('DYNAMIC');
  TwoCoInlineCart.cart.setCurrency('USD');
  
  TwoCoInlineCart.products.removeAll();
  TwoCoInlineCart.products.add({
    name: 'A test physical product',
    quantity: 1,
    price: 20,
    type: 'physical'
  });
  TwoCoInlineCart.products.add({
    name: 'A test shipping',
    quantity: 1,
    price: 7,
    type: 'shipping'
  });
  TwoCoInlineCart.products.add({
    name: 'A test tax',
    quantity: 1,
    price: 10,
    type: 'tax'
  });
  TwoCoInlineCart.products.add({
    name: 'A test promotion',
    quantity: 1,
    price: 5,
    type: 'coupon'
  });
  
  TwoCoInlineCart.cart.setSignature('1563b14f92bfe6bf645a227291120e1a9bbb87bcdf02c410b4522f5d8291fd34');
  TwoCoInlineCart.cart.checkout();
});

Demo

After adding a physical dynamic product with dynamic shipping, dynamic taxes, and dynamic coupon using the above method, your cart should look like this:

 

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.

FieldCode Required (string)
 

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

AdditionalField

Object

 

Additional field object.

Response

bool(true)

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)) {
        //        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.0/';

$merchantCode = "YOURCODE12345"; //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

$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++;

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

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

$FieldCode = 'NewsletterPolicy1234576';

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

?>

Add pricing configuration

Overview

Use the addPricingConfiguration method to add a new pricing configuration for your account.

Parameters

Parameters Type/Description

sessionID

Required (string)

 

Session identifier, the output of the Login method. Include sessionID into all your requests. 2Checkout throws an exception if the values are incorrect.  The sessionID expires in 10 minutes.

PricingConfiguration

Required (object)

 

Use this object to add a new pricing configuration for your account.

ProductCode

Required (string)

 

The code of the produt you assign the configuration to.

Response

bool(true)

Request

<?php

require ('PATH_TO_AUTH');

$PricingConfiguration = new stdClass();
$PricingConfiguration->Default = True;
$PricingConfiguration->Name = 'New Pricing Configuration Through API';
$PricingConfiguration->BillingCountries = array();
$PricingConfiguration->BillingCountries[0] = 'RO';
$PricingConfiguration->BillingCountries[1] = 'DE';
$PricingConfiguration->PricingSchema = 'DYNAMIC';
$PricingConfiguration->PriceType = 'NET';
$PricingConfiguration->DefaultCurrency = 'USD';
$PricingConfiguration->Prices = new stdClass();
$PricingConfiguration->Prices->Regular = array();
$PricingConfiguration->Prices->Regular[0] = new stdClass();
$PricingConfiguration->Prices->Regular[0]->Amount = 69.09;
$PricingConfiguration->Prices->Regular[0]->Currency = 'USD';
$PricingConfiguration->Prices->Regular[0]->MinQuantity = 1;
$PricingConfiguration->Prices->Regular[0]->MaxQuantity = 35;
$PricingConfiguration->Prices->Regular[0]->OptionCodes = array();
$PricingConfiguration->Prices->Regular[0]->OptionCodes[0] = new stdClass();
$PricingConfiguration->Prices->Regular[0]->OptionCodes[0]->Code = 'G77ICHEM1C';
$PricingConfiguration->Prices->Regular[0]->OptionCodes[0]->Options = array();
$PricingConfiguration->Prices->Regular[0]->OptionCodes[0]->Options[0] = 'zh5onfolw7';
$PricingConfiguration->Prices->Regular[0]->OptionCodes[0]->Options[1] = '75rjldfcnz';
$PricingConfiguration->Prices->Regular[0]->OptionCodes[1] = new stdClass();
$PricingConfiguration->Prices->Regular[0]->OptionCodes[1]->Code = 'BAWAQB8LZP';
$PricingConfiguration->Prices->Regular[0]->OptionCodes[1]->Options = array();
$PricingConfiguration->Prices->Regular[0]->OptionCodes[1]->Options[0] = 'r3oi06opvi';
$PricingConfiguration->Prices->Regular[0]->OptionCodes[1]->Options[1] = '76gqbq4bhd';
$PricingConfiguration->Prices->Regular[1] = new stdClass();
$PricingConfiguration->Prices->Regular[1]->Amount = 64.66;
$PricingConfiguration->Prices->Regular[1]->Currency = 'USD';
$PricingConfiguration->Prices->Regular[1]->MinQuantity = 36;
$PricingConfiguration->Prices->Regular[1]->MaxQuantity = 83;
$PricingConfiguration->Prices->Regular[1]->OptionCodes = array();
$PricingConfiguration->Prices->Regular[1]->OptionCodes[0] = new stdClass();
$PricingConfiguration->Prices->Regular[1]->OptionCodes[0]->Code = '8RNXV3T3RE';
$PricingConfiguration->Prices->Regular[1]->OptionCodes[0]->Options = array();
$PricingConfiguration->Prices->Regular[1]->OptionCodes[0]->Options[0] = 'rorqkqnd9p';
$PricingConfiguration->Prices->Regular[1]->OptionCodes[0]->Options[1] = 'aeu89gqdg6';
$PricingConfiguration->Prices->Regular[1]->OptionCodes[1] = new stdClass();
$PricingConfiguration->Prices->Regular[1]->OptionCodes[1]->Code = 'DJYD713MKC';
$PricingConfiguration->Prices->Regular[1]->OptionCodes[1]->Options = array();
$PricingConfiguration->Prices->Regular[1]->OptionCodes[1]->Options[0] = 'y2z2squ7c1';
$PricingConfiguration->Prices->Regular[1]->OptionCodes[1]->Options[1] = 'g74qfskbjg';
$PricingConfiguration->Prices->Renewal = array();
$PricingConfiguration->Prices->Renewal[0] = new stdClass();
$PricingConfiguration->Prices->Renewal[0]->Amount = 7.89;
$PricingConfiguration->Prices->Renewal[0]->Currency = 'USD';
$PricingConfiguration->Prices->Renewal[0]->MinQuantity = 84;
$PricingConfiguration->Prices->Renewal[0]->MaxQuantity = 100;
$PricingConfiguration->Prices->Renewal[0]->OptionCodes = array();
$PricingConfiguration->Prices->Renewal[0]->OptionCodes[0] = new stdClass();
$PricingConfiguration->Prices->Renewal[0]->OptionCodes[0]->Code = '73QCSXYH0E';
$PricingConfiguration->Prices->Renewal[0]->OptionCodes[0]->Options = array();
$PricingConfiguration->Prices->Renewal[0]->OptionCodes[0]->Options[0] = '54xu7mngqm';
$PricingConfiguration->Prices->Renewal[0]->OptionCodes[0]->Options[1] = 'p6m8im2unl';
$PricingConfiguration->Prices->Renewal[0]->OptionCodes[1] = new stdClass();
$PricingConfiguration->Prices->Renewal[0]->OptionCodes[1]->Code = '0QD0CF0OIE';
$PricingConfiguration->Prices->Renewal[0]->OptionCodes[1]->Options = array();
$PricingConfiguration->Prices->Renewal[0]->OptionCodes[1]->Options[0] = 'ytbac9wpmh';
$PricingConfiguration->Prices->Renewal[0]->OptionCodes[1]->Options[1] = 'lpkxxqsqxb';
$PricingConfiguration->Prices->Renewal[1] = new stdClass();
$PricingConfiguration->Prices->Renewal[1]->Amount = 76.99;
$PricingConfiguration->Prices->Renewal[1]->Currency = 'USD';
$PricingConfiguration->Prices->Renewal[1]->MinQuantity = 101;
$PricingConfiguration->Prices->Renewal[1]->MaxQuantity = 544;
$PricingConfiguration->Prices->Renewal[1]->OptionCodes = array();
$PricingConfiguration->Prices->Renewal[1]->OptionCodes[0] = new stdClass();
$PricingConfiguration->Prices->Renewal[1]->OptionCodes[0]->Code = '03APF0H4QF';
$PricingConfiguration->Prices->Renewal[1]->OptionCodes[0]->Options = array();
$PricingConfiguration->Prices->Renewal[1]->OptionCodes[0]->Options[0] = '15ce5uw2j6';
$PricingConfiguration->Prices->Renewal[1]->OptionCodes[0]->Options[1] = 'e88d5hk0tb';
$PricingConfiguration->Prices->Renewal[1]->OptionCodes[1] = new stdClass();
$PricingConfiguration->Prices->Renewal[1]->OptionCodes[1]->Code = 'PT00TYI2VY';
$PricingConfiguration->Prices->Renewal[1]->OptionCodes[1]->Options = array();
$PricingConfiguration->Prices->Renewal[1]->OptionCodes[1]->Options[0] = '10c24smlbl';
$PricingConfiguration->Prices->Renewal[1]->OptionCodes[1]->Options[1] = '0ondbwdk3q';
$PricingConfiguration->PriceOptions = array();
$PricingConfiguration->PriceOptions[0] = new stdClass();
$PricingConfiguration->PriceOptions[0]->Code = 'FKQ8CFLYKM';
$PricingConfiguration->PriceOptions[0]->Required = false;
$PricingConfiguration->PriceOptions[1] = new stdClass();
$PricingConfiguration->PriceOptions[1]->Code = 'TH1HKFOTFR';
$PricingConfiguration->PriceOptions[1]->Required = true;

$ProductCode= 'API_Imported_123456';

$jsonRpcRequest = array (
'jsonrpc' => '2.0',
'id' => $i++,
'method' => 'addPricingConfiguration',
'params' => array($sessionID, $PricingConfiguration, $ProductCode) //Use product ID and not product code for API versions 2.3 and earlier
);

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

?>

Single Sign On 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 2Checkout 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 2CheckoutCustomerReference.

customerType

Required (string)

 

Possible values:

  • ExternalCustomerReference
  • 2CheckoutCustomerReference

page

Optional (string)

 

The specific myAccount page where you redirect the customer.

Possible values:

my_subscription - redirect shoppers to the subscription 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
declare(strict_types=1);

require('PATH_TO_AUTH');

$idCustomer = '352365983';
$customerType = '2CheckoutCustomerReference';
$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'
];

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.

 

Response

bool(true)

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)) {
        //        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.0/';

$merchantCode = "YOURCODE12345"; //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

$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++;

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

$ProductCode = 'AAA4643116';
$FieldCode = 'NewsletterPolicy123457106';
$Required = true;


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

?> 

SSO in cart

Overview

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

How does this work?

When accessing the shopping cart using tokenized payment links:

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

Parameters

Parameters Type/Description

sessionID

Required (string)

 

Session identifier, the output of the Login method. Include sessionID into all your requests. 2Checkout throws an exception if the values are incorrect.  The sessionID expires in 10 minutes.

Customer

Required (string)

 

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

customerType

Required (string)

 

Possible values:

  • ExternalCustomerReference
  • AvangateCustomerReference

url

Required (string)

 

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

 

Possible values:

 

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

validityTime

Optional (int)

 

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

validationIp

Optional (string)

 

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

Response

Parameters Type/Description

Single sign-on URL

String

 

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

 

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

 

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

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

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

 

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

 

Request

<?php

require ('PATH_TO_AUTH');

$idCustomer = '352365983';
$customerType = 'AvangateCustomerReference';
$url = 'https://store.avancart.com/order/checkout.php?PRODS=4639321&QTY=1&CART=1&CARD=2';
$validityTime = 50;
$validationIp = null;

$jsonRpcRequest = array (
'method' => 'getSingleSignOnInCart',
'params' => array($sessionID, $idCustomer, $customerType, $url, $validityTime, $validationIp),
'id' => $i++,
'jsonrpc' => '2.0');

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

Need help?

Do you have a question? If you didn’t find the answer you are looking for in our documentation, you can contact our Support teams for more information. If you have a technical issue or question, please contact us. We are happy to help.

Not yet a Verifone customer?

We’ll help you choose the right payment solution for your business, wherever you want to sell, in-person or online. Our team of experts will happily discuss your needs.

Verifone logo