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 Type
- Channel
- Charge
- Currency
- Customers
- Generic Model
- Split Type
- Status
- Subaccounts
- Terminal Models
- Transaction Splits Models
- Transactions Models
Structs
- This struct represents the authorization data of the transaction status response
- 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
- Builder for
ChargeBody
. - This struct is used to create the body for creating a subaccount on your integration.
- Builder for
CreateSubaccountBody
. - Represents the JSON response for subaccount creation.
- This struct is used to create a split payment on your integration. The struct is constructed using the
CreateTransactionSplitBodyBuilder
- Builder for
CreateTransactionSplitBody
. - This struct represents the Paystack customer data
- This struct is used to create the body for deleting a subaccount on your integration.
- 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 response data.
- Represents the response of the export transaction.
- This struct represents the response for checking the status of an event sent to the Terminal
- This struct represents the data of the event status
- Represents the JSON response for fetch subaccount.
- This struct represents the response for fetch terminal.
- Response Data for Fetch Terminal Route
- This struct represents the response for checking the status of an event sent to the Terminal
- This struct represents the data of the event status
- 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. - Builder for
InitializeTransactionBody
. - Response from List Subaccount route
- MetaData of list response
- 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 - Builder for
PartialDebitTransactionBody
. - Represents the response of the partial debit transaction.
- 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.
- Represents the JSON response of the Paystack API when there is no data property
- 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 - Builder for
SendEventBody
. - This struct represents the response of sending an event to the terminal.
- This struct represents the data of the event response.
- Represents the percentage split data received in the JSON response.
- 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
- Builder for
SubaccountBody
. - Represents the data of th Subaccounts
- A struct to hold all functions in the subaccount API route
- Data of the list Subaccount response
- A Struct to hold all the functions of the terminal API route
- Response of updating the terminal data
- A Struct to hold all the functions of the transaction API route
- This struct represents the transaction history data
- This struct represents the response of the Paystack transaction initialization.
- This struct represents the data of the transaction response.
- A struct to hold all the functions of the transaction split API route
- Represents the JSON response containing percentage split information.
- Represents the JSON response containing percentage split information.
- This struct represents the data of the transaction status response.
- This struct represents a list of transaction status.
- This struct represents the transaction status response.
- This struct represents the transaction timeline data.
- This struct represents the transaction timeline.
- Transaction total data.
- Represents the response of the total amount received on your account
- The terminal update information to send to the API.
- Builder for
UpdateTerminalBody
. - This struct is used to update a transaction split details on your integration. The struct is constructed using the
UpdateTransactionSplitBodyBuilder
- Builder for
UpdateTransactionSplitBody
. - Transaction volume by currency.
Enums
- Represents the different action the Terminal needs to perform.
- Represents the type of bearer for a charge.
- Represents the payment channels supported by Paystack.
- Error type for ChargeBodyBuilder
- Error type for CreateSubaccountBodyBuilder
- Error type for CreateTransactionSplitBodyBuilder
- Represents different currencies supported by the Paystack API.
- Custom Error for the Paystack API
- Represents the different terminal event types supported by the Paystack API.
- Error type for InitializeTransactionBodyBuilder
- Error type for PartialDebitTransactionBodyBuilder
- Error type for SendEventBodyBuilder
- Represents the type of transaction split.
- Represents the status of a transaction.
- Error type for SubaccountBodyBuilder
- Error type for UpdateTerminalBodyBuilder
- Error type for UpdateTransactionSplitBodyBuilder
Functions
- A function for sending DELETE requests to a specified url using the reqwest client.
- A function for sending GET request to a specified url with optional query parameters using reqwest client.
- A function for sending POST requests to a specified url using the reqwest client.
- A function for sending PUT requests to a specified url using the reqwest client.
Type Aliases
- Custom result type for the Paystack API