> For the complete documentation index, see [llms.txt](https://docs.2checkout.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.2checkout.com/json-rpc-api-reference/json-rpc-api-6.0/api-requests/product/product-upgrade-schema.md).

# Product upgrade schema

Use the **setProductUpgradeSchema** method to set a product’s upgrade schema via API.

## Request parameters <a href="#parameters" id="parameters"></a>

<table><thead><tr><th width="340.5999755859375">Parameter</th><th>Type / Description</th></tr></thead><tbody><tr><td><code>UpgradeSettings</code></td><td><p><strong>Required (object)</strong></p><p>Details below.</p></td></tr><tr><td><code>UpgradeSettings.PricingScheme</code></td><td><p><strong>Required (integer)</strong></p><p>The Upgrade pricing scheme.<br>1 – Shopper pays the full upgrade product price;<br>2 – Shopper pays the difference between the original subscription and the upgraded product;<br>3 - Shopper pays a prorated upgrade price calculated using the most recent costs incurred by the customer;<br>4 – Shopper pays prorated upgrade price calculated using the product's pricing set up at the time of the order.</p></td></tr><tr><td><code>UpgradeSettings.OptionPriceOperator</code></td><td><p><strong>Optional (string)</strong></p><p>The operator that specifies how is the upgrade price impacted (not used for prorated upgrade pricing schemes):</p><ul><li>ADD – the value set as <code>OptionPricePercentage</code> is added to the  upgrade price;</li><li>SUBTRACT – the value set as <code>OptionPricePercentage</code> is subtracted from the upgrade price.</li></ul></td></tr><tr><td><code>UpgradeSettings.OptionPricePercentage</code></td><td><p><strong>Optional (integer)</strong></p><p>The percentage of the upgrade price to be added/subtracted from this one (not used for pro-rated upgrade pricing schemes).</p></td></tr><tr><td><code>UseProductCatalogPricing</code></td><td><p><strong>Optional (boolean)</strong></p><p>When true, it enables the usage of product catalog pricing. Removing custom prices also disables any existing retention campaigns for the selected subscriptions.</p></td></tr><tr><td><code>ProrateIgnoreGracePeriod</code></td><td><p><strong>Optional (boolean)</strong></p><p>When true, it makes the grace period be ignored when calculating Upgrade. Use this option to ignore the grace period set in your Renewal Settings when computing the prorated price for the upgrade.</p></td></tr><tr><td><code>SubscriptionUpgradeType</code></td><td><p><strong>Required (integer)</strong></p><p>Determines the Subscription period option for the upgrade:<br>1 - Create a new subscription (disable the existing one);<br>2 - Prolong the subscription from the upgrade purchase date;<br>3 - The upgrade does not affect the original subscription duration. If you upgrade a lifetime subscription to a product that has recurring options, the subscription will remain lifetime, as its duration is not affected by the upgrade process.</p></td></tr><tr><td><code>AllowUpgradeFrom</code></td><td><p><strong>Required (array of strings)</strong></p><p>List of product codes corresponding to the products that can be upgraded to the product of reference.</p></td></tr></tbody></table>

### Request sample <a href="#request-sample" id="request-sample"></a>

```php
<?php

function callRPC($Request, $hostUrl, $Debug = false) {
    $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', 'Cookie: XDEBUG_SESSION=PHPSTORM'));
    $RequestString = json_encode($Request);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $RequestString);

    if ($Debug) {
        var_dump($RequestString);
    }
    $ResponseString = curl_exec($curl);
    if ($Debug) {
        var_dump($ResponseString);
    }

    if (!empty($ResponseString)) {
        $Response = json_decode($ResponseString);
        if (isset($Response->result)) {
            return $Response->result;
        }
        var_dump($Response);

        if (!empty($Response->error)) {
            var_dump($Request->method, $Response->error);
        }
    } else {
        return null;
    }
}

//require_once(realpath(__DIR__ . '/../../../../../') . "/lib/api/v6.0/vendor/autoload.php");
require_once("/srv/www/app/live/htdocs/lib/api/v6.0/vendor/autoload.php");

$apiVersion = '6.0';
$domain = 'api.avangate.local:8081';
$host = "http://{$domain}/rpc/{$apiVersion}/";

// AlexB Inc account #21478
$merchantCode = "120000589445";
$key = "i9u2+w8%s4^5#8%t)A8?";
$productCode = "ADEV17962UPGRADE";            // main upgrade product offered as upgrade for other products
$upgradeFromProductCode1 = "ADEV17962UPOPT1"; // product that can be upgraded #1
$upgradeFromProductCode2 = "ADEV17962UPOPT12"; // product that can be upgraded #2

$date = gmdate('Y-m-d H:i:s');
$string = strlen($merchantCode) . $merchantCode . strlen($date) . $date;
$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 = [$merchantCode, $date, $hash];
$jsonRpcRequest->id = $i++;

$sessionID = callRPC($jsonRpcRequest, $host);
echo PHP_EOL . 'SessionID -> ' . $sessionID . PHP_EOL;

$upgradeSchema = new stdClass();

/** @var \Api\Resources\Product\Assets\UpgradeSettings $upgradeSettings */
$upgradeSettings = new stdClass();
$upgradeSettings->PricingScheme = \Api\Resources\Product\Assets\UpgradeSettings::PRICING_SCHEME_PRICE_DIFFERENCE;
$upgradeSettings->OptionPriceOperator = \Api\Resources\Product\Assets\UpgradeSettings::OPTION_PRICE_OPERATOR_SUBSTRACT;
$upgradeSettings->OptionPricePercentage = 3;
$upgradeSettings->SubscriptionUpgradeType = \Api\Resources\Product\Assets\UpgradeSettings::SUBSCRIPTION_UPGRADE_TYPE_PROLONG_SUBSCRIPTION;
#$upgradeSettings->SubscriptionUpgradeType = 8; // invalid value
$upgradeSettings->UseProductCatalogPricing = true;
#$upgradeSettings->UseProductCatalogPricing = 'yes'; // should be rejected
$upgradeSettings->ProrateIgnoreGracePeriod = false;

$upgradeSchema->UpgradeSettings = $upgradeSettings;
#$upgradeSchema->AllowUpgradeFrom = [$upgradeFromProductCode1, $upgradeFromProductCode2];
$upgradeSchema->AllowUpgradeFrom = [$upgradeFromProductCode1];

$payload = json_encode($upgradeSchema, JSON_PRETTY_PRINT);

echo PHP_EOL . 'Calling ' . $host . ' with productCode: ' . $productCode . ' and payload: ' . PHP_EOL . $payload . PHP_EOL;

$jsonRpcRequest = new stdClass();
$jsonRpcRequest->jsonrpc = '2.0';
$jsonRpcRequest->method = 'setProductUpgradeSchema';
$jsonRpcRequest->params = [$sessionID, $productCode, $upgradeSchema];
$jsonRpcRequest->id = $i++;

$resp = callRPC($jsonRpcRequest, $host);
$response = json_encode($resp, JSON_PRETTY_PRINT);
echo PHP_EOL . 'SetUpgradeSchema response:' . PHP_EOL . var_export($resp, true) . PHP_EOL;

```

### Response sample <a href="#response" id="response"></a>

```php
{
    "UpgradeSettings": {
        "PricingScheme": 1,
        "OptionPriceOperator": "ADD",
        "OptionPricePercentage": 3,
        "SubscriptionUpgradeType": 2,
        "UseProductCatalogPricing": false,
        "ProrateIgnoreGracePeriod": false
    },
    "AllowUpgradeFrom": [
        "ADEV17962UPOPT12"
    ]
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.2checkout.com/json-rpc-api-reference/json-rpc-api-6.0/api-requests/product/product-upgrade-schema.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
