Skip to content

Commit a6d5c57

Browse files
committed
feat(virtual_terminal): added support for all the endpoints in the virtual terminal route
1 parent aeff88a commit a6d5c57

3 files changed

Lines changed: 127 additions & 2 deletions

File tree

src/endpoints/virtual_terminal.rs

Lines changed: 118 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ use std::{marker::PhantomData, sync::Arc};
77
use serde_json::json;
88

99
use crate::{
10-
HttpClient, PaystackAPIError, PaystackResult, Response, VirtualTerminalRequestData,
10+
DestinationRequest, DestinationResponse, HttpClient, PaystackAPIError, PaystackResult,
11+
Response, TransactionSplitResponseData, VirtualTerminalRequestData,
1112
VirtualTerminalResponseData, VirtualTerminalStatus,
1213
};
1314

@@ -165,4 +166,120 @@ impl<T: HttpClient + Default> VirtualTerminalEndpoints<T> {
165166
Err(e) => Err(PaystackAPIError::VirtualTerminal(e.to_string())),
166167
}
167168
}
169+
170+
/// Add a destination (WhatsApp number) to a Virtual Terminal on your integration
171+
///
172+
/// Takes in the following:
173+
/// - `code`: Code of the Virtual Terminal
174+
/// - `destinations`: A vector of `DestinationRequest` containing the notification recipients for payments to the Virtual Terminal.
175+
pub async fn assign_virtual_terminal_destination(
176+
&self,
177+
code: String,
178+
destinations: Vec<DestinationRequest>,
179+
) -> PaystackResult<Vec<DestinationResponse>> {
180+
let url = format!("{}/{}/destination/assign", self.base_url, code);
181+
let body = json!({
182+
"destinations": destinations
183+
});
184+
185+
let response = self.http.post(&url, &self.key, &body).await;
186+
187+
match response {
188+
Ok(response) => {
189+
let parsed_response: Response<Vec<DestinationResponse>> =
190+
serde_json::from_str(&response)
191+
.map_err(|e| PaystackAPIError::VirtualTerminal(e.to_string()))?;
192+
193+
Ok(parsed_response)
194+
}
195+
Err(e) => Err(PaystackAPIError::VirtualTerminal(e.to_string())),
196+
}
197+
}
198+
199+
/// Unassign a destination (WhatsApp Number) summary of transactions from a Virtual Terminal on your integration
200+
///
201+
/// Takes in the following:
202+
/// - `code`: Code of the Virtual Terminal.
203+
/// - `targets`: A vector of destination targets to unassign.
204+
pub async fn unassign_virtual_terminal_destination(
205+
&self,
206+
code: String,
207+
targets: Vec<String>,
208+
) -> PaystackResult<PhantomData<String>> {
209+
let url = format!("{}/{}/destination/unassign", self.base_url, code);
210+
let body = json!({
211+
"targets": targets
212+
});
213+
214+
let response = self.http.post(&url, &self.key, &body).await;
215+
216+
match response {
217+
Ok(response) => {
218+
let parsed_response: Response<PhantomData<String>> =
219+
serde_json::from_str(&response)
220+
.map_err(|e| PaystackAPIError::VirtualTerminal(e.to_string()))?;
221+
222+
Ok(parsed_response)
223+
}
224+
Err(e) => Err(PaystackAPIError::VirtualTerminal(e.to_string())),
225+
}
226+
}
227+
228+
/// Add a split code to a Virtual Terminal on your integration
229+
///
230+
/// Takes in the following:
231+
/// - `code`: Code of the Virtual Terminal
232+
/// - `split_code`: Split code to be added to the Virtual Terminal
233+
pub async fn add_split_code_to_virtual_terminal(
234+
&self,
235+
code: String,
236+
split_code: String,
237+
) -> PaystackResult<TransactionSplitResponseData> {
238+
let url = format!("{}/{}/split_code", self.base_url, code);
239+
let body = json!({
240+
"split_code": split_code
241+
});
242+
243+
let response = self.http.put(&url, &self.key, &body).await;
244+
245+
match response {
246+
Ok(response) => {
247+
let parsed_response: Response<TransactionSplitResponseData> =
248+
serde_json::from_str(&response)
249+
.map_err(|e| PaystackAPIError::VirtualTerminal(e.to_string()))?;
250+
251+
Ok(parsed_response)
252+
}
253+
Err(e) => Err(PaystackAPIError::VirtualTerminal(e.to_string())),
254+
}
255+
}
256+
257+
/// Remove a split code from a Virtual Terminal on your integration
258+
///
259+
/// Takes in the following:
260+
/// - `code`: Code of the Virtual Terminal
261+
/// - `split_code`: Split code to be removed from the Virtual Terminal
262+
pub async fn remove_split_code_from_virtual_terminal(
263+
&self,
264+
code: String,
265+
split_code: String,
266+
) -> PaystackResult<PhantomData<String>> {
267+
let url = format!("{}/{}/split_code", self.base_url, code);
268+
let body = json!({
269+
"split_code": split_code
270+
});
271+
272+
let response = self.http.delete(&url, &self.key, &body).await;
273+
274+
match response {
275+
Ok(response) => {
276+
let parsed_response: Response<PhantomData<String>> =
277+
serde_json::from_str(&response)
278+
.map_err(|e| PaystackAPIError::VirtualTerminal(e.to_string()))?;
279+
280+
Ok(parsed_response)
281+
}
282+
Err(e) => Err(PaystackAPIError::VirtualTerminal(e.to_string())),
283+
}
284+
}
168285
}

src/models/transaction_split.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,12 @@ pub struct TransactionSplitResponseData {
5050
/// The subaccount ID of the bearer associated with the percentage split.
5151
pub bearer_subaccount: u32,
5252
/// The creation timestamp of the percentage split.
53+
#[serde(rename = "createdAt")]
5354
pub created_at: Option<String>,
5455
/// The last update timestamp of the percentage split.
56+
#[serde(rename = "updatedAt")]
5557
pub updated_at: Option<String>,
58+
pub is_dynamic: Option<bool>,
5659
/// The list of subaccounts involved in the percentage split.
5760
pub subaccounts: Vec<SubaccountData>,
5861
/// The total count of subaccounts in the percentage split.

src/models/virtual_terminal.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,16 @@ pub struct VirtualTerminalResponseData {
6060

6161
#[derive(Debug, Deserialize, Clone, Serialize, Default)]
6262
pub struct DestinationResponse {
63+
pub integration: Option<u32>,
6364
pub target: Option<String>,
65+
pub name: Option<String>,
6466
#[serde(rename = "type")]
6567
pub destination_type: Option<String>,
66-
pub name: Option<String>,
68+
pub id: Option<u32>,
69+
#[serde(rename = "createdAt")]
6770
pub created_at: Option<String>,
71+
#[serde(rename = "updatedAt")]
72+
pub updated_at: Option<String>,
6873
}
6974

7075
#[derive(Debug, Serialize, Deserialize, Clone)]

0 commit comments

Comments
 (0)