Skip to content

Commit 3cdefcc

Browse files
committed
chore: made base url a constant and moved it to the mod.rs file for top level access
1 parent f160d7f commit 3cdefcc

10 files changed

Lines changed: 72 additions & 44 deletions

src/endpoints/apple_pay.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
//! Apple Pay
22
//! THe Apple Pay API allows you register your application's top-level domain or subdomain.
33
4-
use std::{marker::PhantomData, sync::Arc};
5-
6-
use serde_json::json;
7-
4+
use super::BASE_URL;
85
use crate::{ApplePayResponseData, HttpClient, PaystackAPIError, PaystackResult};
6+
use serde_json::json;
7+
use std::{marker::PhantomData, sync::Arc};
98

109
#[derive(Debug, Clone)]
1110
pub struct ApplePayEndpoints<T: HttpClient + Default> {
@@ -28,7 +27,7 @@ impl<T: HttpClient + Default> ApplePayEndpoints<T> {
2827
/// # Returns
2928
/// A new ApplePayEndpoints instance
3029
pub fn new(key: Arc<String>, http: Arc<T>) -> ApplePayEndpoints<T> {
31-
let base_url = String::from("https://api.paystack.co/apple-pay/domain");
30+
let base_url = format!("{}/apple-pay/domain", BASE_URL);
3231
ApplePayEndpoints {
3332
key: key.to_string(),
3433
base_url,
@@ -47,7 +46,7 @@ impl<T: HttpClient + Default> ApplePayEndpoints<T> {
4746
&self,
4847
domain_name: String,
4948
) -> PaystackResult<PhantomData<String>> {
50-
let url = format!("{}", self.base_url);
49+
let url = &self.base_url;
5150
let body = json!({
5251
"domainName": domain_name
5352
});
@@ -69,7 +68,7 @@ impl<T: HttpClient + Default> ApplePayEndpoints<T> {
6968
/// # Returns
7069
/// A Result containing the list of registered domains or an error
7170
pub async fn list_domains(&self) -> PaystackResult<ApplePayResponseData> {
72-
let url = format!("{}", self.base_url);
71+
let url = &self.base_url;
7372

7473
let response = self
7574
.http
@@ -94,7 +93,7 @@ impl<T: HttpClient + Default> ApplePayEndpoints<T> {
9493
&self,
9594
domain_name: String,
9695
) -> PaystackResult<PhantomData<String>> {
97-
let url = format!("{}", self.base_url);
96+
let url = &self.base_url;
9897
let body = json!({
9998
"domainName": domain_name
10099
});

src/endpoints/customers.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22
//! =========
33
//! Thse Customers API allows you to create and maange customers on your integration
44
5-
use std::{marker::PhantomData, sync::Arc};
6-
7-
use serde_json::json;
8-
5+
use super::BASE_URL;
96
use crate::{
107
CreateCustomerRequest, CustomerResponseData, HttpClient, PaystackAPIError, PaystackResult,
118
Response, RiskAction, UpdateCustomerRequest, ValidateCustomerRequest,
129
};
10+
use serde_json::json;
11+
use std::{marker::PhantomData, sync::Arc};
1312

1413
/// A struct to hold all the functions of the customers API endpoint
1514
#[derive(Debug, Clone)]
@@ -32,7 +31,7 @@ impl<T: HttpClient + Default> CustomersEndpoints<T> {
3231
/// # Returns
3332
/// A new CustomersEndpoints instance
3433
pub fn new(key: Arc<String>, http: Arc<T>) -> CustomersEndpoints<T> {
35-
let base_url = String::from("https://api.paystack.co/customer");
34+
let base_url = format!("{}/customer", BASE_URL);
3635
CustomersEndpoints {
3736
key: key.to_string(),
3837
base_url,
@@ -52,7 +51,7 @@ impl<T: HttpClient + Default> CustomersEndpoints<T> {
5251
&self,
5352
create_customer_request: CreateCustomerRequest,
5453
) -> PaystackResult<CustomerResponseData> {
55-
let url = format!("{}", self.base_url);
54+
let url = &self.base_url;
5655
let body = serde_json::to_value(create_customer_request)
5756
.map_err(|e| PaystackAPIError::Customer(e.to_string()))?;
5857

@@ -81,7 +80,7 @@ impl<T: HttpClient + Default> CustomersEndpoints<T> {
8180
per_page: Option<u8>,
8281
page: Option<u8>,
8382
) -> PaystackResult<Vec<CustomerResponseData>> {
84-
let url = format!("{}", self.base_url);
83+
let url = &self.base_url;
8584

8685
let per_page = per_page.unwrap_or(50).to_string();
8786
let page = page.unwrap_or(1).to_string();

src/endpoints/dedicated_virtual_account.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22
//! =========================
33
//! The Dedicated Virtual Account API enables Nigerian and Ghanaian merchants to manage unique payment accounts of their customers.
44
5-
use std::{marker::PhantomData, sync::Arc};
6-
7-
use serde_json::json;
8-
5+
use super::BASE_URL;
96
use crate::{
107
BankProviderData, DedicatedVirtualAccountRequest, DedicatedVirtualAccountResponseData,
118
HttpClient, ListDedicatedAccountFilter, PaystackAPIError, PaystackResult, Response,
129
SplitDedicatedAccountTransactionRequest,
1310
};
11+
use serde_json::json;
12+
use std::{marker::PhantomData, sync::Arc};
1413

1514
#[derive(Debug, Clone)]
1615
pub struct DedicatedVirtualAccountEndpoints<T: HttpClient + Default> {
@@ -30,7 +29,7 @@ impl<T: HttpClient + Default> DedicatedVirtualAccountEndpoints<T> {
3029
/// # Returns
3130
/// A new DedicatedVirtualAccountEndpoints instance
3231
pub fn new(key: Arc<String>, http: Arc<T>) -> DedicatedVirtualAccountEndpoints<T> {
33-
let base_url = String::from("https://api.paystack.co/dedicated_account");
32+
let base_url = format!("{}/dedicated_account", BASE_URL);
3433
DedicatedVirtualAccountEndpoints {
3534
key: key.to_string(),
3635
base_url,
@@ -50,7 +49,7 @@ impl<T: HttpClient + Default> DedicatedVirtualAccountEndpoints<T> {
5049
&self,
5150
create_dedicated_virtual_account_request: DedicatedVirtualAccountRequest,
5251
) -> PaystackResult<DedicatedVirtualAccountResponseData> {
53-
let url = format!("{}", self.base_url);
52+
let url = &self.base_url;
5453
let body = serde_json::to_value(create_dedicated_virtual_account_request)
5554
.map_err(|e| PaystackAPIError::DedicatedVirtualAccount(e.to_string()))?;
5655

@@ -79,7 +78,7 @@ impl<T: HttpClient + Default> DedicatedVirtualAccountEndpoints<T> {
7978
&self,
8079
assign_dedicated_virtual_account_request: DedicatedVirtualAccountRequest,
8180
) -> PaystackResult<PhantomData<String>> {
82-
let url = format!("{}", self.base_url);
81+
let url = &self.base_url;
8382
let body = serde_json::to_value(assign_dedicated_virtual_account_request)
8483
.map_err(|e| PaystackAPIError::DedicatedVirtualAccount(e.to_string()))?;
8584

@@ -107,7 +106,7 @@ impl<T: HttpClient + Default> DedicatedVirtualAccountEndpoints<T> {
107106
&self,
108107
filter: Option<ListDedicatedAccountFilter>,
109108
) -> PaystackResult<Vec<DedicatedVirtualAccountResponseData>> {
110-
let url = format!("{}", self.base_url);
109+
let url = &self.base_url;
111110
let mut query = vec![];
112111
// Build the query vec with the value in the filter struct
113112
if let Some(filter) = filter {
@@ -248,7 +247,7 @@ impl<T: HttpClient + Default> DedicatedVirtualAccountEndpoints<T> {
248247
&self,
249248
split_dedocated_account_transaction_request: SplitDedicatedAccountTransactionRequest,
250249
) -> PaystackResult<DedicatedVirtualAccountResponseData> {
251-
let url = format!("{}", self.base_url);
250+
let url = &self.base_url;
252251
let body = serde_json::to_value(split_dedocated_account_transaction_request)
253252
.map_err(|e| PaystackAPIError::DedicatedVirtualAccount(e.to_string()))?;
254253

@@ -276,7 +275,7 @@ impl<T: HttpClient + Default> DedicatedVirtualAccountEndpoints<T> {
276275
&self,
277276
account_number: String,
278277
) -> PaystackResult<DedicatedVirtualAccountResponseData> {
279-
let url = format!("{}", self.base_url);
278+
let url = &self.base_url;
280279
let body = json!({
281280
"account_number": account_number
282281
});

src/endpoints/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,6 @@ pub use terminal::*;
1616
pub use transaction::*;
1717
pub use transaction_split::*;
1818
pub use virtual_terminal::*;
19+
20+
// Const for the base url, since it is used multiple times
21+
pub const BASE_URL: &str = "https://api.paystack.co";

src/endpoints/subaccount.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
//! The Subaccounts API allows you to create and manage subaccounts on your integration.
44
//! Subaccounts can be used to split payment between two accounts (your main account and a subaccount).
55
6+
use super::BASE_URL;
67
use crate::{
78
HttpClient, PaystackAPIError, PaystackResult, Response, SubaccountRequest,
89
SubaccountsResponseData,
@@ -30,7 +31,7 @@ impl<T: HttpClient + Default> SubaccountEndpoints<T> {
3031
/// # Returns
3132
/// A new SubaccountEndpoints instance
3233
pub fn new(key: Arc<String>, http: Arc<T>) -> SubaccountEndpoints<T> {
33-
let base_url = String::from("https://api.paystack.co/subaccount");
34+
let base_url = format!("{}/subaccount", BASE_URL);
3435
SubaccountEndpoints {
3536
key: key.to_string(),
3637
base_url,
@@ -50,7 +51,7 @@ impl<T: HttpClient + Default> SubaccountEndpoints<T> {
5051
&self,
5152
subaccount_request: SubaccountRequest,
5253
) -> PaystackResult<SubaccountsResponseData> {
53-
let url = self.base_url.to_string();
54+
let url = &self.base_url;
5455
let body = serde_json::to_value(subaccount_request)
5556
.map_err(|e| PaystackAPIError::Subaccount(e.to_string()))?;
5657

@@ -64,4 +65,21 @@ impl<T: HttpClient + Default> SubaccountEndpoints<T> {
6465
.map_err(|e| PaystackAPIError::Subaccount(e.to_string()))?;
6566
Ok(parsed_response)
6667
}
68+
69+
/// List subaccounts available on your integration.
70+
///
71+
/// # Arguments
72+
/// * `per_page` - Optional number of subaccounts to return per page. Defaults to 50 if None.
73+
/// * `page` - Specify exactly what page you want to retrieve. Defaults to 1 if None.
74+
///
75+
/// # Returns
76+
/// A Result containing a vector of subaccount data or an error.
77+
pub async fn list_subaccounts(
78+
&self,
79+
per_page: Option<u32>,
80+
page: Option<u32>,
81+
) -> PaystackResult<Vec<SubaccountsResponseData>> {
82+
let url = self.base_url.to_string();
83+
todo!()
84+
}
6785
}

src/endpoints/terminal.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
//! ========
33
//! The Terminal API allows you to build delightful in-person payment experiences.
44
5-
use std::{marker::PhantomData, sync::Arc};
6-
75
use crate::{
86
EventRequest, FetchEventStatusResponseData, FetchTerminalStatusResponseData, HttpClient,
97
PaystackAPIError, PaystackResult, Response, SendEventResponseData, TerminalData,
108
UpdateTerminalRequest,
119
};
10+
use std::{marker::PhantomData, sync::Arc};
11+
12+
use super::BASE_URL;
1213

1314
/// A struct to hold all the functions of the terminal API endpoint
1415
#[derive(Debug, Clone)]
@@ -31,7 +32,7 @@ impl<T: HttpClient + Default> TerminalEndpoints<T> {
3132
/// # Returns
3233
/// A new TerminalEndpoints instance
3334
pub fn new(key: Arc<String>, http: Arc<T>) -> TerminalEndpoints<T> {
34-
let base_url = String::from("https://api.paystack.co/terminal");
35+
let base_url = format!("{}/terminal", BASE_URL);
3536
TerminalEndpoints {
3637
key: key.to_string(),
3738
base_url,
@@ -130,7 +131,7 @@ impl<T: HttpClient + Default> TerminalEndpoints<T> {
130131
/// # Returns
131132
/// A Result containing a vector of terminal data or an error
132133
pub async fn list_terminals(&self, per_page: Option<i32>) -> PaystackResult<Vec<TerminalData>> {
133-
let url = format!("{}", self.base_url);
134+
let url = &self.base_url;
134135
let per_page = per_page.unwrap_or(50).to_string();
135136
let query = vec![("perPage", per_page.as_str())];
136137

src/endpoints/transaction.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
//! =============
33
//! The Transaction route allows to create and manage payments on your integration.
44
5+
use super::BASE_URL;
56
use crate::{
67
ChargeRequest, ChargeResponseData, Currency, ExportTransactionData, HttpClient,
78
PartialDebitTransactionRequest, PaystackAPIError, PaystackResult, Response, Status,
@@ -31,7 +32,7 @@ impl<T: HttpClient + Default> TransactionEndpoints<T> {
3132
/// # Returns
3233
/// A new TransactionEndpoints instance
3334
pub fn new(key: Arc<String>, http: Arc<T>) -> TransactionEndpoints<T> {
34-
let base_url = String::from("https://api.paystack.co/transaction");
35+
let base_url = format!("{}/transaction", BASE_URL);
3536
TransactionEndpoints {
3637
key: key.to_string(),
3738
base_url,
@@ -104,7 +105,7 @@ impl<T: HttpClient + Default> TransactionEndpoints<T> {
104105
per_page: Option<u32>,
105106
status: Option<Status>,
106107
) -> PaystackResult<Vec<TransactionStatusData>> {
107-
let url = self.base_url.to_string();
108+
let url = &self.base_url;
108109

109110
let per_page = per_page.unwrap_or(10).to_string();
110111
let status = status.unwrap_or(Status::Success).to_string();

src/endpoints/transaction_split.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
//! The Transaction Splits API enables merchants split the settlement for a
44
//! transaction across their payout account, and one or more subaccounts.
55
6+
use super::BASE_URL;
67
use crate::{
78
DeleteSubAccountBody, HttpClient, PaystackAPIError, PaystackResult, Response, SubaccountBody,
89
TransactionSplitRequest, TransactionSplitResponseData, UpdateTransactionSplitRequest,
@@ -30,7 +31,7 @@ impl<T: HttpClient + Default> TransactionSplitEndpoints<T> {
3031
/// # Returns
3132
/// A new TransactionSplitEndpoints instance
3233
pub fn new(key: Arc<String>, http: Arc<T>) -> TransactionSplitEndpoints<T> {
33-
let base_url = String::from("https://api.paystack.co/split");
34+
let base_url = format!("{}/split", BASE_URL);
3435
TransactionSplitEndpoints {
3536
key: key.to_string(),
3637
base_url,
@@ -50,7 +51,7 @@ impl<T: HttpClient + Default> TransactionSplitEndpoints<T> {
5051
&self,
5152
split_body: TransactionSplitRequest,
5253
) -> PaystackResult<TransactionSplitResponseData> {
53-
let url = self.base_url.to_string();
54+
let url = &self.base_url;
5455
let body = serde_json::to_value(split_body)
5556
.map_err(|e| PaystackAPIError::TransactionSplit(e.to_string()))?;
5657

@@ -79,7 +80,7 @@ impl<T: HttpClient + Default> TransactionSplitEndpoints<T> {
7980
split_name: Option<&str>,
8081
split_active: Option<bool>,
8182
) -> PaystackResult<Vec<TransactionSplitResponseData>> {
82-
let url = self.base_url.to_string();
83+
let url = &self.base_url;
8384

8485
// Specify a default option for active splits
8586
let split_active = match split_active {
@@ -195,7 +196,7 @@ impl<T: HttpClient + Default> TransactionSplitEndpoints<T> {
195196
/// Removes a subaccount from a transaction split
196197
///
197198
/// # Arguments
198-
/// * `split_id` - ID of the transaction split
199+
/// * `split_id` - ID of the transaction split.
199200
/// * `subaccount` - The subaccount data to remove.
200201
/// It should be created with a `DeleteSubAccountBody` struct.
201202
///

src/endpoints/virtual_terminal.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22
//! ================
33
//! The Virtual Terminal API allows you to accept in-person payments without a POS device.
44
5-
use std::{marker::PhantomData, sync::Arc};
6-
7-
use serde_json::json;
8-
5+
use super::BASE_URL;
96
use crate::{
107
DestinationRequest, DestinationResponse, HttpClient, PaystackAPIError, PaystackResult,
118
Response, TransactionSplitResponseData, VirtualTerminalRequestData,
129
VirtualTerminalResponseData, VirtualTerminalStatus,
1310
};
11+
use serde_json::json;
12+
use std::{marker::PhantomData, sync::Arc};
1413

1514
#[derive(Debug, Clone)]
1615
pub struct VirtualTerminalEndpoints<T: HttpClient + Default> {
@@ -32,7 +31,7 @@ impl<T: HttpClient + Default> VirtualTerminalEndpoints<T> {
3231
/// # Returns
3332
/// A new VirtualTerminalEndpoints instance
3433
pub fn new(key: Arc<String>, http: Arc<T>) -> VirtualTerminalEndpoints<T> {
35-
let base_url = String::from("https://api.paystack.co/virtual_terminal");
34+
let base_url = format!("{}/virtual_terminal", BASE_URL);
3635
VirtualTerminalEndpoints {
3736
key: key.to_string(),
3837
base_url,
@@ -52,7 +51,7 @@ impl<T: HttpClient + Default> VirtualTerminalEndpoints<T> {
5251
&self,
5352
virtual_terminal_request: VirtualTerminalRequestData,
5453
) -> PaystackResult<VirtualTerminalResponseData> {
55-
let url = format!("{}", self.base_url);
54+
let url = &self.base_url;
5655
let body = serde_json::to_value(virtual_terminal_request)
5756
.map_err(|e| PaystackAPIError::VirtualTerminal(e.to_string()))?;
5857

@@ -82,7 +81,7 @@ impl<T: HttpClient + Default> VirtualTerminalEndpoints<T> {
8281
status: VirtualTerminalStatus,
8382
per_page: i32,
8483
) -> PaystackResult<Vec<VirtualTerminalResponseData>> {
85-
let url = format!("{}", self.base_url);
84+
let url = &self.base_url;
8685
let status = status.to_string();
8786
let per_page = per_page.to_string();
8887

src/models/subaccount_models.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
use derive_builder::Builder;
66
use serde::{Deserialize, Serialize};
77

8+
use super::Currency;
9+
810
/// This struct is used to create the body for creating a subaccount on your integration.
911
/// Use the `SubaccountRequestBuilder` to create this object.
1012
#[derive(Serialize, Debug, Builder, Default)]
@@ -85,8 +87,14 @@ pub struct SubaccountsResponseData {
8587
pub is_verified: Option<bool>,
8688
/// The name of the settlement bank for the subaccount.
8789
pub settlement_bank: String,
90+
/// The id of the settlement bank for the subaccount.
91+
pub bank_id: Option<u32>,
8892
/// The account number of the subaccount.
8993
pub account_number: String,
94+
/// Currency of the subaccount
95+
pub currency: Option<Currency>,
96+
/// If the account is active or not, should be 1 for active and 0 for inactive
97+
pub active: Option<bool>,
9098
/// Settlement schedule of subaccount.
9199
pub settlement_schedule: Option<String>,
92100
/// The ID of the subaccount.

0 commit comments

Comments
 (0)