use bachs_sdk::checkout_sessions::{CheckoutCustomer, CreateCheckoutSessionRequest, ProductCartItem};
use bachs_sdk::customers::CreateCustomerRequest;
use bachs_sdk::Bachs;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let api_key = std::env::var("BACHS_API_KEY")
.expect("set BACHS_API_KEY to a sandbox key (sk_sandbox_...)");
let bachs = Bachs::new(api_key)?;
let customer = bachs
.customers()
.create(&CreateCustomerRequest::new("customer@example.com").name("Ada Lovelace"))
.await?;
println!("created customer {} ({})", customer.customer_id, customer.email);
let session = bachs
.checkout_sessions()
.create(
&CreateCheckoutSessionRequest::new(
vec![ProductCartItem::new("prod_abc123", 1)],
CheckoutCustomer::existing(&customer.customer_id),
"https://yoursite.com/success",
)
.cancel_url("https://yoursite.com/cancelled"),
)
.await?;
println!("checkout url: {}", session.url);
Ok(())
}