A Rust SDK for integrating with the AbacatePay payment platform
- Create one-time billings with PIX payment method
- List existing billings
- Create PIX QR code charges
- Check PIX payment status
- Simulate PIX payments (for testing)
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(())
}
use abacatepay_rust_sdk::{AbacatePay, CustomerMetadata};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = AbacatePay::new("api_key".to_string());
// Create a basic PIX charge
let pix_charge = client
.create_pix_charge()
.amount(100.0)
.description(Some("Payment for services".to_string()))
.expires_in(Some(3600)) // Expires in 1 hour
.build()
.await?;
println!("Created PIX charge: {:?}", pix_charge);
println!("QR Code URL: {}", pix_charge.qrcode_image_url);
println!("PIX Copy-and-paste: {}", pix_charge.brcode);
// Create a PIX charge with customer information
let pix_charge_with_customer = client
.create_pix_charge()
.amount(150.0)
.description(Some("Product purchase".to_string()))
.customer(Some(CustomerMetadata {
name: "John Doe".to_string(),
email: "[email protected]".to_string(),
tax_id: "123.456.789-00".to_string(),
cellphone: "5511999999999".to_string(),
}))
.build()
.await?;
println!("Created PIX charge with customer: {:?}", pix_charge_with_customer);
Ok(())
}
use abacatepay_rust_sdk::AbacatePay;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = AbacatePay::new("api_key".to_string());
// Check status of a PIX payment
let payment_status = client
.check_pix_status("pix-charge-id".to_string())
.build()
.await?;
println!("Payment status: {:?}", payment_status.status);
Ok(())
}
use abacatepay_rust_sdk::AbacatePay;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = AbacatePay::new("api_key".to_string());
// Create a PIX charge first
let pix_charge = client
.create_pix_charge()
.amount(100.0)
.build()
.await?;
// Simulate a payment for the created charge
let payment_result = client
.create_simulate_pix_payment(pix_charge.id)
.build()
.await?;
println!("Payment simulation result: {:?}", payment_result);
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(())
}
use abacatepay_rust_sdk::{AbacatePay, CustomerMetadata};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = AbacatePay::new("api_key".to_string());
// Create a basic PIX charge
let pix_charge = client
.create_pix_charge()
.amount(100.0)
.description(Some("Payment for services".to_string()))
.expires_in(Some(3600)) // Expires in 1 hour
.build()
.await?;
println!("Created PIX charge: {:?}", pix_charge);
println!("QR Code URL: {}", pix_charge.qrcode_image_url);
println!("PIX Copy-and-paste: {}", pix_charge.brcode);
// Create a PIX charge with customer information
let pix_charge_with_customer = client
.create_pix_charge()
.amount(150.0)
.description(Some("Product purchase".to_string()))
.customer(Some(CustomerMetadata {
name: "John Doe".to_string(),
email: "[email protected]".to_string(),
tax_id: "123.456.789-00".to_string(),
cellphone: "5511999999999".to_string(),
}))
.build()
.await?;
println!("Created PIX charge with customer: {:?}", pix_charge_with_customer);
Ok(())
}
use abacatepay_rust_sdk::AbacatePay;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = AbacatePay::new("api_key".to_string());
// Create a PIX charge first
let pix_charge = client
.create_pix_charge()
.amount(100.0)
.build()
.await?;
// Simulate a payment for the created charge
let payment_result = client
.create_simulate_pix_payment(pix_charge.id)
.build()
.await?;
println!("Payment simulation result: {:?}", payment_result);
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
The PIX charge builder supports the following methods:
amount(f64)
: Set the charge amount in BRLexpires_in(Option<u64>)
: Set the expiration time in seconds (optional)description(Option<String>)
: Add a description for the charge (optional)customer(Option<CustomerMetadata>)
: Add customer information (optional)
The PIX status check builder supports the following methods:
id(String)
: Set or change the PIX charge ID to check status for
The PIX payment simulation builder supports the following methods:
id(String)
: Set or change the PIX charge ID to simulate payment for
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>,
}
pub struct CustomerMetadata {
pub name: String,
pub email: String,
pub tax_id: String,
pub cellphone: String,
}
The PixChargeData
structure contains information about a created PIX charge, including:
id
: The unique identifier for the PIX chargestatus
: The current status of the chargeqrcode_image_url
: URL to the QR code image that can be scanned for paymentbrcode
: The PIX copy-and-paste codeamount
: The charge amountcreated_at
: When the charge was createdexpires_at
: When the charge expires (if set)paid_at
: When the charge was paid (if applicable)
The CheckPixStatusData
structure contains information about the status of a PIX payment, including:
status
: The current status of the payment (e.g., PENDING, PAID, EXPIRED)paid_at
: When the payment was made (if applicable)