loopback-component-package
Version:
Package/Pricing management for loopback API server
80 lines (68 loc) • 1.9 kB
Markdown
# loopback-component-package
### Package/Pricing management for loopback API server
[](https://travis-ci.org/Minab-Tech/loopback-component-package)
### Installation :
```sh
$ npm install loopback-component-package --save
```
``
then add the following to `component-config.json` file
```
{
"loopback-component-explorer": {
"mountPath": "/explorer"
},
"loopback-component-package": {
"dataSource": "mongodb",
"packages": [
{
"name": "SMS",
"type": "monthly",
"reset": true
},
{
"name": "EMAIL",
"type": "daily",
"reset": false
}
],
"types":[
"daily",
"weekly",
"monthly",
"semiyearly",
"yearly"
]
}
}
```
### usage:
do this before using package element, eg: if you let your user to send 500 SMS per month:
##### create the package:
```
Package.createPackage('SMS-Package','monthly',true).then(function(package){
//do something here
});
```
##### then register the package for the user:
```
Package.registerPackage(package.id,500,true,0).then(function(packageUsage){
//this will return a token, store the token somewhere on your app
// because you are going to need the token from now on.
});
```
##### then use the use method before the user sends SMS
```
Package.use(token,1).then(function(usage){
//it will return current package usage count
// it will return -1 if the package reached/passed its limit
// if it returns -1 then you won't send the SMS for that user
// and obviously if it returns count then the user is good to go
});
```
### to run the test do:
```sh
$ npm install
$ npm test
```
[](http://minabtech.com/)