Skip to content

Commit 3d4dbb4

Browse files
authored
Merge pull request #14 from morukele/Subaccount-API
Subaccount api
2 parents c1ad75a + fcc000a commit 3d4dbb4

19 files changed

+1110
-570
lines changed

.github/workflows/rust.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ on:
99
env:
1010
CARGO_TERM_COLOR: always
1111
PAYSTACK_API_KEY: ${{secrets.PAYSTACK_API_KEY}}
12+
BANK_ACCOUNT: ${{secrets.BANK_ACCOUNT}}
13+
BANK_CODE: ${{secrets.BANK_CODE}}
1214

1315
jobs:
1416
build:

README.md

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
Convenient **Async** rust bindings and types for the [Paystack](https://paystack.com) HTTP API aiming to support the entire API surface. Not the case? Please open an issue. I update the definitions on a weekly basis.
99

10-
The client aims to make recieving payments for African business or business with African clients building with Rust as hassle-free as possible.
10+
The client aims to make receiving payments for African business or business with African clients building with Rust as hassle-free as possible.
1111

1212
The client currently covers the following section of the API, and the sections to be implemented in order are left unchecked:
1313

@@ -17,7 +17,7 @@ The client currently covers the following section of the API, and the sections t
1717
- [ ] Customers
1818
- [ ] Dedicated Virtual Account
1919
- [ ] Apple Pay
20-
- [ ] Subaccounts
20+
- [x] Subaccounts
2121
- [ ] Plans
2222
- [ ] Subscriptions
2323
- [ ] Transfer Recipients
@@ -53,39 +53,33 @@ Initializing an instance of the Paystack client and creating a transaction.
5353
```rust
5454
use std::env;
5555
use dotenv::dotenv;
56-
use paystack::{PaystackClient, InitializeTransactionBody, Error, Currency, Channel};
56+
use paystack::{PaystackClient, InitializeTransactionBodyBuilder, Error, Currency, Channel};
5757

5858
#[tokio::main]
5959
async fn main() -> Result<(), Error>{
6060
dotenv().ok();
6161
let api_key = env::var("PAYSTACK_API_KEY").unwrap();
6262
let client = PaystackClient::new(api_key);
63-
64-
let body = InitializeTransactionBody {
65-
amount: "20000".to_string(),
66-
email: "email@example.com".to_string(),
67-
currency: Some(Currency::NGN),
68-
channels: Some(vec![
69-
Channel::ApplePay,
70-
Channel::BankTransfer,
71-
Channel::Bank,
72-
]),
73-
bearer: None,
74-
callback_url: None,
75-
invoice_limit: None,
76-
metadata: None,
77-
plan: None,
78-
reference: None,
79-
split_code: None,
80-
subaccount: None,
81-
transaction_charge: None,
82-
};
63+
64+
let body = InitializeTransactionBodyBuilder::default()
65+
.amount("10000".to_string())
66+
.email("email@example.com".to_string())
67+
.currency(Some(Currency::NGN))
68+
.channels(Some(vec![
69+
Channel::ApplePay,
70+
Channel::Bank,
71+
Channel::BankTransfer
72+
]))
73+
.build()
74+
.unwrap();
8375

8476
let transaction = client
77+
.transaction
8578
.initialize_transaction(body)
8679
.await
8780
.expect("Unable to create transaction");
88-
Ok(())
81+
82+
Ok(())
8983
}
9084
```
9185

examples/transaction.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,13 @@ async fn main() {
2727
.channels(Some(vec![
2828
Channel::ApplePay,
2929
Channel::Bank,
30-
Channel::BankTransfer
30+
Channel::BankTransfer,
3131
]))
3232
.build()
3333
.unwrap();
3434

3535
let transaction = client
36+
.transaction
3637
.initialize_transaction(body)
3738
.await
3839
.expect("Unable to create transaction");
@@ -47,6 +48,7 @@ async fn main() {
4748
// Verify transaction
4849
// Transaction reference can be a string or pulled out from the transaction response
4950
let transaction_status = client
51+
.transaction
5052
.verify_transaction(&transaction.data.reference.to_string())
5153
.await
5254
.expect("Unable to get transaction status");
@@ -61,6 +63,7 @@ async fn main() {
6163

6264
// List of transactions
6365
let transactions = client
66+
.transaction
6467
.list_transactions(Some(5), Some(Status::Success))
6568
.await
6669
.expect("Unable to get all the transactions");

0 commit comments

Comments
 (0)