LagoClient

Struct LagoClient 

Source
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

Source

pub fn new(config: Config) -> Self

Creates a new Lago client with the provided configuration

§Arguments
  • config - The configuration settings for the client
§Returns

A new instance of LagoClient

Source

pub fn from_env() -> Result<Self>

Creates a new Lago client using default configuration from environment variables

This method will use default settings and attempt to load credentials from environment variables.

§Returns

A Result containing a new LagoClient instance or an error

Source§

impl LagoClient

Activity log-related operations for the Lago client

Source

pub async fn list_activity_logs( &self, request: Option<ListActivityLogsRequest>, ) -> Result<ListActivityLogsResponse>

Retrieves a list of activity logs with optional filtering parameters

§Arguments
  • request - Optional filtering parameters for the activity log list
§Returns

A Result containing the list of activity logs or an error

Source

pub async fn get_activity_log( &self, request: GetActivityLogRequest, ) -> Result<GetActivityLogResponse>

Retrieves a specific activity log by its activity ID

§Arguments
  • request - The request containing the activity log ID to retrieve
§Returns

A Result containing the activity log data or an error

Source§

impl LagoClient

API log-related operations for the Lago client

Source

pub async fn list_api_logs( &self, request: Option<ListApiLogsRequest>, ) -> Result<ListApiLogsResponse>

Retrieves a list of API logs with optional filtering parameters

§Arguments
  • request - Optional filtering parameters for the API log list
§Returns

A Result containing the list of API logs or an error

Source

pub async fn get_api_log( &self, request: GetApiLogRequest, ) -> Result<GetApiLogResponse>

Retrieves a specific API log by its request ID

§Arguments
  • request - The request containing the API log request ID to retrieve
§Returns

A Result containing the API log data or an error

Source§

impl LagoClient

Source

pub async fn list_applied_coupons( &self, request: Option<ListAppliedCouponsRequest>, ) -> Result<ListAppliedCouponsResponse>

Retrieves a list of applied coupons with optional filtering parameters

§Arguments
  • request - Optional filtering parameters for the applied coupon list
§Returns

A Result containing the list of applied coupons or an error

Source

pub async fn apply_coupon( &self, request: ApplyCouponRequest, ) -> Result<ApplyCouponResponse>

Applies a coupon to a customer

§Arguments
  • request - The request containing the coupon application data
§Returns

A Result containing the applied coupon data or an error

Source§

impl LagoClient

Source

pub async fn list_billable_metrics( &self, request: Option<ListBillableMetricsRequest>, ) -> Result<ListBillableMetricsResponse>

Retrieves a list of billable metrics with optional filtering parameters

§Arguments
  • request - Optional filtering parameters for the billable metric list
§Returns

A Result containing the list of billable metrics or an error

Source

pub async fn get_billable_metric( &self, request: GetBillableMetricRequest, ) -> Result<GetBillableMetricResponse>

Retrieves a specific billable metric by its code

§Arguments
  • request - The request containing the billable metric code to retrieve
§Returns

A Result containing the billable metric data or an error

Source

pub async fn create_billable_metric( &self, request: CreateBillableMetricRequest, ) -> Result<CreateBillableMetricResponse>

Creates a new billable metric

§Arguments
  • request - The request containing the billable metric data to create
§Returns

A Result containing the created billable metric data or an error

Source§

impl LagoClient

Source

pub async fn list_coupons( &self, request: Option<ListCouponsRequest>, ) -> Result<ListCouponsResponse>

Retrieves a list of coupons with optional filtering parameters

§Arguments
  • request - Optional filtering parameters for the coupon list
§Returns

A Result containing the list of coupons or an error

Source

pub async fn get_coupon( &self, request: GetCouponRequest, ) -> Result<GetCouponResponse>

Retrieves a coupon by its code

§Arguments
  • request - The request containing the coupon code to retrieve
§Returns

A Result containing the coupon data or an error

Source

pub async fn create_coupon( &self, request: CreateCouponRequest, ) -> Result<CreateCouponResponse>

Creates a new coupon

§Arguments
  • request - The request containing the coupon data to create
§Returns

A Result containing the created coupon data or an error

Source

pub async fn update_coupon( &self, request: UpdateCouponRequest, ) -> Result<UpdateCouponResponse>

Updates an existing coupon

§Arguments
  • request - The request containing the coupon code and update data
§Returns

A Result containing the updated coupon data or an error

Source

pub async fn delete_coupon( &self, request: DeleteCouponRequest, ) -> Result<DeleteCouponResponse>

Deletes a coupon by its code

§Arguments
  • request - The request containing the coupon code to delete
§Returns

A Result containing the deleted coupon data or an error

Source§

impl LagoClient

Credit note-related operations for the Lago client

Source

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());
Source

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);
Source

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);
Source

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

Source

pub async fn list_customers( &self, request: Option<ListCustomersRequest>, ) -> Result<ListCustomersResponse>

Retrieves a list of customers with optional filtering parameters

§Arguments
  • request - Optional filtering parameters for the customer list
§Returns

A Result containing the list of customers or an error

Source

pub async fn get_customer( &self, request: GetCustomerRequest, ) -> Result<GetCustomerResponse>

Retrieves a specific customer by their external ID

§Arguments
  • request - The request containing the customer external ID to retrieve
§Returns

A Result containing the customer data or an error

Source

pub async fn create_customer( &self, request: CreateCustomerRequest, ) -> Result<CreateCustomerResponse>

Creates a new customer

§Arguments
  • request - The request containing the customer data to create
§Returns

A Result containing the created customer data or an error

Source§

impl LagoClient

Source

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

Source

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);
Source

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);
Source§

impl LagoClient

Invoice-related operations for the Lago client

Source

pub async fn list_invoices( &self, request: Option<ListInvoicesRequest>, ) -> Result<ListInvoicesResponse>

Retrieves a list of invoices with optional filtering parameters

§Arguments
  • request - Optional filtering parameters for the invoice list
§Returns

A Result containing the list of invoices or an error

Source

pub async fn get_invoice( &self, request: GetInvoiceRequest, ) -> Result<GetInvoiceResponse>

Retrieves a specific invoice by its ID

§Arguments
  • request - The request containing the invoice ID to retrieve
§Returns

A Result containing the invoice data or an error

Source

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

Source§

impl LagoClient

Source

pub async fn list_plans( &self, request: Option<ListPlansRequest>, ) -> Result<ListPlansResponse>

Lists all plans with optional filters and pagination.

§Arguments
  • request - Optional request with pagination and filter parameters
§Returns

A Result containing the list of plans or an error

Source

pub async fn get_plan(&self, request: GetPlanRequest) -> Result<GetPlanResponse>

Retrieves a specific plan by its code.

§Arguments
  • request - The request containing the plan’s code
§Returns

A Result containing the plan or an error

Source

pub async fn create_plan( &self, request: CreatePlanRequest, ) -> Result<CreatePlanResponse>

Creates a new plan.

§Arguments
  • request - The plan creation request with all plan details
§Returns

A Result containing the created plan or an error

Source

pub async fn update_plan( &self, request: UpdatePlanRequest, ) -> Result<UpdatePlanResponse>

Updates an existing plan.

§Arguments
  • request - The plan update request with the code and update data
§Returns

A Result containing the updated plan or an error

Source

pub async fn delete_plan( &self, request: DeletePlanRequest, ) -> Result<DeletePlanResponse>

Deletes a plan.

§Arguments
  • request - The delete request containing the plan’s code
§Returns

A Result containing the deleted plan or an error

Source§

impl LagoClient

Source

pub async fn list_subscriptions( &self, request: Option<ListSubscriptionsRequest>, ) -> Result<ListSubscriptionsResponse>

Lists all subscriptions with optional filters and pagination.

§Arguments
  • request - Optional request with pagination and filter parameters
§Returns

A Result containing the list of subscriptions or an error

Source

pub async fn get_subscription( &self, request: GetSubscriptionRequest, ) -> Result<GetSubscriptionResponse>

Retrieves a specific subscription by its external ID.

§Arguments
  • request - The request containing the subscription’s external ID
§Returns

A Result containing the subscription or an error

Source

pub async fn list_customer_subscriptions( &self, request: ListCustomerSubscriptionsRequest, ) -> Result<ListSubscriptionsResponse>

Lists all subscriptions for a specific customer.

§Arguments
  • request - The request containing the customer’s external ID and optional filters
§Returns

A Result containing the list of subscriptions or an error

Source

pub async fn create_subscription( &self, request: CreateSubscriptionRequest, ) -> Result<CreateSubscriptionResponse>

Creates a new subscription.

§Arguments
  • request - The subscription creation request with customer and plan details
§Returns

A Result containing the created subscription or an error

Source

pub async fn update_subscription( &self, request: UpdateSubscriptionRequest, ) -> Result<UpdateSubscriptionResponse>

Updates an existing subscription.

§Arguments
  • request - The subscription update request with the external ID and update data
§Returns

A Result containing the updated subscription or an error

Source

pub async fn delete_subscription( &self, request: DeleteSubscriptionRequest, ) -> Result<DeleteSubscriptionResponse>

Deletes (terminates) a subscription.

§Arguments
  • request - The delete request containing the subscription’s external ID
§Returns

A Result containing the terminated subscription or an error

Trait Implementations§

Source§

impl Clone for LagoClient

Source§

fn clone(&self) -> LagoClient

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more