Sha256: 8c392903f5d5770c3b01c3ee6a03aedd867de9243243e15a76773289cff21b75

Contents?: true

Size: 1.3 KB

Versions: 47

Compression:

Stored size: 1.3 KB

Contents

module ForestLiana
  class StripeSourcesGetter < StripeBaseGetter
    attr_accessor :records

    def initialize(params, secret_key, reference)
      @params = params
      Stripe.api_key = ForestLiana.integrations[:stripe][:api_key]
    end

    def count
      @cards.try(:total_count) || 0
    end

    def perform
      params = {
        limit: limit,
        starting_after: starting_after,
        ending_before: ending_before,
        object: @params[:object]
      }
      params['include[]'] = 'total_count'

      resource = collection.find(@params[:id])
      customer = resource[field]

      if customer.blank?
        @records = []
      else
        fetch_bank_accounts(customer, params)
      end
    end

    def fetch_bank_accounts(customer, params)
      @cards = Stripe::Customer.retrieve(customer).sources.all(params)
      if @cards.blank?
        @records = []
        return
      end

      @records = @cards.data.map do |d|
        query = {}
        query[field] = d.customer
        d.customer = collection.find_by(query)

        d
      end
    end

    def starting_after
      if pagination? && @params[:starting_after]
        @params[:starting_after]
      end
    end

    def ending_before
      if pagination? && @params[:ending_before]
        @params[:ending_before]
      end
    end
  end
end

Version data entries

47 entries across 47 versions & 1 rubygems

Version Path
forest_liana-2.10.0 app/services/forest_liana/stripe_sources_getter.rb
forest_liana-2.9.2 app/services/forest_liana/stripe_sources_getter.rb
forest_liana-2.9.1 app/services/forest_liana/stripe_sources_getter.rb
forest_liana-2.9.0 app/services/forest_liana/stripe_sources_getter.rb
forest_liana-2.8.6 app/services/forest_liana/stripe_sources_getter.rb
forest_liana-2.8.5 app/services/forest_liana/stripe_sources_getter.rb
forest_liana-2.8.4 app/services/forest_liana/stripe_sources_getter.rb
forest_liana-2.8.3 app/services/forest_liana/stripe_sources_getter.rb
forest_liana-2.8.2 app/services/forest_liana/stripe_sources_getter.rb
forest_liana-2.8.1 app/services/forest_liana/stripe_sources_getter.rb
forest_liana-2.8.0 app/services/forest_liana/stripe_sources_getter.rb
forest_liana-2.7.0 app/services/forest_liana/stripe_sources_getter.rb
forest_liana-2.6.1 app/services/forest_liana/stripe_sources_getter.rb
forest_liana-2.6.0 app/services/forest_liana/stripe_sources_getter.rb
forest_liana-2.5.5 app/services/forest_liana/stripe_sources_getter.rb
forest_liana-2.5.4 app/services/forest_liana/stripe_sources_getter.rb
forest_liana-2.5.3 app/services/forest_liana/stripe_sources_getter.rb
forest_liana-2.5.2 app/services/forest_liana/stripe_sources_getter.rb
forest_liana-2.5.1 app/services/forest_liana/stripe_sources_getter.rb
forest_liana-2.5.0 app/services/forest_liana/stripe_sources_getter.rb