Lazerpay SDK for Rust 🦀

Overview

💳 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", "[email protected]"),
        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

You might also like...
An unofficial Rust SDK for Clerk.dev

An unofficial clerk.dev SDK for rust Note: This SDK is updated frequently to keep up with any changes to the actual Clerk API. If you see anything tha

Kryptokrona SDK in Rust for building decentralized private communication and payment systems.

Kryptokrona Rust SDK Kryptokrona is a decentralized blockchain from the Nordic based on CryptoNote, which forms the basis for Monero, among others. Cr

Unofficial Rust SDK library for Uniswap smart contracts.

uniswap-rs Unofficial Rust SDK library for Uniswap smart contracts. Quickstart Add this to your Cargo.toml: [dependencies] uniswap-rs = { git = "https

Avalanche APIs/VM SDK in Rust

avalanche-rs ⚠️ avalanche-rs is alpha-level software and is not ready for production use. Do not use avalanche-rs to run production workloads. See the

Unofficial Rust SDK library for Uniswap smart contracts.

uniswap-rs Unofficial Rust SDK library for Uniswap smart contracts. Quickstart Add this to your Cargo.toml: [dependencies] uniswap-rs = { git = "https

A Software Development Kit (SDK) for Zero-Knowledge Transactions

Aleo SDK The Aleo SDK is a developer framework to make it simple to create a new account, craft a transaction, and broadcast it to the network. Table

A Minimal Windows SDK.

Minimal Windows 10 SDK Installs only the necessary Windows 10 .lib files to save you having to download the full Visual Studio package. You can either

Helper library for interacting with Terra assets (SDK coins and CW20 tokens)

terra-asset Helpers for interacting with Terra assets, including native coins and CW20 tokens Usage This crate contains two struct types: AssetInfo st

Rustcoin - A LightWeight SDK For Bitcoin, Ethernum

Rustcoin - A LightWeight SDK For Bitcoin, Ethernum

Comments
  • API Change Proposal

    API Change Proposal

    Right now, Lazerpay Rust SDK looks so much like the node SDK. The issue with that is the library doesn't take full advantage of Rust's type safety all in the spirit of staying true to the official implementation. But node is not Rust. JavaScript is a weakly typed language.

    For the reasons stated above, I would like to propose a slightly different, more Rusty interface for the SDK. Specifying it in a way that doesn't diverge too much from the reference implementation.

    I think it will help with creating a more solid foundation for the project as Lazerpay grows its features.

    let lazerpay = Lazerpay::new()?; // Sets up API keys. Grabs details from .env.
    
    let payment = lazerpay.create_payment(PaymentConfig { // Returns a payment object but doesn't send req.
        customer: Customer::new("Lagbaja Ajanaku", "[email protected]"),
        coin: Coin::USDC,
        currency: Currency::NGN,
        amount: 5_000,
        pk_address: "0x16227d60f7a0e586c66b005219dfc887d13c9531",
        reference: "Just sending some money your way",
        ..Default::default()
    })?;
    
    payment.send()?; // Sends payment req.
    
    payment.check_confirmation()?; // Asks for confirmation.
    
    payment.get_accepted_coins()?; // Get supported coins.
    

    Let me know what you think and if there is any edge case I'm missing.

    opened by appcypher 7
  • Refactor API

    Refactor API

    • Adjust interface
    • Add response deserialisation structs
    • Introduce results
    • Document

    TODO:

    • [x] Fix the tests. (The failing tests seem to be from Lazerpay end)

    Closes https://github.com/Lord-sarcastic/lazerpay-rust-sdk/issues/13 Closes https://github.com/Lord-sarcastic/lazerpay-rust-sdk/issues/12

    Areas of Improvement:

    • Need to have a proper type for coin/currency amounts/values. Right now the types of TransferConfig amount and PaymentConfig amount are different because that's what the Lazerpay API expects. It is not ideal and I have not come up with a better approach yet. Might need to meet with the Lazerpay devs for that.
    opened by appcypher 2
  • Results over Unwraps

    Results over Unwraps

    Might want to return Results instead of unwrapping. This puts error handling into the users hands and prevents unexpected and sometimes unwanted panics.

    opened by appcypher 2
  • Rename Library to `lazerpay`

    Rename Library to `lazerpay`

    I think the library should just be renamed lazerpay or lazerpay-rs. lazerpay-rust-sdk is a mouthful. There is no need for the ...-rust-sdk namespacing since this rust version is only ever going to exist in crates-verse.

    It also helps with discoverability.

    opened by appcypher 5
Releases(v0.1.1)
  • v0.1.1(Mar 1, 2022)

  • v0.1.0(Feb 28, 2022)

    The primordial release. Contains about 5 API integrations:

    • Initialize transaction
    • Verify transaction
    • Get all accepted coins
    • Transfer
    • Get rate

    Future releases would involve more strictness on the typings and an improved structure.

    Source code(tar.gz)
    Source code(zip)
Owner
Lord_Sarcastic
Esteem ment, eschew sanity; eliminate rest, induce strength
Lord_Sarcastic
Pokémon TCG SDK - Rust

Pokémon TCG SDK - Rust This is the Pokémon TCG SDK Rust implementation. It is a wrapper around the Pokémon TCG API of pokemontcg.io. Usage Configurati

Pokémon TCG Developers 2 Dec 14, 2022
A template to build smart contracts in Rust to run inside a Cosmos SDK module on all chains that enable it.

CosmWasm Starter Pack This is a template to build smart contracts in Rust to run inside a Cosmos SDK module on all chains that enable it. To understan

null 1 Mar 7, 2022
Smart Contract built in Rust to run inside Cosmos SDK module on all chains that enable it

CoinSwap is a Smart Contract that is built on the terra blockchain and can be used to swap cryptocurrencies such as LUNA, UST, TerraUSD, Anchor, Mirror Protocol, LUNI and other CW20 tokens. The Project also contains a smart contract which works as a analysis tool for the gas fees on the Terra Blockchain.

Prajjwal Chittori 9 Oct 11, 2022
This crate reimplements Gelato's Relay SDK in Rust

Gelato Relay SDK This crate reimplements Gelato's Relay SDK in Rust. It simply wraps Gelato Relay requests and responses to/from Gelato endpoints with

Nomad 30 Oct 20, 2022
A universal SDK for FDU. Powered by Rust.

libfdu A universal SDK for FDU. Building You need Rust Nightly installed: $ rustup default nightly Build the library by running: $ cargo build or $ ca

旦夕开发组 6 Sep 11, 2022
mirrorworld-sdk-rust

Usage Clone project code. git clone [email protected]:mirrorworld-universe/mirrorworld-sdk-rust.git cd mirrorworld-sdk-rust run. cargo run test. cargo te

Mirror World 17 Nov 12, 2022
Rust SDK for interacting with the Nile.

Nile API Rust Client This is a POC Rust client for the Nile API. Usage Source the Nile environment variables into your environment. export NILE_DEVELO

coredb-io 4 Jan 12, 2023
Rust for the DirectStorage SDK (unofficial)

Rust for the DirectStorage SDK (unofficial) This crate lets you call any DirectStorage SDK API using code generated from the metadata describing the A

Rafael Rivera 5 Jan 13, 2023
🦀 Hop server side SDK for Rust

hop-rs (wip) Hop's Rust library. Requires Rust 1.61+ Installation [dependencies] hop = "0.0.0" Usage Create a project token or personal access token.

Tom 17 Jan 31, 2023
Minimal flashloan borrower contracts with an extensible rust sdk to abstract wrapping generic onchain calls (similar to multicall3) with flashloans.

flashloan-rs • Minimal flashloan borrower contracts with an extensible rust sdk. Getting Started Flashloan-rs is published to crates.io as flashloan-r

White Noise 71 Apr 15, 2023