當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


PHP WHMCS UpgradeProduct用法及代碼示例

升級或計算產品升級

請求參數

參數 類型 說明 必需的
action string “UpgradeProduct” Required
serviceid int 要更新的服務的 ID Required
calconly bool 隻計算升級數量 Optional
paymentmethod string 係統格式的升級支付方式(如paypal) Required
type string 升級類型(‘product’, ‘configoptions’) Required
newproductid int 新產品ID Optional
newproductbillingcycle string 新產品計費周期 Optional
promocode string 適用於升級的促銷代碼 Optional
configoptions array 如果 type=configoptions - 配置要包含在升級中的選項。鍵代表配置選項 ID,而它們的值代表配置選項選項 ID 或值(取決於類型)。在提供的示例中,配置選項 ID=1 是指定選項 ID 4 的下拉列表,配置選項 ID=2 是指定需要 5 個單位的數量。 Optional

響應參數

參數 類型 說明
result string 操作結果:成功或錯誤
upgradeinprogress bool 是否正在進行升級(僅適用於 calconly)

示例請求 (CURL)

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.example.com/includes/api.php');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,
    http_build_query(
        array(
            'action' => 'UpgradeProduct',
            // See https://developers.whmcs.com/api/authentication
            'username' => 'IDENTIFIER_OR_ADMIN_USERNAME',
            'password' => 'SECRET_OR_HASHED_PASSWORD',
            'serviceid' => '1',
            'paymentmethod' => 'paypal',
            'newproductbillingcycle' => 'monthly',
            'type' => 'product',
            'newproductid' => '11',
            'configoptions' => [1 => 4, 2 => 5],
            'responsetype' => 'json',
        )
    )
);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
curl_close($ch);

示例請求(本地 API)

$command = 'UpgradeProduct';
$postData = array(
    'serviceid' => '1',
    'paymentmethod' => 'paypal',
    'newproductbillingcycle' => 'monthly',
    'type' => 'product',
    'newproductid' => '11',
    'configoptions' => [1 => 4, 2 => 5],
);
$adminUsername = 'ADMIN_USERNAME'; // Optional for WHMCS 7.2 and later

$results = localAPI($command, $postData, $adminUsername);
print_r($results);

示例響應 JSON

{
    "result": "success",
    "oldproductid": "12",
    "oldproductname": "5 Years",
    "newproductid": 11,
    "newproductname": "4 Years",
    "daysuntilrenewal": 13,
    "totaldays": 30,
    "newproductbillingcycle": "monthly",
    "price": "$-8.67 USD",
    "id": "44",
    "orderid": 73,
    "order_number": "9093331404",
    "invoiceid": null
}

錯誤響應

可能的錯誤條件響應包括:

  • 未找到服務 ID
  • 無法接受升級訂單。之前的升級服務發票仍未支付。
  • 付款方式無效。有效選項包括 xxx
  • 無效的升級類型

相關用法


注:本文由純淨天空篩選整理自whmcs.com大神的英文原創作品 UpgradeProduct。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。