Skip to content

Commit 821a48c

Browse files
committed
ground work for rewrite
1 parent 27d3634 commit 821a48c

File tree

14 files changed

+121
-12
lines changed

14 files changed

+121
-12
lines changed

.env.example

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
PAYSTACK_API_KEY=your_paystack_key_here
2-
BANK_ACCOUNT=0000000000
2+
BANK_ACCOUNT=0000000001
33
BANK_CODE=058
44
BANK_NAME='Guaranty Trust Bank'

.idea/paystack-rs.iml

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CHANGELOG.md

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
## 0.2.3 (15/07/2024
2+
3+
- A complete rewrite of the paystack-rs crate. The rewrite is necessary because in the current state, the crate is not
4+
extendable and will be difficult to add support for sync and async code. The rewrite is to achieve the following objectives:
5+
- Make the code less complex (relatively speaking)
6+
- Improve the maintainability of the crate
7+
- Support both async and sync code
8+
- Use high level data construct when creating request body
9+
- Have extensive Rust type for every possible response from the API
10+
- Use advanced rust type and how a better understand of the Rust programming language (personal reason)
11+
12+
- The following changes have been implemented
13+
- Change the project file layout to improve separation of concerns. The new layout includes the following
14+
- http (to handle all http related functionalities)
15+
- models (holds all request and response models from the API)
16+
- macros (utility macro to simplify code repetition)
17+
18+
## 0.2.2 (29/11/2023)
19+
20+
- Added support for create customer API route

Cargo.toml

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "paystack-rs"
33
version = "0.2.2"
4-
description = "A unofficial client library for the Paystack API"
4+
description = "Paystack API Wrapper"
55
authors = ["Oghenemarho Orukele <orukele.dev@gmail.com>"]
66
edition = "2021"
77
include = [
@@ -24,17 +24,21 @@ readme = "README.md"
2424
categories = ["api-bindings", "finance"]
2525
license = "MIT"
2626

27-
[lib]
28-
name = "paystack"
27+
[workspace]
28+
members = [
29+
"models",
30+
"http",
31+
"macros"
32+
]
2933

3034

3135
[dependencies]
3236
thiserror = "1"
3337
serde_json = "1"
34-
reqwest = { version = "0.11", features = ["json"] }
38+
reqwest = { version = "0.12.5", features = ["json"] }
3539
tokio = { version = "1", features = ["full"] }
3640
serde = {version ="1", features = ["derive"]}
37-
derive_builder = "0.12.0"
41+
derive_builder = "0.20.0"
3842

3943
[dev-dependencies]
4044
fake = "2"

http/Cargo.toml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[package]
2+
name = "http"
3+
version = "0.2.2"
4+
description = "HTTP layer for paystack-rs"
5+
authors = ["Oghenemarho Orukele <orukele.dev@gmail.com>"]
6+
edition = "2021"
7+
homepage = "https://github.com/morukele/paystack-rs"
8+
repository = "https://github.com/morukele/paystack-rs"
9+
documentation = "https://docs.rs/paystack-rs"
10+
keywords = [
11+
"payment",
12+
"paystack",
13+
"api",
14+
"finance",
15+
]
16+
readme = "../README.md"
17+
categories = ["api-bindings", "finance"]
18+
license = "MIT"

http/src/lib.rs

Whitespace-only changes.

macros/Cargo.toml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[package]
2+
name = "macros"
3+
version = "0.2.2"
4+
description = "Macros for paystack-rs"
5+
authors = ["Oghenemarho Orukele <orukele.dev@gmail.com>"]
6+
edition = "2021"
7+
homepage = "https://github.com/morukele/paystack-rs"
8+
repository = "https://github.com/morukele/paystack-rs"
9+
documentation = "https://docs.rs/paystack-rs"
10+
keywords = [
11+
"payment",
12+
"paystack",
13+
"api",
14+
"finance",
15+
]
16+
readme = "../README.md"
17+
categories = ["api-bindings", "finance"]
18+
license = "MIT"

macros/src/lib.rs

Whitespace-only changes.

models/Cargo.toml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[package]
2+
name = "models"
3+
version = "0.2.2"
4+
description = "Models for paystack-rs"
5+
authors = ["Oghenemarho Orukele <orukele.dev@gmail.com>"]
6+
edition = "2021"
7+
homepage = "https://github.com/morukele/paystack-rs"
8+
repository = "https://github.com/morukele/paystack-rs"
9+
documentation = "https://docs.rs/paystack-rs"
10+
keywords = [
11+
"payment",
12+
"paystack",
13+
"api",
14+
"finance",
15+
]
16+
readme = "../README.md"
17+
categories = ["api-bindings", "finance"]
18+
license = "MIT"

models/src/lib.rs

Whitespace-only changes.

scripts/publish.sh

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
crates=(
2+
macros
3+
models
4+
http
5+
)
6+
7+
for crate in "${crates[@]}"; do
8+
echo "Publishing ${crate}"
9+
(
10+
cd "$crate"
11+
cargo publish --no-verify
12+
)
13+
sleep 20
14+
done
15+
16+
cargo publish

src/endpoints/customers.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use reqwest::StatusCode;
22

3-
use crate::{post_request, CreateCustomerBody, CreateCustomerResponse, Error, PaystackResult};
3+
use crate::{post_request, CreateCustomerBody, CreateCustomerResponse, Error, PaystackResult, ListCustomerResponse};
44

55
/// A struct to hold all the functions of the customer API route
66
#[derive(Debug, Clone)]
@@ -18,6 +18,8 @@ impl<'a> CustomerEndpoints<'a> {
1818
}
1919

2020
/// Create a customer on your integration
21+
///
22+
/// It takes a CreateCustomerBody as its parameter
2123
pub async fn create_customer(
2224
self,
2325
body: CreateCustomerBody,
@@ -38,4 +40,9 @@ impl<'a> CustomerEndpoints<'a> {
3840
Err(err) => Err(Error::FailedRequest(err.to_string())),
3941
}
4042
}
43+
44+
/// List the customers in the integration
45+
pub async fn list_customers() -> PaystackResult<ListCustomerResponse> {
46+
47+
}
4148
}

src/endpoints/transactions.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ impl<'a> TransactionEndpoints<'a> {
2727

2828
/// Initialize a transaction from your backend.
2929
///
30-
/// It takes a Transaction type as its parameter
30+
/// It takes an InitializeTransactionBody type as its parameter
3131
pub async fn initialize_transaction(
3232
&self,
3333
transaction_body: InitializeTransactionBody,
@@ -77,7 +77,7 @@ impl<'a> TransactionEndpoints<'a> {
7777
/// List transactions carried out on your integration.
7878
///
7979
/// The method takes the following parameters:
80-
/// - perPage (Optional): Number of transactions to return. If None is passed as the parameter, the last 10 transactions are returned.
80+
/// - numberOfTransactions (Optional): Number of transactions to return. If None is passed as the parameter, the last 10 transactions are returned.
8181
/// - status (Optional): Filter transactions by status, defaults to Success if no status is passed.
8282
///
8383
pub async fn list_transactions(
@@ -108,7 +108,7 @@ impl<'a> TransactionEndpoints<'a> {
108108

109109
/// Get details of a transaction carried out on your integration.
110110
///
111-
/// This methods take the Id of the desired transaction as a parameter
111+
/// This method take the ID of the desired transaction as a parameter
112112
pub async fn fetch_transactions(
113113
&self,
114114
transaction_id: u32,
@@ -132,7 +132,7 @@ impl<'a> TransactionEndpoints<'a> {
132132

133133
/// All authorizations marked as reusable can be charged with this endpoint whenever you need to receive payments.
134134
///
135-
/// This function takes a Charge Struct as parameter
135+
/// This function takes a ChargeBody Struct as parameter
136136
pub async fn charge_authorization(
137137
&self,
138138
charge: ChargeBody,
@@ -261,7 +261,7 @@ impl<'a> TransactionEndpoints<'a> {
261261

262262
/// Retrieve part of a payment from a customer.
263263
///
264-
/// It takes a PartialDebitTransaction type as a parameter.
264+
/// It takes a PartialDebitTransactionBody type as a parameter.
265265
///
266266
/// NB: it must be created with the PartialDebitTransaction Builder.
267267
pub async fn partial_debit(

src/models/customers.rs

+5
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,8 @@ pub struct CreateCustomerResponseData {
8383
#[serde(rename = "updatedAt")]
8484
pub updated_at: Option<String>,
8585
}
86+
87+
/// This struct represents the response from the list customer route.
88+
pub struct ListCustomerResponse {
89+
90+
}

0 commit comments

Comments
 (0)