<commit_before>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)
      end
      if subscription.present?
        subscription.fail! if !subscription.past_due?
      end
      
      return charge
    end
  end
end<commit_msg>attach missing subscription to invoice<commit_after>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
{'fraction_non_alphanumeric': 0.06885245901639345, 'fraction_numerical': 0.0, 'mean_word_length': 3.1425339366515836, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1862216', 'n_tokens_mistral': 551, 'n_tokens_neox': 542, 'n_words': 97}