Skip to content

Commit

Permalink
feat(tiktokshop): 新增外部订单相关接口
Browse files Browse the repository at this point in the history
  • Loading branch information
fudiwei committed Nov 11, 2024
1 parent ccdc348 commit 8290570
Show file tree
Hide file tree
Showing 15 changed files with 1,010 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/TikTokGlobalShop/Basic_ModelDefinition.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ Notes: The following catalog is consistent with the catalog structure of [TikTok
- Orders
- Get Order List: `OrderSearchOrders`
- Get Order Detail: `OrderBatchGetOrderDetail`
- Get Price Detail: `OrderGetOrderPriceDetail`
- Add External Order References: `OrderCreateExternalOrder`
- Get External Order References: `OrderGetExternalOrders`
- Search Order By External Order Reference: `OrderSearchExternalOrders`
- Fulfillment
- Get Order Split Attributes: `FulfillmentGetOrderSplitAttributes`
- Split Orders: `FulfillmentSplitOrder`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,98 @@ public static class TikTokShopClientExecuteOrderExtensions

return await client.SendFlurlRequesAsJsontAsync<Models.OrderBatchGetOrderDetailResponse>(flurlReq, data: request, cancellationToken: cancellationToken).ConfigureAwait(false);
}

/// <summary>
/// <para>异步调用 [GET] /order/{version}/orders/{order_id}/price_detail 接口。</para>
/// <para>
/// REF: <br/>
/// <![CDATA[ https://partner.tiktokshop.com/docv2/page/66ce16cadefa5102ffda9c6b ]]>
/// </para>
/// </summary>
/// <param name="client"></param>
/// <param name="request"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public static async Task<Models.OrderGetOrderPriceDetailResponse> ExecuteOrderGetOrderPriceDetailAsync(this TikTokShopClient client, Models.OrderGetOrderPriceDetailRequest request, CancellationToken cancellationToken = default)
{
if (client is null) throw new ArgumentNullException(nameof(client));
if (request is null) throw new ArgumentNullException(nameof(request));

IFlurlRequest flurlReq = client
.CreateFlurlRequest(request, HttpMethod.Get, "order", request.ApiVersion, "orders", request.OrderId, "price_detail");

return await client.SendFlurlRequesAsJsontAsync<Models.OrderGetOrderPriceDetailResponse>(flurlReq, data: request, cancellationToken: cancellationToken).ConfigureAwait(false);
}

#region ExternalOrder
/// <summary>
/// <para>异步调用 [POST] /order/{version}/orders/external_orders 接口。</para>
/// <para>
/// REF: <br/>
/// <![CDATA[ https://partner.tiktokshop.com/docv2/page/668cf073a6a5e002e69d4a28 ]]>
/// </para>
/// </summary>
/// <param name="client"></param>
/// <param name="request"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public static async Task<Models.OrderCreateExternalOrderResponse> ExecuteOrderCreateExternalOrderAsync(this TikTokShopClient client, Models.OrderCreateExternalOrderRequest request, CancellationToken cancellationToken = default)
{
if (client is null) throw new ArgumentNullException(nameof(client));
if (request is null) throw new ArgumentNullException(nameof(request));

IFlurlRequest flurlReq = client
.CreateFlurlRequest(request, HttpMethod.Post, "order", request.ApiVersion, "orders", "external_orders");

return await client.SendFlurlRequesAsJsontAsync<Models.OrderCreateExternalOrderResponse>(flurlReq, data: request, cancellationToken: cancellationToken).ConfigureAwait(false);
}

/// <summary>
/// <para>异步调用 [GET] /order/{version}/orders/{order_id}/external_orders 接口。</para>
/// <para>
/// REF: <br/>
/// <![CDATA[ https://partner.tiktokshop.com/docv2/page/668cf073115ebe02f8050b0a ]]>
/// </para>
/// </summary>
/// <param name="client"></param>
/// <param name="request"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public static async Task<Models.OrderGetExternalOrdersResponse> ExecuteOrderGetExternalOrdersAsync(this TikTokShopClient client, Models.OrderGetExternalOrdersRequest request, CancellationToken cancellationToken = default)
{
if (client is null) throw new ArgumentNullException(nameof(client));
if (request is null) throw new ArgumentNullException(nameof(request));

IFlurlRequest flurlReq = client
.CreateFlurlRequest(request, HttpMethod.Get, "order", request.ApiVersion, "orders", request.OrderId, "external_orders")
.SetQueryParam("platform", request.Platform);

return await client.SendFlurlRequesAsJsontAsync<Models.OrderGetExternalOrdersResponse>(flurlReq, data: request, cancellationToken: cancellationToken).ConfigureAwait(false);
}

/// <summary>
/// <para>异步调用 [POST] /order/{version}/orders/external_order_search 接口。</para>
/// <para>
/// REF: <br/>
/// <![CDATA[ https://partner.tiktokshop.com/docv2/page/668cf073737c3702ef051a27 ]]>
/// </para>
/// </summary>
/// <param name="client"></param>
/// <param name="request"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public static async Task<Models.OrderSearchExternalOrdersResponse> ExecuteOrderSearchExternalOrdersAsync(this TikTokShopClient client, Models.OrderSearchExternalOrdersRequest request, CancellationToken cancellationToken = default)
{
if (client is null) throw new ArgumentNullException(nameof(client));
if (request is null) throw new ArgumentNullException(nameof(request));

IFlurlRequest flurlReq = client
.CreateFlurlRequest(request, HttpMethod.Post, "order", request.ApiVersion, "orders", "external_order_search")
.SetQueryParam("external_order_id", request.ExternalOrderId)
.SetQueryParam("platform", request.Platform);

return await client.SendFlurlRequesAsJsontAsync<Models.OrderSearchExternalOrdersResponse>(flurlReq, data: request, cancellationToken: cancellationToken).ConfigureAwait(false);
}
#endregion
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
using System.Collections.Generic;

namespace SKIT.FlurlHttpClient.ByteDance.TikTokGlobalShop.Models
{
/// <summary>
/// <para>表示 [POST] /order/{version}/orders/external_orders 接口的请求。</para>
/// </summary>
public class OrderCreateExternalOrderRequest : TikTokShopRequest
{
public static class Types
{
public class Order
{
public static class Types
{
public class ExternalOrder
{
public static class Types
{
public class LineItem
{
/// <summary>
/// 获取或设置订单行 ID。
/// </summary>
[Newtonsoft.Json.JsonProperty("origin_id")]
[System.Text.Json.Serialization.JsonPropertyName("origin_id")]
public string LineItemId { get; set; } = string.Empty;

/// <summary>
/// 获取或设置外部订单行 ID。
/// </summary>
[Newtonsoft.Json.JsonProperty("id")]
[System.Text.Json.Serialization.JsonPropertyName("id")]
public string ExternalLineItemId { get; set; } = string.Empty;
}
}

/// <summary>
/// 获取或设置外部订单 ID。
/// </summary>
[Newtonsoft.Json.JsonProperty("id")]
[System.Text.Json.Serialization.JsonPropertyName("id")]
public string ExternalOrderId { get; set; } = string.Empty;

/// <summary>
/// 获取或设置来源平台。
/// </summary>
[Newtonsoft.Json.JsonProperty("platform")]
[System.Text.Json.Serialization.JsonPropertyName("platform")]
public string Platform { get; set; } = string.Empty;

/// <summary>
/// 获取或设置订单行列表。
/// </summary>
[Newtonsoft.Json.JsonProperty("line_items")]
[System.Text.Json.Serialization.JsonPropertyName("line_items")]
public IList<Types.LineItem> LineItemList { get; set; } = new List<Types.LineItem>();
}
}

/// <summary>
/// 获取或设置订单 ID。
/// </summary>
[Newtonsoft.Json.JsonProperty("id")]
[System.Text.Json.Serialization.JsonPropertyName("id")]
public string OrderId { get; set; } = string.Empty;

/// <summary>
/// 获取或设置外部订单信息。
/// </summary>
[Newtonsoft.Json.JsonProperty("external_order")]
[System.Text.Json.Serialization.JsonPropertyName("external_order")]
public Types.ExternalOrder ExternalOrder { get; set; } = new Types.ExternalOrder();
}
}

/// <summary>
/// 获取或设置 API 版本号。
/// <para>默认值:202406</para>
/// </summary>
[Newtonsoft.Json.JsonIgnore]
[System.Text.Json.Serialization.JsonIgnore]
public override int ApiVersion { get; set; } = 202406;

/// <summary>
/// 获取或设置订单列表。
/// </summary>
[Newtonsoft.Json.JsonProperty("orders")]
[System.Text.Json.Serialization.JsonPropertyName("orders")]
public IList<Types.Order> OrderList { get; set; } = new List<Types.Order>();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
namespace SKIT.FlurlHttpClient.ByteDance.TikTokGlobalShop.Models
{
/// <summary>
/// <para>表示 [POST] /order/{version}/orders/external_orders 接口的响应。</para>
/// </summary>
public class OrderCreateExternalOrderResponse : TikTokShopResponse<OrderCreateExternalOrderResponse.Types.Data>
{
public static class Types
{
public class Data
{
public static class Types
{
public class Error
{
public static class Types
{
public class Detail
{
public static class Types
{
public class ExternalOrder
{
/// <summary>
/// 获取或设置外部订单 ID。
/// </summary>
[Newtonsoft.Json.JsonProperty("id")]
[System.Text.Json.Serialization.JsonPropertyName("id")]
public string ExternalOrderId { get; set; } = default!;

/// <summary>
/// 获取或设置来源平台。
/// </summary>
[Newtonsoft.Json.JsonProperty("platform")]
[System.Text.Json.Serialization.JsonPropertyName("platform")]
public string Platform { get; set; } = default!;
}
}

/// <summary>
/// 获取或设置订单 ID。
/// </summary>
[Newtonsoft.Json.JsonProperty("order_id")]
[System.Text.Json.Serialization.JsonPropertyName("order_id")]
public string OrderId { get; set; } = default!;

/// <summary>
/// 获取或设置外部订单信息。
/// </summary>
[Newtonsoft.Json.JsonProperty("external_order")]
[System.Text.Json.Serialization.JsonPropertyName("external_order")]
public Types.ExternalOrder ExternalOrder { get; set; } = default!;
}
}

/// <summary>
/// 获取或设置错误码。
/// </summary>
[Newtonsoft.Json.JsonProperty("code")]
[System.Text.Json.Serialization.JsonPropertyName("code")]
public int Code { get; set; }

/// <summary>
/// 获取或设置错误信息。
/// </summary>
[Newtonsoft.Json.JsonProperty("message")]
[System.Text.Json.Serialization.JsonPropertyName("message")]
public string Message { get; set; } = default!;

/// <summary>
/// 获取或设置详细信息。
/// </summary>
[Newtonsoft.Json.JsonProperty("detail")]
[System.Text.Json.Serialization.JsonPropertyName("detail")]
public Types.Detail Detail { get; set; } = default!;
}
}

/// <summary>
/// 获取或设置错误列表。
/// </summary>
[Newtonsoft.Json.JsonProperty("errors")]
[System.Text.Json.Serialization.JsonPropertyName("errors")]
public Types.Error[]? ErrorList { get; set; } = default!;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
namespace SKIT.FlurlHttpClient.ByteDance.TikTokGlobalShop.Models
{
/// <summary>
/// <para>表示 [GET] /order/{version}/orders/{order_id}/external_orders 接口的请求。</para>
/// </summary>
public class OrderGetExternalOrdersRequest : TikTokShopRequest
{
/// <summary>
/// 获取或设置 API 版本号。
/// <para>默认值:202406</para>
/// </summary>
[Newtonsoft.Json.JsonIgnore]
[System.Text.Json.Serialization.JsonIgnore]
public override int ApiVersion { get; set; } = 202406;

/// <summary>
/// 获取或设置订单 ID。
/// </summary>
[Newtonsoft.Json.JsonIgnore]
[System.Text.Json.Serialization.JsonIgnore]
public string OrderId { get; set; } = string.Empty;

/// <summary>
/// 获取或设置来源平台。
/// </summary>
[Newtonsoft.Json.JsonIgnore]
[System.Text.Json.Serialization.JsonIgnore]
public string? Platform { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
namespace SKIT.FlurlHttpClient.ByteDance.TikTokGlobalShop.Models
{
/// <summary>
/// <para>表示 [GET] /order/{version}/orders/{order_id}/external_orders 接口的响应。</para>
/// </summary>
public class OrderGetExternalOrdersResponse : TikTokShopResponse<OrderGetExternalOrdersResponse.Types.Data>
{
public static class Types
{
public class Data
{
public static class Types
{
public class ExternalOrder
{
public static class Types
{
public class LineItem
{
/// <summary>
/// 获取或设置订单行 ID。
/// </summary>
[Newtonsoft.Json.JsonProperty("origin_id")]
[System.Text.Json.Serialization.JsonPropertyName("origin_id")]
public string LineItemId { get; set; } = default!;

/// <summary>
/// 获取或设置外部订单行 ID。
/// </summary>
[Newtonsoft.Json.JsonProperty("id")]
[System.Text.Json.Serialization.JsonPropertyName("id")]
public string ExternalLineItemId { get; set; } = default!;
}
}

/// <summary>
/// 获取或设置外部订单 ID。
/// </summary>
[Newtonsoft.Json.JsonProperty("id")]
[System.Text.Json.Serialization.JsonPropertyName("id")]
public string ExternalOrderId { get; set; } = default!;

/// <summary>
/// 获取或设置来源平台。
/// </summary>
[Newtonsoft.Json.JsonProperty("platform")]
[System.Text.Json.Serialization.JsonPropertyName("platform")]
public string Platform { get; set; } = default!;

/// <summary>
/// 获取或设置订单行列表。
/// </summary>
[Newtonsoft.Json.JsonProperty("line_items")]
[System.Text.Json.Serialization.JsonPropertyName("line_items")]
public Types.LineItem[] LineItemList { get; set; } = default!;
}
}

/// <summary>
/// 获取或设置外部订单列表。
/// </summary>
[Newtonsoft.Json.JsonProperty("external_orders")]
[System.Text.Json.Serialization.JsonPropertyName("external_orders")]
public Types.ExternalOrder[] ExternalOrderList { get; set; } = default!;
}
}
}
}
Loading

0 comments on commit 8290570

Please sign in to comment.