Skip to content

Commit

Permalink
feature(verification module)
Browse files Browse the repository at this point in the history
  • Loading branch information
OAyomide committed May 23, 2021
1 parent 0354bdd commit c67c0a7
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 5 deletions.
6 changes: 6 additions & 0 deletions src/paystack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub mod transactions_split;
pub mod transfer_recipients;
pub mod transfers;
pub mod transfers_control;
pub mod verification;

use bulk_charges::BulkCharges;
use charge::Charge;
Expand All @@ -36,6 +37,7 @@ use transactions_split::TransactionSplit;
use transfer_recipients::TransferRecipients;
use transfers::Transfers;
use transfers_control::TransfersControl;
use verification::Verification;

#[derive(Default)]
pub struct Paystack {
Expand All @@ -57,6 +59,7 @@ pub struct Paystack {
pub control_panel: ControlPanel,
pub charge: Charge,
pub disputes: Disputes,
pub verification: Verification,
}

impl Paystack {
Expand Down Expand Up @@ -118,6 +121,9 @@ impl Paystack {
disputes: Disputes {
bearer_auth: formatted_bearer.to_string(),
},
verification: Verification {
bearer_auth: formatted_bearer.to_string(),
},
}
}
}
4 changes: 2 additions & 2 deletions src/paystack/disputes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ pub struct ExportDisputesBody<'a> {
pub per_page: Option<i64>,
/// Specify exactly what page you want to retrieve. If not specify we use a default value of 1.
pub page: Option<i128>,
pub transaction: &'a str,
pub transaction: Option<&'a str>,
/// Dispute Status. Acceptable values: `{ awaiting-merchant-feedback | awaiting-bank-feedback | pending | resolved }`
pub status: DisputeStatus,
pub status: Option<DisputeStatus>,
}

const DISPUTE_URL: &str = "https://api.paystack.co/dispute";
Expand Down
5 changes: 2 additions & 3 deletions src/paystack/refund.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,9 @@ impl Refunds {
return res;
}
/// Get details of a refund on your integration.
/// takes a parameter reference. An transaction reference for the refund you want to fetch
/// takes a parameter reference. A transaction reference for the refund you want to fetch
pub fn fetch_refund(&self, reference: &str) -> Result<Response, String> {
let url = format!("{}/{}", REFUND_URL.to_owned(), reference);
println!("{}", url);
let url = format!("{}/{}", REFUND_URL, reference);
let res = make_get_request(&self.bearer_auth, &url, None::<String>);
return res;
}
Expand Down
68 changes: 68 additions & 0 deletions src/paystack/verification.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
use crate::utils::{make_get_request, make_request, REQUEST};
use reqwest::blocking::Response;
use serde::Serialize;

/// The Verification API allows you perform KYC processes.
///
/// *NB: due to regulations, Paystack has disabled this service.*
/// - 💡 Feature Availability
/// This feature is only available to businesses in Nigeria.
#[derive(Debug, Default)]
pub struct Verification {
pub(crate) bearer_auth: String,
}

#[derive(Debug, Serialize)]
pub struct VerifyBVNBody<'a> {
/// Bank Account Number
pub account_number: &'a str,
// TODO: link to list of bank here.
/// You can get the [][list of banks] codes by calling the List Bank endpoint
pub bank_code: i64,
/// 11 digits Bank Verification Number
pub bvn: &'a str,
/// Customer's First Name
pub first_name: Option<&'a str>,
/// Customer's Middle Name
pub middle_name: Option<&'a str>,
/// Customer's Last Name
pub last_name: Option<&'a str>,
}

#[derive(Debug, Serialize)]
pub struct ResolveAcctNoBody<'a> {
/// Bank Account Number
pub account_number: &'a str,
// TODO: link to list of bank here.
/// You can get the [][list of banks] codes by calling the List Bank endpoint
pub bank_code: i64,
}
const VERIFY_BVN_MATCH_URL: &str = "https://api.paystack.co/bvn/match";
const RESOLVE_ACCT_NO_URL: &str = "https://api.paystack.co/bank/resolve";
const RESOLVE_CARD_BIN: &str = "https://api.paystack.co/decision/bin";

impl Verification {
/// Check if an account number and BVN are linked
pub fn verify_bvn_match(&self, body: VerifyBVNBody) -> Result<Response, String> {
let res = make_request(
&self.bearer_auth,
VERIFY_BVN_MATCH_URL,
Some(body),
REQUEST::POST,
);
return res;
}

/// Confirm an account belongs to the right customer
pub fn resolve_account_number(&self, params: ResolveAcctNoBody) -> Result<Response, String> {
let res = make_get_request(&self.bearer_auth, RESOLVE_ACCT_NO_URL, Some(params));
return res;
}

/// Get more information about a customer's card
pub fn resolve_card_bin(&self, bin: &str) -> Result<Response, String> {
let url = format!("{}/{}", RESOLVE_CARD_BIN, bin);
let res = make_get_request(&self.bearer_auth, &url, None::<String>);
return res;
}
}

0 comments on commit c67c0a7

Please sign in to comment.