Skip to content

Commit

Permalink
Fix dynamic qr code doc tests
Browse files Browse the repository at this point in the history
  • Loading branch information
c12i committed Nov 20, 2023
1 parent 3ea77d5 commit 5444640
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 15 deletions.
12 changes: 5 additions & 7 deletions docs/client/dynamic_qr.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,17 @@ async fn main() {

let response = client
.dynamic_qr()
.amount(1000)
.ref_no("John Doe")
.amount(2000)
.credit_party_identifier("373132")
.merchant_name("TEST SUPERMARKET")
.ref_no("Invoice Test")
.size("300")
.merchant_name("John Doe")
.credit_party_identifier("600496")
.try_transaction_type("bg")
.unwrap()
.transaction_type(mpesa::TransactionType::BG)
.build()
.unwrap()
.send()
.await;

println!("{:?}", response);
assert!(response.is_ok())
}
```
2 changes: 1 addition & 1 deletion src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ pub enum TransactionType {

impl Display for TransactionType {
fn fmt(&self, f: &mut Formatter) -> FmtResult {
write!(f, "{self:?}")
write!(f, "{self}")
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/services/dynamic_qr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@ use crate::errors::{MpesaError, MpesaResult};
const DYNAMIC_QR_URL: &str = "/mpesa/qrcode/v1/generate";

#[derive(Debug, Serialize)]
#[serde(rename_all = "PascalCase")]
#[serde(rename_all(serialize = "PascalCase"))]
pub struct DynamicQRRequest<'mpesa> {
/// Name of the Company/M-Pesa Merchant Name
pub merchant_name: &'mpesa str,
/// Transaction Reference Number
pub ref_no: &'mpesa str,
/// The total amount of the transaction
pub amount: f64,
#[serde(rename = "TrxCode")]
pub amount: u32,
/// Transaction Type
///
/// This can be a `TransactionType` or a `&str`
Expand All @@ -27,6 +26,7 @@ pub struct DynamicQRRequest<'mpesa> {
/// - `WA` Withdraw Cash
/// - `SM` Send Money (Mobile Number)
/// - `SB` Sent to Business. Business number CPI in MSISDN format.
#[serde(rename = "TrxCode")]
pub transaction_type: TransactionType,
///Credit Party Identifier.
///
Expand All @@ -41,7 +41,7 @@ pub struct DynamicQRRequest<'mpesa> {
}

#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "PascalCase")]
#[serde(rename_all(deserialize = "PascalCase"))]
pub struct DynamicQRResponse {
#[serde(rename(deserialize = "QRCode"))]
pub qr_code: String,
Expand Down Expand Up @@ -91,7 +91,7 @@ impl<'mpesa, Env: ApiEnvironment> From<DynamicQR<'mpesa, Env>> for DynamicQRRequ
DynamicQRRequest {
merchant_name: express.merchant_name,
ref_no: express.ref_no,
amount: express.amount,
amount: express.amount as u32,
transaction_type: express.transaction_type,
credit_party_identifier: express.credit_party_identifier,
size: express.size,
Expand All @@ -115,7 +115,7 @@ impl<'mpesa, Env: ApiEnvironment> DynamicQR<'mpesa, Env> {
client,
merchant_name: request.merchant_name,
ref_no: request.ref_no,
amount: request.amount,
amount: request.amount as f64,
transaction_type: request.transaction_type,
credit_party_identifier: request.credit_party_identifier,
size: request.size,
Expand Down
2 changes: 1 addition & 1 deletion tests/mpesa-rust/dynamic_qr_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ async fn dynamic_qr_code_test_using_struct_initialization() {
});

let request = DynamicQRRequest {
amount: 2000.0,
amount: 2000,
credit_party_identifier: "17408",
merchant_name: "SafaricomLTD",
ref_no: "rf38f04",
Expand Down

0 comments on commit 5444640

Please sign in to comment.