4 个版本
0.1.3 | 2022 年 8 月 24 日 |
---|---|
0.1.2 | 2022 年 5 月 10 日 |
0.1.1 | 2022 年 5 月 9 日 |
0.1.0 | 2022 年 5 月 9 日 |
#25 in #amount
26KB
437 行代码(不含注释)
mvola-rs
MVola Rust 客户端库。
安装
将以下行添加到您的 Cargo.toml
文件
[dependencies]
mvola = "0.1"
用法
use chrono::{DateTime, SecondsFormat, Utc};
use mvola::types::KeyValue;
use mvola::types::Options;
use mvola::types::Service;
use mvola::types::TransactionRequest;
use mvola::{MVola, SANDBOX_URL};
use std::env;
use std::time::SystemTime;
use uuid::Uuid;
#[tokio::main]
async fn main() {
let mut client = MVola::new(SANDBOX_URL);
let auth = client
.auth
.generate_token(
&env::var("CONSUMER_KEY").unwrap(),
&env::var("CONSUMER_SECRET").unwrap(),
)
.await;
client
.transaction
.set_authorization(&auth.unwrap().access_token);
client.transaction.set_options(Options {
version: String::from("1.0"),
correlation_id: Uuid::new_v4().to_string(),
user_language: Some("FR".to_string()),
user_account_identifier: String::from("msisdn;0343500004"),
partner_name: Some("TestMVola".to_string()),
callback_url: None,
});
let transaction_ref = Uuid::new_v4();
let now = SystemTime::now();
let now: DateTime<Utc> = now.into();
let now = now.to_rfc3339_opts(SecondsFormat::Millis, true);
let tx: TransactionRequest = TransactionRequest {
amount: String::from("1000"),
currency: String::from("Ar"),
description_text: String::from("test"),
request_date: now.to_string(),
debit_party: vec![KeyValue {
key: String::from("msisdn"),
value: String::from("0343500003"),
}],
credit_party: vec![KeyValue {
key: String::from("msisdn"),
value: String::from("0343500004"),
}],
metadata: vec![
KeyValue {
key: String::from("partnerName"),
value: String::from("TestMVola"),
},
KeyValue {
key: String::from("fc"),
value: String::from("USD"),
},
KeyValue {
key: String::from("amountFc"),
value: String::from("1"),
},
],
requesting_organisation_transaction_reference: transaction_ref.to_string(),
original_transaction_reference: transaction_ref.to_string(),
};
let response = client.transaction.send_payment(tx).await;
println!("{:#?}", response);
}
测试
cargo test
作者
👤 Tsiry Sandratraina [email protected]
- Twitter: @tsiry_sndr
- Github: @tsirysndr
支持本项目
如果本项目对您有帮助,请给一个 ⭐️!
依赖
~22–33MB
~556K SLoC