Skip to main content

Retrieve price based on specific options

Retrieve price based on specific options

Last updated: 29-Sep-2021
Rate this article:

Overview

Use getPrice to extract cost information for a product/subscription plan, based on a specific list of options. 

Parameters

Parameters Type/Description

Item

Required (Object)

 

Code

Required (string)

 

 

Unique product identifier your control. Max length 256 characters.

 

Quantity

Required (String)

 

 

Number of units.

 

PriceOptions

Optional (Array)

 

 

Array of price option codes.

Billing details

Required (Object)

 

Details below. Can be null. 

 

FirstName

Required (string)

 

 

Shopper name.

 

LastName

Required (string)

 

 

Shopper surname.

 

CountryCode

Optional (string)

 

 

Shopper country. ISO 3166 two-letter code. Include CountryCode in your request in combination with a null value for Currency, to receive the price in the default currency of the country you set. 

 

State

Optional (string) – Required for US, Brazil and Romania

 

 

The state in the shopper's country. Mandatory when you set the Billing Country to US, Brazil and Romania. Use case insensitive utf8 strings for the full name, or just the two letter code.

 

City

Optional (string)

 

 

Shopper city.

 

Address1

Optional (string)

 

 

Shopper address.

 

Address2

Optional (string)

 

 

Shopper address.

 

Zip

Optional (string)

 

 

ZIP/ Postal code.

 

Email

Optional (string)

 

 

Shopper email address.

 

Phone

Optional (string)

 

 

Shopper phone number. Mandatory when you set Brazil as the Billing Country. Can be NULL.

 

Company

Optional (string)

 

 

Company name. Can be null for end users. When present, you also need to provide the FiscalCode.

 

FiscalCode

Optional (string) – Required for Brazil

 

 

• For companies, it needs to be the VAT ID. 2Checkout will validate the value provided and throw an error if the VAT ID is invalid/incorrect when calling setPaymentDetails. When present, you also need to provide the Company name.

• Mandatory when you set Brazil as the Billing Country. For Brazilian customers it represents the Fiscal Code (CPF/CNPJ).

• Can be NULL for end users.

Currency

Required (string)

 

The currency ISO code for the payment - ISO 4217. Example: “usd.”

CouponCode

Optional (string)

 

Promotion coupon/voucher.

PayType

Optional (string)

 

The payment method:

  • CC (credit/debit card - including local Brazilian cards).
  • ENCRYPTED_PAYMENT_DATA (client-side encryption)
  • PAYPAL
  • PAYPAL_EXPRESS
  • TEST (for test orders).
  • PREVIOUS_ORDER (place new orders using the reference of a previous order).
  • EXISTING_PAYMENT_DATA  (use a card one of your customers already used to purchase from your account).
  • WIRE – the placeOrder response includes Wire payment details.
  • CHECK – the placeOrder response includes Check payment details.
  • PURCHASEORDER - use for orders with POs.
  • FREE – for 0 value orders for which you’re not requiring customers to provide payment details.

Response

Parameters Type/Description
ItemPrice Object

UnitNetPrice

Optional (double)

 

The value per product unit, excluding sales tax/VAT expressed in the payment currency.

UnitGrossPrice

Optional (double)

 

Total value per product unit, including sales tax/VAT expressed in the payment currency. UnitGrossPricedoes not reflect any discounts.

UnitVAT

Optional (double)

 

Sales tax/VAT per product unit expressed in the payment currency.

UnitDiscount

Optional (double)

 

Value of the discount per product unit expressed in the payment currency.

UnitNetDiscountedPrice

Optional (double)

 

The value per product unit, expressed in the payment currency, excluding sales tax/VAT, from which 2Checkout deducts the unit discount.

UnitGrossDiscountedPrice

Optional (double)

 

Total costs shoppers incur per product unit, expressed in the payment currency. This value includes sales tax/VAT, 2Checkout and affiliate commissions, but 2Checkout deducts the value of any discounts.

UnitAffiliateCommission

Optional (double)

 

Value of the affiliate commission per product unit calculated expressed in the payment currency.

 

2Checkout deducts discounts from the costs incurred by shoppers before calculating affiliate commissions.

 

2Checkout does not take into account shipping costs when calculating affiliate commissions.

 

NULL when 2Checkout does not apply an affiliate commission.

AffiliateCommission Optional (double)
  Value of the affiliate commission for the order calculated from the NetDiscountedPrice expressed in the payment currency. Or NULL. 2Checkout does not take into account shipping costs when calculating affiliate commissions.
Currency Optional (string)
  The currency ISO code for the payment - ISO 4217. Example: “usd.” Use null as value when you include CountryCode in your request, to receive the price in the default currency of the country you set. 
Discount Optional (double)
  Value of the discounts for an order expressed in the payment currency.
GrossDiscountedPrice Optional (double)
  Total costs shoppers incurexpressed in the payment currencyThis value includes sales tax/VAT, 2Checkout and affiliate commissions, but 2Checkout deducts the value of any discounts.
GrossPrice Optional (double)
  Total order value, including sales tax/VAT expressed in the payment currency. GrossPrice does not reflect any discounts.
NetDiscountedPrice Optional (double)
  The NetPrice order value excluding sales tax/VAT, from which 2Checkout deducts discounts. NetDiscountedPriceis expressed in the payment currency.
NetPrice Optional (double)
  Order value excluding sales tax/VAT expressed in the payment currency.
VAT Optional (double)
  Value of sales tax/VAT expressed in the payment currency.

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;
}
 
var_dump($sessionID);

$CartItem = new stdClass();
 
$CartItem->Code = 'my_subscription_1';
$CartItem->Quantity = 1; 
$CartItem->PriceOptions = array();

/* $CartItem->Trial = new stdClass(); 
$CartItem->Trial->Period = 8;
$CartItem->Trial->Price = 999; */

$BillingDetails = NULL;
$Currency = 'USD';
$CouponCode = '123';
$PayType = 'CC';

try {
    $itemPrice = $client->getPrice($sessionID, $CartItem, $BillingDetails, $Currency, $CouponCode, $PayType);
}
catch (SoapFault $e) {
    echo "itemPrice: " . $e->getMessage();
    exit;
}
var_dump("itemPrice", $itemPrice);

 

Rate this article:

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