向订阅购买加载项
适用于:合作伙伴中心 | 由世纪互联运营的合作伙伴中心 | Microsoft Cloud for US Government 合作伙伴中心
如何购买现有订阅的加载项。
必备条件
合作伙伴中心身份验证中所述的凭据。 此方案支持使用独立应用和应用+用户凭据进行身份验证。
客户 ID (
customer-tenant-id
)。 如果不知道客户的 ID,可以通过选择“客户”工作区、客户列表中的“客户”和“帐户”,在合作伙伴中心中查找该 ID。 在客户的“帐户”页上的“客户帐户信息” 部分查找 Microsoft ID。 Microsoft ID 与客户 ID (customer-tenant-id
) 相同。订阅 ID。 这是要为其购买附加产品/服务的现有订阅。
一个产品/服务 ID,用于标识要购买的附加产品/服务。
通过代码购买加载项
购买订阅的加载项时,你将使用加载项订单更新原始订阅订单。 在下面,customerId 是客户 ID,subscriptionId 是订阅 ID,addOnOfferId 是加载项的产品/服务 ID。
步骤如下:
获取订阅操作的接口。
var subscriptionOperations = partnerOperations.Customers.ById(customerId).Subscriptions.ById(subscriptionId);
使用该接口实例化订阅对象。 这会获取父订阅详细信息,包括订单 ID。
var parentSubscription = subscriptionOperations.Get();
实例化新的 Order 对象。 此订单实例用于更新用于购买订阅的原始订单。 将单行项添加到表示加载项的订单中。
var orderToUpdate = new Order() { ReferenceCustomerId = customerId, LineItems = new List<OrderLineItem>() { new OrderLineItem() { LineItemNumber = 0, OfferId = addOnOfferId, FriendlyName = "Some friendly name", Quantity = 2, ParentSubscriptionId = subscriptionId } } };
使用加载项的新订单更新订阅的原始订单。
Order updatedOrder = partnerOperations.Customers.ById(customerId).Orders.ById(parentSubscription.OrderId).Patch(orderToUpdate);
C#
若要购买加载项,请首先通过调用 IAggregatePartner.Customers.ById 方法(使用客户 ID 标识客户)和 Subscriptions.ById 方法来标识具有附加产品/服务的订阅,获取订阅操作的接口。 使用该 接口 通过调用 Get 检索订阅详细信息。 订阅详细信息包含订阅订单的订单 ID,即要通过加载项更新的订单。
接下来,实例化一个新的 Order 对象,并使用包含用于标识加载项的信息的 LineItem 实例填充它,如以下代码片段所示。 你将使用此新对象通过加载项更新订阅订单。 最后,调用 Patch 方法以更新订阅订单,首先使用 IAggregatePartner.Customers.ById 标识客户,并使用 Orders.ById 标识订单。
// IAggregatePartner partnerOperations;
// string customerId;
// string subscriptionId;
// string addOnOfferId;
// Get an interface to the operations for the subscription.
var subscriptionOperations = partnerOperations.Customers.ById(customerId).Subscriptions.ById(subscriptionId);
// Get the parent subscription details.
var parentSubscription = subscriptionOperations.Get();
// In order to buy an add-on subscription for this offer, we need to patch/update the order through which the base offer was purchased
// by creating an order object with a single line item which represents the add-on offer purchase.
var orderToUpdate = new Order()
{
ReferenceCustomerId = customerId,
LineItems = new List<OrderLineItem>()
{
new OrderLineItem()
{
LineItemNumber = 0,
OfferId = addOnOfferId,
FriendlyName = "Some friendly name",
Quantity = 2,
ParentSubscriptionId = subscriptionId
}
}
};
// Update the order to apply the add on purchase.
Order updatedOrder = partnerOperations.Customers.ById(customerId).Orders.ById(parentSubscription.OrderId).Patch(orderToUpdate);
示例: 控制台测试应用。 项目:合作伙伴中心 SDK 示例 类:AddSubscriptionAddOn.cs
REST 请求
请求语法
方法 | 请求 URI |
---|---|
PATCH | {baseURL}/v1/customers/{customer-tenant-id}/orders/{order-id} HTTP/1.1 |
URI 参数
使用以下参数标识客户和订单。
名称 | 类型 | 必须 | 说明 |
---|---|---|---|
customer-tenant-id | guid | Y | 该值是 GUID 格式 的 customer-tenant-id ,用于标识客户。 |
order-id | guid | Y | 订单标识符。 |
请求标头
有关详细信息,请参阅合作伙伴中心 REST 标头。
请求正文
下表描述了请求正文中的属性。
订单
名称 | 类型 | 必须 | 说明 |
---|---|---|---|
ID | 字符串 | N | 订单 ID。 |
ReferenceCustomerId | 字符串 | Y | 客户 ID。 |
LineItems | 对象数组 | Y | OrderLineItem 对象的数组。 |
CreationDate | string | N | 订单的创建日期,格式为日期-时间。 |
特性 | object | N | 包含“ObjectType”:“Order”。 |
OrderLineItem
名称 | 类型 | 必须 | 说明 |
---|---|---|---|
LineItemNumber | 数字 | Y | 行项编号,从 0 开始。 |
OfferId | 字符串 | Y | 加载项的产品/服务 ID。 |
SubscriptionId | 字符串 | N | 购买的加载项订阅的 ID。 |
ParentSubscriptionId | 字符串 | Y | 具有加载项套餐的父订阅的 ID。 |
FriendlyName | 字符串 | N | 此行项的友好名称。 |
数量 | 数字 | Y | 许可证的数量。 |
PartnerIdOnRecord | 字符串 | N | 记录的合作伙伴的 PartnerID。 |
特性 | object | N | 包含“ObjectType”:“OrderLineItem”。 |
请求示例
PATCH https://api.partnercenter.microsoft.com/v1/customers/4d3cf487-70f4-4e1e-9ff1-b2bfce8d9f04/orders/CF3B0E37-BE0B-4CDD-B584-D1A97D98A922 HTTP/1.1
Authorization: Bearer <token>
Accept: application/json
MS-RequestId: 17a2658e-d2cc-439b-a2f0-2aefd9344fbc
MS-CorrelationId: 60efdd24-17ef-4080-9b02-4fc315f916ff
X-Locale: en-US
Content-Type: application/json
Host: api.partnercenter.microsoft.com
Content-Length: 414
Expect: 100-continue
{
"Id": null,
"ReferenceCustomerId": "4d3cf487-70f4-4e1e-9ff1-b2bfce8d9f04",
"LineItems": [{
"LineItemNumber": 0,
"OfferId": "2828BE95-46BA-4F91-B2FD-0BEF192ECF60",
"SubscriptionId": null,
"ParentSubscriptionId": "1C2B75C1-74A5-472A-A729-7F8CEFC477F9",
"FriendlyName": "Some friendly name",
"Quantity": 2,
"PartnerIdOnRecord": null,
"Attributes": {
"ObjectType": "OrderLineItem"
}
}
],
"CreationDate": null,
"Attributes": {
"ObjectType": "Order"
}
}
REST 响应
如果成功,此方法在响应正文中返回更新的订阅顺序。
响应的成功和错误代码
每个响应都带有一个 HTTP 状态代码,用于指示成功或失败以及其他调试信息。 请使用网络跟踪工具来读取此代码、错误类型和其他参数。 有关完整列表,请参阅 合作伙伴中心错误代码。
响应示例
HTTP/1.1 200 OK
Content-Length: 1135
Content-Type: application/json; charset=utf-8
MS-CorrelationId: 60efdd24-17ef-4080-9b02-4fc315f916ff
MS-RequestId: 17a2658e-d2cc-439b-a2f0-2aefd9344fbc
MS-CV: WtFy3zI8V0u2lnT9.0
MS-ServerId: 020021921
Date: Wed, 25 Jan 2017 23:01:08 GMT
{
"id": "cf3b0e37-be0b-4cdd-b584-d1a97d98a922",
"referenceCustomerId": "4d3cf487-70f4-4e1e-9ff1-b2bfce8d9f04",
"billingCycle": "none",
"lineItems": [{
"lineItemNumber": 0,
"offerId": "195416C1-3447-423A-B37B-EE59A99A19C4",
"subscriptionId": "1C2B75C1-74A5-472A-A729-7F8CEFC477F9",
"friendlyName": "new offer purchase",
"quantity": 5,
"links": {
"subscription": {
"uri": "/customers/4d3cf487-70f4-4e1e-9ff1-b2bfce8d9f04/subscriptions/1C2B75C1-74A5-472A-A729-7F8CEFC477F9",
"method": "GET",
"headers": []
}
}
}, {
"lineItemNumber": 1,
"offerId": "2828BE95-46BA-4F91-B2FD-0BEF192ECF60",
"subscriptionId": "968BA1CF-C146-4ADF-A300-308DCF718EEE",
"friendlyName": "Some friendly name",
"quantity": 2,
"links": {
"subscription": {
"uri": "/customers/4d3cf487-70f4-4e1e-9ff1-b2bfce8d9f04/subscriptions/968BA1CF-C146-4ADF-A300-308DCF718EEE",
"method": "GET",
"headers": []
}
}
}
],
"creationDate": "2017-01-25T14:53:12.093-08:00",
"links": {
"self": {
"uri": "/customers/4d3cf487-70f4-4e1e-9ff1-b2bfce8d9f04/orders/cf3b0e37-be0b-4cdd-b584-d1a97d98a922",
"method": "GET",
"headers": []
}
},
"attributes": {
"etag": "eyJpZCI6ImNmM2IwZTM3LWJlMGItNGNkZC1iNTg0LWQxYTk3ZDk4YTkyMiIsInZlcnNpb24iOjJ9",
"objectType": "Order"
}
}
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈