Class: ForestLiana::StripeSubscriptionsGetter
- Inherits:
-
StripeBaseGetter
- Object
- IntegrationBaseGetter
- StripeBaseGetter
- ForestLiana::StripeSubscriptionsGetter
- Defined in:
- app/services/forest_liana/stripe_subscriptions_getter.rb
Instance Attribute Summary collapse
-
#records ⇒ Object
Returns the value of attribute records.
Instance Method Summary collapse
- #count ⇒ Object
- #ending_before ⇒ Object
- #fetch_subscriptions(params) ⇒ Object
-
#initialize(params, secret_key, reference) ⇒ StripeSubscriptionsGetter
constructor
A new instance of StripeSubscriptionsGetter.
- #perform ⇒ Object
- #starting_after ⇒ Object
Constructor Details
#initialize(params, secret_key, reference) ⇒ StripeSubscriptionsGetter
Returns a new instance of StripeSubscriptionsGetter.
5 6 7 8 |
# File 'app/services/forest_liana/stripe_subscriptions_getter.rb', line 5 def initialize(params, secret_key, reference) @params = params Stripe.api_key = ForestLiana.integrations[:stripe][:api_key] end |
Instance Attribute Details
#records ⇒ Object
Returns the value of attribute records.
3 4 5 |
# File 'app/services/forest_liana/stripe_subscriptions_getter.rb', line 3 def records @records end |
Instance Method Details
#count ⇒ Object
10 11 12 |
# File 'app/services/forest_liana/stripe_subscriptions_getter.rb', line 10 def count @subscriptions.try(:total_count) || 0 end |
#ending_before ⇒ Object
63 64 65 66 67 |
# File 'app/services/forest_liana/stripe_subscriptions_getter.rb', line 63 def ending_before if pagination? && @params[:ending_before] @params[:ending_before] end end |
#fetch_subscriptions(params) ⇒ Object
52 53 54 55 |
# File 'app/services/forest_liana/stripe_subscriptions_getter.rb', line 52 def fetch_subscriptions(params) return if @params[:id] && params[:customer].blank? ::Stripe::Subscription.list(params) end |
#perform ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'app/services/forest_liana/stripe_subscriptions_getter.rb', line 14 def perform begin query = { limit: limit, starting_after: starting_after, ending_before: ending_before } if @params[:id] && collection && field resource = collection.find(@params[:id]) query[:customer] = resource[field] end query['include[]'] = 'total_count' @subscriptions = fetch_subscriptions(query) if @subscriptions.blank? @records = [] return end @records = @subscriptions.data.map do |d| query = {} query[field] = d.customer if collection d.customer = collection.find_by(query) else d.customer = nil end d end rescue ::Stripe::InvalidRequestError => error FOREST_REPORTER.report error FOREST_LOGGER.error "Stripe error: #{error.}" @records = [] end end |
#starting_after ⇒ Object
57 58 59 60 61 |
# File 'app/services/forest_liana/stripe_subscriptions_getter.rb', line 57 def starting_after if pagination? && @params[:starting_after] @params[:starting_after] end end |