This is a ruby wrapper for Lago API
Install the gem and add to the application's Gemfile by executing:
$ bundle add lago-ruby-client
If bundler is not being used to manage dependencies, install the gem by executing:
$ gem install lago-ruby-client
require 'lago-ruby-client'
client = Lago::Api::Client.new({api_key: 'key'})
event = {
transaction_id: "__UNIQUE_ID__",
customer_id: "5eb02857-a71e-4ea2-bcf9-57d8885990ba",
code: "code",
timestamp: 1650893379,
properties: {
custom_field: "custom"
}
}
client.events.create(event)
event = {
transaction_id: "__UNIQUE_ID__",
subscription_ids: [
"5eb02857-a71e-4ea2-bcf9-57d8885990ba", "5eb01117-a71e-4ea2-bcf9-57d8885990ba"
],
code: "code",
timestamp: 1650893379,
properties: {
custom_field: "custom"
}
}
client.events.batch_create(event)
transaction_id = "6afadc2a-f28c-40a4-a868-35636f229765"
event = client.events.get(transaction_id)
customer = {
customer_id: "5eb02857-a71e-4ea2-bcf9-57d8885990ba",
address_line1: nil,
address_line2: nil,
city: nil,
country: nil,
email: "test@example.com",
legal_name: nil,
legal_number: nil,
logo_url: nil,
name: "test name",
phone: nil,
state: nil,
url: nil,
vat_rate: nil,
zipcode: nil,
billing_configuration: {
payment_provider: nil,
provider_customer_id: nil,
sync: true,
}
}
client.customers.create(customer)
customer_usage = client.customer.current_usage(customer_id, subscription_id)
params = {
status: 'succeeded'
}
client.invoices.update(params, '5eb02857-a71e-4ea2-bcf9-57d8885990ba')
client.invoices.get('5eb02857-a71e-4ea2-bcf9-57d8885990ba')
client.invoices.get_all({ per_page: 2, page: 3 })
client.invoices.download("5eb02857-a71e-4ea2-bcf9-57d8885990ba")
subscription = {
customer_id: "5eb02857-a71e-4ea2-bcf9-57d8885990ba",
plan_code: "code",
subscription_id: "sub-id",
name: "name",
unique_id: "unique-id"
billing_time: "anniversary"
}
client.subscriptions.create(subscription)
update_params = {
name: 'new name'
}
client.subscriptions.update(update_params, 'sub_id')
client.subscriptions.destroy('sub_id')
client.subscriptions.get_all({ customer_id: '123' })
applied_coupon = {
customer_id: "5eb02857-a71e-4ea2-bcf9-57d3a41bc6ba",
coupon_code: "code",
amount_cents: 123,
amount_currency: "EUR"
}
client.applied_coupons.create(applied_coupon)
applied_add_on = {
customer_id: "5eb02857-a71e-4ea2-bcf9-57d3a41bc6ba",
add_on_code: "code",
amount_cents: 123,
amount_currency: "EUR"
}
client.applied_add_ons.create(applied_add_on)
billable_metric = {
name: 'BM1',
code: 'code_bm',
description: 'description',
aggregation_type: 'sum_agg',
field_name: 'amount_sum',
}
client.billable_metrics.create(billable_metric)
update_params = {
description: 'description'
}
client.billable_metrics.update(update_params, 'code_bm')
client.billable_metrics.get('code_bm')
client.billable_metrics.destroy('code_bm')
client.billable_metrics.get_all({ per_page: 2, page: 3 })
add_on = {
name: 'add on name',
code: 'code',
description: 'description',
amount_cents: 100,
amount_currency: 'EUR',
}
client.add_ons.create(add_on)
update_params = {
description: 'description'
}
client.add_ons.update(update_params, 'code_bm')
client.add_ons.get('code_bm')
client.add_ons.destroy('code_bm')
client.add_ons.get_all({ per_page: 2, page: 3 })
coupon = {
name: 'coupon name',
code: 'code',
expiration: 'no_expiration',
expiration_duration: 10,
amount_cents: 100,
amount_currency: 'EUR',
}
client.coupons.create(coupon)
update_params = {
name: 'new name'
}
client.coupons.update(update_params, 'code_bm')
client.coupons.get('code_bm')
client.coupons.destroy('code_bm')
client.coupons.get_all({ per_page: 2, page: 3 })
plan = {
name: 'plan name',
code: 'code',
interval: 'monthly',
description: 'description',
amount_cents: 100,
amount_currency: 'EUR',
pay_in_advance: false,
charges: [
{
billable_metric_id: 'id',
amount_currency: 'EUR',
charge_model: 'standard',
properties: {
amount: 0.22
}
}
]
}
client.plans.create(plan)
update_params = {
name: 'new name'
}
client.plans.update(update_params, 'code_bm')
client.plans.get('code_bm')
client.plans.destroy('code_bm')
client.plans.get_all({ per_page: 2, page: 3 })
update_params = {
webhook_url: 'https://webhook_url.com',
vat_rate: 10
}
client.organizations.update(update_params)
bundle install
bundle exec rspec
The Lago documentation is available at doc.getlago.com.
The contribution documentation is available here
Lago Ruby client is distributed under AGPL-3.0.