Skip to main content

Trial and regular products in the same shopping cart

Overview

2Checkout supports scenarios in which you sell one or more regular products and offer one or more free/paid trials (with payment details - mandatory) in the same shopping cart to your customers.

Availability

All 2Checkout accounts.

Requirements

Products for which you're offering evaluation versions must meet the following criteria:

  • They must be free or paid trials for which you're collecting payment details from customers by using the Request payment details and customize your trial option.
  • They must support electronic delivery as the shipping class.
  • They can only be standalone offerings, not bundles.
  • They cannot match any of the regular products added to cart (Note: Customers won't be able to access the trial and purchase the regular version of a product using the same shopping cart session).

Scenarios covered

  • One product and one paid/free trial (with payment details) in the same cart;
  • Multiple products and one paid/free trial (with payment details) in the same cart;
  • One product and multiple paid/free trials (with payment details) in the same cart;
  • Multiple products and multiple paid/free trials (with payment details) in the same cart.

Use checkout.php trial links

Using the Sales Links area of the 2Checkout Control Panel, you can generate trial links such as the one below, which points to the trial.php page:

https://secure.2checkout.com/order/trial.php?PRODS=5566778&PAY_TYPE=CCVISAMC&PRICES5566778[USD]=0&TPERIOD=30&PHASH=1f24f5c938adf4c125ddfe67242d958a

Important: Trial links using the trial.php page cannot be used to build mixt regular product and trial links.

You need to build your own trial links, pointing to the checkout.php page, instead of trial.php, and use them to create mixt regular product and trial links.

checkout.php trial links

trial.php trial links

Build links using checkout.php

Trial links generated automatically use trial.php

Trial period is defined in the link using theTPERIOD[Product ID] parameter as such:TPERIOD[Product ID]=30

Trial period is defined in the link using the TPERIOD parameter as such: TPERIOD=30

HASH signature needs to be generated manually

HASH signature is generated automatically along with the link

Parameters required

Parameter

Info

Mandatory

Secret Key

The secret key is communicated to you when your account with 2Checkout is opened. You can always retrieve the secret key information from the "Account settings" section in the Control Panel (https://secure.2checkout.com/cpanel/account_settings.php). The secret key is listed in the Instant Payment Notification area (scroll down toward the bottom of the page).

The secret key is required to calculate the HMAC_SHA signature. A HMAC_SHA signature is calculated and applied to the request, using a BASE STRING in tandem with the SECRET KEY generated by 2Checkout (View secret key).

YES

PRODS

Product IDs for which the order will be processed, separated by comma (,), with no blanks. Example: PRODS=1234567,1234568. Each product added / imported into the 2Checkout platform is automatically assigned a system generated unique numeric (int) identifier. Example: Product ID = 1234567.

In the Control Panel, click to edit a product, and select theInformation tab. The Product ID of the item you're editing is available at the top of the General area under Information.Note: Product IDs are different than Product Codes, also available in this area, but which you control.

YES

PRICES[Product ID][Currency]

Required parameter to set the price for product default currency. For example, for a product with the 2Checkout product ID: 123456, the currency EUR, and the price 99.99, this parameter would look like: PRICES123456[EUR]=99.99. If not sent for other billing currencies, 2Checkout will convert based on the submitted default price.

YES (only for trials)

TPERIOD[Product ID]

Trial period must be at least 7 days. For example enter TPERIOD[Product ID]=7 for a 7-day trial, or TPERIOD[Product ID]=30 for a 30-day evaluation period. Needs to be used as in the following example: TPERIOD1234567=7, with 1234567 representing the product ID.

YES

PHASH

Required HMAC_SHA signature in order to prevent the request from being exploited.

YES

Build a checkout.php trial Buy Link

For this example, let's assume that we need a trial link for the evaluation version of a product with the ID 5566778. The trial is free and the evaluation period is 30 days. We'll use the parameters listed above.

As already mentioned, system-generated trial links via the Sales Links area of the 2Checkout Control Panel work only for scenarios in which the trial is also the only item in the shopping cart, but not for mixt regular product and trial scenarios. This is why links as the one below should not be used.

https://secure.2checkout.com/order/trial.php?PRODS=5566778&PAY_TYPE=CCVISAMC&PRICES5566778[USD]=0&TPERIOD=30&PHASH=1f24f5c938adf4c125ddfe67242d958a

Instead, you need to build another type of trial link, pointing to checkout.php, and using the PRODS, PRICES[Product ID][Currency], TPERIOD[Product ID] and PHASH parameters. In this specific case:

  • PRODS=5566778
  • PRICES5566778[USD]=0
  • TPERIOD5566778=30
  1. Using the parameters above, you get the following sequence PRODS=5566778&PRICES5566778[USD]=0&TPERIOD5566778=30
  2. Next, you need to prefix (prepend) the length of the character sequence to calculate the hash, namely 52. The resulting BASE STRING is 52PRODS=5566778&PRICES5566778[USD]=0&TPERIOD5566778=30
  3. For the purpose of this demo, let's assume that your secret key is SECRET_KEY.
  4. Use the secret key and the base string to calculate the HMAC-SHA HASH. The result (valid exclusively for this example) should be:
  • 6dd3bd013ee2d19782f16b734a98703e4c71abbea0c4058e7248fd6268229d43 (SHA2)
  • 878519d71a697d4b8829d351e59d4f8d46cc60f0c2e9ccc827c9af7fcbc7aae9 (SHA3)

 5.  Build your complete link, adding the following elements together for:

As such:

https://secure.2checkout.com/order/checkout.php?PRODS=5566778&PRICES5566778[USD]=0&TPERIOD5566778=30&PHASH=6dd3bd013ee2d19782f16b734a98703e4c71abbea0c4058e7248fd6268229d43

As such:

https://secure.2checkout.com/order/checkout.php?PRODS=5566778&PRICES5566778[USD]=0&TPERIOD5566778=30&PHASH=878519d71a697d4b8829d351e59d4f8d46cc60f0c2e9ccc827c9af7fcbc7aae9

Use this link in the process described below, under the Alternative work flow section.

Build mixt regular products and trial Buy Links

Mixt Buy Links containing both regular products and trials have to be created manually, and need to paint users directly to Checkout. Note: You offer shoppers the trial and regular versions of the same product in the same shopping cart.

Let's assume that you generated two build links, one for a regular product with ID 1234567 and a trial for a different product with the ID 5566778, just as in the examples below:

https://secure.2checkout.com/order/checkout.php?PRODS=1234567&CART=1&CARD=2
https://secure.2checkout.com/order/trial.php?PRODS=5566778&PAY_TYPE=CCVISAMC&PRICES5566778[USD]=0&TPERIOD=30&PHASH=ae929a5009ca5737d50c5f929d34650c

The steps required to build a mixt regular product and trial Buy Link are detailed below:

  1. Make sure that the mandatory information necessary to build the link is available, namely, the secret key for your 2Checkout account (necessary for the hash calculation), and the following parameters: PRODS, PRICES[Product ID][Currency] (along with its corresponding value, in this case the price of the trial version, that can be zero (0)), and TPERIOD[Product ID] (along with its corresponding value, in this case the duration of the evaluation period in days).
  2. You'll build the link from the https://secure.2checkout.com/order/checkout.php?, or https://secure.YourStore.com/order/checkout.php? In case you're using a custom domain.
  3. In this particular example, here is the list of parameters with their respective values:
    • PRODS=1234567,5566778
    • PRICES5566778 [USD]=0
    • TPERIOD5566778=30
  4. Using the parameters above, you get the following sequence PRODS=1234567,5566778&PRICES5566778[USD]=0&TPERIOD5566778=30. Next, you need to prefix (prepend) the length of the character sequence to calculate the hash, namely 60. The resulting BASE STRING is 60PRODS=1234567,5566778&PRICES5566778[USD]=0&TPERIOD5566778=30
  5. For the purpose of this demo, let's assume that your secret key is SECRET_KEY.
  6. Use the secret key and the base string to calculate the HMAC-SHA HASH. The result (valid exclusively for this example) should be: 
  • 849c5a6ff5e453600225ee675bd27037f81383c24769a2152eb4bf8e1a4bc6a9 (SHA2)
  • a815a304725c54ea0eac2fd7214f654bb8b6cd1ce2245ee65769d765745f3f7a (SHA3)

  7.  Build your complete link, adding the following elements together for:

As such:

https://secure.2checkout.com/order/checkout.php?PRODS=1234567,5566778&PRICES5566778[USD]=0&TPERIOD5566778=30&PHASH=849c5a6ff5e453600225ee675bd27037f81383c24769a2152eb4bf8e1a4bc6a9

As such:

https://secure.2checkout.com/order/checkout.php?PRODS=1234567,5566778&PRICES5566778[USD]=0&TPERIOD5566778=30&PHASH=a815a304725c54ea0eac2fd7214f654bb8b6cd1ce2245ee65769d765745f3f7a

Alternative workflow

To allow your customers to buy one or multiple products while also accessing free/paid trials in the same shopping cart (during the same browser session) follow these steps:

  1. Generate the buy link for the regular product(s). Use the links on the purchase call to action on your online shop, such as the Buy buttons.
  2. Build the trial links as per the example above. Use the links on the call to actions designed to enable access to trials on your online shop, such as the Download trial buttons.  Important: make sure your trial links use checkout.php and NOT trial.php, otherwise this alternative workflow would fail. Use this link in the process described below, under the Build a checkout.php trial Buy Link section.
  3. Shoppers will click on the buy link for a regular product and add it to the cart.
  4. Shoppers continue the purchase process and click on the link to download a trial.
  5. The trial gets added to the same shopping cart as the regular product, provided that the browser session is still valid.
  6. Shoppers go through the steps of the purchase process to acquire the regular product as well as access the trial added to cart.

Important: Trial links using the trial.php page cannot be used to build mixt regular product and trial links. This is because trial.php links open a new browser session and generate a new cart for shoppers. As such, when adding a trial on top of a regular product already in the cart, the trial would simply replace the offering. Vice versa, when adding a regular product on top of a trial already in the cart, the regular product would replace the trial.

Limitations

Important: make sure your trial links use checkout.php and NOT trial.php, otherwise this alternative workflow would fail. Use this link in the process described below, under the Build a checkout.php trial Buy Link section.

The following scenario is not supported: both the regular and the trial versions of a product added to the same shopping cart. Customers can buy a product or access its evaluation version, but not both simultaneously in the same cart.

Scenarios:

  1. Product A and Trial for Product A in the same cart
    • Customers add Product A to cart;
    • Customers add Trial for Product A to cart during the same browser session;
    • Result: Trial for Product A replaces Product A in the cart. Customers can access Trial for Product A but will need to buy Product A in a different shopping cart / via a new browser session.
  2. Trial for Product A and Product A in the same cart
    • Customers add Trial for Product A to cart;
    • Customers add Product A to cart during the same browser session;
    • Result: Product A replaces Trial for Product A in the cart. Customers can buy Product A but will need to access Trial for Product A in a different shopping cart / via a new browser session.

Promotions/discounts

Discount coupons for Regular and Multi-product promotions used by shoppers acquiring a regular product and accessing a trial in the same shopping cart will only impact the trial when the evaluation period comes to an end and it's converted to a full product. Essentially, discounts are offered to shoppers for the first transaction marking the conversion of the trial to a regular product, equivalent to a new purchase, and not when the trial is first accessed. If, following the evaluation period the trial is not converted to a regular subscription, no discount is offered.

Order promotions will discount the total value of the initial order containing both regular products and trials. Order promotion discounts will no longer impact the transaction associated with the conversion of the trial to a full product.

Payment methods

Shoppers that access trials while concomitantly purchasing regular products will be able to use a number of payment methods supporting recurring billing such as credit/debit cards, PayPal and DirectDebit. Trials are set to auto-renew by default, and customers can opt out of a purchase during the evaluation period in order to not be billed for the trial conversion to a regular subscription.

Auto-renewal

The auto-renewal option doesn't impact trials, which are set to auto-renew by default. You can manually cancel new subscription purchases before trial ends.

Up-selling and cross-selling campaigns

Up-selling and Cross-selling campaigns will be triggered only for the regular products added to cart, but not for the trials of such offerings.

LCN read receipt response for 2Checkout

To validate the success of the notification process insert an inline response in the script output of your LCN listener. Once 2Checkout validates the response it considers the LCN successful. Otherwise, 2Checkout continues to send notifications per the failure recovery process until you provide a valid response.

Read receipt response for 2Checkout

To validate the fact that you received a LCN notification, return an inline response anywhere in the document (in the script output), in the following format:

  • <EPAYMENT>DATE|HASH</EPAYMENT> (if MD5 is used)
  • <sig algo="sha256" date= " ">HASH</sig> (if SHA256 is used)
  • <sig algo="sha3-256" date= " ">HASH</sig> (if SHA3-256 is used)

The parameters are as follows:

Parameters  

DATE

Date in the YmdGis format. (20081117145935)

HASH

HMAC_MD5 / HMAC_SHA signature calculated using the secret key for your account and the values received for :

• LICENSE_CODE 
• EXPIRATION_DATE 
• DATE (the above field)

 

Create the hash using only these three parameters, and not all the parameters you receive as part of the LCN message. 

HMAC_SHA signature

Access https://datatracker.ietf.org/doc/html/rfc6234 for a description of the SHA-based HMAC algorithm, or http://www.ietf.org/ rfc/rfc2104.txt for a description of the HMAC_MD5 algorithm.

Field name

Field length

Field value

FIRSTNAME

4

John

LASTNAME

5

Smith

COMPANY

0

 

EMAIL

19

johnsmith@email.com

PHONE

12

951-121-2121

FAX

0

 

COUNTRY

24

United States of America

STATE

8

New York

CITY

8

New York

ADDRESS

15

101 Main Street

LICENSE_CODE

10

3C343D0FAF

EXPIRATION_DATE

10

2005-03-03

STATUS

8

DISABLED

Considering a LCN containing all the information above, you only need the LICENSE_CODE,  EXPIRATION_DATE and  DATE (this is the date when your script receives the LCN message) to create the response. Calculate the signature for the above data received in LCN and create inline response:

DATE

20081117145935. This is the date when your script receives the LCN message. 

HMAC_SHA / HMAC_MD5 source string

103C343D0FAF102005-03-031420081117145935

Secret key

AABBCCDDEEFF

HMAC_MD5 signature cb34fe2991668eb82364edf62f845a34

HMAC_SHA2 signature

cdd64ce75e6cf013a60291229c83063a5d903eae3bfa216e99aae8af65a055e8

HMAC_SHA3 signature 7fc19d21103ea56f1b413315fb3feb5fbdd137758623a73c7ed12d9bb84f21db
Inline response MD5 <EPAYMENT>20081117145935|cb34fe2991668eb82364edf62f845a34</EPAYMENT>

Inline response SHA2

<sig algo="sha256" date="20081117145935">cdd64ce75e6cf013a60291229c83063a5d903eae3bfa216e99aae8af65a055e8</sig>

Inline response SHA3 <sig algo="sha3-256" date="20081117145935">7fc19d21103ea56f1b413315fb3feb5fbdd137758623a73c7ed12d9bb84f21db</sig>

Requirements

  1. Do not include HASH in the string needed for calculating the HMAC_MD5 / HMAC_SHA2/HMAC_SHA3 signature.
  2. Use the variables in the same order as described above when putting together the string used for the HASH signature.
  3. To create the HMAC_MD5 / HMAC_SHA source string, prefix each value with its own length in bytes (for UTF-8 characters the length in bytes might be longer that the string length).
  4. HASH fields values are case insensitive.
  5. Output the inline response anywhere in the page receiving the notification.

Add a 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 product 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));

?>

Clear shopping cart contents

Overview

Use this method to completely clear the contents of the shopping cart.

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

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/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

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

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

Static pricing

Overview

Static pricing (without base price) configurations enable you to control product costs for each possible combination of options available to shoppers in the cart. 

Example

A yearly subscription for which you need to set pricing based on the number of users while also offering volume discounts. Static pricing (without base price) offers the most control over the costs shoppers pay for any combination of options. You need to keep in mind that you have to define prices manually for all combinations and that with the addition of pricing options, the setup grows in complexity. 

#

Units

Users

USD

EUR

1.

1 - 10

1 User

99

88

2.

1 - 10

2 Users

149

139

3.

1 - 10

Family pack

199

189

4.

1 - 10

NONE

50

40

5.

11 - 20

1 User

799

749

6.

11 - 20

2 Users

1299

1249

7.

11 - 20

Family pack

1599

1549

8.

11 - 20

NONE

700

680

9.

21 - maximum

1 User

2599

2499

10.

21 - maximum

2 Users

2799

2699

11.

21 - maximum

Family pack

2999

2899

12.

21 - maximum

NONE

2500

2400

Availability

All 2Checkout accounts. 

Requirements 

Create at least a product/subscription plan before defining pricing. 

Type 

  • Net: without taxes - 2Checkout applies extra taxes to the default price, such as Tax/VAT for US/EU orders during  the ordering process. 
  • Gross: with taxes included - 2Checkout takes the taxes out of the costs paid by shoppers, without modifying the price during the ordering process. 

Currency 

When defining product prices you can:

  1. Configure the price only for the default currency - 2Checkout converts amounts in the cart based on the currency selected by/for shoppers. Currency rates are available here: https://secure.2checkout.com/content/...p?CURRENCY=USD

    This is an XML schema with the corresponding values for the other currencies compared to the one supplied in the CURRENCY query parameter.

  2. Specify prices in all currencies available for your account - 2Checkout serves shoppers the prices for all the currencies you set up without converting the amounts. 

Basic setup

You don't define a price when using static pricing (without base price). Instead, make your way to the Pricing tab, and first create all options for a product, like volume pricing and any other price options. Configure costs only after you add all product options since any change resets your configuration.

Advanced setup

Access advanced pricing/charge options by editing product and navigating to the Pricing tab. This area enables you to edit and create pricing configurations and create charge models that include:

  • Volume pricing
  • Custom recurring charges
  • Advanced pricing options
  • Pay-per-use (Metered billing)
  • Tiered charges

When using Static pricing (without base price), you need to define the pricing scheme through each individual pricing option, and as such, introducing a single price parameter becomes irrelevant. The 2Checkout system automatically displays all possible combinations (unit intervals and pricing options). In the Pricing area at the top of the screen but all combinations will need to be configured manually, at least for the default currency.  Define the price for each option, choose between Net and Gross, and hit Update Prices. 

Import a static pricing configuration

For products/subscription plans with Static pricing (without base price), you have the option of importing the pricing configuration. 

  1. Define the pricing scheme. 
  2. Select the Import tab in the Prices area. 
  3. Optional: Download an example of the product prices schema.
  4. Fill in prices for each possible combination of options. 
  5. Upload the resulting CSV file. 

Remove promotion coupon

Overview

Use the deletePromotionCoupon method via JSON-RPC API 4.0 to remove multiple coupons from a promotion. You cannot delete a single coupon. A coupon is required for the promotion.

Parameters

Parameter Type/Description

sessionID

Required (string)

 

Output of the Login method.

promotionCode

Required (string)

 

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

promotionCoupon

Required (object)

 

Type

Required (string)

 

 

Coupon type. Available values:

  • MULTIPLE, use in conjunction with Codes

 

Code/Codes

Required (string/array of strings)

 

 

Array of coupon codes (for MULTIPLE).

Response

Parameter Type/Description
promotionCoupon Object

Request

<?php

function callRPC($Request, $host, $Debug = true) {
    $curl = curl_init($host);
    curl_setopt($curl, CURLOPT_POST, 1);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($curl, CURLOPT_VERBOSE, true);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($curl, CURLOPT_SSLVERSION, 0);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Accept: application/json'));
    $RequestString = json_encode($Request);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $RequestString);
    if ($Debug) {
        $RequestString;
    }
    $ResponseString = curl_exec($curl);
    if ($Debug) {
        $ResponseString;
    }
    if (!empty($ResponseString)) {
        var_dump($ResponseString);
        $Response = json_decode($ResponseString);
        if (isset($Response->result)) {
            return $Response->result;
        }
        if (!is_null($Response->error)) {
            var_dump($Request->method, $Response->error);
        }
    } else {
        return null;
    }
}

$host = 'https://api.avangate.com/rpc/3.1/';

$merchantCode = "YOUR_MERCHANT_CODE"; // your account's merchant code available in the 'System settings' area of the cPanel: https://secure.avangate.com/cpanel/account_settings.php
$key = "YOUR_SECRET_KEY"; // your account's secret key available in the 'System settings' area of the cPanel: https://secure.avangate.com/cpanel/account_settings.php

$string = strlen($merchantCode) . $merchantCode . strlen(gmdate('Y-m-d H:i:s')) . gmdate('Y-m-d H:i:s');
$hash = hash_hmac('md5', $string, $key);

$i = 1;

$jsonRpcRequest = new stdClass();
$jsonRpcRequest->jsonrpc = '2.0';
$jsonRpcRequest->method = 'login';
$jsonRpcRequest->params = array($merchantCode, gmdate('Y-m-d H:i:s'), $hash);
$jsonRpcRequest->id = $i++;

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

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

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

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

Next renewal price

Overview

The object below is returned directly or within a successful response from the following API requests:

Retrieve next renewal price

Next renewal price object

Parameters Type/Description

NetPrice

Double

 

Price without taxes

NetCurrency

String

 

Currency for the price without taxes. The currency ISO code used for the payment - ISO 4217.

FinalPrice

Double

 

Price with taxes

FinalCurrency

String

 

Currency used for prices with taxes. The currency ISO code used for the payment - ISO 4217.

Set grace period

Overview

Use the setSubscriptionGracePeriod method to set a custom grace period for an Active or Past Due subscription. This method changes per-subscription end user data and not customer details.

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.

SubscriptionReference

Required (string)

 

Unique, system-generated subscription identifier. Needs to belong to an Active or Past Due subscription.

SubscriptionGracePeriod

Required (int)

 

The number of days for the grace period, during which time, customers can still renew/upgrade expired subscriptions. During the grace period, subscriptions feature the Past Due status.

 

Can be NULL. When NULL, the grace period for a subscription is the same as that you defined in the per-product or per-account grace period settings. You can use this to set a custom grace period for a subscription.

 

Can be sent with value 0.

To reset the grace period back to product/account default value, send the parameter empty (with no value).

Response

Boolean

true or false depending on whether the changes were successful or not.

Request


<?php
$host   = "https://api.2checkout.com";
$client = new SoapClient($host . "/soap/4.0/?wsdl", array(
    'location' => $host . "/soap/4.0/",
    "stream_context" => stream_context_create(array(
        'ssl' => array(
            'verify_peer' => false,
            'verify_peer_name' => false
        )
    ))
));

function hmac($key, $data)
{
    $b = 64; // byte length for md5
    if (strlen($key) > $b) {
        $key = pack("H*", md5($key));
    }
    
    $key    = str_pad($key, $b, chr(0x00));
    $ipad   = str_pad('', $b, chr(0x36));
    $opad   = str_pad('', $b, chr(0x5c));
    $k_ipad = $key ^ $ipad;
    $k_opad = $key ^ $opad;
    return md5($k_opad . pack("H*", md5($k_ipad . $data)));
}
$merchantCode = "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;
}
$subscriptionReference = 'DC47E143FA';
$gracePeriod = 14;
try {
    $customGracePeriod = $client->setSubscriptionGracePeriod($sessionID, $subscriptionReference, $gracePeriod);
}
catch (SoapFault $e) {
    echo "customGracePeriod: " . $e->getMessage();
    exit;
}
var_dump("customGracePeriod", $customGracePeriod);

 

Update promotion coupon

Overview

Use the updatePromotionCoupon method via JSON-RPC API 4.0 to add single or multiple coupons to a promotion.

Updating a promotion with multiple coupons causes any existing single coupon to be removed.

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 update.

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

function callRPC($Request, $host, $Debug = true) {
    $curl = curl_init($host);
    curl_setopt($curl, CURLOPT_POST, 1);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($curl, CURLOPT_VERBOSE, true);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($curl, CURLOPT_SSLVERSION, 0);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Accept: application/json'));
    $RequestString = json_encode($Request);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $RequestString);
    if ($Debug) {
        $RequestString;
    }
    $ResponseString = curl_exec($curl);
    if ($Debug) {
        $ResponseString;
    }
    if (!empty($ResponseString)) {
        var_dump($ResponseString);
        $Response = json_decode($ResponseString);
        if (isset($Response->result)) {
            return $Response->result;
        }
        if (!is_null($Response->error)) {
            var_dump($Request->method, $Response->error);
        }
    } else {
        return null;
    }
}

$host = 'https://api.avangate.com/rpc/3.1/';

$merchantCode = "YOUR_MERCHANT_CODE"; // your account's merchant code available in the 'System settings' area of the cPanel: https://secure.avangate.com/cpanel/account_settings.php
$key = "YOUR_SECRET_KEY"; // your account's secret key available in the 'System settings' area of the cPanel: https://secure.avangate.com/cpanel/account_settings.php

$string = strlen($merchantCode) . $merchantCode . strlen(gmdate('Y-m-d H:i:s')) . gmdate('Y-m-d H:i:s');
$hash = hash_hmac('md5', $string, $key);

$i = 1;

$jsonRpcRequest = new stdClass();
$jsonRpcRequest->jsonrpc = '2.0';
$jsonRpcRequest->method = 'login';
$jsonRpcRequest->params = array($merchantCode, gmdate('Y-m-d H:i:s'), $hash);
$jsonRpcRequest->id = $i++;

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

// Promotion code corresponding to the promotion you want to add coupons to
$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'];

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

Trigger renewal before usage upload interval

Overview

Trigger the renewal for a pay-per-usage subscription even before the end of the usage upload interval. Once the API call is made, the subscription is marked as ready to renew, and a renewal will be attempted. If the first attempt is not successful, the renewal of the subscription will be attempted again based on the regular renewal schedule.

Request Parameters

Parameter Type Required Description
sessionID String Required 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.
subscriptionReference String Required Unique, system-generated subscription identifier.
2Checkout charges customers using the payment data attached to subscriptions. In the case of credit/debit cards, if customers update their payment information in MyAccount or if you update these details on behalf of your subscribers, the 2Checkout system uses the latest card info provided to charge subscription renewals.

Request Sample

<?php

require ('PATH_TO_AUTH');

$subscriptionReference = 'YOUR_SUBSCRIPTION_REFERENCE';

try {
    $success = $client->markUsageSubscriptionToRenewNow($sessionID, $subscriptionReference, $Days, $Price, $Currency);
}
catch (SoapFault $e) {
    echo "Fault: " . $e->getMessage();
    exit;
}
var_dump("Success", $success);

Response Parameters

Parameter Type/Description
Boolean true or false depending on whether or not the subscription was marked as ready to be renewed. The response does not reflect the success of the renewal attempt.

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