Skip to content

Commit

Permalink
Merge pull request #4 from OAyomide/all-major-cleanup
Browse files Browse the repository at this point in the history
🧹 another major cleanup
  • Loading branch information
OAyomide authored May 23, 2021
2 parents 979ec9d + b7310be commit 90ff490
Show file tree
Hide file tree
Showing 15 changed files with 839 additions and 242 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@

#/target
Cargo.lock
impl.md
impl.md
42 changes: 39 additions & 3 deletions src/paystack.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,41 @@
pub mod customers;
pub mod dedicated_nuban;
pub mod invoices;
pub mod payment_pages;
pub mod plans;
pub mod products;
pub mod refund;
pub mod settlements;
pub mod subaccounts;
pub mod subscription;
pub mod transactions;
pub mod transactions_split;

use dedicated_nuban::DedicatedNuban;
use refund::Refund;
use invoices::Invoices;
use payment_pages::PaymentPages;
use plans::Plans;
use products::Products;
use refund::Refunds;
use settlements::Settlements;
use subaccounts::Subaccount;
use subscription::Subscription;
use transactions::Transaction;
use transactions_split::TransactionSplit;

#[derive(Default)]
pub struct Paystack {
pub transaction: Transaction,
pub transaction_split: TransactionSplit,
pub refund: Refund,
pub refund: Refunds,
pub subaccounts: Subaccount,
pub dedicated_nuban: DedicatedNuban,
pub plans: Plans,
pub subscription: Subscription,
pub products: Products,
pub payment_pages: PaymentPages,
pub invoices: Invoices,
pub settlements: Settlements,
}

impl Paystack {
Expand All @@ -31,7 +49,7 @@ impl Paystack {
transaction_split: TransactionSplit {
bearer_auth: formatted_bearer.to_string(),
},
refund: Refund {
refund: Refunds {
bearer_auth: formatted_bearer.to_string(),
},
subaccounts: Subaccount {
Expand All @@ -40,6 +58,24 @@ impl Paystack {
dedicated_nuban: DedicatedNuban {
bearer_auth: formatted_bearer.to_string(),
},
plans: Plans {
bearer_auth: formatted_bearer.to_string(),
},
subscription: Subscription {
bearer_auth: formatted_bearer.to_string(),
},
products: Products {
bearer_auth: formatted_bearer.to_string(),
},
payment_pages: PaymentPages {
bearer_auth: formatted_bearer.to_string(),
},
invoices: Invoices {
bearer_auth: formatted_bearer.to_string(),
},
settlements: Settlements {
bearer_auth: formatted_bearer.to_string(),
},
}
}
}
23 changes: 7 additions & 16 deletions src/paystack/customers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,29 +86,20 @@ const CUSTOMER_URL: &str = "https://api.paystack.co/customer";
impl Customer {
/// Create a customer on your integration
pub fn create_customer(&self, body: CreateCustomerBody) -> Result<Response, String> {
let res = make_request(
self.bearer_auth.clone(),
CUSTOMER_URL.to_owned(),
Some(body),
REQUEST::POST,
);
let res = make_request(&self.bearer_auth, CUSTOMER_URL, Some(body), REQUEST::POST);
return res;
}

/// List customers available on your integration.
pub fn list_customers(&self, queries: Option<ListCustomersParams>) -> Result<Response, String> {
let res = make_get_request(
self.bearer_auth.to_owned(),
CUSTOMER_URL.to_owned(),
queries,
);
let res = make_get_request(&self.bearer_auth, CUSTOMER_URL, queries);
return res;
}
/// Get details of a customer on your integration.
/// takes a parameter email_or_code. An email or customer code for the customer you want to fetch
pub fn fetch_customer(&self, email_or_code: &str) -> Result<Response, String> {
let url = format!("{}/{}", CUSTOMER_URL.to_owned(), email_or_code);
let res = make_get_request(self.bearer_auth.clone(), url, None::<String>);
let res = make_get_request(&self.bearer_auth, &url, None::<String>);
return res;
}

Expand All @@ -118,7 +109,7 @@ impl Customer {
body: UpdateCustomerBody,
) -> Result<Response, String> {
let url = format!("{}/{}", CUSTOMER_URL.to_owned(), code);
let res = make_request(self.bearer_auth.clone(), url, Some(body), REQUEST::PUT);
let res = make_request(&self.bearer_auth, &url, Some(body), REQUEST::PUT);
return res;
}

Expand All @@ -128,7 +119,7 @@ impl Customer {
body: ValidateCustomerBody,
) -> Result<Response, String> {
let url = format!("{}/{}/identification", CUSTOMER_URL.to_owned(), code);
let res = make_request(self.bearer_auth.clone(), url, Some(body), REQUEST::POST);
let res = make_request(&self.bearer_auth, &url, Some(body), REQUEST::POST);
return res;
}

Expand All @@ -138,7 +129,7 @@ impl Customer {
body: WhitelistOrBlacklistCustomerBody,
) -> Result<Response, String> {
let url = format!("{}/set_risk_action", CUSTOMER_URL.to_owned());
let res = make_request(self.bearer_auth.clone(), url, Some(body), REQUEST::POST);
let res = make_request(&self.bearer_auth, &url, Some(body), REQUEST::POST);
return res;
}

Expand All @@ -148,7 +139,7 @@ impl Customer {
body: DeactivateAuthorizationBody,
) -> Result<Response, String> {
let url = format!("{}/deactivate_authorization", CUSTOMER_URL.to_owned());
let res = make_request(self.bearer_auth.clone(), url, Some(body), REQUEST::POST);
let res = make_request(&self.bearer_auth, &url, Some(body), REQUEST::POST);
return res;
}
}
37 changes: 15 additions & 22 deletions src/paystack/dedicated_nuban.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ impl DedicatedNuban {
body: CreateDedicatedAccountBody,
) -> Result<Response, String> {
let res = make_request(
self.bearer_auth.clone(),
DEDICATED_NUBAN_URL.to_owned(),
&self.bearer_auth,
DEDICATED_NUBAN_URL,
Some(body),
REQUEST::POST,
);
Expand All @@ -72,30 +72,21 @@ impl DedicatedNuban {
&self,
params: Option<ListDedicatedAccountsParams>,
) -> Result<Response, String> {
let res = make_get_request(
self.bearer_auth.clone(),
DEDICATED_NUBAN_URL.to_owned(),
Some(params),
);
let res = make_get_request(&self.bearer_auth, DEDICATED_NUBAN_URL, Some(params));
return res;
}

/// Get details of a dedicated account on your integration.
pub fn fetch_dedicated_account(&self, id: &str) -> Result<Response, String> {
let url = format!("{}/{}", DEDICATED_NUBAN_URL.to_owned(), id);
let res = make_get_request(self.bearer_auth.clone(), url, None::<String>);
let url = format!("{}/{}", DEDICATED_NUBAN_URL, id);
let res = make_get_request(&self.bearer_auth, &url, None::<String>);
return res;
}

/// Deactivate a dedicated account on your integration.
pub fn deactivate_dedicated_account(&self, id: &str) -> Result<Response, String> {
let url = format!("{}/{}", DEDICATED_NUBAN_URL.to_owned(), id);
let res = make_request(
self.bearer_auth.clone(),
url,
None::<String>,
REQUEST::DELETE,
);
let url = format!("{}/{}", DEDICATED_NUBAN_URL, id);
let res = make_request(&self.bearer_auth, &url, None::<String>, REQUEST::DELETE);
return res;
}

Expand All @@ -105,30 +96,32 @@ impl DedicatedNuban {
body: SplitDedicatedAccountTxBody,
) -> Result<Response, String> {
let res = make_request(
self.bearer_auth.clone(),
DEDICATED_NUBAN_URL.to_owned(),
&self.bearer_auth,
&DEDICATED_NUBAN_URL,
Some(body),
REQUEST::POST,
);
return res;
}

/// If you've previously set up split payment for transactions on a dedicated account, you can remove it with this endpoint
pub fn remove_split_from_dedicated_acct(
&self,
body: RemoveSplitFromDedicatedAcctBody,
) -> Result<Response, String> {
let res = make_request(
self.bearer_auth.clone(),
DEDICATED_NUBAN_URL.to_owned(),
&self.bearer_auth,
DEDICATED_NUBAN_URL,
Some(body),
REQUEST::DELETE,
);
return res;
}

/// Get available bank providers for Dedicated NUBAN
pub fn fetch_bank_providers(&self) -> Result<Response, String> {
let url = format!("{}/available_providers", DEDICATED_NUBAN_URL.to_owned());
let res = make_get_request(self.bearer_auth.clone(), url, None::<String>);
let url = format!("{}/available_providers", DEDICATED_NUBAN_URL);
let res = make_get_request(&self.bearer_auth, &url, None::<String>);
return res;
}
}
Loading

0 comments on commit 90ff490

Please sign in to comment.