Sha256: 09d5a8609cf244353e0af83317ad18b976628815c37497bf2795151d2aa3ef39

Contents?: true

Size: 688 Bytes

Versions: 5

Compression:

Stored size: 688 Bytes

Contents

class StripeModelCallbacks::Customer::SourceUpdatedService < StripeModelCallbacks::BaseEventService
  def perform
    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

private

  def stripe_class
    if object.object == "card"
      StripeCard
    else
      StripeSource
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
stripe_model_callbacks-0.1.7 app/services/stripe_model_callbacks/customer/source_updated_service.rb
stripe_model_callbacks-0.1.6 app/services/stripe_model_callbacks/customer/source_updated_service.rb
stripe_model_callbacks-0.1.5 app/services/stripe_model_callbacks/customer/source_updated_service.rb
stripe_model_callbacks-0.1.4 app/services/stripe_model_callbacks/customer/source_updated_service.rb
stripe_model_callbacks-0.1.3 app/services/stripe_model_callbacks/customer/source_updated_service.rb