Skip to content

Commit

Permalink
Add main function to bill manager docs code snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
c12i committed Nov 20, 2023
1 parent 9a700e1 commit 2119979
Show file tree
Hide file tree
Showing 6 changed files with 174 additions and 89 deletions.
87 changes: 50 additions & 37 deletions docs/client/bill_manager/bulk_invoice.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +4,58 @@ Safaricom API docs [reference](https://developer.safaricom.co.ke/APIs/BillManage

# Example
```rust,ignore
use chrone::prelude::Utc;
use mpesa::{Mpesa, Environment, Invoice, InvoiceItem};
use chrono::prelude::Utc;
let response = client
.bulk_invoice()
#[tokio::main]
async fn main() {
dotenv::dotenv().ok();
// Add multiple invoices at once
.invoices(vec![
Invoice {
amount: 1000.0,
account_reference: "John Doe",
billed_full_name: "John Doe",
billed_period: "August 2021",
billed_phone_number: "0712345678",
due_date: Utc::now(),
external_reference: "INV2345",
invoice_items: Some(
vec![InvoiceItem {amount: 1000.0, item_name: "An item"}]
),
invoice_name: "Invoice 001"
}
])
let client = Mpesa::new(
env!("CLIENT_KEY"),
env!("CLIENT_SECRET"),
Environment::Sandbox,
);
// Add a single invoice
.invoice(
Invoice {
amount: 1000.0,
account_reference: "John Doe",
billed_full_name: "John Doe",
billed_period: "August 2021",
billed_phone_number: "0712345678",
due_date: Utc::now(),
external_reference: "INV2345",
invoice_items: Some(vec![InvoiceItem {
let response = client
.bulk_invoice()
// Add multiple invoices at once
.invoices(vec![
Invoice {
amount: 1000.0,
item_name: "An item",
}]),
invoice_name: "Invoice 001",
}
)
.send()
.await;
account_reference: "John Doe",
billed_full_name: "John Doe",
billed_period: "August 2021",
billed_phone_number: "0712345678",
due_date: Utc::now(),
external_reference: "INV2345",
invoice_items: Some(
vec![InvoiceItem {amount: 1000.0, item_name: "An item"}]
),
invoice_name: "Invoice 001"
}
])
// Add a single invoice
.invoice(
Invoice {
amount: 1000.0,
account_reference: "John Doe",
billed_full_name: "John Doe",
billed_period: "August 2021",
billed_phone_number: "0712345678",
due_date: Utc::now(),
external_reference: "INV2345",
invoice_items: Some(vec![InvoiceItem {
amount: 1000.0,
item_name: "An item",
}]),
invoice_name: "Invoice 001",
}
)
.send()
.await;
assert!(response.is_ok());
}
```
24 changes: 19 additions & 5 deletions docs/client/bill_manager/cancel_invoice.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,25 @@ Safaricom API docs [reference](https://developer.safaricom.co.ke/APIs/BillManage

# Example
```rust,ignore
use mpesa::{Mpesa, Environment, SendRemindersTypes};
use chrono::prelude::Utc;
let response = client
.cancel_invoice()
.external_references(vec!["9KLSS011"])
.send()
.await;
#[tokio::main]
async fn main() {
dotenv::dotenv().ok();
let client = Mpesa::new(
env!("CLIENT_KEY"),
env!("CLIENT_SECRET"),
Environment::Sandbox,
);
let response = client
.cancel_invoice()
.external_references(vec!["9KLSS011"])
.send()
.await;
assert!(response.is_ok());
}
```
35 changes: 25 additions & 10 deletions docs/client/bill_manager/onboard.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,29 @@ Safaricom API docs [reference](https://developer.safaricom.co.ke/APIs/BillManage

# Example
```rust,ignore
let response = client
.onboard()
.callback_url("https://testdomain.com/true")
.email("[email protected]")
.logo("https://file.domain/file.png")
.official_contact("0712345678")
.send_reminders(SendRemindersTypes::Enable)
.short_code("600496")
.send()
.await;
use mpesa::{Mpesa, Environment, SendRemindersTypes};
#[tokio::main]
async fn main() {
dotenv::dotenv().ok();
let client = Mpesa::new(
env!("CLIENT_KEY"),
env!("CLIENT_SECRET"),
Environment::Sandbox,
);
let response = client
.onboard()
.callback_url("https://testdomain.com/true")
.email("[email protected]")
.logo("https://file.domain/file.png")
.official_contact("0712345678")
.send_reminders(SendRemindersTypes::Enable)
.short_code("718003")
.send()
.await;
assert!(response.is_ok());
}
```
35 changes: 25 additions & 10 deletions docs/client/bill_manager/onboard_modify.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,29 @@ Safaricom API docs [reference](https://developer.safaricom.co.ke/APIs/BillManage

# Example
```rust,ignore
let response = client
.onboard_modify()
.callback_url("https://testdomain.com/true")
.email("[email protected]")
.logo("https://file.domain/file.png")
.official_contact("0712345678")
.send_reminders(SendRemindersTypes::Enable)
.short_code("600496")
.send()
.await;
use mpesa::{Mpesa, Environment, SendRemindersTypes};
#[tokio::main]
async fn main() {
dotenv::dotenv().ok();
let client = Mpesa::new(
env!("CLIENT_KEY"),
env!("CLIENT_SECRET"),
Environment::Sandbox,
);
let response = client
.onboard_modify()
.callback_url("https://testdomain.com/true")
.email("[email protected]")
.logo("https://file.domain/file.png")
.official_contact("0712345678")
.send_reminders(SendRemindersTypes::Enable)
.short_code("600496")
.send()
.await;
assert!(response.is_ok());
}
```
38 changes: 26 additions & 12 deletions docs/client/bill_manager/reconciliation.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,32 @@ Safaricom API docs [reference](https://developer.safaricom.co.ke/APIs/BillManage

# Example
```rust,ignore
use mpesa::{Mpesa, Environment};
use chrono::prelude::Utc;
let response = client
.reconciliation()
.account_reference("John Doe")
.external_reference("INV2345")
.full_name("John Doe")
.invoice_name("Invoice 001")
.paid_amount(1000.0)
.payment_date(Utc::now())
.phone_number("0712345678")
.transaction_id("TRANSACTION_ID")
.send()
.await;
#[tokio::main]
async fn main() {
dotenv::dotenv().ok();
let client = Mpesa::new(
env!("CLIENT_KEY"),
env!("CLIENT_SECRET"),
Environment::Sandbox,
);
let response = client
.reconciliation()
.account_reference("John Doe")
.external_reference("INV2345")
.full_name("John Doe")
.invoice_name("Invoice 001")
.paid_amount(1000.0)
.payment_date(Utc::now())
.phone_number("0712345678")
.transaction_id("TRANSACTION_ID")
.send()
.await;
assert!(response.is_ok());
}
```
44 changes: 29 additions & 15 deletions docs/client/bill_manager/single_invoice.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,35 @@ Safaricom API docs [reference](https://developer.safaricom.co.ke/APIs/BillManage

# Example
```rust,ignore
use mpesa::{Mpesa, Environment, InvoiceItem};
use chrono::prelude::Utc;
let response = client
.single_invoice()
.amount(1000.0)
.account_reference("John Doe")
.billed_full_name("John Doe")
.billed_period("August 2021")
.billed_phone_number("0712345678")
.due_date(Utc::now())
.external_reference("INV2345")
.invoice_items(vec![
InvoiceItem {amount: 1000.0, item_name: "An item"}
])
.invoice_name("Invoice 001")
.send()
.await;
#[tokio::main]
async fn main() {
dotenv::dotenv().ok();
let client = Mpesa::new(
env!("CLIENT_KEY"),
env!("CLIENT_SECRET"),
Environment::Sandbox,
);
let response = client
.single_invoice()
.amount(1000.0)
.account_reference("John Doe")
.billed_full_name("John Doe")
.billed_period("August 2021")
.billed_phone_number("0712345678")
.due_date(Utc::now())
.external_reference("INV2345")
.invoice_items(vec![
InvoiceItem {amount: 1000.0, item_name: "An item"}
])
.invoice_name("Invoice 001")
.send()
.await;
assert!(response.is_ok());
}
```

0 comments on commit 2119979

Please sign in to comment.