This is a Node.js wrapper for Lago API
Install the lago-nodejs-client via npm:
$ npm install lago-nodejs-client
import Client from 'lago-nodejs-client'
let client = new Client('api_key')
import Event from 'lago-nodejs-client/event'
import BatchEvent from 'lago-nodejs-client/batch_event'
let event = new Event({
externalCustomerId: "5eb02857-a71e-4ea2-bcf9-57d8885990ba",
transactionId: "__UNIQUE_TRANSACTION_ID__",
code: "code",
timestamp: 1650893379,
properties: {custom_field: "custom"}
})
await client.createEvent(event);
let batchEvent = new BatchEvent({
externalSubscriptionIds: ["5eb02857-a71e-4ea2-bcf9-57d8885990ba", "75e02857-a71e-4ea2-bcf9-57d8885990ba"],
transactionId: "__UNIQUE_TRANSACTION_ID__",
code: "code",
timestamp: 1650893379,
properties: {custom_field: "custom"}
})
await client.createBatchEvent(batchEvent);
import Event from 'lago-nodejs-client/event'
let transactionId = 'transactionId';
let event = await client.findEvent(transactionId);
import Customer from 'lago-nodejs-client/customer'
let customer = new Customer(
"5eb02857-a71e-4ea2-bcf9-57d8885990ba", // externalId
None, // addressLine1
None, // addressLine2
None, // city
None, // country
"test@example.com", // email
None, // legalName
None, // legalNumber
None, // lagoUrl
"test name", // name
None, // phone
None, // state
None, // url
None, // vatRate
None, // zipcode
new BillingConfiguration(
"stripe",
"cus_12345",
false
)
)
await client.createCustomer(customer);
await client.findCustomer("5eb02857-a71e-4ea2-bcf9-57d8885990b");
await client.findAllCustomers({per_page: 2, page: 3});
let customerUsage = await client.customerCurrentUsage('external_customer_id', 'external_subscription_id')
import Subscription from 'lago-nodejs-client/subscription'
let subscription = new Subscription({
externalCustomerId: "5eb02857-a71e-4ea2-bcf9-57d8885990ba",
planCode: "code",
name: "name",
billingTime: "anniversary"
})
await client.createSubscription(subscription);
await client.updateSubscription(new Subscription({name: 'new name'}), 'external_id');
await client.destroySubscription('external_id');
await client.findAllSubscriptions({external_customer_id: '123'});
await client.updateInvoiceStatus({
lagoId: "5eb02857-a71e-4ea2-bcf9-57d8885990ba",
status: "succeeded"
})
await client.findInvoice("5eb02857-a71e-4ea2-bcf9-57d8885990b");
await client.findAllInvoices({per_page: 2, page: 3});
await client.downloadInvoice("5eb02857-a71e-4ea2-bcf9-57d8885990ba")
import AppliedCoupon from 'lago-nodejs-client/applied_coupon'
let appliedCoupon = new AppliedCoupon(
"5eb02857-a71e-4ea2-bcf9-57d8885990ba", // externalCustomerId
"code" // couponCode
)
await client.applyCoupon(appliedCoupon);
import AppliedAddOn from 'lago-nodejs-client/applied_add_on'
let appliedAddOn = new AppliedAddOn(
"5eb02857-a71e-4ea2-bcf9-57d8885990ba", // externalCustomerId
"code" // addOnCode
)
await client.applyAddOn(appliedAddOn);
import Organization from 'lago-nodejs-client/organization'
await client.updateOrganization(new Organization({
webhookUrl: "https://newwebhookurl.com",
vatRate: 15.5
}))
import BillableMetric from 'lago-nodejs-client/billable_metric'
let billableMetric = new BillableMetric({name: 'name1', code: 'code1', aggregationType: 'sum_agg',
fieldName: 'field_name'
})
await client.createBillableMetric(billableMetric);
await client.updateBillableMetric(new BillableMetric({name: 'new name', fieldName: 'new_field_name'}), 'code');
await client.findBillableMetric('code');
await client.destroyBillableMetric('code');
await client.findAllBillableMetrics({per_page: 2, page: 3});
import Coupon from 'lago-nodejs-client/coupon'
let coupon = new Coupon({name: 'name1', code: 'code1', expiration: 'no_expiration',
amountCents: 10000, amountCurrency: 'USD'
})
await client.createCoupon(coupon);
await client.updateCoupon(new Coupon({name: 'new name', code: 'new_code'}), 'code');
await client.findCoupon('code');
await client.destroyCoupon('code');
await client.findAllCoupons({per_page: 2, page: 3});
import AddOn from 'lago-nodejs-client/add_on'
let addOn = new AddOn({'name: name1', code: 'code1', amountCents: 10000, amountCurrency: 'USD',
description: 'description'
})
await client.createAddOn(addOn);
await client.updateAddOn(new AddOn({name: 'new name', code: 'new_code'}), 'code');
await client.findAddOn('code');
await client.destroyAddOn('code');
await client.findAllAddOns({per_page: 2, page: 3});
import Plan from 'lago-nodejs-client/plan'
import Charge from 'lago-nodejs-client/charge'
let charge = new Charge({billableMetricId: 'billable_metric_id', chargeModel: 'standard'})
let charges = [charge]
let plan = new Plan({name: 'name1', code: 'code1', interval: 'weekly', amountCents: 1000,
amountCurrency: 'USD', payInAdvance: true, trialPeriod: 2, description: 'decs',
billChargesMonthly: false, charges: charges
})
await client.createPlan(plan);
await client.updatePlan(plan, 'code');
await client.findPlan('code');
await client.destroyPlan('code');
await client.findAllPlans({per_page: 2, page: 3});
import Wallet from 'lago-nodejs-client/wallet'
let wallet = new Wallet({externalCustomerId: '123', rateAmount: '1', name: 'name',
paidCredits: '100', grantedCredits: '100', expirationDate: '2022-07-07'
})
await client.createWallet(wallet);
await client.updateWallet(new Wallet({name: 'new name'}), 'id');
await client.findWallet('id');
await client.destroyWallet('id');
await client.findAllWllets({external_customer_id: '123', per_page: 2, page: 3});
import WalletTransaction from 'lago-nodejs-client/wallet_transaction'
let transaction = new WalletTransaction({walletId: '123', paidCredits: '100', grantedCredits: '100'})
await client.createWalletTransaction(transaction);
yarn
yarn test
The Lago documentation is available at doc.getlago.com.
The contribution documentation is available here
Lago Node.js client is distributed under AGPL-3.0.