eversend_rust_sdk

Crates.ioeversend_rust_sdk
lib.rseversend_rust_sdk
version0.1.3
sourcesrc
created_at2024-08-03 06:17:05.260498
updated_at2024-08-12 06:32:48.228931
descriptionEversend Rust SDK
homepage
repository
max_upload_size
id1324134
size225,269
Raymond Nambaale (rnambaale)

documentation

README

Eversend Rust SDK

CI Codecov Dependency status

[Experimental] Rust SDK for interacting with the Eversend API.

Table of Contents

  1. Installation
  2. Initialization
  3. Usage

Installation

cargo add eversend_rust_sdk

Or add the following to your Cargo.toml:

[dependencies]
eversend_rust_sdk = "0.1"

Initialization

use eversend_rust_sdk::{ClientId,ClientSecret,Eversend};

let eversend_client = Eversend::new(
    &ClientId::from("clientId"),
    &ClientSecret::from("clientSecret")
);

You can get your clientId and clientSecret from the settings section in the dashboard

Usage

Wallets

Get all wallets

let wallets = eversend_client
    .wallets()
    .get_wallets()
    .await?;

Get one wallet

use eversend_rust_sdk::wallets::types::WalletId;

let wallet = eversend_client
    .wallets()
    .get_wallet(&WalletId::from("UGX"))
    .await?;

Transactions

Get all transactions

use eversend_rust_sdk::transactions::{
    GetTransactionsParams,
    TransactionCurrencyOption,
    TransactionRangeOption,
    TransactionStatusOption,
    TransactionTypeOption
};

let transactions = eversend_client
    .transactions()
    .get_transactions(
        &GetTransactionsParams {
            currency: TransactionCurrencyOption::UGX,
            from: String::from("2024-01-01"),
            to: String::from("2024-01-01"),
            limit: 10,
            page: 1,
            range: TransactionRangeOption::MONTH,
            search: String::from("BE11640235387619"),
            transaction_status: TransactionStatusOption::PENDING,
            transaction_type: TransactionTypeOption::PAYOUT,
        }
    )
    .await?;

Get one transaction

use eversend_rust_sdk::transactions::GetTransactionParams;

let transaction = eversend_client
    .transactions()
    .get_transaction(
        &GetTransactionParams {
            transaction_id: String::from("BE11640235387619"),
        }
    )
    .await?;

Exchange

To exchange from one wallet to another, you first have to generate a quotation. This returns a token with a 30s timeout that you can use to make the exchange.

Get exchange quotation

use eversend_rust_sdk::wallets::types::WalletId;
use eversend_rust_sdk::exchange::CreateQuotationParams;

let quotation = eversend_client
    .exchange()
    .create_quotation(&CreateQuotationParams{
        amount: String::from("10.0"),
        from: &WalletId::from("UGX"),
        to: &WalletId::from("KES")
    })
    .await?;

Exchange currency

use eversend_rust_sdk::exchange::CreateExchangeParams;

let exchange = eversend_client
    .exchange()
    .create_exchange(&CreateExchangeParams{
        quotation_token: String::from("dhhsggajjshhdhdhd")
    })
    .await?;

Beneficiaries

Get beneficiaries

use eversend_rust_sdk::beneficiaries::GetBeneficiariesParams;

let beneficiaries = eversend_client
    .beneficiaries()
    .get_beneficiaries(&GetBeneficiariesParams::default())
    .await?;

The page and limit parameters default to 1 and 10 respectively.

Get single beneficiary

let beneficiary = eversend_client
    .beneficiaries()
    .get_beneficiary(100)
    .await?;

Create a beneficiary

use eversend_rust_sdk::beneficiaries::CreateBeneficaryParams;

let response = eversend_client
    .beneficiaries()
    .create_beneficiary(
        &CreateBeneficaryParams {
            first_name: String::from("Jane"),
            last_name: String::from("Doe"),
            country: String::from("KE"), // Alpha-2 country code
            phone_number: String::from("+254781650002"), // Should be in international format
            bank_account_name: Some(String::from("Stanbic Bank")),
            bank_account_number: Some(String::from("28776353527287")),
            is_bank: true,
            is_momo: true,
        },
    );

Delete a beneficiary

let response = eversend_client
    .beneficiaries()
    .delete_beneficiary(
        206
    )
    .await?;

Collections

Get collection fees

use eversend_rust_sdk::collections::{GetCollectionFeesParams, CollectionMethod};

let fees = eversend_client
    .collections()
    .get_collection_fees(
        &GetCollectionFeesParams {
            method: CollectionMethod::MOMO,
            currency: String::from("KES"),
            amount: 1000
        }
    )
    .await?;

Get collection OTP

Required when initiating mobile money collections

use eversend_rust_sdk::collections::GetCollectionOtpParams;

let otp = eversend_client
    .collections()
    .get_collection_otp(
        &GetCollectionOtpParams {
            phone_number: String::from("+256712345678"),
        }
    )
    .await?;

Initiate Mobile Money collection

use eversend_rust_sdk::collections::GetMobileMoneyCollectionParams;

let collection = eversend_client
    .collections()
    .get_mobile_money_collection(
        &GetMobileMoneyCollectionParams {
            amount: 1000,
            country: String::from("UG"),
            currency: String::from("UGX"),
            phone_number: String::from("+256712345678"),
            transaction_ref: Some(String::from("ADR234526534")),
            redirect_url: Some(String::from("https://eversend.co")),
            customer: None,
            otp: None,
        }
    )
    .await?;

Payouts

Get delivery countries

let countries = eversend_client
    .payouts()
    .get_delivery_countries()
    .await?;

Get delivery banks

let banks = eversend_client
    .payouts()
    .get_delivery_banks(String::from("UG"))
    .await?;

Get payout quotation (Momo and Bank)

use eversend_rust_sdk::payouts::CreateMomoAndBankPayoutQuotationParams;

let quotation = eversend_client
    .payouts()
    .create_momo_and_bank_payout_quotation(
        &CreateMomoAndBankPayoutQuotationParams {
            amount: 20,
            amount_type: String::from("SOURCE"),
            destination_country: String::from("KE"),
            destination_currency: String::from("KES"),
            source_wallet: String::from("KES"),
            transaction_type: String::from("momo"),
        }
    )
    .await?;

Get payout quotation (Eversend)

use eversend_rust_sdk::payouts::CreateEversendPayoutQuotationParams;

let quotation = eversend_client
    .payouts()
    .create_eversend_payout_quotation(
        &CreateEversendPayoutQuotationParams {
            amount: 20,
            amount_type: String::from("SOURCE"),
            email: String::from("satowind@gmail.com"),
            identifier: String::from("email"),
            phone: String::from("+256789123456"),
            source_wallet: String::from("KES"),
            tag: String::from("the-tag"),
        }
    )
    .await?;

Create Momo payout transaction

use eversend_rust_sdk::payouts::CreateMomoPayoutTransactionParams;

let transaction = eversend_client
    .payouts()
    .create_momo_payout_transaction(
        &CreateMomoPayoutTransactionParams {
            country: String::from("UG"),
            first_name: String::from("John"),
            last_name: String::from("Doe"),
            phone_number: String::from("+256789123456"),
            token: String::from("some-token"),
            transaction_ref: String::from("some-reference")
        }
    )
    .await?;

Create Bank payout transaction

use eversend_rust_sdk::payouts::CreateBankPayoutTransactionParams;

let transaction = eversend_client
    .payouts()
    .create_bank_payout_transaction(
        &CreateBankPayoutTransactionParams {
            country: String::from("UG"),
            first_name: String::from("John"),
            last_name: String::from("Doe"),
            phone_number: String::from("+256789123456"),
            token: String::from("some-token"),
            transaction_ref: String::from("some-reference"),
            bank_account_name: String::from("John Doe"),
            bank_account_number: String::from("12345"),
            bank_code: String::from("1234"),
            bank_name: String::from("World Bank"),
        }
    )
    .await?;

Create Beneficiary payout transaction

use eversend_rust_sdk::payouts::CreateBeneficiaryPayoutTransactionParams;

let transaction = eversend_client
    .payouts()
    .create_beneficiary_payout_transaction(
        &CreateBeneficiaryPayoutTransactionParams {
            token: String::from("some-token"),
            beneficiary_id: String::from("123"),
        }
    )
    .await?;

Create Eversend payout transaction

use eversend_rust_sdk::payouts::CreateEversendPayoutTransactionParams;

let transaction = eversend_client
    .payouts()
    .create_eversend_payout_transaction(
        &CreateEversendPayoutTransactionParams {
            token: String::from("some-token"),
            transaction_ref: String::from("some-reference"),
        }
    )
    .await?;

Contributing

Contributions are welcome. For more info please read the Contribution Guideline.

Commit count: 0

cargo fmt