Product Upgrade Schema
Last updated: 08-Sep-2020
Rate this article:
Overview
Use the setProductUpgradeSchema method to set a product’s upgrade schema via API.
Parameters
Parameter | Type | Required | Description |
---|---|---|---|
UpgradeSettings | Object | Required | Details below. |
PricingScheme |
Integer | Required |
The Upgrade pricing scheme. |
OptionPriceOperator | String | Optional | The operator that specifies how is the upgrade price impacted (not used for prorated upgrade pricing schemes): - ADD – the value set as OptionPricePercentage is added to the upgrade price; - SUBTRACT – the value set as OptionPricePercentage is subtracted from the upgrade price. |
OptionPricePercentage | Integer | Optional | The percentage of the upgrade price to be added/subtracted from this one (not used for pro-rated upgrade pricing schemes). |
UseProductCatalogPricing | Boolean | Optional | When true, it enables the usage of product catalog pricing. Removing custom prices also disables any existing retention campaigns for the selected subscriptions. |
ProrateIgnoreGracePeriod | Boolean | Optional | 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. |
SubscriptionUpgradeType | Integer | Required | Determines the Subscription period option for the upgrade: 1 - Create a new subscription (disable the existing one); 2 - Prolong the subscription from the upgrade purchase date; 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. |
AllowUpgradeFrom | Array of Strings | Required | List of product codes corresponding to the products that can be upgraded to the product of reference. |
Request Sample
<?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
{
"UpgradeSettings": {
"PricingScheme": 1,
"OptionPriceOperator": "ADD",
"OptionPricePercentage": 3,
"SubscriptionUpgradeType": 2,
"UseProductCatalogPricing": false,
"ProrateIgnoreGracePeriod": false
},
"AllowUpgradeFrom": [
"ADEV17962UPOPT12"
]
}
Related articles
Rate this article: