@@ -7,7 +7,8 @@ use std::{marker::PhantomData, sync::Arc};
77use serde_json:: json;
88
99use 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}
0 commit comments