共用方式為


使用客戶訂單建立購物車

適用於:合作夥伴中心 |由 21Vianet 營運的合作夥伴中心 |美國政府Microsoft雲端合作夥伴中心

您可以在購物車中為客戶新增訂單。 如需目前可供銷售之專案的詳細資訊,請參閱 雲端解決方案提供者 方案中的合作夥伴供應專案

注意

購物車從初始建立起 7 天到期。

必要條件

C#

若要為客戶建立訂單:

  1. 具現化 Cart 物件。

  2. 建立 CartLineItem 物件清單,並將清單指派給購物車的 LineItems 屬性。 每個購物車明細專案都包含一項產品的購買資訊。 您必須至少有一個購物車明細專案。

  3. 使用客戶標識符呼叫 IAggregatePartner.Customers.ById 方法來識別客戶,然後從 Cart 屬性擷取介面,以取得購物車作業的介面。

  4. 呼叫 Create 或 CreateAsync 方法來建立購物車。

  5. 若要完成證明並包含其他轉銷商,請參閱下列範例要求和回應範例:

要求範例


{
    "PartnerOnRecordAttestationAccepted":true,     "lineItems": [
        {
            "id": 0,
            "catalogItemId": "CFQ7TTC0LH0Z:0001:CFQ7TTC0K18P",
            "quantity": 1,
            "billingCycle": "monthly",
            "termDuration": "P1M",
            "renewsTo": null,
            "provisioningContext": {},
            "customTermEndDate": "2022-02-19T00:00:00Z"
        },
        {
            "id": 1,
            "catalogItemId": "CFQ7TTC0LFLS:0002:CFQ7TTC0KDLJ",
            "quantity": 2,
            "billingCycle": "monthly",
            "termDuration": "P1Y",
            "participants": [
                {
                    "key": "transaction_reseller",
                    "value": "5357564"
                },
                 {
                    "key": "additional_transaction_reseller",                     
                    "value": "517285"
                },
                 {
                    "key": "additional_transaction_reseller", 
                    "value": "5357563"
                }
            ]
        }
    ]
}


回應範例


{
    "id": "3e22b548-647d-4223-9675-1fcb6cb57665",
    "creationTimestamp": "2021-08-18T17:29:52.3517492Z",
    "lastModifiedTimestamp": "2021-08-18T17:29:52.3517553Z",
    "expirationTimestamp": "2021-08-25T17:30:11.2406416Z",
    "lastModifiedUser": "da62a0dc-35e9-4601-b48e-a047bd3ec7c1",
    "status": "Active",
    "lineItems": [
        {
            "id": 0,
            "catalogItemId": "CFQ7TTC0LH0Z:0001:CFQ7TTC0K18P",
            "quantity": 1,
            "currencyCode": "USD",
            "billingCycle": "monthly",
            "termDuration": "P1M",
	    "customTermEndDate": "2022-02-19T00:00:00Z";
            "provisioningContext": {},
            "orderGroup": "0"
        },
        {
            "id": 1,
            "catalogItemId": "CFQ7TTC0LFLS:0002:CFQ7TTC0KDLJ",
            "quantity": 2,
            "currencyCode": "USD",
            "billingCycle": "monthly",
            "termDuration": "P1Y",
            "participants": [
                {
                    "key": "transaction_reseller",
                    "value": "5357564"
                },
                {
                    "key": "additional_transaction_reseller", 
                    "value": "517285"
                },
                {
                    "key": "additional_transaction_reseller", 
                    "value": "5357563"
                }
            ],
            "provisioningContext": {},
            "orderGroup": "0"
        }
    ],
    "links": {
        "self": {
            "uri": "/customers/f81d98dd-c2f4-499e-a194-5619e260344e/carts/3e22b548-647d-4223-9675-1fcb6cb57665",
            "method": "GET",
            "headers": []
        }
    },
    "attributes": {
        "objectType": "Cart"
    }
}


C# 範例

// IAggregatePartner partnerOperations;
// string customerId;
// string subscriptionId;

var cart = new Cart()
{
    LineItems = new List<CartLineItem>()
    {
        new CartLineItem()
        {
      /* Microsoft Azure Subscription */
            Id = 0,
            CatalogItemId = "MS-AZR-0145P",
            Quantity = 1,
            BillingCycle = BillingCycleType.Monthly,
            TermDuration = "P1Y"
        },
        new CartLineItem()
        {
      /* Azure Reserved Instance */
            Id = 1,
            CatalogItemId = "DZH318Z0BQ36:004G:DZH318Z08C0S",
            Quantity = 1,
            BillingCycle = BillingCycleType.OneTime,
            TermDuration = "P1Y",
            ProvisioningContext = new Dictionary<string, string>
            {
                { "subscriptionId", subscriptionId },
                { "scope", "shared" }
            }
        },
        new CartLineItem()
        {
      /* Azure Reserved Instance */
            Id = 2,
            CatalogItemId = "DZH318Z0BQ36:004J:DZH318Z08B8X",
            Quantity = 1,
            BillingCycle = BillingCycleType.OneTime,
            TermDuration = "P3Y",
            ProvisioningContext = new Dictionary<string, string>
            {
                { "subscriptionId", subscriptionId },
                { "scope", "shared" }
            }
        },
        new CartLineItem()
        {
      /* Perpetual Software */
            Id = 3,
            CatalogItemId = "DG7GMGF0DWM3:0002:DG7GMGF0DT1M",
            Quantity = 1,
            BillingCycle = BillingCycleType.OneTime
        },
        new CartLineItem()
        {
      /* SaaS */
            Id = 4,
            CatalogItemId = "DZH318Z0BXWC:0002:DZH318Z0BMRV",
            Quantity = 1,
            BillingCycle = BillingCycleType.Monthly,
            TermDuration = "P1M"
        },
        new CartLineItem()
        {
      /* SaaS Free Trial */
            Id = 5,
            CatalogItemId = "DZH318Z0C0WF:0001:DZH318Z0BP69",
            Quantity = 10,
            BillingCycle = BillingCycleType.None,
            TermDuration = "P1M",
            RenewsTo = new RenewsTo
            {
                TermDuration = "P1Y"
            }
        }
    }
};

cart = partnerOperations.Customers.ById(customerId).Carts.Create(cart);

Java

合作夥伴中心 Java SDK 可用來管理合作夥伴中心資源。 這是合作夥伴社群維護的開放原始碼專案,Microsoft未正式支援。 如果您遇到問題,可以從社群取得協助在 GitHub 上提出問題

若要為客戶建立訂單:

  1. 具現化 Cart 物件。

  2. 建立 CartLineItem 物件清單,並將清單指派給購物車的明細專案。 每個購物車明細專案都包含一項產品的購買資訊。 您必須至少有一個購物車明細專案。

  3. 使用客戶標識符呼叫 IAggregatePartner.getCustomers()。byId 函式來識別客戶,然後從 getCart 函式擷取介面,以取得購物車作業的介面。

  4. 呼叫 create式以建立購物車。

Java 範例

// IAggregatePartner partnerOperations;
// String customerId;
// String subscriptionId;
// String catalogItemId;

CartLineItem lineItem = new CartLineItem();

lineItem.setBillingCycle(BillingCycleType.OneTime);
lineItem.setCatalogItemId(catalogItemId);
lineItem.setFriendlyName("Sample RI Purchase");
lineItem.setQuantity(1);

Map<String, String> provisioningContext = new HashMap<String,String>();

provisioningContext.put("duration", "3Years");
provisioningContext.put("scope", "shared");
provisioningContext.put("subscriptionId", subscriptionId);

lineItem.setProvisioningContext(provisioningContext);

List<CartLineItem> lineItemList = new ArrayList<CartLineItem>();
lineItemList.add(lineItem);

Cart cart = new Cart();
cart.setLineItems(lineItemList);

Cart cartCreated = partnerOperations.getCustomers().byId(customerId).getCarts().create(cart);

PowerShell

合作夥伴中心 PowerShell 模組可用來管理合作夥伴中心資源。 這是合作夥伴社群維護的開放原始碼專案,Microsoft未正式支援。 如果您遇到問題,可以從社群取得協助在 GitHub 上提出問題

若要為客戶建立訂單:

  1. 具現化 Cart 物件。

  2. 建立 CartLineItem 物件清單,並將清單指派給購物車的明細專案。 每個購物車明細專案都包含一項產品的購買資訊。 您必須至少有一個購物車明細專案。

  3. 執行 New-PartnerCustomerCart 命令來建立購物車。

# $customerId
# $subscriptionId
# $catalogItemId

$lineItem = New-Object -TypeName Microsoft.Store.PartnerCenter.PowerShell.Models.Carts.PSCartLineItem

$lineItem.BillingCycle = 'OneTime'
$lineItem.CatalogItemId = $catalogItemId
$lineItem.FriendlyName = 'Sample RI Purchase'
$lineItem.ProvisioningContext.Add('duration', '1Year')
$lineItem.ProvisioningContext.Add('scope', 'shared')
$lineItem.ProvisioningContext.Add('subscriptionId', $subsciptionId)
$lineItem.Quantity = 10

New-PartnerCustomerCart -CustomerId $customerId -LineItems $lineItem

REST 要求

要求語法

方法 要求 URI
POST {baseURL}/v1/customers/{customer-id}/carts HTTP/1.1

URI 參數

使用下列路徑參數來識別客戶。

名稱 類型​​ 必要 描述
customer-id 字串 Yes 識別客戶的 GUID 格式客戶識別碼。

要求標頭

如需詳細資訊,請參閱合作夥伴中心 REST 標頭

要求本文

下表描述 要求本文中的 Cart 屬性。

屬性 型別 必要 描述
id string No 成功建立購物車時提供的購物車標識碼。
creationTimeStamp Datetime No 以日期時間格式建立購物車的日期。 在成功建立購物車時套用。
lastModifiedTimeStamp Datetime No 購物車上次更新的日期,以日期時間格式顯示。 在成功建立購物車時套用。
expirationTimeStamp Datetime No 購物車到期的日期,以日期時間格式顯示。 在成功建立購物車時套用。
lastModifiedUser 字串 No 上次更新購物車的使用者。 在成功建立購物車時套用。
明細項目 物件陣列 Yes CartLineItem 資源的陣列
PartnerOnRecordAttestationAccepted 布林值 Yes 確認證明完成

下表描述 要求本文中的 CartLineItem 屬性。

屬性 型別 必要 描述
id string No 購物車明細專案的唯一標識符。 在成功建立購物車時套用。
catalogId 字串 Yes 目錄項目識別碼。 請確定目錄專案的可用性適用於正確的區段。
friendlyName 字串 No 選擇性。 夥伴所定義之專案的易記名稱,以協助釐清。
promotionId 字串 No 選擇性。 大部分 NCE 促銷都會自動套用,不過對於選擇性促銷(例如 Bridge to the Cloud 2)套用至購物車明細專案,合作夥伴必須在新增至購物車要求中包含促銷標識符。
數量 int Yes 授權或實例的數目。
currencyCode 字串 No 貨幣代碼。
billingCycle Object Yes 目前期間所設定的計費周期類型。
customTermEndDate Datetime No 您要共同決定新訂用帳戶之現有訂用帳戶的結束日期。
參與者 物件字串組的清單 No 購買時之 Record (PartnerID) 上的 PartnerId 集合。
provisioningContext <字典字串,字串> No 布建目錄中某些專案所需的資訊。 SKU 中的 provisioningVariables 屬性會指出目錄中特定專案需要哪些屬性。
orderGroup 字串 No 表示哪些專案可以放在一起的群組。
error Object No 如果發生錯誤,則會在購物車建立之後套用。
renewsTo 物件陣列 No RenewsTo 資源的陣列
證明Accepted 布林值 No 表示供應專案或 SKU 條件的合約。 僅適用於 SkuAttestationProperties 或 OfferAttestationProperties 強制Attestation 為 True 的供應專案或 SKU。
transaction_reseller String No 當間接提供者代表間接轉銷商下訂單時,僅以間接轉銷商的 PartnerID 填入此字段(絕不是間接提供者的識別符)。 這可確保適當地考慮獎勵。
additional_transaction_reseller String No 當間接提供者代表間接轉銷商下訂單時,僅以其他間接轉銷商的 PartnerID 填入此字段(絕不是間接提供者的標識符)。 獎勵不適用於這些額外的轉銷商。 最多只能輸入5個間接轉銷商。 這隻是歐盟/EFTA 國家/地區內交易的適用合作夥伴。

下表描述 要求本文中的 RenewsTo 屬性。

屬性 型別 必要 描述
termDuration 字串 No 更新期限的 ISO 8601 表示法。 目前的支援值為 P1M (1 個月)和 P1Y (1 年)。

要求範例

POST /v1/customers/d6bf25b7-e0a8-4f2d-a31b-97b55cfc774d/carts HTTP/1.1
Authorization: Bearer <token>
Accept: application/json
MS-RequestId: 4fa6dad6-a89f-4875-8247-8294a10ae1cf
MS-CorrelationId: 0e93c70c-977a-4a88-9580-7cf084c73286
X-Locale: en-US
MS-PartnerCenter-Client: Partner Center .NET SDK
Content-Type: application/json
Host: api.partnercenter.microsoft.com
Content-Length: 496
Expect: 100-continue

{
  "lineItems": [
    {
    /* Microsoft Azure Subscription */
      "id": 0,
      "catalogItemId": "MS-AZR-0145P",
      "quantity": 1,
      "billingCycle": "monthly",
      "termDuration": "P1Y"
    },
    {
    /* Azure Reserved Instance */
      "id": 1,
      "catalogItemId": "DZH318Z0BQ36:004G:DZH318Z08C0S",
      "quantity": 1,
      "billingCycle": "one_time",
      "termDuration": "P1Y",
      "provisioningContext": {
        "subscriptionId": "1C461A25-F729-4FA5-AADB-280947DD05E8",
        "scope": "shared"
      }
    },
    {
    /* Azure Reserved Instance */
      "id": 2,
      "catalogItemId": "DZH318Z0BQ36:004J:DZH318Z08B8X",
      "quantity": 1,
      "billingCycle": "one_time",
      "termDuration": "P3Y",
      "provisioningContext": {
        "subscriptionId": "1C461A25-F729-4FA5-AADB-280947DD05E8",
        "scope": "single"
      }
    },
    {
    /* Perpetual Software */
      "id": 3,
      "catalogItemId": "DG7GMGF0DWTL:0001:DG7GMGF0DSFM",
      "quantity": 1,
      "billingCycle": "one_time"
    },
    {
    /* SaaS */
      "id": 4,
      "catalogItemId": "DZH318Z0BXWC:0002:DZH318Z0BMRV",
      "quantity": 1,
      "billingCycle": "monthly",
      "termDuration": "P1M"
    },
  {
    /* SaaS Free Trial */
       "id": 5,
       "catalogItemId": "DZH318Z0C0WF:0001:DZH318Z0BP69",
       "quantity": 10,
       "billingCycle": "none",
       "termDuration": "P1M",
       "renewsTo": {
         "termDuration": "P1Y"
       }
    }
  ]
}

重要

自 2023 年 6 月起,最新的合作夥伴中心 .NET SDK 3.4.0 版現已封存。 您可以從 GitHub 下載 SDK 版本,以及 包含實用資訊的自述檔

鼓勵合作夥伴繼續使用 合作夥伴中心 REST API

REST 回應

如果成功,這個方法會在回應本文中傳回填入 的 Cart 資源。

回應成功和錯誤碼

每個回應都有一個 HTTP 狀態代碼,指出成功或失敗和偵錯資訊。 使用網路追蹤工具來讀取此程式代碼、錯誤類型和其他參數。 如需完整清單,請參閱錯誤碼

回應範例

HTTP/1.1 201 Created
Content-Length: 764
Content-Type: application/json; charset=utf-8
MS-CorrelationId: 0e93c70c-977a-4a88-9580-7cf084c73286
MS-RequestId: 4fa6dad6-a89f-4875-8247-8294a10ae1cf
X-Locale: en-US,en-US
MS-CV: sF/wRa2ih0CzbABc.0
MS-ServerId: 000001
Date: Thu, 15 Mar 2018 17:15:01 GMT
{
  "id": "3655b1a0-b1c9-4268-9824-577fdbc4d0be",
  "creationTimestamp": "2019-01-16T00:45:41.6062996Z",
  "lastModifiedTimestamp": "2019-01-16T00:45:41.6062996Z",
  "expirationTimestamp": "2019-01-16T01:00:54.4188497Z",
  "lastModifiedUser": "1824b7fc-2fac-4478-b177-66823c40ab75",
  "status": "Active",
  "lineItems": [
    {
      "id": 0,
      "catalogItemId": "MS-AZR-0145P",
      "quantity": 1,
      "currencyCode": "USD",
      "billingCycle": "monthly",
      "termDuration": "P1Y",
      "orderGroup": "OMS-0"
    },
    {
      "id": 1,
      "catalogItemId": "DZH318Z0BQ36:004G:DZH318Z08C0S",
      "quantity": 1,
      "currencyCode": "USD",
      "billingCycle": "one_time",
      "termDuration": "P1Y",
      "provisioningContext": {
        "subscriptionId": "1C461A25-F729-4FA5-AADB-280947DD05E8",
        "scope": "shared"
      },
      "orderGroup": "0"
    },
    {
      "id": 2,
      "catalogItemId": "DZH318Z0BQ36:004J:DZH318Z08B8X",
      "quantity": 1,
      "currencyCode": "USD",
      "billingCycle": "one_time",
      "termDuration": "P3Y",
      "provisioningContext": {
        "subscriptionId": "1C461A25-F729-4FA5-AADB-280947DD05E8",
        "scope": "shared"
      },
      "orderGroup": "0"
    },
    {
      "id": 3,
      "catalogItemId": "DG7GMGF0DWM3:0002:DG7GMGF0DT1M",
      "quantity": 1,
      "currencyCode": "USD",
      "billingCycle": "one_time",
      "orderGroup": "0"
    },
    {
      "id": 4,
      "catalogItemId": "DZH318Z0BXWC:0002:DZH318Z0BMRV",
      "quantity": 1,
      "currencyCode": "USD",
      "billingCycle": "monthly",
      "termDuration": "P1M",
      "orderGroup": "1"
    },
  {
      "id": 5,
      "catalogItemId": "DZH318Z0C0WF:0001:DZH318Z0BP69",
      "quantity": 10,
      "currencyCode": "USD",
      "billingCycle": "none",
      "termDuration": "P1M",
      "renewsTo": {
  "termDuration": "P1Y"
      },
    "orderGroup": "2"
    }
  ],
  "links": {
    "self": {
      "uri": "/customers/28045616-f6b9-462f-9701-0d89b5e65c44/carts/3655b1a0-b1c9-4268-9824-577fdbc4d0be",
      "method": "GET",
      "headers": []
    }
  },
  "attributes": {
    "objectType": "Cart"
  }
}

新商務授權型服務的範例

注意

授權型服務的新商務體驗包含許多新功能,可供所有 雲端解決方案提供者 (CSP) 使用。 如需詳細資訊,請參閱 新的商務體驗概觀

要求範例

POST /v1/customers/932c4101-dc08-461b-b4c1-75d80e905775/carts HTTP/1.1
Host: api.partnercenter.microsoft.com
Content-Type: application/json
Content-Length: 165

{
	"LineItems": [
		{
			"CatalogItemId":"CFQ7TTC0LFLZ:0002:CFQ7TTC0K4TS",
			"Quantity": 1,
			"TermDuration": "P1M",
			"BillingCycle": "Monthly"
		}
	]
}

重要

Azure 方案和永久軟體明細專案不支援 termDuration 屬性。 避免在擷取這些類型的專案時納入此專案。

REST 回應

如果成功,這個方法會在回應本文中傳回填入 的 Cart 資源。

回應成功和錯誤碼

每個回應都有一個 HTTP 狀態代碼,指出成功或失敗和其他偵錯資訊。 使用網路追蹤工具來讀取此程式代碼、錯誤類型和其他參數。 如需完整清單,請參閱錯誤碼

回應範例


{
    "id": "2517c51b-58cd-4abe-87ed-3ab812401ab4",
    "creationTimestamp": "2023-07-11T21:16:11.55149Z",
    "lastModifiedTimestamp": "2023-07-11T21:16:11.5515713Z",
    "expirationTimestamp": "2023-07-18T21:16:17.2480482Z",
    "lastModifiedUser": "9db12087-fbc3-481c-8965-73d44ff88e27",
    "status": "Active",
    "lineItems": [
        {
            "id": 0,
            "catalogItemId": "CFQ7TTC0LF8S:0001:CFQ7TTC0VZW5",
            "quantity": 1,
            "currencyCode": "USD",
            "billingCycle": "monthly",
            "termDuration": "P1Y",
            "provisioningContext": {},
            "orderGroup": "0",
            "pricing": {
                "listPrice": 30.4,
                "discountedPrice": 30.4,
                "proratedPrice": 30.4,
                "price": 30.4,
                "extendedPrice": 364.8
            }
        }
    ],
    "links": {
        "self": {
            "uri": "/customers/ebd8b4c2-4069-46a8-bd70-123d6dec3e39/carts/2517c51b-58cd-4abe-87ed-3ab812401ab4",
            "method": "GET",
            "headers": []
        }
    },
    "attributes": {
        "objectType": "Cart"
    }
}