   # See https://docs.recurly.com/api/subscriptions for documentation
   #
 
-  subObj = (sub)->
+  createSubscriptionObject = (sub)->
     sub =
       plan        : sub.plan[0].plan_code[0]
       quantity    : sub.quantity[0]._

  # on subscription's renewal (typically monthly)
  @chargePending: (accountCode, callback)->
    post "accounts/#{accountCode}/invoices", '', (err, res)->
      callback err, unless err then transObj res.transaction

  #
  # ADJUSTMENTS (ONE-TIME CHARGE/CREDIT TO SUBSCRIPTION)
  # See https://docs.recurly.com/api/invoices for XML format
  #

  adjObj = (a)->
    uuid        : a.uuid[0]
    amount      : a.total_in_cents[0]._
    currency    : a.currency[0]

      """

    put "subscriptions/#{data.uuid}", xml, (err, res)->
      callback err, unless err then createSubscriptionObject res.subscription

  @terminateSubscription: (accountCode, data, callback)->
    data.refund ?= 'none'

    put "subscriptions/#{data.uuid}/terminate?refund=#{data.refund}", '', (err, res)->
      callback err, unless err then createSubscriptionObject res.subscription

  @cancelSubscription: (accountCode, data, callback)->
    put "subscriptions/#{data.uuid}/cancel", '', (err, res)->
      callback err, unless err then createSubscriptionObject res.subscription

  @reactivateUserSubscription: (accountCode, data, callback)->
    put "subscriptions/#{data.uuid}/reactivate", '', (err, res)->
      callback err, unless err then createSubscriptionObject res.subscription

  #
  # TRANSACTIONS
  # See https://docs.recurly.com/api/transactions for documentation
  #

  createTransactionObject = (t)->
    trans =
      uuid       : t.uuid[0]
      status     : t.status[0]
