Skip to content

Commit 849b048

Browse files
authored
Merge pull request #53 from morukele/feature/virtual-terminal
Feature/virtual terminal
2 parents 7df0fa1 + a6d5c57 commit 849b048

18 files changed

Lines changed: 620 additions & 59 deletions

src/client.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//! This file contains the Paystack API client, and it associated endpoints.
44
use crate::{
55
HttpClient, SubaccountEndpoints, TerminalEndpoints, TransactionEndpoints,
6-
TransactionSplitEndpoints,
6+
TransactionSplitEndpoints, VirtualTerminalEndpoints,
77
};
88
use std::sync::Arc;
99

@@ -18,6 +18,8 @@ pub struct PaystackClient<T: HttpClient + Default> {
1818
pub subaccount: SubaccountEndpoints<T>,
1919
/// Terminal API route
2020
pub terminal: TerminalEndpoints<T>,
21+
/// Virutal Terminal API route
22+
pub virutal_terminal: VirtualTerminalEndpoints<T>,
2123
}
2224

2325
impl<T: HttpClient + Default> PaystackClient<T> {
@@ -29,6 +31,7 @@ impl<T: HttpClient + Default> PaystackClient<T> {
2931
transaction_split: TransactionSplitEndpoints::new(Arc::clone(&key), Arc::clone(&http)),
3032
subaccount: SubaccountEndpoints::new(Arc::clone(&key), Arc::clone(&http)),
3133
terminal: TerminalEndpoints::new(Arc::clone(&key), Arc::clone(&http)),
34+
virutal_terminal: VirtualTerminalEndpoints::new(Arc::clone(&key), Arc::clone(&http)),
3235
}
3336
}
3437
}

src/endpoints/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ pub mod subaccount;
22
pub mod terminal;
33
pub mod transaction;
44
pub mod transaction_split;
5+
pub mod virtual_terminal;
56

67
// public re-export
78
pub use subaccount::*;
89
pub use terminal::*;
910
pub use transaction::*;
1011
pub use transaction_split::*;
12+
pub use virtual_terminal::*;

src/endpoints/terminal.rs

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//! ========
33
//! The Terminal API allows you to build delightful in-person payment experiences.
44
5-
use std::sync::Arc;
5+
use std::{marker::PhantomData, sync::Arc};
66

77
use crate::{
88
EventRequest, FetchEventStatusResponseData, FetchTerminalStatusResponseData, HttpClient,
@@ -164,17 +164,18 @@ impl<T: HttpClient + Default> TerminalEndpoints<T> {
164164
&self,
165165
terminal_id: String,
166166
update_request: UpdateTerminalRequest,
167-
) -> PaystackResult<String> {
167+
) -> PaystackResult<PhantomData<String>> {
168168
let url = format!("{}/{}", self.base_url, terminal_id);
169169
let body = serde_json::to_value(update_request)
170170
.map_err(|e| PaystackAPIError::Terminal(e.to_string()))?;
171171

172-
let response = self.http.post(&url, &self.key, &body).await;
172+
let response = self.http.put(&url, &self.key, &body).await;
173173

174174
match response {
175175
Ok(response) => {
176-
let parsed_response: Response<String> = serde_json::from_str(&response)
177-
.map_err(|e| PaystackAPIError::Terminal(e.to_string()))?;
176+
let parsed_response: Response<PhantomData<String>> =
177+
serde_json::from_str(&response)
178+
.map_err(|e| PaystackAPIError::Terminal(e.to_string()))?;
178179

179180
Ok(parsed_response)
180181
}
@@ -188,7 +189,10 @@ impl<T: HttpClient + Default> TerminalEndpoints<T> {
188189
/// - `serial_number`: The device serial number
189190
/// NB: The generic for the result here is a `String`, because there is no data field in the response from the API.
190191
/// The string will be ignored because the underlying `data` field in the `response` is an `Option`.
191-
pub async fn commission_terminal(&self, serial_number: String) -> PaystackResult<String> {
192+
pub async fn commission_terminal(
193+
&self,
194+
serial_number: String,
195+
) -> PaystackResult<PhantomData<String>> {
192196
let url = format!("{}/commission_device", self.base_url);
193197
let body = serde_json::json!({
194198
"serial_number": serial_number
@@ -198,8 +202,9 @@ impl<T: HttpClient + Default> TerminalEndpoints<T> {
198202

199203
match response {
200204
Ok(response) => {
201-
let parsed_response: Response<String> = serde_json::from_str(&response)
202-
.map_err(|e| PaystackAPIError::Terminal(e.to_string()))?;
205+
let parsed_response: Response<PhantomData<String>> =
206+
serde_json::from_str(&response)
207+
.map_err(|e| PaystackAPIError::Terminal(e.to_string()))?;
203208

204209
Ok(parsed_response)
205210
}
@@ -213,7 +218,10 @@ impl<T: HttpClient + Default> TerminalEndpoints<T> {
213218
/// - `serial_number`: The device serial number
214219
/// NB: The generic for the result here is a `String`, because there is no data field in the response from the API.
215220
/// The string will be ignored because the underlying `data` field in the `response` is an `Option`.
216-
pub async fn decommission_terminal(&self, serial_number: String) -> PaystackResult<String> {
221+
pub async fn decommission_terminal(
222+
&self,
223+
serial_number: String,
224+
) -> PaystackResult<PhantomData<String>> {
217225
let url = format!("{}/decommission_device", self.base_url);
218226
let body = serde_json::json!({
219227
"serial_number": serial_number
@@ -223,8 +231,9 @@ impl<T: HttpClient + Default> TerminalEndpoints<T> {
223231

224232
match response {
225233
Ok(response) => {
226-
let parsed_response: Response<String> = serde_json::from_str(&response)
227-
.map_err(|e| PaystackAPIError::Terminal(e.to_string()))?;
234+
let parsed_response: Response<PhantomData<String>> =
235+
serde_json::from_str(&response)
236+
.map_err(|e| PaystackAPIError::Terminal(e.to_string()))?;
228237

229238
Ok(parsed_response)
230239
}

0 commit comments

Comments
 (0)