14 个版本 (5 个重大更改)
0.6.1 | 2023 年 1 月 18 日 |
---|---|
0.6.0 | 2023 年 1 月 17 日 |
0.5.0 | 2023 年 1 月 17 日 |
0.4.2 | 2023 年 1 月 16 日 |
0.1.1 | 2023 年 1 月 9 日 |
#1813 in 网页编程
每月 39 次下载
190KB
2K SLoC
ezstripe 💳
A Stripe-SDK for Rustlang
使用 ezstripe 轻松与 Stripe API 通信。
用法
安装
# Cargo.toml
[dependencies]
ezstripe = "0.6.1"
或 cargo add ezstripe
功能
默认启用所有功能,但您可以根据项目需求选择所需的功能。
# Cargo.toml
[dependencies]
ezstripe = { version = "0.6.1", default-features = false, features = ["payment_intent", "refund"] }
示例
# Cargo.toml
[dependencies]
ezstripe = "0.6.1"
env_logger = "0.10.0" # Optional
// Required to use the `ezbody!` macro
#[macro_use] extern crate ezstripe;
#[tokio::main]
async fn main() {
// To show possible errors (recommended for development)
env_logger::init_from_env(env_logger::Env::default().filter_or("MY_LOG_LEVEL", "debug"));
// We need a client to make requests
let client = ezstripe::Client::new("SECRET_KEY");
// Create a body for the request
let stripe_body = ezbody!(
"amount" => 1500,
"currency" => "eur",
"payment_method_types[]" => "card",
"payment_method_types[]" => "sofort",
"capture_method" => "automatic",
"shipping[name]" => "Your Name",
"shipping[address][city]" => "Test"
);
// Now send a request to Stripe's API
let stripe_response = client.create_payment_intent(stripe_body).send().await;
if let Err((e_msg, e_info)) = stripe_response {
if let Some(r) = e_info {
println!("{}: {} | {} | {}", e_msg, r.r#type, r.code, r.message);
} else { // Such an error only occurs when a request to Stripe failed
println!("{}", e_msg);
}
std::process::exit(1);
}
// No error, so let's unpack the answer
let stripe_result = stripe_response.unwrap();
// Print the unique ID from the created PaymentIntent
println!("Created: {}", stripe_result.id);
}
状态
目前支持和计划的功能列表。
- 余额
- 余额交易
- 费用
- 客户
- 争议
- 事件
- 文件
- 文件链接
- 指令
- 支付意图
- 设置意图
- 设置尝试
- 付款
- 退款
- 令牌
贡献
注意
我们不从其他项目中引入代码!请尊重他人的项目和投入的时间和精力,不要复制任何内容!没有结构!没有行!
有兴趣为此 SDK 贡献吗?GitHub 为您提供了创建 pull requests 的可能性,您可以在其中为 ezstripe 贡献您的作品以改进体验!
许可证
我花费了几个小时编写代码并为结构体中的每个成员创建内容。所以请尊重我的时间和工作。
本项目采用 MIT 许可证。
依赖关系
~3–18MB
~243K SLoC