Skip to content

emmanuelthegeek/lazerpay-rust-sdk

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

51 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

💳 Lazerpay Rust SDK

This crate integrates the Lazerpay payment gateway for accepting cryptocurrency payments.

Crates.io License Contributors

Usage

Add the following to your cargo dependencies:

lazerpay-rust-sdk = "0.1.1"

Next you get your test LAZERPAY_PUBLIC_KEY and LAZERPAY_SECRET_KEY from Lazerpay dashboard

Add those to a .env file at the root of your project. You can check .env.example for an example.

With that out of the way, you can use the API to make payments.

use lazerpay_rust_sdk::{utils, Customer, Lazerpay, PaymentConfig};

#[tokio::main]
async fn main() {
    let api = Lazerpay::new();

    let mut payment = api.create_payment(PaymentConfig {
        customer: Customer::new("Enoch", "enochchejieh@gmail.com"),
        reference: utils::generate_unique_reference(),
        coin: "USDC".into(),
        amount: "1000".into(),
        currency: "USD".into(),
        accept_partial_payment: true,
    });

    dbg!(payment.send().await.unwrap());
    dbg!(payment.check_confirmation().await.unwrap());
}

And transfer funds using the transfer API.

use lazerpay_rust_sdk::{utils, Customer, Lazerpay, TransferConfig};

#[tokio::main]
async fn main() {
    let api = Lazerpay::new();

    let mut transfer = api.create_transfer(TransferConfig {
        recipient: "0x0000000000000000000000000000000000000000".into(),
        blockchain: "Binance Smart Chain".into(),
        coin: "USDC".into(),
        amount: 1000,
    });

    dbg!(transfer.send().await.unwrap());
}

Finally, you can use get information on supported coins and their rates.

use lazerpay_rust_sdk::Lazerpay;

#[tokio::main]
async fn main() {
    let api = Lazerpay::new();

    dbg!(api.get_rates("USD", "USDC").await.unwrap());
    dbg!(api.get_accepted_coins().await.unwrap());
}

and that's it.

Examples

You could also try out the examples in the project. For example, to run the payment example, run:

cargo run --example payment

If you need more reference on this crate feel free to check the source code

About

Lazerpay SDK for Rust 🦀

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Rust 100.0%