Module: RedLine::Customer::InstanceMethods
- Defined in:
- lib/redline/customer/instance.rb
Instance Method Summary collapse
- #braintree_customer_attributes ⇒ Object
- #create_customer ⇒ Object
- #customer ⇒ Object
- #delete_customer ⇒ Object
- #update_customer ⇒ Object
Instance Method Details
#braintree_customer_attributes ⇒ Object
4 5 6 7 8 9 |
# File 'lib/redline/customer/instance.rb', line 4 def braintree_customer_attributes wanted_attributes = Braintree::Customer._create_signature.reject{|a| a.is_a? Hash}.reject{|a| a == :id} wanted_attributes.inject({}) {|hash, key| hash.merge(key => (self.send(self.class.braintree_customer_attribute_map[key] || key) rescue nil))}. merge(:custom_fields => self.class.braintree_customer_custom_fields.inject({}) {|hash, key| hash.merge(key => (self.send(self.class.braintree_customer_attribute_map[key] || key) rescue nil))}). reject { |key, value| value == {}} end |
#create_customer ⇒ Object
13 14 15 |
# File 'lib/redline/customer/instance.rb', line 13 def create_customer self.customer_id ||= Braintree::Customer.create!(braintree_customer_attributes).id end |
#customer ⇒ Object
10 11 12 |
# File 'lib/redline/customer/instance.rb', line 10 def customer Braintree::Customer.find(customer_id) if customer_id end |
#delete_customer ⇒ Object
19 20 21 22 23 24 |
# File 'lib/redline/customer/instance.rb', line 19 def delete_customer if customer_id Braintree::Customer.delete(customer_id) self.customer_id = nil end end |
#update_customer ⇒ Object
16 17 18 |
# File 'lib/redline/customer/instance.rb', line 16 def update_customer Braintree::Customer.update!(customer_id, braintree_customer_attributes) && flush_cache(:customer) if customer_id end |