A Rust SDK for integrating with the AbacatePay payment platform
- Create one-time billings with PIX payment method
- List existing billings
Add this to your Cargo.toml
:
[dependencies]
abacatepay-rust-sdk = "0.1.2"
use abacatepay_rust_sdk::AbacatePay;
let client = AbacatePay::new("your_api_key".to_string());
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(())
}
#[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(())
}
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
pub enum BillingStatus {
PENDING,
EXPIRED,
CANCELLED,
PAID,
REFUNDED,
}
pub enum BillingMethods {
Pix,
}
pub struct CreateBillingProduct {
pub external_id: String,
pub name: String,
pub quantity: i64,
pub price: f64,
pub description: Option<String>,
}