1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
use crate::api::*;
use crate::{ApiError, ClientConfig, HttpClient, QueryBuilder, RequestOptions};
use reqwest::Method;
pub struct LineItemClient {
pub http_client: HttpClient,
}
impl LineItemClient {
pub fn new(config: ClientConfig) -> Result<Self, ApiError> {
Ok(Self {
http_client: HttpClient::new(config.clone())?,
})
}
/// Adds products and services to an entrypoint's catalog. These are used as line items for invoicing and transactions. In the response, "responseData" displays the item's code.
///
/// # Arguments
///
/// * `entry` - The paypoint's entrypoint identifier. [Learn more](/developers/api-reference/api-overview#entrypoint-vs-entry)
/// * `options` - Additional request options such as headers, timeout, etc.
///
/// # Returns
///
/// JSON response from the API
pub async fn add_item(
&self,
entry: &str,
request: &LineItem,
options: Option<RequestOptions>,
) -> Result<PayabliApiResponse6, ApiError> {
self.http_client
.execute_request(
Method::POST,
&format!("LineItem/{}", entry),
Some(serde_json::to_value(request).map_err(ApiError::Serialization)?),
None,
options,
)
.await
}
/// Deletes an item.
///
/// # Arguments
///
/// * `line_item_id` - ID for the line item (also known as a product, service, or item).
/// * `options` - Additional request options such as headers, timeout, etc.
///
/// # Returns
///
/// JSON response from the API
pub async fn delete_item(
&self,
line_item_id: i64,
options: Option<RequestOptions>,
) -> Result<DeleteItemResponse, ApiError> {
self.http_client
.execute_request(
Method::DELETE,
&format!("LineItem/{}", line_item_id),
None,
None,
options,
)
.await
}
/// Gets an item by ID.
///
/// # Arguments
///
/// * `line_item_id` - ID for the line item (also known as a product, service, or item).
/// * `options` - Additional request options such as headers, timeout, etc.
///
/// # Returns
///
/// JSON response from the API
pub async fn get_item(
&self,
line_item_id: i64,
options: Option<RequestOptions>,
) -> Result<LineItemQueryRecord, ApiError> {
self.http_client
.execute_request(
Method::GET,
&format!("LineItem/{}", line_item_id),
None,
None,
options,
)
.await
}
/// Retrieves a list of line items and their details from an entrypoint. Line items are also known as items, products, and services. Use filters to limit results.
///
/// # Arguments
///
/// * `entry` - The paypoint's entrypoint identifier. [Learn more](/developers/api-reference/api-overview#entrypoint-vs-entry)
/// * `from_record` - The number of records to skip before starting to collect the result set.
/// * `limit_record` - Max number of records to return for the query. Use `0` or negative value to return all records.
/// * `parameters` - Collection of field names, conditions, and values used to filter the query
/// <Info>
/// **You must remove `parameters=` from the request before you send it, otherwise Payabli will ignore the filters.**
///
/// Because of a technical limitation, you can't make a request that includes filters from the API console on this page. The response won't be filtered. Instead, copy the request, remove `parameters=` and run the request in a different client.
///
/// For example:
///
/// --url https://api-sandbox.payabli.com/api/Query/transactions/org/236?parameters=totalAmount(gt)=1000&limitRecord=20
///
/// should become:
///
/// --url https://api-sandbox.payabli.com/api/Query/transactions/org/236?totalAmount(gt)=1000&limitRecord=20
///
/// </Info>
/// See [Filters and Conditions Reference](/developers/developer-guides/pay-ops-reporting-engine-overview#filters-and-conditions-reference) for help.
///
/// List of field names accepted:
///
/// - `categories` (ct, nct)
/// - `code` (ne, eq, ct, nct)
/// - `commodityCode` (ne, eq, ct, nct)
/// - `createdDate` (gt, ge, lt, le, eq, ne)
/// - `description` (ne, eq, ct, nct)
/// - `externalPaypointID` (ct, nct, ne, eq)
/// - `mode` (eq, ne)
/// - `name` (ne, eq, ct, nct)
/// - `orgName` (ne, eq, ct, nct)
/// - `paypointDba` (ne, eq, ct, nct)
/// - `paypointId` (ne, eq)
/// - `paypointLegal` (ne, eq, ct, nct)
/// - `quantity` (gt, ge, lt, le, eq, ne)
/// - `uom` (ne, eq, ct, nct)
/// - `updatedDate` (gt, ge, lt, le, eq, ne)
/// - `value` (gt, ge, lt, le, eq, ne)
///
/// List of comparison accepted - enclosed between parentheses:
///
/// - eq or empty => equal
/// - gt => greater than
/// - ge => greater or equal
/// - lt => less than
/// - le => less or equal
/// - ne => not equal
/// - ct => contains
/// - nct => not contains
/// - in => inside array separated by "|"
/// - nin => not inside array separated by "|"
///
/// List of parameters accepted:
/// - limitRecord : max number of records for query (default="20", "0" or negative value for all)
/// - fromRecord : initial record in query
///
/// Example: name(ct)=john return all records with name containing john
/// * `sort_by` - The field name to use for sorting results. Use `desc(field_name)` to sort descending by `field_name`, and use `asc(field_name)` to sort ascending by `field_name`.
/// * `options` - Additional request options such as headers, timeout, etc.
///
/// # Returns
///
/// JSON response from the API
pub async fn list_line_items(
&self,
entry: &str,
request: &ListLineItemsQueryRequest,
options: Option<RequestOptions>,
) -> Result<QueryResponseItems, ApiError> {
self.http_client
.execute_request(
Method::GET,
&format!("Query/lineitems/{}", entry),
None,
QueryBuilder::new()
.int("fromRecord", request.from_record.clone())
.int("limitRecord", request.limit_record.clone())
.serialize("parameters", request.parameters.clone())
.string("sortBy", request.sort_by.clone())
.build(),
options,
)
.await
}
/// Updates an item.
///
/// # Arguments
///
/// * `line_item_id` - ID for the line item (also known as a product, service, or item).
/// * `options` - Additional request options such as headers, timeout, etc.
///
/// # Returns
///
/// JSON response from the API
pub async fn update_item(
&self,
line_item_id: i64,
request: &LineItem,
options: Option<RequestOptions>,
) -> Result<PayabliApiResponse6, ApiError> {
self.http_client
.execute_request(
Method::PUT,
&format!("LineItem/{}", line_item_id),
Some(serde_json::to_value(request).map_err(ApiError::Serialization)?),
None,
options,
)
.await
}
}