express = require("express") app = express() bodyParser = require('body-parser') app.use(bodyParser.json()) module.exports = MockRecurlyApi = subscriptions: {} accounts: {} redemptions: {} coupons: {} run: () -> app.get '/subscriptions/:id', (req, res, next) => subscription = @subscriptions[req.params.id] if !subscription? res.status(404).end() else res.send """ #{subscription.plan_code} #{subscription.currency} #{subscription.state} #{subscription.tax_in_cents} #{subscription.tax_rate} #{subscription.current_period_ends_at} #{subscription.unit_amount_in_cents} #{subscription.trial_ends_at} """ app.get '/accounts/:id', (req, res, next) => account = @accounts[req.params.id] if !account? res.status(404).end() else res.send """ #{req.params.id} #{account.hosted_login_token} """ app.get '/coupons/:code', (req, res, next) => coupon = @coupons[req.params.code] if !coupon? res.status(404).end() else res.send """ #{req.params.code} #{coupon.name or ''} #{coupon.description or ''} """ app.get '/accounts/:id/redemptions', (req, res, next) => redemptions = @redemptions[req.params.id] or [] redemptionsListXml = '' for redemption in redemptions redemptionsListXml += """ #{redemption.state} #{redemption.coupon_code} """ res.send """ #{redemptionsListXml} """ app.listen 6034, (error) -> throw error if error? MockRecurlyApi.run()