Expand description
Convenient rust bindings and types for the Paystack HTTP API aiming to support the entire API surface. Not the case? Please open an issue. I update the definitions on a weekly basis.
§Documentation
See the Rust API docs or the examples.
§Installation
paystack-rs
uses the reqwest
http client under the hood and the tokio
runtime for async operations
[dependencies]
paystack-rs = "0.1"
§Usage
Initializing an instance of the Paystack client and creating a transaction.
use std::env;
use dotenv::dotenv;
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 = 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(())
}
§Contributing
See CONTRIBUTING.md for information on contributing to paystack-rs.
Licensed under MIT license (LICENSE-MIT).
Modules§
- bearer
- Bearer Type
- channel
- Channel
- charge
- Charge
- currency
- Currency
- customers
- Customers
- generic
- Generic Model
- split
- Split Type
- status
- Status
- subaccounts
- Subaccounts
- terminal
- Terminal Models
- transaction_
split - Transaction Splits Models
- transactions
- Transactions Models
Structs§
- Authorization
- This struct represents the authorization data of the transaction status response
- Charge
Body - This struct is used to create a charge body for creating a Charge Authorization using the Paystack API.
The struct is constructed using the
ChargeBodyBuilder
- Charge
Body Builder - Builder for
ChargeBody
. - Create
Subaccount Body - This struct is used to create the body for creating a subaccount on your integration.
- Create
Subaccount Body Builder - Builder for
CreateSubaccountBody
. - Create
Subaccount Response - Represents the JSON response for subaccount creation.
- Create
Transaction Split Body - This struct is used to create a split payment on your integration.
The struct is constructed using the
CreateTransactionSplitBodyBuilder
- Create
Transaction Split Body Builder - Builder for
CreateTransactionSplitBody
. - Customer
- This struct represents the Paystack customer data
- Delete
SubAccount Body - This struct is used to create the body for deleting a subaccount on your integration.
- Event
Data - The data about the event to send to the API.
For the
invoice
type, you need to pass the invoice id and offline reference:{id: invoice_id, reference: offline_reference}
. For thetransaction type, you can pass the transaction id:
{id: transaction_id}` - Export
Transaction Data - Export transaction response data.
- Export
Transaction Response - Represents the response of the export transaction.
- Fetch
Event Status Response - This struct represents the response for checking the status of an event sent to the Terminal
- Fetch
Event Status Response Data - This struct represents the data of the event status
- Fetch
Subaccount Response - Represents the JSON response for fetch subaccount.
- Fetch
Terminal Response - This struct represents the response for fetch terminal.
- Fetch
Terminal Response Data - Response Data for Fetch Terminal Route
- Fetch
Terminal Status Response - This struct represents the response for checking the status of an event sent to the Terminal
- Fetch
Terminal Status Response Data - This struct represents the data of the event status
- Initialize
Transaction Body - This struct is used to create a transaction body for creating a transaction using the Paystack API.
This struct should be created using the
InitializeTransactionBodyBuilder
The Builder derivation allows for the automatic implementation of the builder pattern. - Initialize
Transaction Body Builder - Builder for
InitializeTransactionBody
. - List
Subaccounts Response - Response from List Subaccount route
- Meta
Data - MetaData of list response
- Partial
Debit Transaction Body - This struct is used to create a partial debit transaction body for creating a partial debit using the Paystack API.
This struct should be created using the
PartialDebitTransactionBodyBuilder
The derive Builder allows for the automatic creation of the BuilderPattern - Partial
Debit Transaction Body Builder - Builder for
PartialDebitTransactionBody
. - Partial
Debit Transaction Response - Represents the response of the partial debit transaction.
- Paystack
Client - This is the struct that allows you to authenticate to the PayStack API. It contains the API key which allows you to interact with the API.
- Response
Without Data - Represents the JSON response of the Paystack API when there is no data property
- Send
Event Body - This struct is used to create an event body for sending an event to the paystack Terminal using the Paystack API.
This struct should be created using the
SendEventBodyBuilder
The Builder derivation allows for the automatic implementation of the builder - Send
Event Body Builder - Builder for
SendEventBody
. - Send
Event Response - This struct represents the response of sending an event to the terminal.
- Send
Event Response Data - This struct represents the data of the event response.
- Split
Data - Represents the percentage split data received in the JSON response.
- Subaccount
Body - This struct represents the subaccount.
It can be used as the payload for the API end points that require a subaccount as a payload.
It is also possible to extract a single field from this struct to use as well.
The Struct is constructed using the
SubaccountBuilder
- Subaccount
Body Builder - Builder for
SubaccountBody
. - Subaccount
Data - Represents the data of th Subaccounts
- Subaccount
Endpoints - A struct to hold all functions in the subaccount API route
- Subaccounts
Response Data - Data of the list Subaccount response
- Terminal
Endpoints - A Struct to hold all the functions of the terminal API route
- Terminal
Response With NoData - Response of updating the terminal data
- Transaction
Endpoints - A Struct to hold all the functions of the transaction API route
- Transaction
History Response - This struct represents the transaction history data
- Transaction
Response - This struct represents the response of the Paystack transaction initialization.
- Transaction
Response Data - This struct represents the data of the transaction response.
- Transaction
Split Endpoints - A struct to hold all the functions of the transaction split API route
- Transaction
Split List Response - Represents the JSON response containing percentage split information.
- Transaction
Split Response - Represents the JSON response containing percentage split information.
- Transaction
Status Data - This struct represents the data of the transaction status response.
- Transaction
Status List Response - This struct represents a list of transaction status.
- Transaction
Status Response - This struct represents the transaction status response.
- Transaction
Timeline Data - This struct represents the transaction timeline data.
- Transaction
Timeline Response - This struct represents the transaction timeline.
- Transaction
Total Data - Transaction total data.
- Transaction
Totals Response - Represents the response of the total amount received on your account
- Update
Terminal Body - The terminal update information to send to the API.
- Update
Terminal Body Builder - Builder for
UpdateTerminalBody
. - Update
Transaction Split Body - This struct is used to update a transaction split details on your integration.
The struct is constructed using the
UpdateTransactionSplitBodyBuilder
- Update
Transaction Split Body Builder - Builder for
UpdateTransactionSplitBody
. - Volume
ByCurrency - Transaction volume by currency.
Enums§
- Action
Type - Represents the different action the Terminal needs to perform.
- Bearer
Type - Represents the type of bearer for a charge.
- Channel
- Represents the payment channels supported by Paystack.
- Charge
Body Builder Error - Error type for ChargeBodyBuilder
- Create
Subaccount Body Builder Error - Error type for CreateSubaccountBodyBuilder
- Create
Transaction Split Body Builder Error - Error type for CreateTransactionSplitBodyBuilder
- Currency
- Represents different currencies supported by the Paystack API.
- Error
- Custom Error for the Paystack API
- Event
Type - Represents the different terminal event types supported by the Paystack API.
- Initialize
Transaction Body Builder Error - Error type for InitializeTransactionBodyBuilder
- Partial
Debit Transaction Body Builder Error - Error type for PartialDebitTransactionBodyBuilder
- Send
Event Body Builder Error - Error type for SendEventBodyBuilder
- Split
Type - Represents the type of transaction split.
- Status
- Represents the status of a transaction.
- Subaccount
Body Builder Error - Error type for SubaccountBodyBuilder
- Update
Terminal Body Builder Error - Error type for UpdateTerminalBodyBuilder
- Update
Transaction Split Body Builder Error - Error type for UpdateTransactionSplitBodyBuilder
Functions§
- delete_
request - A function for sending DELETE requests to a specified url using the reqwest client.
- get_
request - A function for sending GET request to a specified url with optional query parameters using reqwest client.
- post_
request - A function for sending POST requests to a specified url using the reqwest client.
- put_
request - A function for sending PUT requests to a specified url using the reqwest client.
Type Aliases§
- Paystack
Result - Custom result type for the Paystack API