Class: ForestLiana::StripeBankAccountsGetter
- Inherits:
-
Object
- Object
- ForestLiana::StripeBankAccountsGetter
- Defined in:
- app/services/forest_liana/stripe_bank_accounts_getter.rb
Instance Attribute Summary collapse
-
#records ⇒ Object
Returns the value of attribute records.
Instance Method Summary collapse
- #collection ⇒ Object
- #count ⇒ Object
- #ending_before ⇒ Object
- #fetch_bank_accounts(customer, params) ⇒ Object
- #field ⇒ Object
-
#initialize(params, secret_key, reference) ⇒ StripeBankAccountsGetter
constructor
A new instance of StripeBankAccountsGetter.
- #limit ⇒ Object
- #pagination? ⇒ Boolean
- #perform ⇒ Object
- #starting_after ⇒ Object
Constructor Details
#initialize(params, secret_key, reference) ⇒ StripeBankAccountsGetter
Returns a new instance of StripeBankAccountsGetter.
5 6 7 8 |
# File 'app/services/forest_liana/stripe_bank_accounts_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_bank_accounts_getter.rb', line 3 def records @records end |
Instance Method Details
#collection ⇒ Object
75 76 77 |
# File 'app/services/forest_liana/stripe_bank_accounts_getter.rb', line 75 def collection @params[:collection].singularize.camelize.constantize end |
#count ⇒ Object
10 11 12 |
# File 'app/services/forest_liana/stripe_bank_accounts_getter.rb', line 10 def count @cards.try(:total_count) || 0 end |
#ending_before ⇒ Object
55 56 57 58 59 |
# File 'app/services/forest_liana/stripe_bank_accounts_getter.rb', line 55 def ending_before if pagination? && @params[:ending_before] @params[:ending_before] end end |
#fetch_bank_accounts(customer, params) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'app/services/forest_liana/stripe_bank_accounts_getter.rb', line 33 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 |
#field ⇒ Object
79 80 81 82 83 84 |
# File 'app/services/forest_liana/stripe_bank_accounts_getter.rb', line 79 def field ForestLiana.integrations[:stripe][:mapping].select { |value| value.split('.')[0] == ForestLiana::SchemaUtils .find_model_from_collection_name(@params[:collection]).try(:name) }.first.split('.')[1] end |
#limit ⇒ Object
61 62 63 64 65 66 67 68 69 |
# File 'app/services/forest_liana/stripe_bank_accounts_getter.rb', line 61 def limit return 10 unless pagination? if @params[:page][:size] @params[:page][:size].to_i else 10 end end |
#pagination? ⇒ Boolean
71 72 73 |
# File 'app/services/forest_liana/stripe_bank_accounts_getter.rb', line 71 def pagination? @params[:page] end |
#perform ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/services/forest_liana/stripe_bank_accounts_getter.rb', line 14 def perform params = { limit: limit, starting_after: starting_after, ending_before: ending_before, object: 'bank_account' } params['include[]'] = 'total_count' resource = collection.find(@params[:id]) customer = resource[field] if customer.blank? @records = [] else fetch_bank_accounts(customer, params) end end |
#starting_after ⇒ Object
49 50 51 52 53 |
# File 'app/services/forest_liana/stripe_bank_accounts_getter.rb', line 49 def starting_after if pagination? && @params[:starting_after] @params[:starting_after] end end |