profitwell
v1.0.1
Published
Unofficial Node.js bindings to the ProfitWell API - https://profitwellapiv2.docs.apiary.io/
Downloads
209
Readme
Installation
This client is intended for server side use only.
npm install profitwell --save
Usage
const ProfitWell = require('profitwell')
const profitWell = new ProfitWell({
apiToken: 'Wx15BlcpDfVPWbsTdNX<3'
})
Resources
Subscriptions
// Create a subscription
const response = await profitWell.subscriptions.create({
user_id: '7927fc01',
user_alias: 'luiz\'s alias',
subscription_alias: 'subscription\'s alias',
email: '[email protected]',
plan_id: 'standard_plan',
plan_interval: planInterval.monthly,
plan_currency: planCurrency.BRL,
status: subscriptionStatus.active,
value: 12000,
effective_date: 1514764800
})
// Upgrade/downgrade an existing subscription.
const response = await profitWell.subscriptions.update('7927fc01', {
plan_id: 'standard_plan',
plan_interval: planInterval.yearly,
status: subscriptionStatus.trialing,
value: 7500,
effective_date: 1522432854
})
// Churn subscription
const response = await profitWell.subscriptions.churn('7927fc01', {
churn_type: churnType.delinquent,
effective_date: 1522432854
})
// Unchurn subscription - Remove the churn event associated with a subscription.
const response = await profitWell.subscriptions.unchurn('7927fc01')
Users
// Get the history of subscription updates you've made to a user
const response = await profitWell.users.getSubscriptions('field')
// Update a user's email address
// This can actually be any sort of text, not necessarily an email address.
// Some prefer to store a name here instead
const response = await profitWell.users.update('luiz', { email: '[email protected]' })
// Completely delete a user and his subscription history
const response = await profitWell.users.delete('luiz')
Plans
// List all plans.
const response = await profitWell.plans.list()
// Create a new plan
const response = await profitWell.plans.create({
id: 'foo_plan',
name: 'Foo plan'
})
// Update the name of an existing plan
const response = await profitWell.plans.update('foo_plan', {
name: 'Foo plan'
})
Metrics
// Retrieve all monthly financial metrics for your company.
// Optionally scope to an individual metric and/or plan.
const response = await profitWell.metrics.getMonthly({
plan_id: 'field_plan',
metrics: [
monthlyMetrics.activeCustomers,
monthlyMetrics.churnedCustomersCancellations,
monthlyMetrics.churnedRecurringRevenue
]
})
// Retrieve financial metrics broken down by day for either the current month or the last.
// Optionally scope to an individual metric and/or plan.
const response = await profitWell.metrics.getDaily({
month: '2020-07',
plan_id: 'field_plan3',
metrics: [
dailyMetrics.futureChurnMRR,
dailyMetrics.upgradedRecurringRevenue,
dailyMetrics.reactivatedRecurringRevenue
]
})
// Exclude user's data from the calculation of all metrics.
const response = await profitWell.metrics.excludeCustomer('da044c6e')
Company
// Get your company's ProfitWell account settings.
const response = await profitWell.company.getSettings()
Pull Requests
- Add tests! Your patch won't be accepted if it doesn't have tests.
- Document any change in behaviour. Make sure the README and any other relevant documentation are kept up-to-date.
- Create topic branches. Don't ask us to pull from your master branch.
- One pull request per feature. If you want to do more than one thing, send multiple pull requests.
License
This project is licensed under the MIT License - see the LICENSE file for details.