1 unstable release
new 0.1.2 | Jan 13, 2025 |
---|
#1656 in Web programming
18KB
390 lines
AbacatePay Rust SDK
A Rust SDK for integrating with the AbacatePay payment platform
Features
- Create one-time billings with PIX payment method
- List existing billings
Installation
Add this to your Cargo.toml
:
[dependencies]
abacatepay-rust-sdk = "0.1.2"
Usage
Creating a Client
use abacatepay_rust_sdk::AbacatePay;
let client = AbacatePay::new("your_api_key".to_string());
Creating a Billing
use abacatepay_rust_sdk::{AbacatePay, BillingKind, BillingMethods, CreateBillingProduct};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = AbacatePay::new("api_key".to_string());
let billing = client
.create_billing()
.frequency(BillingKind::OneTime)
.method(BillingMethods::Pix)
.product(CreateBillingProduct {
external_id: "123".to_string(),
name: "Product".to_string(),
quantity: 1,
price: 100.0,
description: Some("Description".to_string()),
})
.return_url("http://localhost:3000/".to_string())
.completion_url("http://localhost:3000/".to_string())
.build()
.await?;
println!("Created billing: {:?}", billing);
Ok(())
}
Listing Billings
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = AbacatePay::new("api_key".to_string());
let billings = client.list_billings().await?;
println!("All billings: {:?}", billings);
Ok(())
}
API Reference
Billing Creation Options
The billing builder supports the following methods:
frequency(BillingKind)
: Set the billing frequency (currently supportsOneTime
)method(BillingMethods)
: Add a payment method (currently supportsPix
)product(CreateBillingProduct)
: Add a product to the billingreturn_url(String)
: Set the return URL for the billingcompletion_url(String)
: Set the completion URL for the billingcustomer_id(String)
: Set an optional customer ID
Data Types
BillingStatus
pub enum BillingStatus {
PENDING,
EXPIRED,
CANCELLED,
PAID,
REFUNDED,
}
BillingMethods
pub enum BillingMethods {
Pix,
}
CreateBillingProduct
pub struct CreateBillingProduct {
pub external_id: String,
pub name: String,
pub quantity: i64,
pub price: f64,
pub description: Option<String>,
}
Dependencies
~11–24MB
~335K SLoC