Facilities
A facility is an Organization
that has a type
: facility
. In this guide you will learn how to create main and branch facilities, start/cancel a trial/active subscription.
As soon as you verify an account's login credential(s), it can be used to create a facility
(though only one main facility is allowed to be associated to an account). That account will then be the owner
of the subscription
for the created facility
and be the only one allowed to manipulate it.
Creating a facility
A facility
(Organization
with type: 'facility'
) can be created using the organizations
API's create
method. it can optionally contain a subscription
object w/c will be used to create its subscription
Example
# Creating a free facility
curl <base-uri>/organizations \
-X POST \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer <access_token>",
-d "{
"type": "facility",
"types": ["aesthetics-clinic"], // for specialized facilities
"name": "My Clinic",
"superadmin": "account-uid-her"
}"
# Response
{
"id": "facility-id",
"createdAt": 12345567, // js timestamp
"createdBy": "some-uid",
"type": "facility",
"types": ["aesthetics-clinic"],
"name": "My Clinic"
}
# Creating a free facility while signing up
curl <base-uri>/accounts \
-X POST \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer <access_token>",
-d "{
"email": "email@domain.com",
"password": "password",
"personalDetails": {
"name": {
"firstName": "Name",
"lastName": "Last"
}
},
"organization": {
"type": "facility",
"types": ["aesthetics-clinic"], // for specialized facilities
"name": "My Clinic",
// optional subscription for starting trial/paid subscription instead of free
// "subscription": {
// ...payload
// }
}
}"
# Response
{
"uid": "some-id",
"createdAt": 12345567, // js timestamp
"email": "email@domain.com",
"organization": {
"id": "facility-id",
"createdAt": 12345567, // js timestamp
"createdBy": "some-uid",
"type": "facility",
"types": ["aesthetics-clinic"],
"name": "My Clinic"
// optional subscription object
// "subscription": { ...payload }
}
}
Adding / Replacing Credit Card
Credit card can be added immediately on create method (by adding stripeToken
field) or by patching stripeToken
field in the subscriptions
API
Stripe Subscription details
By adding the query operator $stripeSubscriptionExpand: true
in the query params, subscriptions
API's find
and get
method will populate the field stripeSubscription
with the stripe Subscription
object
Stripe Customer details
By adding the query operator $stripeCustomerExpand: true
in the query params, subscriptions
API's find
and get
method will populate the field stripeCustomer
with the stripe Customer
object
Starting a trial subscription
A trial subscription
can be made only when there are no previous active
subscription for the facility
where the trial
subscription
is intended. A trial subscription can be started using the subscriptions
API's create
or patch
method by providing a trial
flag as one of the fields in the payload
Caveats
storageMax
,doctorSeatsMax
,staffSeatsMax
cannot be set greater the their default (free) values when starting a trialtrial
mode is only available when the subscription has never been to anactive
status and has never been intrial
mode- when in
trial
mode,storageMax
,doctorSeatsMax
,staffSeatsMax
cannot be changed - a
child
facility cannot be created when ontrial
mode
Example
# Creating a free facility with trial subscription
curl <base-uri>/organizations \
-X POST \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer <access_token>",
-d "{
"type": "facility",
"types": ["aesthetics-clinic"], // for specialized facilities
"name": "My Clinic",
"subscription": {
// "storageMax": 2, // this will throw an error if included #refer to caveat
"trial": true, // aside from the caveates, this is the only difference between trial and paid
"lis": true, // if no billable flag was toggled, no stripe session will be created
"ris": true
}
}"
# Response
{
"id": "facility-id",
"createdAt": 12345567, // js timestamp
"createdBy": "some-uid",
"type": "facility",
"types": ["aesthetics-clinic"],
"name": "My Clinic",
"subscription": {
"id": "facility-id",
"createdAt": 12345567, // js timestamp
"createdBy": "some-uid",
"lis": false,
"ris": false,
"pendingUpdates": {
"stripeSession": "some-session-id",
"lis": true,
"ris": true
}
}
}
Starting with paid subscription
A paid subscription
can be made only when there are no previous subscription is associated to the creating account
. A paid subscription can be started using the subscriptions
API's create
or patch
method by providing flags for billable modules and/or providing values for storageMax
, doctorSeatsMax
, staffSeatsMax
that are greater than the base/free values (currently all 1
for all). the returned Subscription
object will then contain a Subscription.updatesPending.stripeSession
field w/c will contain the stripe session that can be used by the receiving client to redirect the user (via stripe checkout) to a page where billing details will be collected (implicitly confirming availment intent). A stripe webhook will then be fired by stripe that will be handled by the API w/c will update the current subscription (optionally applying pendingUpdates
to current subscription if the status is either active
or trialing
)
Caveats
- only one top-level (not child)
facility
can be made per account.
Examples
# Creating a facility with paid subscription
curl <base-uri>/organizations \
-X POST \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer <access_token>",
-d "{
"type": "facility",
"types": ["aesthetics-clinic"], // for specialized facilities
"name": "My Clinic",
"subscription": {
"storageMax": 2, // this will be billed as `n - base` storage plan, where base is the free value (1)
"lis": true, // if no billable flag or billable additions (storage, doctor/staff seats) was toggled, no stripe session will be created
"ris": true,
},
}"
# Response
{
"id": "facility-id",
"createdAt": 12345567, // js timestamp
"createdBy": "some-uid",
"type": "facility",
"types": ["aesthetics-clinic"],
"name": "My Clinic",
"subscription": {
"id": "facility-id",
"createdAt": 12345567, // js timestamp
"createdBy": "some-uid",
"lis": false,
"ris": false,
"pendingUpdates": {
"stripeSession": "some-session-id",
"storageMax": 2,
"lis": true,
"ris": true,
},
},
}
Availing/Discontuing additional modules, storage capacity, doctor/staff seats
Active subscriptions can add/remove modules
, storage capacity
, doctor/staff seats
by updating their Subscription
using the subscriptions
API's patch
method.
Caveats
- only active subscriptions can add additional modules, storage capacity, and seats
storageMax
must be an non-negative integer. it cannot be less than the currentstorageUsed
.doctorSeatsMax
must be an non-negative integer. it cannot be less than the currentdoctorSeatsOccupied
.staffSeatsMax
must be an non-negative integer. it cannot be less than the currentstaffSeatsOccupied
.
Examples
# Adding/removing modules, storage, and/or seats
curl <base-uri>/subscriptions/sub-id \
-X PATCH \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer <access_token>",
-d "{
"storageMax": 1, // move back to free. remove from billable subcription items
"doctorSeatsMax": 3, // add additional seat. (n - base) is billable, where base is the free value (1)
"lis": false, // discontinue LIS
"pme": true, // enable PME module
}"
# Response
{
"id": "sub-id",
"createdAt": 12345567, // js timestamp
"createdBy": "some-uid",
"status": "active",
"storageMax": 1,
"doctorSeatsMax": 3,
"lis": false,
"ris": true,
"pme": true,
"stripeSubscription": "stripe-subs-id",
"stripeCustomer": "stripe-customer-id"
}
Cancelling a trial susbcription
A trial
Subscription
can be cancelled (making the subscription active
, thus billing the customer) using the subscriptions
API's patch
method by providing a trial: false
flag in the update payload.
Examples
# Cancelling a trial subscription (subscription with `status`: 'trialing')
curl <base-uri>/subscriptions/sub-id \
-X PATCH \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer <access_token>",
-d "{
"trial": false // stop trial, proceed to paid subscription
}"
# Response
{
"id": "sub-id",
"createdAt": 12345567, // js timestamp
"createdBy": "some-uid",
"status": "active", // status becoms 'active' from 'trialing'
"storageMax": 1,
"trialStartedAt": 12345567,
"trialEndAt": 12345567,
"doctorSeatsMax": 3,
"lis": true,
"ris": true,
"pme": true,
"stripeSubscription": "stripe-subs-id",
"stripeCustomer": "stripe-customer-id"
}
Cancelling an active subscription
An active
Subscription
can be cancelled (returning everything to free
mode) using the subscriptions
API's patch
method by providing a cancel: true
flag in the update payload.
Examples
# Creating a free facility with trial subscription
curl <base-uri>/subscriptions/sub-id \
-X PATCH \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer <access_token>",
-d "{
"cancel": true // stop subscription, reverting to free facility
}"
# Response
{
"id": "sub-id",
"createdAt": 12345567, // js timestamp
"createdBy": "some-uid",
"status": "canceled",
"storageMax": 1,
"doctorSeatsMax": 1,
"lis": false,
"ris": false,
"pme": false,
"stripeSubscription": "stripe-subs-id",
"stripeCustomer": "stripe-customer-id"
}
Creating a branch facility
A branch
Facility
can be created using the organizations
API's create
method by providing a parent
field w/c is the id of the parent facility
. it can optionally contain a subscription
object w/c will be used to create its subscription
(w/ must also contain a parent
field pointing to its parent Subscription
if the user wishes to bill the branch subscription
to the existing parent Subscription
)
Caveats
- branch
Facility
s can only be created from an existing top-levelFacility
(not child) w/c has anactive
Subscription
Example
# Creating a branch facility
curl <base-uri>/organizations \
-X POST \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer <access_token>",
-d "{
"parent": "parent-facility-id",
"type": "facility",
"types": ["aesthetics-clinic"], // for specialized facilities
"name": "My Clinic",
"subscription": {
"parent": "parent-subscription-id", // so the billable items will be included in the parent subscription's stripe subscription instead of starting a new one
// any other field, same rule from "stargin trial/paid" subscription applies
},
}"
# Response
{
"id": "facility-id",
"createdAt": 12345567, // js timestamp
"createdBy": "some-uid",
"type": "facility",
"types": ["aesthetics-clinic"],
"name": "My Clinic"
}