Skip to content
rymai edited this page Feb 16, 2012 · 14 revisions

Newsletter Deals

Idea

The link in the newsletter will direct to https://my.sublimevideo.net/d/rts1

  • d is for deal
  • rts1 is the token of the deal.

Note:

  • The user has to be logged-in to be able to activate a deal.
  • The user has to satisfy the deal's availability_scope scope to be able activate a deal.
  • A cookie is set in case the user doesn't have an account yet so the deal will be activated upon his first log-in (i.e. after sign-up).

Visiting such URL:

When a deal is currently available:

  • A sticky notice is shown to inform the user that the deal is currently available (in /sites, /sites/new and /sites/:token/plan/edit)
  • Discounted prices are shown in /sites/new and /sites/:token/plan/edit.

When a deal is used (for an invoice item):

  • Discount is displayed as "promotional discount" in the invoice.

New models

Deal

  • name: Real-Time Stats promotion #1
  • description: 20% discount on the Yearly plans
  • token: rts1
  • kind: yearly_plans_discount (other possible value is monthly_plans_discount, plans_discount and PLAN_NAME_plan_discount, e.g. plus_plan_discount)
  • value: 0.2 => 20% (can be nil because maybe it'd not be applicable for all deals)
  • availability_scope: subscribed_to_newsletter => A scope that defines which users have access to the deal
  • started_at/ended_at

In Plan, the #discounted?(site) method should:

  • take the latest activated deal for the site's user
  • if the site's trial started before the deal ended or if the deal is still active, return true if the deal is applicable to the tested plan
  • return nil otherwise

In Plan, the #discounted_percentage(site) method should:

  • return the deal's value if #discounted?(site) is true
  • return 0 otherwise

In Plan, the #price(site) method should:

  • return price * (1 - discounted_percentage(site))

DealActivation

Table: deal_activations

Keeps track of which deals a user has activated.

  • deal_id
  • user_id
  • activated_at

InvoiceItem

Table: invoice_items

New field to keep track of the deal used in an invoice item: deal_id

Deal::Stats (later)

Store stats about activated deals every day.

Collection: deals_stats

  • d => Day
  • activated: { 'rts1' => 1000 }
  • used: { 'rts1' => 200 }

Deploy

heroku run rake db:migrate

Deal.create!(token: 'rts1', name: 'Real-Time Stats promotion #1', description: '<strong>Exclusive Newsletter Promotion: Save 20%</strong> when you sign up for or upgrade to a yearly plan', kind: 'yearly_plans_discount', value: 0.2, availability_scope: 'newsletter(true)', started_at: Time.now.utc, ended_at: Time.utc(2012, 3, 1).midnight)