Product upgrade schema

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

Request parameters

Parameter
Type / Description

UpgradeSettings

Required (object) Details below.

UpgradeSettings.PricingScheme

Required (integer) The Upgrade pricing scheme.

  1. Shopper pays the full upgrade product price;

  2. Shopper pays the difference between the original subscription and the upgraded product;

  3. Shopper pays a prorated upgrade price calculated using the most recent costs incurred by the customer;

  4. Shopper pays prorated upgrade price calculated using the product's pricing set up at the time of the order.

UpgradeSettings.OptionPriceOperator

Optional (string) 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.

UpgradeSettings.OptionPricePercentage

Optional (integer) The percentage of the upgrade price to be added/subtracted from this one (not used for pro-rated upgrade pricing schemes).

UseProductCatalogPricing

Optional (boolean) When true, it enables the usage of product catalog pricing. Removing custom prices also disables any existing retention campaigns for the selected subscriptions.

ProrateIgnoreGracePeriod

Optional (boolean) 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

Required (integer) 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

Required (array of strings) List of product codes corresponding to the products that can be upgraded to the product of reference.

Request sample

<?php

//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}/soap/{$apiVersion}/";

$client = new SoapClient($host . "?wsdl", array('location' => $host, 'cache_wsdl' => WSDL_CACHE_NONE));
$client->__setCookie('XDEBUG_SESSION', 'PHPSTORM');

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

try {
    $sessionID = $client->login($merchantCode, $date, $hash);
} catch (SoapFault $e) {
    echo  $e->getMessage();

}
echo "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 = 2;
$upgradeSettings->SubscriptionUpgradeType = \Api\Resources\Product\Assets\UpgradeSettings::SUBSCRIPTION_UPGRADE_TYPE_PROLONG_SUBSCRIPTION;
#$upgradeSettings->SubscriptionUpgradeType = 8; // invalid value
$upgradeSettings->UseProductCatalogPricing = true;
#$upgradeSettings->UseProductCatalogPricing = new SoapVar(5, XSD_INTEGER); // integer value 5 => will trigger exception
$upgradeSettings->ProrateIgnoreGracePeriod = false;

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

$payload = json_encode($upgradeSchema, JSON_PRETTY_PRINT);

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

try {
    $resp = $client->setProductUpgradeSchema($sessionID, $productCode, $upgradeSchema);
} catch (SoapFault $e) {
    echo  '(SoapFault) Exception caught: ' . $e->getMessage() . PHP_EOL;
    die();
}

echo PHP_EOL . 'SetUpgradeSchema response:' . PHP_EOL . var_export($resp, true) . PHP_EOL;

Response sample

Last updated

Was this helpful?