如何為間接轉銷商的客戶建立訂單。
先決條件
合作夥伴中心驗證中所提到的憑證。 此案例僅支援使用 App+User 認證進行驗證。
客戶標識碼 (
customer-tenant-id
)。 如果您不知道客戶的標識碼,您可以在 合作夥伴中心 中選取 [客戶 工作區],然後從客戶清單中選取客戶,最後選擇 [帳戶]。 在客戶的 [帳戶] 頁中,在 [客戶帳戶資訊] 區段中尋找 Microsoft ID。 Microsoft識別碼與客戶標識碼 (customer-tenant-id
) 相同。要購買之商品的優惠標識碼。
間接轉銷商的租用戶識別碼。
C#
若要為間接轉銷商的客戶建立訂單:
取得與已登入合作夥伴有關係的間接轉銷商集合。
取得集合中符合間接轉銷商標識符的項目的對應局部變數。 此步驟可協助您在建立訂單時存取轉銷商的 MpnId 屬性。
具現化 Order 物件,並將 ReferenceCustomerID 屬性設定為客戶標識碼,以便記錄客戶。
建立 OrderLineItem 物件清單,並將清單指派給訂單的 LineItems 屬性。 每個訂單明細都包含一個優惠的購買資訊。 請確保在每個明細專案的 PartnerIdOnRecord 屬性中填入間接轉銷商的 PartnerID。 您必須至少有一個訂單項目。
要取得訂單作業的介面,首先使用客戶標識符來呼叫 IAggregatePartner.Customers.ById 方法以識別客戶,然後從 Orders 屬性擷取介面。
呼叫 Create 或 CreateAsync 方法來建立訂單。
C# 範例
// IAggregatePartner partnerOperations;
// string customerId;
// string offerId;
// string indirectResellerId;
// Get the indirect resellers with a relationship to the signed-in partner.
var indirectResellers = partnerOperations.Relationships.Get(PartnerRelationshipType.IsIndirectCloudSolutionProviderOf);
// Find the matching reseller in the collection.
var selectedIndirectReseller = (indirectResellers != null && indirectResellers.Items.Any()) ?
indirectResellers.Items.FirstOrDefault(reseller => reseller.Id.Equals(indirectResellerId, StringComparison.OrdinalIgnoreCase)) :
null;
// Prepare the order and populate the PartnerIdOnRecord with the reseller's Partner Id.
var order = new Order()
{
ReferenceCustomerId = customerId,
LineItems = new List<OrderLineItem>()
{
new OrderLineItem()
{
OfferId = offerId,
FriendlyName = "New offer purchase.",
Quantity = 5,
PartnerIdOnRecord = selectedIndirectReseller != null ? selectedIndirectReseller.MpnId : null
}
}
};
// Place the order.
var createdOrder = partnerOperations.Customers.ById(customerId).Orders.Create(order);
範例:主控台測試應用程式專案:合作夥伴中心 SDK 範例 類別:PlaceOrderForCustomer.cs
REST 要求
要求語法
方法 | 要求 URI |
---|---|
POST | {baseURL}/v1/customers/{customer-id}/orders HTTP/1.1 |
URI 參數
使用下列路徑參數來識別客戶。
名字 | 類型 | 必填 | 描述 |
---|---|---|---|
客戶編號 | 字串 | 是的 | 識別客戶的 GUID 格式化字串。 |
要求標頭
如需詳細資訊,請參閱 合作夥伴中心 REST 標頭。
請求主體
次序
本表描述了請求正文中的 Order 屬性。
名字 | 類型 | 必填 | 描述 |
---|---|---|---|
識別碼 | 字串 | 不 | 成功建立訂單時所提供的訂單標識碼。 |
參考客戶編號 | 字串 | 是的 | 客戶標識碼。 |
billingCycle | 字串 | 不 | 合作夥伴針對此訂單的計費頻率。 默認值為 「每月」,並會在成功建立訂單時套用。 支援的值是 BillingCycleType中找到的成員名稱。 注意:年度計費功能尚未正式推出。 年度計費功能即將推出。 |
lineItems | 對象的陣列 | 是的 | 一個包含 OrderLineItem 資源的陣列。 |
創建日期 | 字串 | 不 | 訂單建立的日期,採用日期時間格式。 訂單成功建立後套用。 |
屬性 | 物件 | 不 | 包含 “ObjectType”: “Order” |
訂單項目
下表描述請求正文中的 OrderLineItem 屬性。
名字 | 類型 | 必填 | 描述 |
---|---|---|---|
lineItemNumber | 整數 (int) | 是的 | 集合中的每個項目都會取得唯一的行號,從 0 計算到 count-1。 |
offerId | 字串 | 是的 | 優惠識別碼。 |
訂閱ID | 字串 | 不 | 訂用帳戶標識碼。 |
親訂閱識別碼 | 字串 | 不 | 自選。 附加方案中父訂閱的識別碼。 僅適用於 PATCH。 |
友好名稱 | 字串 | 不 | 自選。 合作夥伴所定義的訂用帳戶易記名稱,用於辨識。 |
數量 | int | 是的 | 授權型訂閱的授權數目。 |
紀錄中的夥伴ID | 字串 | 不 | 當間接提供者代表間接轉銷商下訂單時,請將 間接轉銷商的 PartnerID 填入此欄位(而不是間接提供者的ID)。 這可確保適當地考慮獎勵。 無法提供轉銷商 PartnerID 並不會造成訂單失敗。 不過,轉銷商不會記錄,因此獎勵計算可能不會包含銷售。 |
屬性 | 物件 | 不 | 包含 「ObjectType」:“OrderLineItem”。 |
要求範例
POST https://api.partnercenter.microsoft.com/v1/customers/c501c3c4-d776-40ef-9ecf-9cefb59442c1/orders HTTP/1.1
Authorization: Bearer <token>
Accept: application/json
MS-RequestId: 02109f46-3ff2-4be4-9f37-b2eb6d58d542
MS-CorrelationId: aaaa0000-bb11-2222-33cc-444444dddddd
X-Locale: en-US
Content-Type: application/json
Host: api.partnercenter.microsoft.com
Content-Length: 410
Expect: 100-continue
{
"Id": null,
"ReferenceCustomerId": "c501c3c4-d776-40ef-9ecf-9cefb59442c1",
"BillingCycle": "unknown",
"LineItems": [{
"LineItemNumber": 0,
"OfferId": "DB2E705F-B82A-4024-A3D5-D88E12F2DB35",
"SubscriptionId": null,
"ParentSubscriptionId": null,
"FriendlyName": "New offer purchase.",
"Quantity": 5,
"PartnerIdOnRecord": "4847383",
"Attributes": {
"ObjectType": "OrderLineItem"
}
}
],
"CreationDate": null,
"Attributes": {
"ObjectType": "Order"
}
}
REST 回應
如果成功,回應主體會包含填入 訂單 資源。
回應成功和錯誤碼
每個回應都有一個 HTTP 狀態代碼,指出成功或失敗和其他偵錯資訊。 使用網路追蹤工具來讀取此程式代碼、錯誤類型和其他參數。 如需完整清單,請參閱 合作夥伴中心錯誤碼。
回應範例
HTTP/1.1 201 Created
Content-Length: 831
Content-Type: application/json; charset=utf-8
MS-CorrelationId: aaaa0000-bb11-2222-33cc-444444dddddd
MS-RequestId: 02109f46-3ff2-4be4-9f37-b2eb6d58d542
MS-CV: Nd3Oum/L5EywtKQK.0
MS-ServerId: 020021921
Date: Mon, 10 Apr 2017 23:02:24 GMT
{
"id": "3eddcac6-63b2-4c40-b0b6-f47e18301492",
"referenceCustomerId": "c501c3c4-d776-40ef-9ecf-9cefb59442c1",
"billingCycle": "monthly",
"lineItems": [{
"lineItemNumber": 0,
"offerId": "DB2E705F-B82A-4024-A3D5-D88E12F2DB35",
"subscriptionId": "aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e",
"friendlyName": "New offer purchase.",
"quantity": 5,
"partnerIdOnRecord": "4847383",
"links": {
"subscription": {
"uri": "/customers/c501c3c4-d776-40ef-9ecf-9cefb59442c1/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e",
"method": "GET",
"headers": []
}
}
}
],
"creationDate": "2017-04-10T16:02:25.983-07:00",
"links": {
"self": {
"uri": "/customers/c501c3c4-d776-40ef-9ecf-9cefb59442c1/orders/3eddcac6-63b2-4c40-b0b6-f47e18301492",
"method": "GET",
"headers": []
}
},
"attributes": {
"etag": "eyJpZCI6IjNlZGRjYWM2LTYzYjItNGM0MC1iMGI2LWY0N2UxODMwMTQ5MiIsInZlcnNpb24iOjF9",
"objectType": "Order"
}
}