4 个版本
新版本 0.1.3 | 2024年8月12日 |
---|---|
0.1.2 | 2024年8月9日 |
0.1.1 | 2024年8月6日 |
0.1.0 | 2024年8月3日 |
#47 在 值格式化
464 次每月下载
215KB
4.5K SLoC
Eversend Rust SDK
[实验性] 用于与 Eversend API 交互的 Rust SDK。
目录
安装
cargo add eversend_rust_sdk
或者将以下内容添加到您的 Cargo.toml 中
[dependencies]
eversend_rust_sdk = "0.1"
初始化
use eversend_rust_sdk::{ClientId,ClientSecret,Eversend};
let eversend_client = Eversend::new(
&ClientId::from("clientId"),
&ClientSecret::from("clientSecret")
);
您可以从 仪表板 的设置部分获取您的 clientId 和 clientSecret
使用方法
钱包
获取所有钱包
let wallets = eversend_client
.wallets()
.get_wallets()
.await?;
获取单个钱包
use eversend_rust_sdk::wallets::types::WalletId;
let wallet = eversend_client
.wallets()
.get_wallet(&WalletId::from("UGX"))
.await?;
交易
获取所有交易
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?;
获取单个交易
use eversend_rust_sdk::transactions::GetTransactionParams;
let transaction = eversend_client
.transactions()
.get_transaction(
&GetTransactionParams {
transaction_id: String::from("BE11640235387619"),
}
)
.await?;
兑换
要从一个钱包兑换到另一个钱包,您首先需要生成一个报价。这将返回一个30秒超时的令牌,您可以使用它来进行兑换。
获取兑换报价
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?;
兑换货币
use eversend_rust_sdk::exchange::CreateExchangeParams;
let exchange = eversend_client
.exchange()
.create_exchange(&CreateExchangeParams{
quotation_token: String::from("dhhsggajjshhdhdhd")
})
.await?;
收款人
获取收款人
use eversend_rust_sdk::beneficiaries::GetBeneficiariesParams;
let beneficiaries = eversend_client
.beneficiaries()
.get_beneficiaries(&GetBeneficiariesParams::default())
.await?;
默认情况下,page
和 limit
参数分别默认为 1
和 10
。
获取单个收款人
let beneficiary = eversend_client
.beneficiaries()
.get_beneficiary(100)
.await?;
创建收款人
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,
},
);
删除收款人
let response = eversend_client
.beneficiaries()
.delete_beneficiary(
206
)
.await?;
收款
获取收款手续费
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?;
获取收款 OTP
在启动移动货币收款时需要
use eversend_rust_sdk::collections::GetCollectionOtpParams;
let otp = eversend_client
.collections()
.get_collection_otp(
&GetCollectionOtpParams {
phone_number: String::from("+256712345678"),
}
)
.await?;
启动移动货币收款
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?;
付款
获取配送国家
let countries = eversend_client
.payouts()
.get_delivery_countries()
.await?;
获取配送银行
let banks = eversend_client
.payouts()
.get_delivery_banks(String::from("UG"))
.await?;
获取付款报价(Momo 和银行)
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?;
获取付款报价(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("[email protected]"),
identifier: String::from("email"),
phone: String::from("+256789123456"),
source_wallet: String::from("KES"),
tag: String::from("the-tag"),
}
)
.await?;
创建 Momo 付款交易
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?;
创建银行付款交易
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?;
创建收款人付款交易
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?;
创建 Eversend 付款交易
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?;
贡献
欢迎贡献。有关更多信息,请阅读 贡献指南。
依赖
~4–15MB
~213K SLoC