Skip to main content

Create price option groups

Create price option groups

Last updated: 11-Dec-2020
Rate this article:

Overview

Use the addPriceOptionGroup method to create price options for your subscription plans/products.

  • Send options for each pricing group or 2Checkout throws an exception.
  • When adding an interval with no min/max values or overlapping values, 2Checkout throws an exception. 

Parameters

Parameters Type/Description

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.

PriceOptionsGroup

Required (object)

 

Use this object to create a new price option group for your account.

Response

bool(true)

Request

<?php

require ('PATH_TO_AUTH');

$PriceOptionGroup = new stdClass();
$PriceOptionGroup->Name = 'New Multi Users';
$PriceOptionGroup->Description = 'Quos aut ipsam ipsum omnis aut molestiae. Et quod molestias distinctio. Fugiat sit asperiores reprehenderit officia eaque quae quia. Aperiam quia quia illo eos nesciunt accusamus.';
$PriceOptionGroup->Translations = array();
$PriceOptionGroup->Translations[0] = new stdClass();
$PriceOptionGroup->Translations[0]->Name = 'xdrki7ljix';
$PriceOptionGroup->Translations[0]->Description = 'Beatae doloribus ipsam voluptatem et. Iure dignissimos non amet. Quibusdam fugiat dolor repudiandae temporibus harum.';
$PriceOptionGroup->Translations[0]->Language = 'en';
$PriceOptionGroup->Translations[1] = new stdClass();
$PriceOptionGroup->Translations[1]->Name = '37wr8ie2dj';
$PriceOptionGroup->Translations[1]->Description = 'Esse distinctio voluptatibus omnis et et quia dolor. Quibusdam dicta dolores odio consequatur velit voluptate. Laboriosam reiciendis libero vel quae molestiae ad.';
$PriceOptionGroup->Translations[1]->Language = 'ru';
$PriceOptionGroup->Type = 'RADIO';
$PriceOptionGroup->Options = array();
$PriceOptionGroup->Options[0] = new stdClass();
$PriceOptionGroup->Options[0]->Name = 'SingleUser';
$PriceOptionGroup->Options[0]->Description = 'Nisi ea autem a labore similique. Minus natus cumque nemo. Aut aliquam laboriosam dolorem ad.';
$PriceOptionGroup->Options[0]->Translations = array();
$PriceOptionGroup->Options[0]->Translations[0] = new stdClass();
$PriceOptionGroup->Options[0]->Translations[0]->Name = '0q2r3kcj0q';
$PriceOptionGroup->Options[0]->Translations[0]->Description = 'Voluptatem in vitae rerum ea tempore. Non cumque ullam optio quis. Laborum maxime sunt facere. Dolor fugit a fugiat quasi facere totam.';
$PriceOptionGroup->Options[0]->Translations[0]->Language = 'en';
$PriceOptionGroup->Options[0]->Translations[1] = new stdClass();
$PriceOptionGroup->Options[0]->Translations[1]->Name = 'dwfxuw4lrn';
$PriceOptionGroup->Options[0]->Translations[1]->Description = 'Debitis omnis maiores quia praesentium totam error corrupti. Consectetur eum magnam quam vero. Sit aperiam natus perspiciatis iusto sint ut fugit. Adipisci illum non voluptatem voluptas.';
$PriceOptionGroup->Options[0]->Translations[1]->Language = 'it';
$PriceOptionGroup->Options[0]->Code = 'singleuser1';
$PriceOptionGroup->Options[0]->SubscriptionImpact = new stdClass();
$PriceOptionGroup->Options[0]->SubscriptionImpact->Impact = 'Add';
$PriceOptionGroup->Options[0]->SubscriptionImpact->Months = 1;
$PriceOptionGroup->Options[0]->PriceImpact = new stdClass();
$PriceOptionGroup->Options[0]->PriceImpact->Method = 'FIXED';
$PriceOptionGroup->Options[0]->PriceImpact->Amounts = array();
$PriceOptionGroup->Options[0]->PriceImpact->Amounts[0] = new stdClass();
$PriceOptionGroup->Options[0]->PriceImpact->Amounts[0]->Currency = 'USD';
$PriceOptionGroup->Options[0]->PriceImpact->Amounts[0]->Amount = 90.61;
$PriceOptionGroup->Options[0]->PriceImpact->Amounts[1] = new stdClass();
$PriceOptionGroup->Options[0]->PriceImpact->Amounts[1]->Currency = 'EUR';
$PriceOptionGroup->Options[0]->PriceImpact->Amounts[1]->Amount = 6.70;
$PriceOptionGroup->Options[0]->PriceImpact->ImpactOn = 'BASE';
$PriceOptionGroup->Options[0]->PriceImpact->Impact = 'ADD';
$PriceOptionGroup->Options[0]->PriceImpact->Percent = 39;
$PriceOptionGroup->Options[0]->Default = false;
$PriceOptionGroup->Options[1] = new stdClass();
$PriceOptionGroup->Options[1]->Name = 'MultiUser';
$PriceOptionGroup->Options[1]->Description = 'Vero voluptatum fuga et repellendus sed qui. Dolores molestiae error non ad aperiam. In error quos eum quas repudiandae pariatur et suscipit.';
$PriceOptionGroup->Options[1]->Translations = array();
$PriceOptionGroup->Options[1]->Translations[0] = new stdClass();
$PriceOptionGroup->Options[1]->Translations[0]->Name = 'MultiUser';
$PriceOptionGroup->Options[1]->Translations[0]->Description = 'Debitis et saepe facere blanditiis. Tempore et nemo aut ullam possimus ipsum nisi. Ad libero et consequuntur aliquam libero. Rerum aut illum eveniet earum.';
$PriceOptionGroup->Options[1]->Translations[0]->Language = 'en';
$PriceOptionGroup->Options[1]->Translations[1] = new stdClass();
$PriceOptionGroup->Options[1]->Translations[1]->Name = 'dw5zgkcki9';
$PriceOptionGroup->Options[1]->Translations[1]->Description = 'Vel et excepturi veniam. In iusto eveniet pariatur hic labore. Et qui dolorem accusantium molestias iusto.';
$PriceOptionGroup->Options[1]->Translations[1]->Language = 'pt';
$PriceOptionGroup->Options[1]->Code = 'multiuser999';
$PriceOptionGroup->Options[1]->SubscriptionImpact = new stdClass();
$PriceOptionGroup->Options[1]->SubscriptionImpact->Impact = 'ADD';
$PriceOptionGroup->Options[1]->SubscriptionImpact->Months = 2;
$PriceOptionGroup->Options[1]->PriceImpact = new stdClass();
$PriceOptionGroup->Options[1]->PriceImpact->Method = 'FIXED';
$PriceOptionGroup->Options[1]->PriceImpact->Amounts = array();
$PriceOptionGroup->Options[1]->PriceImpact->Amounts[0] = new stdClass();
$PriceOptionGroup->Options[1]->PriceImpact->Amounts[0]->Currency = 'USD';
$PriceOptionGroup->Options[1]->PriceImpact->Amounts[0]->Amount = 65.03;
$PriceOptionGroup->Options[1]->PriceImpact->Amounts[1] = new stdClass();
$PriceOptionGroup->Options[1]->PriceImpact->Amounts[1]->Currency = 'EUR';
$PriceOptionGroup->Options[1]->PriceImpact->Amounts[1]->Amount = 64.58;
$PriceOptionGroup->Options[1]->PriceImpact->ImpactOn = 'BASE';
$PriceOptionGroup->Options[1]->PriceImpact->Impact = 'ADD';
$PriceOptionGroup->Options[1]->PriceImpact->Percent = 51;
$PriceOptionGroup->Options[1]->Default = true;
$PriceOptionGroup->Code = null;
$PriceOptionGroup->Required = false;

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

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

?>

Pay-per-Usage

Use this option to create and assign PAYPERUSE price options to your portfolio.

For non PAYPERUSAGE cases, the Usage and UsagePricingModel fields are not required.

 Request sample with PAYPERUSE

<?php
declare(strict_types=1);

class Configuration
{
    public const MERCHANT_CODE = '';
    public const MERCHANT_KEY = '';
    public const URL = 'http://api.2checkout.com/rpc/6.0';
    public const ACTION = 'addPriceOptionGroup';
    public const ADDITIONAL_OPTIONS = null;
    //array or JSON
    public const PAYLOAD = <<<JSON
{
    "Type": "INTERVAL",
    "Code": "PayPerUsage-CODE",
    "Required": false,
    "Name": "Pay per usage pricing option group",
    "Description": "Test option description",
    "Usage": "PAYPERUSAGE",
    "UsagePricingModel": "STEPPED",
    "Options": [
        {
            "Code": "9876545678",
            "ScaleMin": "1",
            "ScaleMax": "9",
            "SubscriptionImpact": {
                "Months": "0.00",
                "Impact": null
            },
            "PriceImpact": {
                "Amounts": {
                    "USD": {
                        "Currency": "USD",
                        "Amount": "1.00"
                    },
                    "EUR": {
                        "Currency": "EUR",
                        "Amount": "6.00"
                    }
                },
                "ImpactOn": null,
                "Method": "FIXED",
                "Percent": null,
                "Impact": null
            },
            "Default": false,
            "Name": "translation_5f90150268bef",
            "Description": "Translation value",
            "Translations": [
                {
                    "Name": "translation_5f90150268bf7",
                    "Description": "Translation value",
                    "Language": "RO"
                },
                {
                    "Name": "translation_5f90150268bef",
                    "Description": "Translation value",
                    "Language": "EN"
                },
                {
                    "Name": "translation_5f90150268bf9",
                    "Description": "Translation value",
                    "Language": "FR"
                },
                {
                    "Name": "translation_5f90150268bf5",
                    "Description": "Translation value",
                    "Language": "RU"
                }
            ]
        },
        {
            "Code": "98765456789",
            "ScaleMin": "10",
            "ScaleMax": "19",
            "SubscriptionImpact": {
                "Months": "0.00",
                "Impact": null
            },
            "PriceImpact": {
                "Amounts": {
                    "USD": {
                        "Currency": "USD",
                        "Amount": "1.00"
                    },
                    "EUR": {
                        "Currency": "EUR",
                        "Amount": "6.00"
                    }
                },
                "ImpactOn": null,
                "Method": "FIXED",
                "Percent": null,
                "Impact": null
            },
            "Default": false,
            "Name": "translation_5f90150268bef",
            "Description": "Translation value",
            "Translations": [
                {
                    "Name": "translation_5f90150268bf7",
                    "Description": "Translation value",
                    "Language": "RO"
                },
                {
                    "Name": "translation_5f90150268bef",
                    "Description": "Translation value",
                    "Language": "EN"
                },
                {
                    "Name": "translation_5f90150268bf9",
                    "Description": "Translation value",
                    "Language": "FR"
                },
                {
                    "Name": "translation_5f90150268bf5",
                    "Description": "Translation value",
                    "Language": "RU"
                }
            ]
        }
    ],
    "Translations": [
        {
            "Name": "Pay per usage pricing option group",
            "Description": "Test option description",
            "Language": "EN"
        }
    ]
}
JSON;
}

class Client
{
    private const LOGIN_METHOD = 'login';
    private $calls = 1;
    private $sessionId;


    private function generateAuth(): array
    {
        $merchantCode = Configuration::MERCHANT_CODE;
        $key = Configuration::MERCHANT_KEY;
        $date = gmdate('Y-m-d H:i:s');
        $string = strlen($merchantCode) . $merchantCode . strlen($date) . $date;
        $hash = hash_hmac('md5', $string, $key);

        return compact('merchantCode', 'date', 'hash');
    }


    public function login(string $url)
    {
        $payload = $this->generateAuth();
        $response = $this->call($url, array_values($payload), self::LOGIN_METHOD);
        $this->sessionId = $response['result'];
    }


    public function call(
        string $url = Configuration::URL,
        $payload = Configuration::PAYLOAD,
        string $action = Configuration::ACTION
    ): ?array {
        if (empty($this->sessionId) && $action !== self::LOGIN_METHOD) {
            $this->login($url);
        }
        if(is_string($payload)) {
            $payload = json_decode($payload, true);
        }
        if (!empty($this->sessionId)) {
            $payload = [$this->sessionId, $payload, Configuration::ADDITIONAL_OPTIONS];
        }
        $payload = array_filter($payload);

        $request = json_encode([
            'jsonrpc' => '2.0',
            'method' => $action,
            'params' => $payload,
            'id' => $this->calls++,
        ]);
        $curl = curl_init($url);
        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', 'Cookie: XDEBUG_SESSION=PHPSTORM'));
        curl_setopt($curl, CURLOPT_POSTFIELDS, $request);
        $response = curl_exec($curl);
        if(empty($response)) {
            die('Server unavailable');
        }
        echo $response . '</br>';
        return json_decode($response, true);;
    }
}
$client = new Client();
$result = $client->call();
var_dump($result);

 Request sample without PAYPERUSE

<?php
declare(strict_types=1);

class Configuration
{
    public const MERCHANT_CODE = '';
    public const MERCHANT_KEY = '';
    public const URL = 'http://api.2checkout.com/rpc/6.0';
    public const ACTION = 'addPriceOptionGroup';
    public const ADDITIONAL_OPTIONS = null;
    //array or JSON
    public const PAYLOAD = <<<JSON
{
    "Type": "RADIO",
    "Code": "RADIO-CODE",
    "Required": false,
    "Name": "Radio pricing option group",
    "Description": "Test option description",
    "Options": [
        {
            "Code": "9876545678",
            "ScaleMin": "1",
            "ScaleMax": "9",
            "SubscriptionImpact": {
                "Months": "0.00",
                "Impact": null
            },
            "PriceImpact": {
                "Amounts": {
                    "USD": {
                        "Currency": "USD",
                        "Amount": "1.00"
                    },
                    "EUR": {
                        "Currency": "EUR",
                        "Amount": "6.00"
                    }
                },
                "ImpactOn": null,
                "Method": "FIXED",
                "Percent": null,
                "Impact": null
            },
            "Default": false,
            "Name": "translation_5f90150268bef",
            "Description": "Translation value",
            "Translations": [
                {
                    "Name": "translation_5f90150268bf7",
                    "Description": "Translation value",
                    "Language": "RO"
                },
                {
                    "Name": "translation_5f90150268bef",
                    "Description": "Translation value",
                    "Language": "EN"
                },
                {
                    "Name": "translation_5f90150268bf9",
                    "Description": "Translation value",
                    "Language": "FR"
                },
                {
                    "Name": "translation_5f90150268bf5",
                    "Description": "Translation value",
                    "Language": "RU"
                }
            ]
        },
        {
            "Code": "98765456789",
            "ScaleMin": "10",
            "ScaleMax": "19",
            "SubscriptionImpact": {
                "Months": "0.00",
                "Impact": null
            },
            "PriceImpact": {
                "Amounts": {
                    "USD": {
                        "Currency": "USD",
                        "Amount": "1.00"
                    },
                    "EUR": {
                        "Currency": "EUR",
                        "Amount": "6.00"
                    }
                },
                "ImpactOn": null,
                "Method": "FIXED",
                "Percent": null,
                "Impact": null
            },
            "Default": false,
            "Name": "translation_5f90150268bef",
            "Description": "Translation value",
            "Translations": [
                {
                    "Name": "translation_5f90150268bf7",
                    "Description": "Translation value",
                    "Language": "RO"
                },
                {
                    "Name": "translation_5f90150268bef",
                    "Description": "Translation value",
                    "Language": "EN"
                },
                {
                    "Name": "translation_5f90150268bf9",
                    "Description": "Translation value",
                    "Language": "FR"
                },
                {
                    "Name": "translation_5f90150268bf5",
                    "Description": "Translation value",
                    "Language": "RU"
                }
            ]
        }
    ],
    "Translations": [
        {
            "Name": "Radio pricing option group",
            "Description": "Test option description",
            "Language": "EN"
        }
    ]
}
JSON;
}

class Client
{
    private const LOGIN_METHOD = 'login';
    private $calls = 1;
    private $sessionId;


    private function generateAuth(): array
    {
        $merchantCode = Configuration::MERCHANT_CODE;
        $key = Configuration::MERCHANT_KEY;
        $date = gmdate('Y-m-d H:i:s');
        $string = strlen($merchantCode) . $merchantCode . strlen($date) . $date;
        $hash = hash_hmac('md5', $string, $key);

        return compact('merchantCode', 'date', 'hash');
    }


    public function login(string $url)
    {
        $payload = $this->generateAuth();
        $response = $this->call($url, array_values($payload), self::LOGIN_METHOD);
        $this->sessionId = $response['result'];
    }


    public function call(
        string $url = Configuration::URL,
        $payload = Configuration::PAYLOAD,
        string $action = Configuration::ACTION
    ): ?array {
        if (empty($this->sessionId) && $action !== self::LOGIN_METHOD) {
            $this->login($url);
        }
        if(is_string($payload)) {
            $payload = json_decode($payload, true);
        }
        if (!empty($this->sessionId)) {
            $payload = [$this->sessionId, $payload, Configuration::ADDITIONAL_OPTIONS];
        }
        $payload = array_filter($payload);

        $request = json_encode([
            'jsonrpc' => '2.0',
            'method' => $action,
            'params' => $payload,
            'id' => $this->calls++,
        ]);
        $curl = curl_init($url);
        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', 'Cookie: XDEBUG_SESSION=PHPSTORM'));
        curl_setopt($curl, CURLOPT_POSTFIELDS, $request);
        $response = curl_exec($curl);
        if(empty($response)) {
            die('Server unavailable');
        }
        echo $response . '</br>';
        return json_decode($response, true);;
    }
}
$client = new Client();
$result = $client->call();
var_dump($result);

 

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