使用客户订单创建购物车

适用于:合作伙伴中心 | 由世纪互联运营的合作伙伴中心 | Microsoft Cloud for US Government 合作伙伴中心

可以在购物车中添加客户的订单。 有关当前可供销售的内容的详细信息,请参阅云解决方案提供商计划中合作伙伴产品/服务

注意

购物车自初始创建起 7 天后过期。

先决条件

  • 合作伙伴中心身份验证中所述的凭据。 此方案支持使用独立应用和 App+User 凭据进行身份验证。

  • 客户 ID (customer-tenant-id)。 如果不知道客户的 ID,可以通过选择“客户”工作区,然后从客户列表中选择客户,然后选择“帐户”,在合作伙伴中心查找该 ID。 在客户的“帐户”页上的“客户帐户信息”部分查找 Microsoft ID。 Microsoft ID 与客户 ID (customer-tenant-id) 相同。

C#

为客户创建订单:

  1. 实例化 Cart 对象。

  2. 创建 CartLineItem 对象列表,并将列表分配给购物车的 LineItems 属性。 每个购物车行项都包含一个产品的购买信息。 必须至少有一个购物车行项。

  3. 通过使用客户 ID 调用 IAggregatePartner.Customers.ById 方法来获取购物车操作的接口,然后从 Cart 属性检索接口。

  4. 调用 CreateCreateAsync 方法以创建购物车。

  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. 通过使用客户 ID 调用 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 string 标识客户的 GUID 格式的客户 ID。

请求标头

有关详细信息,请参阅合作伙伴中心 REST 标头

请求正文

下表描述了 请求正文中的 Cart 属性。

properties 类型 必需 描述
id string 成功创建购物车时提供的购物车标识符。
creationTimeStamp 日期时间 以日期时间格式创建购物车的日期。 成功创建购物车时应用。
lastModifiedTimeStamp 日期时间 上次更新购物车的日期,采用日期时间格式。 成功创建购物车时应用。
expirationTimeStamp 日期时间 购物车过期的日期,采用日期时间格式。 成功创建购物车时应用。
lastModifiedUser string 上次更新购物车的用户。 成功创建购物车时应用。
lineItems 对象数组 CartLineItem 资源的数组
PartnerOnRecordAttestationAccepted 布尔 确认证明完成

下表描述了 请求正文中的 CartLineItem 属性。

properties 类型 必需 描述
id string 购物车行项的唯一标识符。 成功创建购物车时应用。
catalogId string 目录项标识符。 确保目录项的可用性适用于正确的段。
friendlyName string 可选。 合作伙伴定义的项的友好名称,以帮助消除歧义。
promotionId string 可选。 大多数 NCE 促销将自动应用,但对于可选促销(如 Bridge to the Cloud 2),要应用于购物车行项,合作伙伴必须在添加到购物车请求中包含促销 ID。
quantity int 许可证或实例数。
currencyCode string 货币代码。
billingCycle Object 为当前时间段设置的计费周期类型。
customTermEndDate 日期时间 要确定新订阅的现有订阅的结束日期。
participants 对象字符串对列表 购买时记录上的 PartnerId 集合(PartnerID)。
provisioningContext 字典<字符串,字符串> 为目录中的某些项目预配所需的信息。 SKU 中的 provisioningVariables 属性指示目录中特定项需要哪些属性。
orderGroup string 一个组,用于指示哪些项可以放在一起。
error Object 如果出现错误,在创建购物车后应用。
renewsTo 对象数组 RenewsTo 资源的数组
AttestationAccepted 布尔 指示提供或 SKU 条件的协议。 仅适用于 SkuAttestationProperties 或 OfferAttestationProperties 强制实施Attestation 的套餐或 SKU。
transaction_reseller 字符串 当间接提供商代表间接经销商下订单时,仅使用间接经销商的 PartnerID 填充此字段(从不为间接提供商的 ID)。 这可以确保正确地针对奖励进行记账。
additional_transaction_reseller 字符串 当间接提供商代表间接经销商下订单时,仅使用附加间接经销商的 PartnerID 填充此字段(从不为间接提供商的 ID)。 奖励不适用于这些额外的经销商。 最多只能输入 5 个间接经销商。 这只是欧盟/EFTA 国家/地区内交易的适用合作伙伴。

下表描述了 请求正文中的 RenewsTo 属性。

properties 类型 必需 说明
termDuration string 续订期限持续时间的 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"
    }
}