Skip to content
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

chore: move express-request and transaction reversal to builder pattern #88

Merged
merged 35 commits into from
Jan 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
7c53407
chore: move express-request to builder pattern
itsyaasir Nov 15, 2023
c85bea8
chore: migrate api, reorganise imports and remove redundant tests
itsyaasir Nov 18, 2023
1241c25
chore: remove unecessary deps
itsyaasir Nov 18, 2023
2e840db
chore: fix imports order
itsyaasir Nov 18, 2023
9bad181
chore: remove vscode files
itsyaasir Nov 18, 2023
f0fa2d7
Add more tests
itsyaasir Nov 18, 2023
9531c4f
Add validator module and implement phone number validation
itsyaasir Nov 18, 2023
30e1988
chore: rename method
itsyaasir Nov 19, 2023
12672cf
Fix phone number validation and remove unnecessary
itsyaasir Nov 22, 2023
fefa13c
Add more variants for phone validator
itsyaasir Nov 22, 2023
667a8c6
Merge branch 'master' into chore/move-express-request-tx-reversal
itsyaasir Nov 22, 2023
59c4e0c
Fix URL path in express_request.rs and
itsyaasir Nov 22, 2023
6029743
Fix import order in lib.rs
itsyaasir Nov 22, 2023
ffd7689
Update amount field from f64 to u32 in
itsyaasir Nov 23, 2023
357bf5a
Merge branch 'master' into chore/move-express-request-tx-reversal
itsyaasir Nov 30, 2023
a011ed6
Update dependencies and add receiver identifier
itsyaasir Nov 30, 2023
733e06d
Merge branch 'master' into chore/move-express-request-tx-reversal
itsyaasir Jan 6, 2024
90ab130
Fix merge conflicts
itsyaasir Jan 6, 2024
ae5fa3e
Fix doc tests
itsyaasir Jan 6, 2024
87e9eb8
Fix dotenvy crate
itsyaasir Jan 6, 2024
376e55b
Fix: dotenv failure to read .env messages
itsyaasir Jan 28, 2024
80038b3
fix: uninitialized pass key
itsyaasir Jan 28, 2024
30a1d1d
fix: timestamp
itsyaasir Jan 28, 2024
bc5b783
chore: clean up codes
itsyaasir Jan 28, 2024
6007cad
fix: compilation
itsyaasir Jan 28, 2024
bbef3b6
chore: update intiaitor password
itsyaasir Jan 28, 2024
94d9a46
chore: revert removal of identifier receiver
itsyaasir Jan 28, 2024
113c5aa
chore: revert removal of identifier receiver
itsyaasir Jan 28, 2024
ab23d7b
chore: revert removal of identifier receiver
itsyaasir Jan 28, 2024
3466e9e
fix: express request tests
itsyaasir Jan 28, 2024
6d81444
fix: express request tests
itsyaasir Jan 28, 2024
33641a8
fix: express request tests
itsyaasir Jan 28, 2024
1687128
fix: express request tests
itsyaasir Jan 28, 2024
32c11cd
chore: refactor codes
itsyaasir Jan 28, 2024
25dc220
further investigation
itsyaasir Jan 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
/.idea
Cargo.lock
.env
.DS_Store
.DS_Store

.vscode
5 changes: 0 additions & 5 deletions .vscode/settings.json

This file was deleted.

49 changes: 26 additions & 23 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,6 @@ repository = "https://github.com/collinsmuriuki/mpesa-rust"
readme = "./README.md"
license = "MIT"

[dependencies]
cached = { version = "0.46", features = ["wasm", "async", "proc_macro"] }
chrono = { version = "0.4", optional = true, default-features = false, features = [
"clock",
"serde",
] }
openssl = { version = "0.10", optional = true }
reqwest = { version = "0.11", features = ["json"] }
derive_builder = "0.12"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
serde_repr = "0.1"
thiserror = "1.0.37"
wiremock = "0.5"
secrecy = "0.8.0"
serde-aux = "4.2.0"

[dev-dependencies]
dotenv = "0.15"
tokio = { version = "1", features = ["rt", "rt-multi-thread", "macros"] }
wiremock = "0.5"

[features]
default = [
"account_balance",
Expand All @@ -42,7 +20,7 @@ default = [
"express_request",
"transaction_reversal",
"transaction_status",
"dynamic_qr"
"dynamic_qr",
]
dynamic_qr = []
account_balance = ["dep:openssl"]
Expand All @@ -54,3 +32,28 @@ c2b_simulate = []
express_request = ["dep:chrono"]
transaction_reversal = ["dep:openssl"]
transaction_status = ["dep:openssl"]


[dependencies]
cached = { version = "0.46", features = ["wasm", "async", "proc_macro"] }
chrono = { version = "0.4", optional = true, default-features = false, features = [
"clock",
"serde",
] }
openssl = { version = "0.10", optional = true }
reqwest = { version = "0.11", features = ["json"] }
derive_builder = "0.12"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
serde_repr = "0.1"
thiserror = "1.0"
secrecy = "0.8"
serde-aux = "4.2"
url = { version = "2", features = ["serde"] }
regex = { version = "1.10", default-features = false, features = ["std"] }


[dev-dependencies]
dotenvy = "0.15.7"
tokio = { version = "1", features = ["rt", "rt-multi-thread", "macros"] }
wiremock = "0.5"
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ use mpesa::{Mpesa, Environment};

#[tokio::main]
async fn main() {
dotenv::dotenv().ok();
dotenvy::dotenv().ok();

let client = Mpesa::new(
env!("CLIENT_KEY"),
env!("CLIENT_SECRET"),
dotenvy::var("CLIENT_KEY").unwrap(),
dotenvy::var("CLIENT_SECRET").unwrap(),
Environment::Sandbox,
);

Expand All @@ -73,11 +73,11 @@ use std::str::FromStr;

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
dotenv::dotenv().ok();
dotenvy::dotenv().ok();

let client = Mpesa::new(
env!("CLIENT_KEY"),
env!("CLIENT_SECRET"),
dotenvy::var("CLIENT_KEY").unwrap(),
dotenvy::var("CLIENT_SECRET").unwrap(),
Environment::from_str("sandbox")?, // or
// Environment::try_from("sandbox")?,
);
Expand Down Expand Up @@ -121,11 +121,11 @@ impl ApiEnvironment for CustomEnvironment {

#[tokio::main]
async fn main() {
dotenv::dotenv().ok();
dotenvy::dotenv().ok();

let client = Mpesa::new(
env!("CLIENT_KEY"),
env!("CLIENT_SECRET"),
dotenvy::var("CLIENT_KEY").unwrap(),
dotenvy::var("CLIENT_SECRET").unwrap(),
CustomEnvironment,
);
}
Expand All @@ -139,11 +139,11 @@ use mpesa::{Mpesa, Environment};

#[tokio::main]
async fn main() {
dotenv::dotenv().ok();
dotenvy::dotenv().ok();

let client = Mpesa::new(
env!("CLIENT_KEY"),
env!("CLIENT_SECRET"),
dotenvy::var("CLIENT_KEY").unwrap(),
dotenvy::var("CLIENT_SECRET").unwrap(),
Environment::Sandbox,
);

Expand Down Expand Up @@ -177,8 +177,8 @@ The table below shows all the MPESA APIs from Safaricom and those supported by t

**Collins Muriuki**

- Twitter: [@c12i\_](https://twitter.com/c12i_)
- Not affiliated with Safaricom.
- Twitter: [@c12i\_](https://twitter.com/c12i_)
- Not affiliated with Safaricom.

## Contributing

Expand Down
11 changes: 7 additions & 4 deletions docs/client/account_balance.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
# Account Balance

The Account Balance API is used to request the account balance of a short code. This can be used for both B2C, buy goods and pay bill accounts.

Requires an `initiator_name`.
Returns an `AccountBalanceBuilder` for enquiring the balance on an MPESA BuyGoods.

Safaricom API docs [reference](https://developer.safaricom.co.ke/APIs/AccountBalance)

# Example
## Example

```rust
use mpesa::{Mpesa, Environment};

#[tokio::main]
async fn main() {
dotenv::dotenv().ok();
dotenvy::dotenv().ok();

let client = Mpesa::new(
env!("CLIENT_KEY"),
env!("CLIENT_SECRET"),
dotenvy::var("CLIENT_KEY").unwrap(),
dotenvy::var("CLIENT_SECRET").unwrap(),
Environment::Sandbox,
);

Expand Down
11 changes: 7 additions & 4 deletions docs/client/b2b.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# B2B

This API enables you to pay bills directly from your business account to a pay bill number, or a paybill store. You can use this API to pay on behalf of a consumer/requester.

The transaction moves money from your MMF/Working account to the recipient’s utility account.
Expand All @@ -7,17 +9,18 @@ Requires an `initiator_name`, the credential/ username used to authenticate the

Safaricom API docs [reference](https://developer.safaricom.co.ke/APIs/BusinessPayBill)

# Example
## Example

```rust
use mpesa::{Mpesa, Environment};

#[tokio::main]
async fn main() {
dotenv::dotenv().ok();
dotenvy::dotenv().ok();

let client = Mpesa::new(
env!("CLIENT_KEY"),
env!("CLIENT_SECRET"),
dotenvy::var("CLIENT_KEY").unwrap(),
dotenvy::var("CLIENT_SECRET").unwrap(),
Environment::Sandbox,
);

Expand Down
11 changes: 7 additions & 4 deletions docs/client/b2c.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
# B2C

Requires an `initiator_name`, the credential/ username used to authenticate the transaction request
Returns a `B2cBuilder` for building a B2C transaction struct.

Safaricom the API docs [reference](https://developer.safaricom.co.ke/APIs/BusinessToCustomer).

# Example
## Example

```rust
use mpesa::{Mpesa, Environment};

#[tokio::main]
async fn main() {
dotenv::dotenv().ok();
dotenvy::dotenv().ok();

let client = Mpesa::new(
env!("CLIENT_KEY"),
env!("CLIENT_SECRET"),
dotenvy::var("CLIENT_KEY").unwrap(),
dotenvy::var("CLIENT_SECRET").unwrap(),
Environment::Sandbox,
);

Expand Down
11 changes: 7 additions & 4 deletions docs/client/bill_manager/bulk_invoice.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
# Bulk Invoice

Creates a `BulkInvoiceBuilder` which allows you to send invoices to your customers in bulk.

Safaricom API docs [reference](https://developer.safaricom.co.ke/APIs/BillManager)

# Example
## Example

```rust,ignore
use mpesa::{Mpesa, Environment, Invoice, InvoiceItem};
use chrono::prelude::Utc;

#[tokio::main]
async fn main() {
dotenv::dotenv().ok();
dotenvy::dotenv().ok();

let client = Mpesa::new(
env!("CLIENT_KEY"),
env!("CLIENT_SECRET"),
dotenvy::var("CLIENT_KEY").unwrap(),
dotenvy::var("CLIENT_SECRET").unwrap(),
Environment::Sandbox,
);

Expand Down
11 changes: 7 additions & 4 deletions docs/client/bill_manager/cancel_invoice.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
# Cancel Invoice

Creates a `CancelInvoiceBuilder` which allows you to recall a sent invoice.

Safaricom API docs [reference](https://developer.safaricom.co.ke/APIs/BillManager)

# Example
## Example

```rust,ignore
use mpesa::{Mpesa, Environment, SendRemindersTypes};
use chrono::prelude::Utc;

#[tokio::main]
async fn main() {
dotenv::dotenv().ok();
dotenvy::dotenv().ok();

let client = Mpesa::new(
env!("CLIENT_KEY"),
env!("CLIENT_SECRET"),
dotenvy::var("CLIENT_KEY").unwrap(),
dotenvy::var("CLIENT_SECRET").unwrap(),
Environment::Sandbox,
);

Expand Down
11 changes: 7 additions & 4 deletions docs/client/bill_manager/onboard.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
# Onboard

Creates a `OnboardBuilder` which allows you to opt in as a biller to the bill manager features.

Safaricom API docs [reference](https://developer.safaricom.co.ke/APIs/BillManager)

# Example
## Example

```rust,ignore
use mpesa::{Mpesa, Environment, SendRemindersTypes};

#[tokio::main]
async fn main() {
dotenv::dotenv().ok();
dotenvy::dotenv().ok();

let client = Mpesa::new(
env!("CLIENT_KEY"),
env!("CLIENT_SECRET"),
dotenvy::var("CLIENT_KEY").unwrap(),
dotenvy::var("CLIENT_SECRET").unwrap(),
Environment::Sandbox,
);

Expand Down
11 changes: 7 additions & 4 deletions docs/client/bill_manager/onboard_modify.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
# Onboard Modify

Creates a `OnboardModifyBuilder` which allows you to opt in as a biller to the bill manager features.

Safaricom API docs [reference](https://developer.safaricom.co.ke/APIs/BillManager)

# Example
## Example

```rust,ignore
use mpesa::{Mpesa, Environment, SendRemindersTypes};

#[tokio::main]
async fn main() {
dotenv::dotenv().ok();
dotenvy::dotenv().ok();

let client = Mpesa::new(
env!("CLIENT_KEY"),
env!("CLIENT_SECRET"),
dotenvy::var("CLIENT_KEY").unwrap(),
dotenvy::var("CLIENT_SECRET").unwrap(),
Environment::Sandbox,
);

Expand Down
11 changes: 7 additions & 4 deletions docs/client/bill_manager/reconciliation.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
# Reconciliation

Creates a `ReconciliationBuilder` which enables your customers to receive e-receipts for payments made to your paybill account.

Safaricom API docs [reference](https://developer.safaricom.co.ke/APIs/BillManager)

# Example
## Example

```rust,ignore
use mpesa::{Mpesa, Environment};
use chrono::prelude::Utc;

#[tokio::main]
async fn main() {
dotenv::dotenv().ok();
dotenvy::dotenv().ok();

let client = Mpesa::new(
env!("CLIENT_KEY"),
env!("CLIENT_SECRET"),
dotenvy::var("CLIENT_KEY").unwrap(),
dotenvy::var("CLIENT_SECRET").unwrap(),
Environment::Sandbox,
);

Expand Down
11 changes: 7 additions & 4 deletions docs/client/bill_manager/single_invoice.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
# Single Invoice

Creates a `SingleInvoiceBuilder` which allows you to create and send invoices to your customers.

Safaricom API docs [reference](https://developer.safaricom.co.ke/APIs/BillManager)

# Example
## Example

```rust,ignore
use mpesa::{Mpesa, Environment, InvoiceItem};
use chrono::prelude::Utc;

#[tokio::main]
async fn main() {
dotenv::dotenv().ok();
dotenvy::dotenv().ok();

let client = Mpesa::new(
env!("CLIENT_KEY"),
env!("CLIENT_SECRET"),
dotenvy::var("CLIENT_KEY").unwrap(),
dotenvy::var("CLIENT_SECRET").unwrap(),
Environment::Sandbox,
);

Expand Down
Loading
Loading