Skip to content

Commit

Permalink
Add editor config, fix indentation inconsistencies in docs
Browse files Browse the repository at this point in the history
  • Loading branch information
c12i committed Nov 20, 2023
1 parent b6e2c84 commit 4c5ae4d
Show file tree
Hide file tree
Showing 13 changed files with 189 additions and 174 deletions.
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
indent_style = space
indent_size = 4

[*.rs]
indent_style = space
indent_size = 4
38 changes: 19 additions & 19 deletions docs/client/account_balance.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,25 @@ use mpesa::{Mpesa, Environment};

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

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

let response = client
.account_balance("testapi496")
.result_url("https://testdomain.com/err")
.timeout_url("https://testdomain.com/ok")
.party_a("600496")
.command_id(mpesa::CommandId::AccountBalance) // optional, defaults to `CommandId::AccountBalance`
.identifier_type(mpesa::IdentifierTypes::ShortCode) // optional, defaults to `IdentifierTypes::ShortCode`
.remarks("Your Remarks") // optional, defaults to "None"
.send()
.await;
let response = client
.account_balance("testapi496")
.result_url("https://testdomain.com/err")
.timeout_url("https://testdomain.com/ok")
.party_a("600496")
.command_id(mpesa::CommandId::AccountBalance) // optional, defaults to `CommandId::AccountBalance`
.identifier_type(mpesa::IdentifierTypes::ShortCode) // optional, defaults to `IdentifierTypes::ShortCode`
.remarks("Your Remarks") // optional, defaults to "None"
.send()
.await;

assert!(response.is_ok())
}
```
assert!(response.is_ok())
}
```
2 changes: 1 addition & 1 deletion docs/client/auth.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ Safaricom API docs [reference](https://developer.safaricom.co.ke/APIs/Authorizat
Returns auth token as a `String` that is ttl-cached in memory for subsequent requests.

# Errors
Returns a `MpesaError` on failure
Returns a `MpesaError` on failure
50 changes: 25 additions & 25 deletions docs/client/b2b.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
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.
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 @@ -14,28 +14,28 @@ use mpesa::{Mpesa, Environment};

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

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

let response = client.b2b("testapi496")
.party_a("600496")
.party_b("600000")
.result_url("https://testdomain.com/err")
.timeout_url("https://testdomain.com/ok")
.account_ref("254708374149")
.amount(1000)
.command_id(mpesa::CommandId::BusinessToBusinessTransfer) // optional, defaults to `CommandId::BusinessToBusinessTransfer`
.remarks("None") // optional, defaults to "None"
.sender_id(mpesa::IdentifierTypes::ShortCode) // optional, defaults to `IdentifierTypes::ShortCode`
.receiver_id(mpesa::IdentifierTypes::ShortCode) // optional, defaults to `IdentifierTypes::ShortCode`
.send()
.await;

assert!(response.is_ok());
dotenv::dotenv().ok();

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

let response = client.b2b("testapi496")
.party_a("600496")
.party_b("600000")
.result_url("https://testdomain.com/err")
.timeout_url("https://testdomain.com/ok")
.account_ref("254708374149")
.amount(1000)
.command_id(mpesa::CommandId::BusinessToBusinessTransfer) // optional, defaults to `CommandId::BusinessToBusinessTransfer`
.remarks("None") // optional, defaults to "None"
.sender_id(mpesa::IdentifierTypes::ShortCode) // optional, defaults to `IdentifierTypes::ShortCode`
.receiver_id(mpesa::IdentifierTypes::ShortCode) // optional, defaults to `IdentifierTypes::ShortCode`
.send()
.await;

assert!(response.is_ok());
}
```
```
20 changes: 10 additions & 10 deletions docs/client/b2c.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ use mpesa::{Mpesa, Environment};

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

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

let response = client
let response = client
.b2c("testapi496")
.party_a("600496")
.party_b("254708374149")
Expand All @@ -28,7 +28,7 @@ async fn main() {
.occasion("Your Occasion") // optional, defaults to "None"
.command_id(mpesa::CommandId::BusinessPayment) // optional, defaults to `CommandId::BusinessPayment`
.send()
.await;
assert!(response.is_ok())
.await;
assert!(response.is_ok())
}
```
```
40 changes: 20 additions & 20 deletions docs/client/c2b_register.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Register URL API works hand in hand with Customer to Business (C2B) APIs and all

There are two URLs required for Register URL API: Validation URL and Confirmation URL.

Returns a `C2bRegisterBuilder`
Returns a `C2bRegisterBuilder`

See more from the Safaricom API docs [here](https://developer.safaricom.co.ke/APIs/CustomerToBusinessRegisterURL)

Expand All @@ -12,23 +12,23 @@ use mpesa::{Mpesa, Environment};

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

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

let response = client
.c2b_register()
.short_code("600496")
.confirmation_url("https://testdomain.com/true")
.validation_url("https://testdomain.com/valid")
.response_type(mpesa::ResponseType::Completed) // optional, defaults to `ResponseTypes::Complete`
.send()
.await;

assert!(response.is_ok())
dotenv::dotenv().ok();

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

let response = client
.c2b_register()
.short_code("600496")
.confirmation_url("https://testdomain.com/true")
.validation_url("https://testdomain.com/valid")
.response_type(mpesa::ResponseType::Completed) // optional, defaults to `ResponseTypes::Complete`
.send()
.await;

assert!(response.is_ok())
}
```
```
32 changes: 16 additions & 16 deletions docs/client/c2b_simulate.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@ use mpesa::{Mpesa, Environment};

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

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

let response = client.c2b_simulate()
.short_code("600496")
.msisdn("254700000000")
.amount(1000)
.command_id(mpesa::CommandId::CustomerPayBillOnline) // optional, defaults to `CommandId::CustomerPayBillOnline`
.bill_ref_number("Your_BillRefNumber") // optional, defaults to "None"
.send()
.await;
let response = client.c2b_simulate()
.short_code("600496")
.msisdn("254700000000")
.amount(1000)
.command_id(mpesa::CommandId::CustomerPayBillOnline) // optional, defaults to `CommandId::CustomerPayBillOnline`
.bill_ref_number("Your_BillRefNumber") // optional, defaults to "None"
.send()
.await;

assert!(response.is_ok())
assert!(response.is_ok())
}
```
```
40 changes: 20 additions & 20 deletions docs/client/dynamic_qr.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,27 @@ use mpesa::{Mpesa, Environment};

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

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

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

assert!(response.is_ok())
assert!(response.is_ok())
}
```
```
44 changes: 22 additions & 22 deletions docs/client/express_request.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,26 @@ use mpesa::{Mpesa, Environment};

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

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

let response = client
.express_request("174379")
.phone_number("254708374149")
.party_a("254708374149")
.party_b("174379")
.amount(500)
.callback_url("https://test.example.com/api")
.transaction_type(mpesa::CommandId::CustomerPayBillOnline) // Optional, defaults to `CommandId::CustomerPayBillOnline`
.transaction_desc("Description") // Optional, defaults to "None"
.send()
.await;

assert!(response.is_ok())
dotenv::dotenv().ok();

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

let response = client
.express_request("174379")
.phone_number("254708374149")
.party_a("254708374149")
.party_b("174379")
.amount(500)
.callback_url("https://test.example.com/api")
.transaction_type(mpesa::CommandId::CustomerPayBillOnline) // Optional, defaults to `CommandId::CustomerPayBillOnline`
.transaction_desc("Description") // Optional, defaults to "None"
.send()
.await;

assert!(response.is_ok())
}
```
```
14 changes: 7 additions & 7 deletions docs/client/new.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ Constructs a new `Mpesa` instance.
use mpesa::{Mpesa, Environment};

fn main() {
dotenv::dotenv().ok();
dotenv::dotenv().ok();

let client = Mpesa::new(
env!("CLIENT_KEY"),
env!("CLIENT_SECRET"),
Environment::Sandbox,
);
let client = Mpesa::new(
env!("CLIENT_KEY"),
env!("CLIENT_SECRET"),
Environment::Sandbox,
);
}
```

# Panics
This method can panic if a TLS backend cannot be initialized for the internal http_client
This method can panic if a TLS backend cannot be initialized for the internal http_client
Loading

0 comments on commit 4c5ae4d

Please sign in to comment.