Skip to content

Commit

Permalink
πŸŽ‰ miscellaneous module- the last module πŸŽ‰
Browse files Browse the repository at this point in the history
  • Loading branch information
OAyomide committed May 23, 2021
1 parent c67c0a7 commit ec25be1
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/paystack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pub mod customers;
pub mod dedicated_nuban;
pub mod disputes;
pub mod invoices;
pub mod miscellaneous;
pub mod payment_pages;
pub mod plans;
pub mod products;
Expand All @@ -25,6 +26,7 @@ use control_panel::ControlPanel;
use dedicated_nuban::DedicatedNuban;
use disputes::Disputes;
use invoices::Invoices;
use miscellaneous::Miscellaneous;
use payment_pages::PaymentPages;
use plans::Plans;
use products::Products;
Expand Down Expand Up @@ -60,6 +62,7 @@ pub struct Paystack {
pub charge: Charge,
pub disputes: Disputes,
pub verification: Verification,
pub miscellaneous: Miscellaneous,
}

impl Paystack {
Expand Down Expand Up @@ -124,6 +127,9 @@ impl Paystack {
verification: Verification {
bearer_auth: formatted_bearer.to_string(),
},
miscellaneous: Miscellaneous {
bearer_auth: formatted_bearer.to_string(),
},
}
}
}
2 changes: 1 addition & 1 deletion src/paystack/invoices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub struct CreateInvoiceBody<'a> {

#[derive(Debug, Serialize)]
pub struct ListInvoicesParams<'a> {
#[serde(rename = "per_page")]
#[serde(rename = "perPage")]
/// Specify how many records you want to retrieve per page. If not specify we use a default value of 50.
pub per_page: Option<i64>,
/// Specify exactly what invoice you want to page. If not specify we use a default value of 1.
Expand Down
79 changes: 79 additions & 0 deletions src/paystack/miscellaneous.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
use reqwest::blocking::Response;
use serde::Serialize;

use crate::{prelude::Currency, utils::make_get_request};

/// The Miscellaneous API are supporting APIs that can be used to provide more details to other APIs
#[derive(Debug, Default)]
pub struct Miscellaneous {
pub(crate) bearer_auth: String,
}

#[derive(Debug, Serialize)]
#[serde(rename_all = "lowercase")]
pub enum Gateway {
Emandate,
DigitalBankMandate,
}
const LIST_BANKS_URL: &str = "https://api.paystack.co/bank";
const LIST_COUNTRIES_URL: &str = "https://api.paystack.co/country";
const LIST_STATES_URL: &str = "https://api.paystack.co/address_verification/states";
#[derive(Debug, Serialize)]
pub struct ListBanksParams<'a> {
/// The country from which to obtain the list of supported banks. e.g `country=ghana` or `country=nigeria`
pub country: &'a str,
/// Flag to enable cursor pagination on the endpoint
pub use_cursor: bool,
#[serde(rename = "perPage")]
/// Specify how many records you want to retrieve per page. If not specify we use a default value of 50.
pub per_page: i64,
/// A cursor that indicates your place in the list. It can be used to fetch the next page of the list
pub next: Option<&'a str>,
/// A cursor that indicates your place in the list. It should be used to fetch the previous page of the list after an intial next request
pub previous: Option<&'a str>,
/// The gateway type of the bank. It can be one of these: [emandate, digitalbankmandate]
pub gateway: Option<Gateway>,
/// Type of financial channel. For Ghanaian channels, please use either **mobile_money** for mobile money channels OR **ghipps** for bank channels
#[serde(rename = "type")]
pub ttype: &'a str,
/// Any of `NGN`, `USD`, `GHS` or `ZAR`
pub currency: Option<Currency>,
}

#[derive(Debug, Serialize)]
pub struct ListProvidersParams {
/// A flag to filter for available providers
pub pay_with_bank_transfer: bool,
}

#[derive(Debug, Serialize)]
pub struct ListStatesParams {
/// The country code of the states to list. It is gotten after the charge request.
pub country: i64,
}
impl Miscellaneous {
/// Get a list of all supported banks and their properties
pub fn list_banks(&self, params: ListBanksParams) -> Result<Response, String> {
let res = make_get_request(&self.bearer_auth, LIST_BANKS_URL, Some(params));
return res;
}

// TODO: link with dedicated nuban
/// Get a list of all providers for [][Dedicated NUBAN]
pub fn list_providers(&self, params: ListProvidersParams) -> Result<Response, String> {
let res = make_get_request(&self.bearer_auth, LIST_BANKS_URL, Some(params));
return res;
}

/// Gets a list of Countries that Paystack currently supports
pub fn list_or_search_countries(&self) -> Result<Response, String> {
let res = make_get_request(&self.bearer_auth, LIST_COUNTRIES_URL, None::<String>);
return res;
}

/// Get a list of states for a country for address verification.
pub fn list_states(&self, params: ListStatesParams) -> Result<Response, String> {
let res = make_get_request(&self.bearer_auth, LIST_STATES_URL, Some(params));
return res;
}
}

0 comments on commit ec25be1

Please sign in to comment.