Crate paystack

Source
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 = "1.4.0"

§Usage

Initializing an instance of the Paystack client and creating a transaction.

use std::env;
use std::error::Error;
use dotenv::dotenv;
use paystack::{PaystackClient, TransactionRequestBuilder, PaystackAPIError, Currency, Channel, ReqwestClient};


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


    let email = "email@example.com".to_string();
    let amount ="10000".to_string();
    let body = TransactionRequestBuilder::default()
        .amount(amount)
        .email(email)
        .currency(Currency::NGN)
        .channel(vec![
            Channel::Card,
            Channel::ApplePay,
            Channel::BankTransfer,
            Channel::Bank,
        ])
        .build()?;

    let res = client
        .transactions
        .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).

Re-exports§

pub use client::*;
pub use endpoints::*;
pub use errors::*;
pub use http::*;
pub use models::*;
pub use utils::*;

Modules§

client
Client
endpoints
errors
Error
http
The HTTP client can be different and it is toggled during the configuration process of the crate The default client will is th Reqwest client, in the case of none being selected. If both are selected, a compiler error is raised.
macros
models
utils

Type Aliases§

PaystackResult
Custom result type for the Paystack API