使用客户订单创建购物车
适用于:合作伙伴中心|由世纪互联运营的合作伙伴中心|Microsoft Cloud for US Government合作伙伴中心
可以在购物车中为客户添加订单。 有关当前可供销售的内容的详细信息,请参阅 云解决方案提供商计划中的合作伙伴产品/服务。
必备条件
合作伙伴中心身份验证中所述的凭据。 此方案支持使用独立应用和 App+用户凭据进行身份验证。
客户 ID (
customer-tenant-id)。 如果不知道客户的 ID,则可以在合作伙伴中心仪表板中查找它。 从“合作伙伴中心”菜单中选择“CSP” ,然后选择“客户” 。 从客户列表中选择客户,然后选择“帐户” 。 在客户的“帐户”页上的“客户帐户信息” 部分查找 Microsoft ID。 Microsoft ID 与客户 ID (customer-tenant-id) 相同。
C#
为客户创建订单:
实例化 Cart 对象。
创建 CartLineItem 对象列表,并将该列表分配给购物车的 LineItems 属性。 每个购物车行项都包含一个产品的购买信息。 必须至少有一个购物车行项。
使用客户 ID 调用 IAggregatePartner.Customers.ById 方法来获取购物车操作的接口,然后从 Cart 属性检索接口。
调用 Create 或 CreateAsync 方法以创建购物车。
若要完成证明并包括其他经销商,请参阅以下示例请求和响应示例:
请求示例
{
"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 上创建问题。
为客户创建订单:
实例化 Cart 对象。
创建 CartLineItem 对象列表,并将该列表分配给购物车的行项。 每个购物车行项都包含一个产品的购买信息。 必须至少有一个购物车行项。
使用客户 ID 调用 IAggregatePartner.getCustomers () .byId 函数来获取购物车操作的接口,然后从 getCart 函数检索接口。
调用 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 上创建问题。
为客户创建订单:
实例化 Cart 对象。
创建 CartLineItem 对象列表,并将该列表分配给购物车的行项。 每个购物车行项都包含一个产品的购买信息。 必须至少有一个购物车行项。
执行 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 | 字符串 | 是 | 标识客户的 GUID 格式的客户 ID。 |
请求标头
有关详细信息,请参阅合作伙伴中心 REST 标头。
请求正文
下表介绍请求正文中的 Cart 属性。
| 属性 | 类型 | 必需 | 说明 |
|---|---|---|---|
| id | 字符串 | 否 | 成功创建购物车时提供的购物车标识符。 |
| creationTimeStamp | DateTime | 否 | 创建购物车的日期,采用日期时间格式。 成功创建购物车时应用。 |
| lastModifiedTimeStamp | DateTime | 否 | 上次更新购物车的日期,采用日期时间格式。 成功创建购物车时应用。 |
| expirationTimeStamp | DateTime | 否 | 购物车将过期的日期,采用日期时间格式。 成功创建购物车时应用。 |
| lastModifiedUser | 字符串 | 否 | 上次更新购物车的用户。 成功创建购物车时应用。 |
| lineItems | 对象数组 | 是 | CartLineItem 资源的数组。 |
| PartnerOnRecordAttestationAccepted | 布尔 | 是 | 确认证明完成 |
下表描述了请求正文中的 CartLineItem 属性。
| 属性 | 类型 | 必需 | 说明 |
|---|---|---|---|
| id | 字符串 | 否 | 购物车行项的唯一标识符。 成功创建购物车时应用。 |
| catalogId | 字符串 | 是 | 目录项标识符。 |
| friendlyName | 字符串 | 否 | 可选。 合作伙伴定义的项的友好名称,以帮助消除歧义。 |
| quantity | int | 是 | 许可证或实例数。 |
| currencyCode | string | 否 | 货币代码。 |
| billingCycle | Object | 是 | 为当前周期设置的计费周期类型。 |
| customTermEndDate | DateTime | 否 | 要确定新订阅的现有订阅的结束日期。 |
| participants | 对象字符串对列表 | 否 | 记录 (MPNID) 购买的 PartnerId 集合。 |
| provisioningContext | <字典字符串,字符串> | 否 | 为目录中的某些项目预配所需的信息。 SKU 中的 provisioningVariables 属性指示目录中特定项需要哪些属性。 |
| orderGroup | 字符串 | 否 | 一个组,用于指示哪些项可以放在一起。 |
| error | Object | 否 | 如果出现错误,则创建购物车后应用。 |
| renewsTo | 对象数组 | 否 | RenewsTo 资源的数组。 |
| 证明Accepted | 布尔 | 否 | 指示产品/服务或 SKU 条件的协议。 仅适用于 SkuAttestationProperties 或 OfferAttestationProperties 强制实施Attestation 的产品/服务或 SKU。 |
| transaction_reseller | 字符串 | 否 | 当间接提供商代表间接经销商下订单时,使用间接经销商的 MPN ID 填充此字段, (从 不) 间接提供商的 ID。 这可以确保正确地针对奖励进行记账。 |
| additional_transaction_reseller | 字符串 | 否 | 当间接提供商代表间接经销商下订单时,使用 其他间接经销商 的 MPN ID 填充此字段, (绝不是间接提供商) 的 ID。 奖励不适用于这些额外的经销商。 最多只能输入 5 个间接经销商。 这只是在欧盟/EFTA 国家/地区交易的适用合作伙伴。 |
下表描述了请求正文中的 RenewsTo 属性。
| 属性 | 类型 | 必需 | 说明 |
|---|---|---|---|
| termDuration | 字符串 | 否 | 续订期限持续时间的 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"
}
}
]
}
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"
}
]
}
REST 响应
如果成功,此方法在响应正文中返回填充的 Cart 资源。
响应的成功和错误代码
每个响应都带有一个 HTTP 状态代码,用于指示成功或失败以及其他调试信息。 请使用网络跟踪工具来读取此代码、错误类型和其他参数。 有关完整列表,请参阅错误代码。
响应示例
{
"id": "6b6ba6ea-d1ea-4c2c-9e1c-bec4f61e2049",
"creationTimestamp": "2021-02-24T19:26:06.947164Z",
"lastModifiedTimestamp": "2021-02-24T19:26:06.9471649Z",
"expirationTimestamp": "2021-03-03T19:26:09.0035129Z",
"lastModifiedUser": "004ec05e-8999-4d02-9315-2b1b667c0deb",
"status": "Active",
"lineItems": [
{
"id": 0,
"catalogItemId": "CFQ7TTC0LFLZ:0002:CFQ7TTC0K4TS",
"quantity": 1,
"currencyCode": "USD",
"billingCycle": "monthly",
"termDuration": "P1M",
"provisioningContext": {},
"orderGroup": "0"
}
],
"links": {
"self": {
"uri": "/customers/932c4101-dc08-461b-b4c1-75d80e905775/carts/6b6ba6ea-d1ea-4c2c-9e1c-bec4f61e2049",
"method": "GET",
"headers": []
}
},
"attributes": {
"objectType": "Cart"
}
}