Sha256: 29a5330dba1e4d6f2bab2c3b46449f4aa805f3431b7b1fc1486aea3360c7b060

Contents?: true

Size: 901 Bytes

Versions: 3

Compression:

Stored size: 901 Bytes

Contents

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

      # 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)
      if subscription.nil?
        stripe_subscription = Stripe::Subscription.retrieve(stripe_invoice.subscription)
        subscription = Subscription.from_stripe(stripe_subscription)
        invoice.update(subscription: subscription)
      end
      if subscription.present?
        subscription.fail! if !subscription.past_due?
      end
      
      return charge
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
tang-0.2.2 app/services/tang/fail_invoice.rb
tang-0.2.1 app/services/tang/fail_invoice.rb
tang-0.2.0 app/services/tang/fail_invoice.rb