app/services/tang/update_customer.rb in tang-0.0.1 vs app/services/tang/update_customer.rb in tang-0.0.8
- old
+ new
@@ -1,24 +1,28 @@
module Tang
class UpdateCustomer
def self.call(customer)
- if !customer.valid?
- return customer
- end
+ return customer if !customer.valid?
if customer.stripe_id.present?
begin
c = Stripe::Customer.retrieve(customer.stripe_id)
- c.email = customer.email
- c.account_balance = customer.account_balance if customer.account_balance.present?
- c.business_vat_id = customer.business_vat_id if customer.business_vat_id.present?
- c.description = customer.description
+ c = populate_customer(c, customer)
c.save
rescue Stripe::StripeError => e
customer.errors[:base] << e.message
end
end
return customer
+ end
+
+ def self.populate_customer(stripe_customer, customer)
+ stripe_customer.email = customer.email
+ stripe_customer.account_balance = customer.account_balance if customer.account_balance.present?
+ stripe_customer.business_vat_id = customer.business_vat_id if customer.business_vat_id.present?
+ stripe_customer.description = customer.description
+ stripe_customer.coupon = customer.coupon.stripe_id if customer.coupon.present?
+ return stripe_customer
end
end
end
\ No newline at end of file