paystack_transaction/
verify.rs1use std::time;
2
3use async_trait::async_trait;
4use reqwest::Client;
5use serde::{Deserialize, Serialize};
6
7use crate::ResponseError;
8
9pub type VerificationResult<T> = Result<T, ResponseError>;
11
12#[derive(Debug, Serialize, Deserialize)]
13pub struct VerificationData {
14 pub status: bool,
15 pub message: String,
16 data: String,
17}
18
19#[async_trait]
21pub trait Verify {
22 async fn verify_transaction(&self, reference: String) -> VerificationResult<VerificationData>;
24}
25
26pub async fn verify_transaction(
28 key: String,
29 reference: String,
30) -> Result<VerificationData, ResponseError> {
31 let timeout = time::Duration::from_millis(10000);
32 let http_client = Client::builder().timeout(timeout).build().unwrap();
33
34 let url = format!("https://api.paystack.co/transaction/verify/{reference}");
35
36 let response = http_client
37 .get(url)
38 .header("Authorization", format!("Bearer {}", key))
39 .header("Accept", "application/json")
40 .header("Content-Type", "application/json")
41 .header("Cache-Control", "no-cache")
42 .send()
43 .await
44 .unwrap();
45
46 let json_data: VerificationData = response.json().await.unwrap();
47
48 Ok(json_data)
49}