<commit_before>module Tang
  class PayInvoice
    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
      stripe_subscription = Stripe::Subscription.retrieve(stripe_invoice.subscription)      
      subscription = Subscription.find_by(stripe_id: stripe_invoice.subscription)

      # update discount
      if stripe_subscription.discount.nil?
        subscription.update(coupon: nil, coupon_start: nil)
      end

      # update customer active until
      customer = subscription.customer
      customer.update_subscription_end(stripe_subscription)<commit_msg>check for actual subscription<commit_after>module Tang
  class PayInvoice
    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
      stripe_subscription = Stripe::Subscription.retrieve(stripe_invoice.subscription)      
      subscription = Subscription.find_by(stripe_id: stripe_invoice.subscription)

      if subscription.present?
        # update discount
        if stripe_subscription.discount.nil?
          subscription.update(coupon: nil, coupon_start: nil)
        end

        # update customer active until
        customer = subscription.customer
        customer.update_subscription_end(stripe_subscription)
      end
{'fraction_non_alphanumeric': 0.06881948120698782, 'fraction_numerical': 0.0, 'mean_word_length': 3.2376681614349776, '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': '2624642', 'n_tokens_mistral': 558, 'n_tokens_neox': 542, 'n_words': 97}