-
Notifications
You must be signed in to change notification settings - Fork 15
fix: feature-gated imports #110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,29 @@ use std::cell::RefCell; | |
use std::time::Duration; | ||
|
||
use cached::Cached; | ||
#[cfg(any( | ||
feature = "account_balance", | ||
feature = "b2b", | ||
feature = "b2c", | ||
feature = "transaction_reversal", | ||
feature = "transaction_status" | ||
))] | ||
use openssl::base64; | ||
#[cfg(any( | ||
feature = "account_balance", | ||
feature = "b2b", | ||
feature = "b2c", | ||
feature = "transaction_reversal", | ||
feature = "transaction_status" | ||
))] | ||
use openssl::rsa::Padding; | ||
#[cfg(any( | ||
feature = "account_balance", | ||
feature = "b2b", | ||
feature = "b2c", | ||
feature = "transaction_reversal", | ||
feature = "transaction_status" | ||
))] | ||
use openssl::x509::X509; | ||
use reqwest::Client as HttpClient; | ||
use secrecy::{ExposeSecret, Secret}; | ||
|
@@ -12,13 +33,31 @@ use serde::Serialize; | |
|
||
use crate::auth::AUTH; | ||
use crate::environment::ApiEnvironment; | ||
#[cfg(feature = "account_balance")] | ||
use crate::services::AccountBalanceBuilder; | ||
#[cfg(feature = "b2b")] | ||
use crate::services::B2bBuilder; | ||
#[cfg(feature = "b2c")] | ||
use crate::services::B2cBuilder; | ||
#[cfg(feature = "c2b_register")] | ||
use crate::services::C2bRegisterBuilder; | ||
#[cfg(feature = "c2b_simulate")] | ||
use crate::services::C2bSimulateBuilder; | ||
#[cfg(feature = "transaction_status")] | ||
use crate::services::TransactionStatusBuilder; | ||
#[cfg(feature = "bill_manager")] | ||
use crate::services::{ | ||
AccountBalanceBuilder, B2bBuilder, B2cBuilder, BulkInvoiceBuilder, C2bRegisterBuilder, | ||
C2bSimulateBuilder, CancelInvoiceBuilder, DynamicQR, DynamicQRBuilder, MpesaExpress, | ||
MpesaExpressBuilder, MpesaExpressQuery, MpesaExpressQueryBuilder, OnboardBuilder, | ||
OnboardModifyBuilder, ReconciliationBuilder, SingleInvoiceBuilder, TransactionReversal, | ||
TransactionReversalBuilder, TransactionStatusBuilder, | ||
BulkInvoiceBuilder, CancelInvoiceBuilder, OnboardBuilder, OnboardModifyBuilder, | ||
ReconciliationBuilder, SingleInvoiceBuilder, | ||
}; | ||
#[cfg(feature = "dynamic_qr")] | ||
use crate::services::{DynamicQR, DynamicQRBuilder}; | ||
#[cfg(feature = "express")] | ||
use crate::services::{ | ||
MpesaExpress, MpesaExpressBuilder, MpesaExpressQuery, MpesaExpressQueryBuilder, | ||
}; | ||
#[cfg(feature = "transaction_reversal")] | ||
use crate::services::{TransactionReversal, TransactionReversalBuilder}; | ||
use crate::{auth, MpesaError, MpesaResult, ResponseError}; | ||
|
||
/// Source: [test credentials](https://developer.safaricom.co.ke/test_credentials) | ||
|
@@ -273,6 +312,13 @@ impl Mpesa { | |
/// | ||
/// # Errors | ||
/// Returns `EncryptionError` variant of `MpesaError` | ||
#[cfg(any( | ||
feature = "account_balance", | ||
feature = "b2b", | ||
feature = "b2c", | ||
feature = "transaction_reversal", | ||
feature = "transaction_status" | ||
))] | ||
Comment on lines
+315
to
+321
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same for this |
||
pub(crate) fn gen_security_credentials(&self) -> MpesaResult<String> { | ||
let pem = self.certificate.as_bytes(); | ||
let cert = X509::from_pem(pem)?; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,9 +5,53 @@ mod onboard_modify; | |
mod reconciliation; | ||
mod single_invoice; | ||
|
||
use std::fmt::{Display, Formatter, Result as FmtResult}; | ||
|
||
pub use bulk_invoice::{BulkInvoiceBuilder, BulkInvoiceResponse}; | ||
pub use cancel_invoice::{CancelInvoiceBuilder, CancelInvoiceResponse}; | ||
use chrono::{DateTime, Utc}; | ||
pub use onboard::{OnboardBuilder, OnboardResponse}; | ||
pub use onboard_modify::{OnboardModifyBuilder, OnboardModifyResponse}; | ||
pub use reconciliation::{ReconciliationBuilder, ReconciliationResponse}; | ||
use serde::Serialize; | ||
pub use single_invoice::{SingleInvoiceBuilder, SingleInvoiceResponse}; | ||
|
||
#[derive(Debug, Serialize)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct Invoice<'i> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ahh, I see you've moved this from the constants module to the bill manager module. This works as I don't think any other API (apart from bill manager) uses the invoice construct 👍 |
||
pub amount: f64, | ||
pub account_reference: &'i str, | ||
pub billed_full_name: &'i str, | ||
pub billed_period: &'i str, | ||
pub billed_phone_number: &'i str, | ||
pub due_date: DateTime<Utc>, | ||
pub external_reference: &'i str, | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub invoice_items: Option<Vec<InvoiceItem<'i>>>, | ||
pub invoice_name: &'i str, | ||
} | ||
|
||
impl<'i> Display for Invoice<'i> { | ||
fn fmt(&self, f: &mut Formatter) -> FmtResult { | ||
write!( | ||
f, | ||
"amount: {}, account_reference: {}, due_date: {}, invoice_name: {}", | ||
self.amount, | ||
self.account_reference, | ||
self.due_date.format("%Y-%m-%d"), | ||
self.invoice_name, | ||
) | ||
} | ||
} | ||
|
||
#[derive(Debug, Serialize)] | ||
pub struct InvoiceItem<'i> { | ||
pub amount: f64, | ||
pub item_name: &'i str, | ||
} | ||
|
||
impl<'i> Display for InvoiceItem<'i> { | ||
fn fmt(&self, f: &mut Formatter) -> FmtResult { | ||
write!(f, "amount: {}, item_name: {}", self.amount, self.item_name) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be possible cleaned up by deriving a
feature_locked!
(better name needed) declarative macro