Skip to content

Instantly share code, notes, and snippets.

@ecordell
Created March 28, 2010 04:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ecordell/346566 to your computer and use it in GitHub Desktop.
Save ecordell/346566 to your computer and use it in GitHub Desktop.
class Subscription < Base
def self.find_by_customer_reference(reference)
customer = Customer.find_by_reference(reference)
find(:first, :params => {:customer_id => customer.id})
end
# Strip off nested attributes of associations before saving, or type-mismatch errors will occur
def save
self.attributes.delete('customer')
self.attributes.delete('product')
self.attributes.delete('credit_card')
super
end
def cancel
destroy
end
# Perform a one-time charge on an existing subscription.
# For more information, please see the one-time charge API docs available
# at: http://support.chargify.com/faqs/api/api-charges
def charge(attrs = {})
post :charges, :charge => attrs
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment