Sha256: 421a7341984031666f4eda2b8efec61a89227d2b51ca02a2443572d1805b57a1

Contents?: true

Size: 745 Bytes

Versions: 2

Compression:

Stored size: 745 Bytes

Contents

module Tang
  class UpdateSubscription
    def self.call(subscription)
      if !subscription.valid?
        return subscription
      end

      begin
        s = Stripe::Subscription.retrieve(subscription.stripe_id)
        s.plan = subscription.plan.stripe_id
        s.quantity = subscription.quantity
        s.trial_end = subscription.stripe_trial_end if subscription.stripe_trial_end.present?
        # s.tax_percent = subscription.tax_percent if subscription.tax_percent.present?
        s.coupon = subscription.coupon.stripe_id if subscription.coupon.present?
        s.save
      rescue Stripe::StripeError => e
        subscription.errors.add(:base, :invalid, message: e.message)
      end

      return subscription
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
tang-0.2.2 app/services/tang/update_subscription.rb
tang-0.2.1 app/services/tang/update_subscription.rb