Skip to content

Commit

Permalink
Merge pull request #14 from morukele/Subaccount-API
Browse files Browse the repository at this point in the history
Subaccount api
  • Loading branch information
morukele authored Sep 18, 2023
2 parents c1ad75a + fcc000a commit 3d4dbb4
Show file tree
Hide file tree
Showing 19 changed files with 1,110 additions and 570 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ on:
env:
CARGO_TERM_COLOR: always
PAYSTACK_API_KEY: ${{secrets.PAYSTACK_API_KEY}}
BANK_ACCOUNT: ${{secrets.BANK_ACCOUNT}}
BANK_CODE: ${{secrets.BANK_CODE}}

jobs:
build:
Expand Down
42 changes: 18 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

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.

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

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

Expand All @@ -17,7 +17,7 @@ The client currently covers the following section of the API, and the sections t
- [ ] Customers
- [ ] Dedicated Virtual Account
- [ ] Apple Pay
- [ ] Subaccounts
- [x] Subaccounts
- [ ] Plans
- [ ] Subscriptions
- [ ] Transfer Recipients
Expand Down Expand Up @@ -53,39 +53,33 @@ Initializing an instance of the Paystack client and creating a transaction.
```rust
use std::env;
use dotenv::dotenv;
use paystack::{PaystackClient, InitializeTransactionBody, Error, Currency, Channel};
use paystack::{PaystackClient, InitializeTransactionBodyBuilder, Error, Currency, Channel};

#[tokio::main]
async fn main() -> Result<(), Error>{
dotenv().ok();
let api_key = env::var("PAYSTACK_API_KEY").unwrap();
let client = PaystackClient::new(api_key);

let body = InitializeTransactionBody {
amount: "20000".to_string(),
email: "email@example.com".to_string(),
currency: Some(Currency::NGN),
channels: Some(vec![
Channel::ApplePay,
Channel::BankTransfer,
Channel::Bank,
]),
bearer: None,
callback_url: None,
invoice_limit: None,
metadata: None,
plan: None,
reference: None,
split_code: None,
subaccount: None,
transaction_charge: None,
};

let body = InitializeTransactionBodyBuilder::default()
.amount("10000".to_string())
.email("email@example.com".to_string())
.currency(Some(Currency::NGN))
.channels(Some(vec![
Channel::ApplePay,
Channel::Bank,
Channel::BankTransfer
]))
.build()
.unwrap();

let transaction = client
.transaction
.initialize_transaction(body)
.await
.expect("Unable to create transaction");
Ok(())

Ok(())
}
```

Expand Down
5 changes: 4 additions & 1 deletion examples/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ async fn main() {
.channels(Some(vec![
Channel::ApplePay,
Channel::Bank,
Channel::BankTransfer
Channel::BankTransfer,
]))
.build()
.unwrap();

let transaction = client
.transaction
.initialize_transaction(body)
.await
.expect("Unable to create transaction");
Expand All @@ -47,6 +48,7 @@ async fn main() {
// Verify transaction
// Transaction reference can be a string or pulled out from the transaction response
let transaction_status = client
.transaction
.verify_transaction(&transaction.data.reference.to_string())
.await
.expect("Unable to get transaction status");
Expand All @@ -61,6 +63,7 @@ async fn main() {

// List of transactions
let transactions = client
.transaction
.list_transactions(Some(5), Some(Status::Success))
.await
.expect("Unable to get all the transactions");
Expand Down
Loading

0 comments on commit 3d4dbb4

Please sign in to comment.