use snippe::models::session::{AllowedMethod, CreateSessionRequest, SessionCustomer};
use snippe::{Client, IdempotencyKey};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let api_key = std::env::var("SNIPPE_API_KEY").expect("set SNIPPE_API_KEY");
let client = Client::new(api_key)?;
let request = CreateSessionRequest::fixed_amount(50_000)
.with_allowed_methods([AllowedMethod::MobileMoney, AllowedMethod::Qr])
.with_customer(
SessionCustomer::new("John Doe")
.with_phone("+255712345678")
.with_email("john@example.com"),
)
.with_redirect_url("https://yoursite.com/order/12345/success")
.with_webhook_url("https://yoursite.com/webhooks/snippe")
.with_description("Order #12345");
let key = IdempotencyKey::new("sess-12345-att-1")?;
let session = client.sessions().create(&request, Some(&key)).await?;
println!("session: {}", session.reference);
println!("share this URL with the customer: {}",
session.payment_link_url.as_deref().unwrap_or(&session.checkout_url));
Ok(())
}