pub struct LagoClient { /* private fields */ }Expand description
The main client for interacting with the Lago API
This client handles HTTP requests, authentication, retries, and error handling when communicating with the Lago billing API.
Implementations§
Source§impl LagoClient
Activity log-related operations for the Lago client
impl LagoClient
Activity log-related operations for the Lago client
Sourcepub async fn list_activity_logs(
&self,
request: Option<ListActivityLogsRequest>,
) -> Result<ListActivityLogsResponse>
pub async fn list_activity_logs( &self, request: Option<ListActivityLogsRequest>, ) -> Result<ListActivityLogsResponse>
Sourcepub async fn get_activity_log(
&self,
request: GetActivityLogRequest,
) -> Result<GetActivityLogResponse>
pub async fn get_activity_log( &self, request: GetActivityLogRequest, ) -> Result<GetActivityLogResponse>
Source§impl LagoClient
API log-related operations for the Lago client
impl LagoClient
API log-related operations for the Lago client
Sourcepub async fn list_api_logs(
&self,
request: Option<ListApiLogsRequest>,
) -> Result<ListApiLogsResponse>
pub async fn list_api_logs( &self, request: Option<ListApiLogsRequest>, ) -> Result<ListApiLogsResponse>
Sourcepub async fn get_api_log(
&self,
request: GetApiLogRequest,
) -> Result<GetApiLogResponse>
pub async fn get_api_log( &self, request: GetApiLogRequest, ) -> Result<GetApiLogResponse>
Source§impl LagoClient
impl LagoClient
Sourcepub async fn list_applied_coupons(
&self,
request: Option<ListAppliedCouponsRequest>,
) -> Result<ListAppliedCouponsResponse>
pub async fn list_applied_coupons( &self, request: Option<ListAppliedCouponsRequest>, ) -> Result<ListAppliedCouponsResponse>
Sourcepub async fn apply_coupon(
&self,
request: ApplyCouponRequest,
) -> Result<ApplyCouponResponse>
pub async fn apply_coupon( &self, request: ApplyCouponRequest, ) -> Result<ApplyCouponResponse>
Source§impl LagoClient
impl LagoClient
Sourcepub async fn list_billable_metrics(
&self,
request: Option<ListBillableMetricsRequest>,
) -> Result<ListBillableMetricsResponse>
pub async fn list_billable_metrics( &self, request: Option<ListBillableMetricsRequest>, ) -> Result<ListBillableMetricsResponse>
Sourcepub async fn get_billable_metric(
&self,
request: GetBillableMetricRequest,
) -> Result<GetBillableMetricResponse>
pub async fn get_billable_metric( &self, request: GetBillableMetricRequest, ) -> Result<GetBillableMetricResponse>
Sourcepub async fn create_billable_metric(
&self,
request: CreateBillableMetricRequest,
) -> Result<CreateBillableMetricResponse>
pub async fn create_billable_metric( &self, request: CreateBillableMetricRequest, ) -> Result<CreateBillableMetricResponse>
Source§impl LagoClient
impl LagoClient
Sourcepub async fn list_coupons(
&self,
request: Option<ListCouponsRequest>,
) -> Result<ListCouponsResponse>
pub async fn list_coupons( &self, request: Option<ListCouponsRequest>, ) -> Result<ListCouponsResponse>
Sourcepub async fn get_coupon(
&self,
request: GetCouponRequest,
) -> Result<GetCouponResponse>
pub async fn get_coupon( &self, request: GetCouponRequest, ) -> Result<GetCouponResponse>
Sourcepub async fn create_coupon(
&self,
request: CreateCouponRequest,
) -> Result<CreateCouponResponse>
pub async fn create_coupon( &self, request: CreateCouponRequest, ) -> Result<CreateCouponResponse>
Sourcepub async fn update_coupon(
&self,
request: UpdateCouponRequest,
) -> Result<UpdateCouponResponse>
pub async fn update_coupon( &self, request: UpdateCouponRequest, ) -> Result<UpdateCouponResponse>
Sourcepub async fn delete_coupon(
&self,
request: DeleteCouponRequest,
) -> Result<DeleteCouponResponse>
pub async fn delete_coupon( &self, request: DeleteCouponRequest, ) -> Result<DeleteCouponResponse>
Source§impl LagoClient
Credit note-related operations for the Lago client
impl LagoClient
Credit note-related operations for the Lago client
Sourcepub async fn list_credit_notes(
&self,
request: Option<ListCreditNotesRequest>,
) -> Result<ListCreditNotesResponse>
pub async fn list_credit_notes( &self, request: Option<ListCreditNotesRequest>, ) -> Result<ListCreditNotesResponse>
Retrieves a list of credit notes with optional filtering parameters
§Arguments
request- Optional filtering parameters for the credit note list
§Returns
A Result containing the list of credit notes or an error
§Example
use lago_client::LagoClient;
use lago_types::requests::credit_note::ListCreditNotesRequest;
use lago_types::filters::credit_note::CreditNoteFilter;
let client = LagoClient::from_env()?;
let request = ListCreditNotesRequest::new()
.with_filters(CreditNoteFilter::new().with_external_customer_id("customer_123".to_string()));
let response = client.list_credit_notes(Some(request)).await?;
println!("Found {} credit notes", response.credit_notes.len());Sourcepub async fn get_credit_note(
&self,
request: GetCreditNoteRequest,
) -> Result<GetCreditNoteResponse>
pub async fn get_credit_note( &self, request: GetCreditNoteRequest, ) -> Result<GetCreditNoteResponse>
Retrieves a specific credit note by its Lago ID
§Arguments
request- The request containing the Lago ID to retrieve
§Returns
A Result containing the credit note data or an error
§Example
use lago_client::LagoClient;
use lago_types::requests::credit_note::GetCreditNoteRequest;
let client = LagoClient::from_env()?;
let request = GetCreditNoteRequest::new("1a901a90-1a90-1a90-1a90-1a901a901a90".to_string());
let response = client.get_credit_note(request).await?;
println!("Credit note number: {}", response.credit_note.number);Sourcepub async fn create_credit_note(
&self,
request: CreateCreditNoteRequest,
) -> Result<CreateCreditNoteResponse>
pub async fn create_credit_note( &self, request: CreateCreditNoteRequest, ) -> Result<CreateCreditNoteResponse>
Creates a new credit note
Credit notes are issued to refund or credit customers for invoices, either partially or in full.
§Arguments
request- The request containing the credit note data to create
§Returns
A Result containing the created credit note or an error
§Example
use lago_client::LagoClient;
use lago_types::requests::credit_note::{
CreateCreditNoteInput, CreateCreditNoteItemInput, CreateCreditNoteRequest,
};
use lago_types::models::CreditNoteReason;
let client = LagoClient::from_env()?;
let items = vec![
CreateCreditNoteItemInput::new("fee_lago_id".to_string(), 1000),
];
let input = CreateCreditNoteInput::new(
"invoice_lago_id".to_string(),
CreditNoteReason::Other,
1000,
0,
items,
)
.with_description("Credit for billing error".to_string());
let request = CreateCreditNoteRequest::new(input);
let response = client.create_credit_note(request).await?;
println!("Created credit note: {}", response.credit_note.number);Sourcepub async fn update_credit_note(
&self,
request: UpdateCreditNoteRequest,
) -> Result<UpdateCreditNoteResponse>
pub async fn update_credit_note( &self, request: UpdateCreditNoteRequest, ) -> Result<UpdateCreditNoteResponse>
Updates an existing credit note
Currently, only the refund_status can be updated on a credit note.
§Arguments
request- The request containing the Lago ID and update data
§Returns
A Result containing the updated credit note or an error
§Example
use lago_client::LagoClient;
use lago_types::requests::credit_note::{UpdateCreditNoteInput, UpdateCreditNoteRequest};
use lago_types::models::CreditNoteRefundStatus;
let client = LagoClient::from_env()?;
let input = UpdateCreditNoteInput::new()
.with_refund_status(CreditNoteRefundStatus::Succeeded);
let request = UpdateCreditNoteRequest::new(
"1a901a90-1a90-1a90-1a90-1a901a901a90".to_string(),
input,
);
let response = client.update_credit_note(request).await?;
println!("Updated credit note: {}", response.credit_note.number);Source§impl LagoClient
impl LagoClient
Sourcepub async fn list_customers(
&self,
request: Option<ListCustomersRequest>,
) -> Result<ListCustomersResponse>
pub async fn list_customers( &self, request: Option<ListCustomersRequest>, ) -> Result<ListCustomersResponse>
Sourcepub async fn get_customer(
&self,
request: GetCustomerRequest,
) -> Result<GetCustomerResponse>
pub async fn get_customer( &self, request: GetCustomerRequest, ) -> Result<GetCustomerResponse>
Sourcepub async fn create_customer(
&self,
request: CreateCustomerRequest,
) -> Result<CreateCustomerResponse>
pub async fn create_customer( &self, request: CreateCustomerRequest, ) -> Result<CreateCustomerResponse>
Source§impl LagoClient
impl LagoClient
Sourcepub async fn get_customer_current_usage(
&self,
request: GetCustomerCurrentUsageRequest,
) -> Result<GetCustomerCurrentUsageResponse>
pub async fn get_customer_current_usage( &self, request: GetCustomerCurrentUsageRequest, ) -> Result<GetCustomerCurrentUsageResponse>
Retrieves the current usage for a customer’s subscription
This endpoint enables the retrieval of usage-based billing data for a customer within the current billing period.
§Arguments
request- The request containing the customer and subscription IDs
§Returns
A Result containing the customer usage data or an error
Source§impl LagoClient
impl LagoClient
Sourcepub async fn get_event(
&self,
request: GetEventRequest,
) -> Result<GetEventResponse>
pub async fn get_event( &self, request: GetEventRequest, ) -> Result<GetEventResponse>
Retrieves a specific event by its transaction ID
§Arguments
request- The request containing the transaction ID to retrieve
§Returns
A Result containing the event data or an error
§Example
use lago_client::LagoClient;
use lago_types::requests::event::GetEventRequest;
let client = LagoClient::from_env()?;
let request = GetEventRequest::new("transaction_123".to_string());
let response = client.get_event(request).await?;
println!("Event code: {}", response.event.code);Sourcepub async fn create_event(
&self,
request: CreateEventRequest,
) -> Result<CreateEventResponse>
pub async fn create_event( &self, request: CreateEventRequest, ) -> Result<CreateEventResponse>
Creates a new usage event
This endpoint is used for transmitting usage measurement events to either a designated customer or a specific subscription.
§Arguments
request- The request containing the event data to create
§Returns
A Result containing the created event acknowledgment or an error
§Example
use lago_client::LagoClient;
use lago_types::requests::event::{CreateEventInput, CreateEventRequest};
use serde_json::json;
let client = LagoClient::from_env()?;
let event_input = CreateEventInput::for_customer(
"transaction_456".to_string(),
"customer_123".to_string(),
"api_calls".to_string(),
)
.with_properties(json!({"calls": 150}));
let request = CreateEventRequest::new(event_input);
let response = client.create_event(request).await?;
println!("Event created: {}", response.event.transaction_id);Sourcepub async fn list_events(
&self,
request: Option<ListEventsRequest>,
) -> Result<ListEventsResponse>
pub async fn list_events( &self, request: Option<ListEventsRequest>, ) -> Result<ListEventsResponse>
Retrieves a list of events with optional filtering parameters
This endpoint is used for retrieving all events, with support for filtering by subscription, billable metric code, and timestamp range.
§Arguments
request- Optional request containing filter and pagination parameters. IfNone, returns all events with default pagination.
§Returns
A Result containing the list of events with pagination metadata or an error
§Example
use lago_client::LagoClient;
use lago_types::requests::event::ListEventsRequest;
use lago_types::models::PaginationParams;
let client = LagoClient::from_env()?;
// List all events
let events = client.list_events(None).await?;
println!("Found {} events", events.events.len());
// List events with filters
let request = ListEventsRequest::new()
.with_pagination(PaginationParams::new().with_per_page(50))
.with_external_subscription_id("sub_123".to_string())
.with_code("api_calls".to_string())
.with_timestamp_range(
"2024-01-01T00:00:00Z".to_string(),
"2024-01-31T23:59:59Z".to_string(),
);
let filtered_events = client.list_events(Some(request)).await?;Source§impl LagoClient
Invoice-related operations for the Lago client
impl LagoClient
Invoice-related operations for the Lago client
Sourcepub async fn list_invoices(
&self,
request: Option<ListInvoicesRequest>,
) -> Result<ListInvoicesResponse>
pub async fn list_invoices( &self, request: Option<ListInvoicesRequest>, ) -> Result<ListInvoicesResponse>
Sourcepub async fn get_invoice(
&self,
request: GetInvoiceRequest,
) -> Result<GetInvoiceResponse>
pub async fn get_invoice( &self, request: GetInvoiceRequest, ) -> Result<GetInvoiceResponse>
Sourcepub async fn preview_invoice(
&self,
request: InvoicePreviewRequest,
) -> Result<InvoicePreviewResponse>
pub async fn preview_invoice( &self, request: InvoicePreviewRequest, ) -> Result<InvoicePreviewResponse>
Previews an invoice without creating it
This endpoint allows you to retrieve an estimated invoice before finalization. It can be used to preview invoices for new subscriptions or existing customers.
§Arguments
request- The invoice preview request containing customer and subscription details
§Returns
A Result containing the previewed invoice or an error
Sourcepub async fn create_invoice(
&self,
request: CreateInvoiceRequest,
) -> Result<CreateInvoiceResponse>
pub async fn create_invoice( &self, request: CreateInvoiceRequest, ) -> Result<CreateInvoiceResponse>
Sourcepub async fn update_invoice(
&self,
request: UpdateInvoiceRequest,
) -> Result<UpdateInvoiceResponse>
pub async fn update_invoice( &self, request: UpdateInvoiceRequest, ) -> Result<UpdateInvoiceResponse>
Sourcepub async fn list_customer_invoices(
&self,
request: ListCustomerInvoicesRequest,
) -> Result<ListInvoicesResponse>
pub async fn list_customer_invoices( &self, request: ListCustomerInvoicesRequest, ) -> Result<ListInvoicesResponse>
Sourcepub async fn refresh_invoice(
&self,
request: RefreshInvoiceRequest,
) -> Result<RefreshInvoiceResponse>
pub async fn refresh_invoice( &self, request: RefreshInvoiceRequest, ) -> Result<RefreshInvoiceResponse>
Sourcepub async fn download_invoice(
&self,
request: DownloadInvoiceRequest,
) -> Result<DownloadInvoiceResponse>
pub async fn download_invoice( &self, request: DownloadInvoiceRequest, ) -> Result<DownloadInvoiceResponse>
Downloads an invoice PDF
This endpoint triggers the generation of the invoice PDF if not already generated, and returns the invoice with a file_url field containing the URL to download the PDF.
§Arguments
request- The request containing the invoice ID to download
§Returns
A Result containing the invoice with file_url or an error
Sourcepub async fn retry_invoice(
&self,
request: RetryInvoiceRequest,
) -> Result<RetryInvoiceResponse>
pub async fn retry_invoice( &self, request: RetryInvoiceRequest, ) -> Result<RetryInvoiceResponse>
Sourcepub async fn retry_invoice_payment(
&self,
request: RetryInvoicePaymentRequest,
) -> Result<RetryInvoicePaymentResponse>
pub async fn retry_invoice_payment( &self, request: RetryInvoicePaymentRequest, ) -> Result<RetryInvoicePaymentResponse>
Retries a failed invoice payment
This endpoint resends the invoice for collection and retries the payment with the payment provider. Only invoices with failed payment status can be retried.
§Arguments
request- The request containing the invoice ID to retry payment for
§Returns
A Result containing the invoice or an error
Sourcepub async fn void_invoice(
&self,
request: VoidInvoiceRequest,
) -> Result<VoidInvoiceResponse>
pub async fn void_invoice( &self, request: VoidInvoiceRequest, ) -> Result<VoidInvoiceResponse>
Source§impl LagoClient
Payment-related operations for the Lago client
impl LagoClient
Payment-related operations for the Lago client
Sourcepub async fn list_payments(
&self,
request: Option<ListPaymentsRequest>,
) -> Result<ListPaymentsResponse>
pub async fn list_payments( &self, request: Option<ListPaymentsRequest>, ) -> Result<ListPaymentsResponse>
Sourcepub async fn get_payment(
&self,
request: GetPaymentRequest,
) -> Result<GetPaymentResponse>
pub async fn get_payment( &self, request: GetPaymentRequest, ) -> Result<GetPaymentResponse>
Sourcepub async fn create_payment(
&self,
request: CreatePaymentRequest,
) -> Result<CreatePaymentResponse>
pub async fn create_payment( &self, request: CreatePaymentRequest, ) -> Result<CreatePaymentResponse>
Sourcepub async fn list_customer_payments(
&self,
request: ListCustomerPaymentsRequest,
) -> Result<ListPaymentsResponse>
pub async fn list_customer_payments( &self, request: ListCustomerPaymentsRequest, ) -> Result<ListPaymentsResponse>
Source§impl LagoClient
impl LagoClient
Sourcepub async fn list_plans(
&self,
request: Option<ListPlansRequest>,
) -> Result<ListPlansResponse>
pub async fn list_plans( &self, request: Option<ListPlansRequest>, ) -> Result<ListPlansResponse>
Sourcepub async fn get_plan(&self, request: GetPlanRequest) -> Result<GetPlanResponse>
pub async fn get_plan(&self, request: GetPlanRequest) -> Result<GetPlanResponse>
Sourcepub async fn create_plan(
&self,
request: CreatePlanRequest,
) -> Result<CreatePlanResponse>
pub async fn create_plan( &self, request: CreatePlanRequest, ) -> Result<CreatePlanResponse>
Sourcepub async fn update_plan(
&self,
request: UpdatePlanRequest,
) -> Result<UpdatePlanResponse>
pub async fn update_plan( &self, request: UpdatePlanRequest, ) -> Result<UpdatePlanResponse>
Sourcepub async fn delete_plan(
&self,
request: DeletePlanRequest,
) -> Result<DeletePlanResponse>
pub async fn delete_plan( &self, request: DeletePlanRequest, ) -> Result<DeletePlanResponse>
Source§impl LagoClient
impl LagoClient
Sourcepub async fn list_subscriptions(
&self,
request: Option<ListSubscriptionsRequest>,
) -> Result<ListSubscriptionsResponse>
pub async fn list_subscriptions( &self, request: Option<ListSubscriptionsRequest>, ) -> Result<ListSubscriptionsResponse>
Sourcepub async fn get_subscription(
&self,
request: GetSubscriptionRequest,
) -> Result<GetSubscriptionResponse>
pub async fn get_subscription( &self, request: GetSubscriptionRequest, ) -> Result<GetSubscriptionResponse>
Sourcepub async fn list_customer_subscriptions(
&self,
request: ListCustomerSubscriptionsRequest,
) -> Result<ListSubscriptionsResponse>
pub async fn list_customer_subscriptions( &self, request: ListCustomerSubscriptionsRequest, ) -> Result<ListSubscriptionsResponse>
Sourcepub async fn create_subscription(
&self,
request: CreateSubscriptionRequest,
) -> Result<CreateSubscriptionResponse>
pub async fn create_subscription( &self, request: CreateSubscriptionRequest, ) -> Result<CreateSubscriptionResponse>
Sourcepub async fn update_subscription(
&self,
request: UpdateSubscriptionRequest,
) -> Result<UpdateSubscriptionResponse>
pub async fn update_subscription( &self, request: UpdateSubscriptionRequest, ) -> Result<UpdateSubscriptionResponse>
Sourcepub async fn delete_subscription(
&self,
request: DeleteSubscriptionRequest,
) -> Result<DeleteSubscriptionResponse>
pub async fn delete_subscription( &self, request: DeleteSubscriptionRequest, ) -> Result<DeleteSubscriptionResponse>
Trait Implementations§
Source§impl Clone for LagoClient
impl Clone for LagoClient
Source§fn clone(&self) -> LagoClient
fn clone(&self) -> LagoClient
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more