Class: StripeModelCallbacks::Customer::SourceUpdatedService

Inherits:
BaseEventService
  • Object
show all
Defined in:
app/services/stripe_model_callbacks/customer/source_updated_service.rb

Instance Method Summary collapse

Instance Method Details

#executeObject



2
3
4
5
6
7
8
9
10
11
12
13
14
# File 'app/services/stripe_model_callbacks/customer/source_updated_service.rb', line 2

def execute
  source = stripe_class.find_or_initialize_by(stripe_id: object.id)
  source.assign_from_stripe(object)
  source.deleted_at = Time.zone.now if event.type == "customer.source.deleted"

  if source.save
    source.create_activity :deleted if event.type == "customer.source.deleted"
    source.create_activity :expiring if event.type == "customer.source.expiring"
    succeed!
  else
    fail! source.errors.full_messages
  end
end