plan/unsubscribe

This commit is contained in:
jysperm
2014-05-14 12:05:22 +08:00
parent 179f1848f6
commit eb90b72d73
2 changed files with 31 additions and 0 deletions

View File

@@ -25,3 +25,7 @@ Request:
}
No Response.
Exception:
* not_in_plan

View File

@@ -40,3 +40,30 @@ module.exports =
return res.json {}
unsubscribe: (req, res) ->
mAccount.authenticate req.token, (account) ->
unless account
return res.json 400, error: 'auth_failed'
unless req.body.plan in account.attribute.plans
return res.json 400, error: 'not_in_plan'
billing.calcBiling account, (account) ->
async.each config.plans[req.body.plan].service, (serviceName, callback) ->
stillInService = do ->
for item in account.attribute.plans
if serviceName in config.plans[req.body.plan].service
return true
return false
if stillInService
callback()
else
mAccount.uodate _id: account._id,
$pull:
'attribute.service': serviceName
, {}, ->
(plugin.get serviceName).service.delete account, ->
callback()
, ->
return res.json {}