Sha256: 9b4a068cf46ce228e93c1060325e7912fc07dfc5e49da81b15a7c1cc4fab6ec1

Contents?: true

Size: 552 Bytes

Versions: 2

Compression:

Stored size: 552 Bytes

Contents

module Tang
  class FailInvoice
    def self.call(stripe_invoice)
      invoice = Invoice.find_by(stripe_id: stripe_invoice.id)

      # create charge
      charge = nil
      if stripe_invoice.charge.present?
        stripe_charge = Stripe::Charge.retrieve(stripe_invoice.charge)
        charge = Charge.from_stripe(stripe_charge, invoice)
      end

      # update subscription
      subscription = Subscription.find_by(stripe_id: stripe_invoice.subscription)
      subscription.fail! if !subscription.past_due?

      return charge
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
tang-0.0.9 app/services/tang/fail_invoice.rb
tang-0.0.8 app/services/tang/fail_invoice.rb