Skip to content

Instantly share code, notes, and snippets.

@pat-whitrock
Created June 17, 2016 16:55
Show Gist options
  • Save pat-whitrock/f95f8d0d523d3b22a46229e267221eff to your computer and use it in GitHub Desktop.
Save pat-whitrock/f95f8d0d523d3b22a46229e267221eff to your computer and use it in GitHub Desktop.
Account Balance Plan
  • Goal

    • charges table becomes balance_adjustments table
    • Credit and Debit models inherit (STI) from BalanceAdjustment
      • add type column (:credit, :debit)
    • Account balance is Debit amounts less Credit amounts
    • Debits are created when ad spend is purchased
      • amount is the amount of FB dollars received
      • not the amount of dollars spent via stripe
        • this isn’t persisted
        • it can be gotten via stripe
      • must have a stripe_charge_id
    • Credits are created when campaigns are published
      • must have a campaign_id
    • Credits are updated when campaigns are ended/paused without achieving budget
      • amount is updated to the amount actually spent
    • NOTE: There is no real state machine on Campaign right now, so campaigns aren’t “paused” or “published” or “draft"
      • For now, create a debit when the campaign is created
      • Follow-up pr to update credits for ended campaigns
        • We need to track which campaigns have ended
          • Need to get that info from FBAA via reports job or another scheduled job
    • Questions:
      • What do we do about the charges we’re persisting for subscriptions?
        • The only thing we kind of care about is the stripe_charge_id, but we don’t really need that
        • It doesn’t belong on the balance_adjustments table
        • It’s not a good enough reason to keep the charges table around as its own thing
  • Plan

    • Change charges table name to balance_adjustments
    • Columns to drop from balance_adjustments
      • charge_id
      • monthly_amount
      • package_name
      • total_amount
      • promotion_id
      • fb_amount
      • fb_bonus
      • subscription_plan
      • ad_spend_package
    • Columns to add to balance_adjustments
      • type (for STI)
      • campaign_id (used by credits)
    • Run script
      • set “type” to “debit” for all existing charges
      • update “amount” to FB dollars earned, not dollars charged by stripe
      • create credits for all campaigns
  • Alternative Goal

    • Use Charge#amount and Campaign#budget to determine account balance
      • Use Campaign#spend instead of Campaign#budget when available (have to get this from FBAA)
    • Have to change Charge#amount we persist from stripe amount to FB amount
    • Also have to run script to change Charge#amount for existing charges
    • Exclude charges for subscriptions
  • Additional notes

    • We should drop the promotions and redemptions tables and remove their models
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment