Skip to content

Instantly share code, notes, and snippets.

@kdiogenes
Last active September 8, 2015 19:13
Show Gist options
  • Select an option

  • Save kdiogenes/ebbf7593eb048f123cc7 to your computer and use it in GitHub Desktop.

Select an option

Save kdiogenes/ebbf7593eb048f123cc7 to your computer and use it in GitHub Desktop.
iugu: customer syncronization
class User < ActiveRecord::Base
after_create :create_iugu_customer
after_update :update_iugu_customer, if: 'name_changed? or email_changed?'
private
def create_iugu_customer
iugu_customer = Iugu::Customer.create({
email: self.email,
name: self.name
})
self.update_column(:iugu_customer_id, iugu_customer.id)
end
def update_iugu_customer
customer = Iugu::Customer.fetch(self.iugu_customer_id)
customer.email = self.email
customer.name = self.name
customer.save
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment