This crate integrates the Lazerpay payment gateway for accepting cryptocurrency payments.
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.
You could also try out the examples in the project. For example, to run the payment example, run:
cargo run --example paymentIf you need more reference on this crate feel free to check the source code