Skip to main content

shopify_client/admin/order/
mod.rs

1pub mod remote;
2
3use crate::common::ServiceContext;
4
5use std::sync::Arc;
6
7use crate::{
8    common::types::{APIError, RequestCallbacks},
9    types::order::{
10        GetOrderResp, OrderDiscountsAndTransactionsResp, OrderQueryResp, PatchOrderRequest,
11    },
12};
13
14pub struct Order {
15    pub(crate) ctx: ServiceContext,
16}
17
18impl Order {
19    pub fn new(
20        shop_url: Arc<String>,
21        version: Arc<String>,
22        access_token: Arc<String>,
23        callbacks: Arc<RequestCallbacks>,
24    ) -> Self {
25        Self::with_ctx(ServiceContext::new(
26            shop_url,
27            version,
28            access_token,
29            callbacks,
30        ))
31    }
32
33    /// Build the service from a shared `ServiceContext`. Cheaper than `new` at
34    /// construction sites that already hold a context (one `Arc` clone per service).
35    pub fn with_ctx(ctx: ServiceContext) -> Self {
36        Self { ctx }
37    }
38
39    pub async fn get_with_id(&self, order_id: &String) -> Result<GetOrderResp, APIError> {
40        remote::get_order_with_id(&self.ctx, order_id).await
41    }
42
43    pub async fn discounts_and_transactions(
44        &self,
45        order_gid: &str,
46        lines: u32,
47    ) -> Result<OrderDiscountsAndTransactionsResp, APIError> {
48        remote::get_order_discounts_and_transactions(&self.ctx, order_gid, lines).await
49    }
50
51    pub async fn get_with_name(&self, order_name: &String) -> Result<OrderQueryResp, APIError> {
52        remote::get_order_with_name(&self.ctx, order_name).await
53    }
54
55    pub async fn patch(
56        &self,
57        order_id: &String,
58        patch_request: &PatchOrderRequest,
59    ) -> Result<GetOrderResp, APIError> {
60        remote::patch_order(&self.ctx, order_id, patch_request).await
61    }
62}