forest_liana 1.9.7 → 1.9.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9462b0d19f31865276806971df2b76edf71c0412
4
- data.tar.gz: 15dbdb96aafee2802b0a3b5c1f7ce2adc005adef
3
+ metadata.gz: 9ce5ea697e568c0b4a0e09ab82d43f3282ca521d
4
+ data.tar.gz: 3c2f2d65713d2eebd007e8b43bbdbdc0566835ae
5
5
  SHA512:
6
- metadata.gz: 838d8881cb2b599ada29d505ee43d82f295309f54c0a3e8accd4bb0a3ded3b459dda05d6056eb68299e4d687b9dcae3d4701339c6058d90527506a60311d378c
7
- data.tar.gz: 22ee0b986558390217c0a10617099eebd091182877b3e6eb64e95e497d75297308ce70cda6ea84b7415a5c56a15559c7070a6caefe95b632267e73964d0d9aae
6
+ metadata.gz: 27cfc6f40884c10ff33f1e8880ebdc8d834f5b627f5095093b56301e4ac30f4b9f8d9cd64ce33a687139229e58687a741829c95b7de6bbba50645c4cf870a524
7
+ data.tar.gz: 3fbb9eea9f7a0d75edd6eea0a037f66c2e43d99e31028b54e78bbed564a8d826a9ca0a8b89757a6e9d9120ef5aba6645f7d476b8698a077801d1452db220fb94
@@ -2,9 +2,8 @@ module ForestLiana
2
2
  class StripeController < ForestLiana::ApplicationController
3
3
 
4
4
  def payments
5
- getter = StripePaymentsGetter.new(params,
6
- request.headers['Stripe-Secret-Key'],
7
- request.headers['Stripe-Reference'])
5
+ getter = StripePaymentsGetter.new(params, request.headers['Stripe-Secret-Key'],
6
+ request.headers['Stripe-Reference'])
8
7
  getter.perform
9
8
 
10
9
  render serializer: nil, json: serialize_models(getter.records, {
@@ -14,6 +13,18 @@ module ForestLiana
14
13
  })
15
14
  end
16
15
 
16
+ def payment
17
+ getter = StripePaymentGetter.new(params, request.headers['Stripe-Secret-Key'],
18
+ request.headers['Stripe-Reference'])
19
+ getter.perform
20
+
21
+ render serializer: nil, json: serialize_model(getter.record, {
22
+ context: { type: get_serializer_type('stripe_payments') },
23
+ skip_collection_check: true,
24
+ include: ['customer']
25
+ })
26
+ end
27
+
17
28
  def refund
18
29
  begin
19
30
  refunder = StripePaymentRefunder.new(params)
@@ -26,9 +37,9 @@ module ForestLiana
26
37
  end
27
38
 
28
39
  def cards
29
- getter = StripeCardsGetter.new(params,
30
- request.headers['Stripe-Secret-Key'],
31
- request.headers['Stripe-Reference'])
40
+ params[:object] = 'card'
41
+ getter = StripeSourcesGetter.new(params, request.headers['Stripe-Secret-Key'],
42
+ request.headers['Stripe-Reference'])
32
43
  getter.perform
33
44
 
34
45
  render serializer: nil, json: serialize_models(getter.records, {
@@ -38,10 +49,21 @@ module ForestLiana
38
49
  })
39
50
  end
40
51
 
52
+ def card
53
+ getter = StripeSourceGetter.new(params, request.headers['Stripe-Secret-Key'],
54
+ request.headers['Stripe-Reference'])
55
+ getter.perform
56
+
57
+ render serializer: nil, json: serialize_model(getter.record, {
58
+ context: { type: get_serializer_type('stripe_cards') },
59
+ skip_collection_check: true,
60
+ include: ['customer']
61
+ })
62
+ end
63
+
41
64
  def invoices
42
- getter = StripeInvoicesGetter.new(params,
43
- request.headers['Stripe-Secret-Key'],
44
- request.headers['Stripe-Reference'])
65
+ getter = StripeInvoicesGetter.new(params, request.headers['Stripe-Secret-Key'],
66
+ request.headers['Stripe-Reference'])
45
67
  getter.perform
46
68
 
47
69
  render serializer: nil, json: serialize_models(getter.records, {
@@ -51,10 +73,21 @@ module ForestLiana
51
73
  })
52
74
  end
53
75
 
76
+ def invoice
77
+ getter = StripeInvoiceGetter.new(params, request.headers['Stripe-Secret-Key'],
78
+ request.headers['Stripe-Reference'])
79
+ getter.perform
80
+
81
+ render serializer: nil, json: serialize_model(getter.record, {
82
+ context: { type: get_serializer_type('stripe_invoices') },
83
+ skip_collection_check: true,
84
+ include: ['customer']
85
+ })
86
+ end
87
+
54
88
  def subscriptions
55
- getter = StripeSubscriptionsGetter.new(params,
56
- request.headers['Stripe-Secret-Key'],
57
- request.headers['Stripe-Reference'])
89
+ getter = StripeSubscriptionsGetter.new(params, request.headers['Stripe-Secret-Key'],
90
+ request.headers['Stripe-Reference'])
58
91
  getter.perform
59
92
 
60
93
  render serializer: nil, json: serialize_models(getter.records, {
@@ -64,10 +97,22 @@ module ForestLiana
64
97
  })
65
98
  end
66
99
 
100
+ def subscription
101
+ getter = StripeSubscriptionGetter.new(params, request.headers['Stripe-Secret-Key'],
102
+ request.headers['Stripe-Reference'])
103
+ getter.perform
104
+
105
+ render serializer: nil, json: serialize_model(getter.record, {
106
+ context: { type: get_serializer_type('stripe_subscriptions') },
107
+ skip_collection_check: true,
108
+ include: ['customer']
109
+ })
110
+ end
111
+
67
112
  def bank_accounts
68
- getter = StripeBankAccountsGetter.new(params,
69
- request.headers['Stripe-Secret-Key'],
70
- request.headers['Stripe-Reference'])
113
+ params[:object] = 'bank_account'
114
+ getter = StripeSourcesGetter.new(params, request.headers['Stripe-Secret-Key'],
115
+ request.headers['Stripe-Reference'])
71
116
  getter.perform
72
117
 
73
118
  render serializer: nil, json: serialize_models(getter.records, {
@@ -77,6 +122,18 @@ module ForestLiana
77
122
  })
78
123
  end
79
124
 
125
+ def bank_account
126
+ getter = StripeSourceGetter.new(params, request.headers['Stripe-Secret-Key'],
127
+ request.headers['Stripe-Reference'])
128
+ getter.perform
129
+
130
+ render serializer: nil, json: serialize_model(getter.record, {
131
+ context: { type: get_serializer_type('stripe_bank_accounts') },
132
+ skip_collection_check: true,
133
+ include: ['customer']
134
+ })
135
+ end
136
+
80
137
  def get_serializer_type(suffix)
81
138
  "#{params[:collection]}_#{suffix}"
82
139
  end
@@ -111,6 +111,10 @@ module ForestLiana
111
111
  ret[:href] = "/forest/#{ForestLiana.name_for(object.class)}/#{object.id}/stripe_invoices"
112
112
  when :stripe_cards
113
113
  ret[:href] = "/forest/#{ForestLiana.name_for(object.class)}/#{object.id}/stripe_cards"
114
+ when :stripe_subscriptions
115
+ ret[:href] = "/forest/#{ForestLiana.name_for(object.class)}/#{object.id}/stripe_subscriptions"
116
+ when :stripe_bank_accounts
117
+ ret[:href] = "/forest/#{ForestLiana.name_for(object.class)}/#{object.id}/stripe_bank_accounts"
114
118
  end
115
119
  end
116
120
 
@@ -241,6 +245,8 @@ module ForestLiana
241
245
  serializer.send(:has_many, :stripe_payments) { }
242
246
  serializer.send(:has_many, :stripe_invoices) { }
243
247
  serializer.send(:has_many, :stripe_cards) { }
248
+ serializer.send(:has_many, :stripe_subscriptions) { }
249
+ serializer.send(:has_many, :stripe_bank_accounts) { }
244
250
  end
245
251
 
246
252
  ForestLiana::SerializerFactory.define_serializer(active_record_class,
@@ -2,16 +2,14 @@ module ForestLiana
2
2
  class StripeBankAccountSerializer
3
3
  include JSONAPI::Serializer
4
4
 
5
- attribute :account
6
5
  attribute :account_holder_name
7
6
  attribute :account_holder_type
8
7
  attribute :bank_name
9
8
  attribute :country
10
9
  attribute :currency
11
- attribute :default_for_currency
12
10
  attribute :fingerprint
13
11
  attribute :last4
14
- attribute :rooting_number
12
+ attribute :routing_number
15
13
  attribute :status
16
14
 
17
15
  has_one :customer
@@ -0,0 +1,23 @@
1
+ module ForestLiana
2
+ class IntegrationBaseGetter
3
+ private
4
+
5
+ def pagination?
6
+ @params[:page] && @params[:page][:number]
7
+ end
8
+
9
+ def limit
10
+ return 10 unless pagination?
11
+
12
+ if @params[:page][:size]
13
+ @params[:page][:size].to_i
14
+ else
15
+ 10
16
+ end
17
+ end
18
+
19
+ def collection
20
+ @params[:collection].singularize.camelize.constantize
21
+ end
22
+ end
23
+ end
@@ -1,5 +1,5 @@
1
1
  module ForestLiana
2
- class IntercomAttributesGetter
2
+ class IntercomAttributesGetter < IntegrationBaseGetter
3
3
  attr_accessor :record
4
4
 
5
5
  def initialize(params)
@@ -21,11 +21,5 @@ module ForestLiana
21
21
  FOREST_LOGGER.error "Cannot retrieve the Intercom attributes: #{exception.message}"
22
22
  end
23
23
  end
24
-
25
- private
26
-
27
- def collection
28
- @params[:collection].singularize.camelize.constantize
29
- end
30
24
  end
31
25
  end
@@ -1,5 +1,5 @@
1
1
  module ForestLiana
2
- class IntercomConversationGetter
2
+ class IntercomConversationGetter < IntegrationBaseGetter
3
3
  attr_accessor :record
4
4
 
5
5
  def initialize(params)
@@ -1,5 +1,5 @@
1
1
  module ForestLiana
2
- class IntercomConversationsGetter
2
+ class IntercomConversationsGetter < IntegrationBaseGetter
3
3
  def initialize(params)
4
4
  @params = params
5
5
  @access_token = ForestLiana.integrations[:intercom][:access_token]
@@ -38,10 +38,6 @@ module ForestLiana
38
38
 
39
39
  private
40
40
 
41
- def collection
42
- @params[:collection].singularize.camelize.constantize
43
- end
44
-
45
41
  def pagination
46
42
  offset..(offset + limit - 1)
47
43
  end
@@ -56,19 +52,5 @@ module ForestLiana
56
52
  0
57
53
  end
58
54
  end
59
-
60
- def limit
61
- return 10 unless pagination?
62
-
63
- if @params[:page][:size]
64
- @params[:page][:size].to_i
65
- else
66
- 10
67
- end
68
- end
69
-
70
- def pagination?
71
- @params[:page] && @params[:page][:number]
72
- end
73
55
  end
74
56
  end
@@ -16,7 +16,7 @@ module ForestLiana
16
16
  when 'day'
17
17
  '%d/%m/%Y'
18
18
  when 'week'
19
- 'W%W-%Y'
19
+ 'W%V-%Y'
20
20
  when 'month'
21
21
  '%b %Y'
22
22
  when 'year'
@@ -40,7 +40,11 @@ module ForestLiana
40
40
  value = value.where(conditions.join(filter_operator))
41
41
  end
42
42
 
43
- value = value.send(time_range, group_by_date_field, { time_zone: client_timezone })
43
+ value = value.send(time_range, group_by_date_field, {
44
+ time_zone: client_timezone,
45
+ week_start: :mon
46
+ })
47
+
44
48
  value = value.send(@params[:aggregate].downcase, @params[:aggregate_field])
45
49
  .map do |k, v|
46
50
  { label: k.strftime(get_format), values: { value: v }}
@@ -0,0 +1,12 @@
1
+ module ForestLiana
2
+ class StripeBaseGetter < IntegrationBaseGetter
3
+ private
4
+
5
+ def field
6
+ ForestLiana.integrations[:stripe][:mapping].select { |value|
7
+ value.split('.')[0] == ForestLiana::SchemaUtils
8
+ .find_model_from_collection_name(@params[:collection]).try(:name)
9
+ }.first.split('.')[1]
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,30 @@
1
+ module ForestLiana
2
+ class StripeInvoiceGetter < StripeBaseGetter
3
+ attr_accessor :record
4
+
5
+ def initialize(params, secret_key, reference)
6
+ @params = params
7
+ Stripe.api_key = ForestLiana.integrations[:stripe][:api_key]
8
+ end
9
+
10
+ def perform
11
+ query = {}
12
+ @record = Stripe::Invoice.retrieve(@params[:invoice_id])
13
+
14
+ @record.date = Time.at(@record.date).to_datetime
15
+ @record.period_start = Time.at(@record.period_start).to_datetime
16
+ @record.period_end = Time.at(@record.period_end).to_datetime
17
+ @record.subtotal /= 100.00
18
+ @record.total /= 100.00
19
+ @record.amount_due /= 100.00
20
+
21
+ query[field] = @record.customer
22
+ if collection
23
+ @record.customer = collection.find_by(query)
24
+ else
25
+ @record.customer = nil
26
+ end
27
+ @record
28
+ end
29
+ end
30
+ end
@@ -1,5 +1,5 @@
1
1
  module ForestLiana
2
- class StripeInvoicesGetter
2
+ class StripeInvoicesGetter < StripeBaseGetter
3
3
  attr_accessor :records
4
4
 
5
5
  def initialize(params, secret_key, reference)
@@ -66,30 +66,5 @@ module ForestLiana
66
66
  @params[:ending_before]
67
67
  end
68
68
  end
69
-
70
- def limit
71
- return 10 unless pagination?
72
-
73
- if @params[:page][:size]
74
- @params[:page][:size].to_i
75
- else
76
- 10
77
- end
78
- end
79
-
80
- def pagination?
81
- @params[:page]
82
- end
83
-
84
- def collection
85
- @params[:collection].singularize.camelize.constantize
86
- end
87
-
88
- def field
89
- ForestLiana.integrations[:stripe][:mapping].select { |value|
90
- value.split('.')[0] == ForestLiana::SchemaUtils
91
- .find_model_from_collection_name(@params[:collection]).try(:name)
92
- }.first.split('.')[1]
93
- end
94
69
  end
95
70
  end
@@ -0,0 +1,26 @@
1
+ module ForestLiana
2
+ class StripePaymentGetter < StripeBaseGetter
3
+ attr_accessor :record
4
+
5
+ def initialize(params, secret_key, reference)
6
+ @params = params
7
+ Stripe.api_key = ForestLiana.integrations[:stripe][:api_key]
8
+ end
9
+
10
+ def perform
11
+ query = {}
12
+ @record = Stripe::Charge.retrieve(@params[:payment_id])
13
+
14
+ @record.created = Time.at(@record.created).to_datetime
15
+ @record.amount /= 100.00
16
+
17
+ query[field] = @record.customer
18
+ if collection
19
+ @record.customer = collection.find_by(query)
20
+ else
21
+ @record.customer = nil
22
+ end
23
+ @record
24
+ end
25
+ end
26
+ end
@@ -1,5 +1,5 @@
1
1
  module ForestLiana
2
- class StripePaymentsGetter
2
+ class StripePaymentsGetter < StripeBaseGetter
3
3
  attr_accessor :records
4
4
 
5
5
  def initialize(params, secret_key, reference)
@@ -64,30 +64,5 @@ module ForestLiana
64
64
  @params[:ending_before]
65
65
  end
66
66
  end
67
-
68
- def limit
69
- return 10 unless pagination?
70
-
71
- if @params[:page][:size]
72
- @params[:page][:size].to_i
73
- else
74
- 10
75
- end
76
- end
77
-
78
- def pagination?
79
- @params[:page]
80
- end
81
-
82
- def collection
83
- @params[:collection].singularize.camelize.constantize
84
- end
85
-
86
- def field
87
- ForestLiana.integrations[:stripe][:mapping].select { |value|
88
- value.split('.')[0] == ForestLiana::SchemaUtils
89
- .find_model_from_collection_name(@params[:collection]).try(:name)
90
- }.first.split('.')[1]
91
- end
92
67
  end
93
68
  end
@@ -0,0 +1,25 @@
1
+ module ForestLiana
2
+ class StripeSourceGetter < StripeBaseGetter
3
+ attr_accessor :record
4
+
5
+ def initialize(params, secret_key, reference)
6
+ @params = params
7
+ Stripe.api_key = ForestLiana.integrations[:stripe][:api_key]
8
+ end
9
+
10
+ def perform
11
+ resource = collection.find(@params[:recordId])
12
+ customer = resource[field]
13
+
14
+ @record = Stripe::Customer
15
+ .retrieve(customer)
16
+ .sources.retrieve(@params[:objectId])
17
+
18
+ query = {}
19
+ query[field] = @record.customer
20
+ @record.customer = collection.find_by(query)
21
+
22
+ @record
23
+ end
24
+ end
25
+ end
@@ -1,5 +1,5 @@
1
1
  module ForestLiana
2
- class StripeBankAccountsGetter
2
+ class StripeSourcesGetter < StripeBaseGetter
3
3
  attr_accessor :records
4
4
 
5
5
  def initialize(params, secret_key, reference)
@@ -16,7 +16,7 @@ module ForestLiana
16
16
  limit: limit,
17
17
  starting_after: starting_after,
18
18
  ending_before: ending_before,
19
- object: 'bank_account'
19
+ object: @params[:object]
20
20
  }
21
21
  params['include[]'] = 'total_count'
22
22
 
@@ -57,30 +57,5 @@ module ForestLiana
57
57
  @params[:ending_before]
58
58
  end
59
59
  end
60
-
61
- def limit
62
- return 10 unless pagination?
63
-
64
- if @params[:page][:size]
65
- @params[:page][:size].to_i
66
- else
67
- 10
68
- end
69
- end
70
-
71
- def pagination?
72
- @params[:page]
73
- end
74
-
75
- def collection
76
- @params[:collection].singularize.camelize.constantize
77
- end
78
-
79
- def field
80
- ForestLiana.integrations[:stripe][:mapping].select { |value|
81
- value.split('.')[0] == ForestLiana::SchemaUtils
82
- .find_model_from_collection_name(@params[:collection]).try(:name)
83
- }.first.split('.')[1]
84
- end
85
60
  end
86
61
  end
@@ -0,0 +1,23 @@
1
+ module ForestLiana
2
+ class StripeSubscriptionGetter < StripeBaseGetter
3
+ attr_accessor :record
4
+
5
+ def initialize(params, secret_key, reference)
6
+ @params = params
7
+ Stripe.api_key = ForestLiana.integrations[:stripe][:api_key]
8
+ end
9
+
10
+ def perform
11
+ query = {}
12
+ @record = Stripe::Subscription.retrieve(@params[:subscription_id])
13
+
14
+ query[field] = @record.customer
15
+ if collection
16
+ @record.customer = collection.find_by(query)
17
+ else
18
+ @record.customer = nil
19
+ end
20
+ @record
21
+ end
22
+ end
23
+ end
@@ -1,5 +1,5 @@
1
1
  module ForestLiana
2
- class StripeSubscriptionsGetter
2
+ class StripeSubscriptionsGetter < StripeBaseGetter
3
3
  attr_accessor :records
4
4
 
5
5
  def initialize(params, secret_key, reference)
@@ -31,15 +31,6 @@ module ForestLiana
31
31
  end
32
32
 
33
33
  @records = @subscriptions.data.map do |d|
34
- d.canceled_at = Time.at(d.canceled_at).to_datetime
35
- d.created = Time.at(d.created).to_datetime
36
- d.current_period_end = Time.at(d.current_period_end).to_datetime
37
- d.current_period_start = Time.at(d.current_period_start).to_datetime
38
- d.ended_at = Time.at(d.ended_at).to_datetime
39
- d.start = Time.at(d.start).to_datetime
40
- d.trial_end = Time.at(d.trial_end).to_datetime
41
- d.trial_start = Time.at(d.trial_start).to_datetime
42
-
43
34
  query = {}
44
35
  query[field] = d.customer
45
36
  if collection
@@ -68,30 +59,5 @@ module ForestLiana
68
59
  @params[:ending_before]
69
60
  end
70
61
  end
71
-
72
- def limit
73
- return 10 unless pagination?
74
-
75
- if @params[:page][:size]
76
- @params[:page][:size].to_i
77
- else
78
- 10
79
- end
80
- end
81
-
82
- def pagination?
83
- @params[:page]
84
- end
85
-
86
- def collection
87
- @params[:collection].singularize.camelize.constantize
88
- end
89
-
90
- def field
91
- ForestLiana.integrations[:stripe][:mapping].select { |value|
92
- value.split('.')[0] == ForestLiana::SchemaUtils
93
- .find_model_from_collection_name(@params[:collection]).try(:name)
94
- }.first.split('.')[1]
95
- end
96
62
  end
97
63
  end
data/config/routes.rb CHANGED
@@ -17,15 +17,20 @@ ForestLiana::Engine.routes.draw do
17
17
  post '/stats/:collection' => 'stats#show'
18
18
 
19
19
  # Stripe Integration
20
- get '(:collection)_stripe_payments' => 'stripe#payments'
20
+ get '(*collection)_stripe_payments' => 'stripe#payments'
21
21
  get ':collection/:id/stripe_payments' => 'stripe#payments'
22
+ get '(*collection)_stripe_payments/:payment_id' => 'stripe#payment'
22
23
  post 'stripe_payments/refunds' => 'stripe#refund'
23
- get '(:collection)_stripe_invoices' => 'stripe#invoices'
24
+ get '(*collection)_stripe_invoices' => 'stripe#invoices'
24
25
  get ':collection/:id/stripe_invoices' => 'stripe#invoices'
26
+ get '(*collection)_stripe_invoices/:invoice_id' => 'stripe#invoice'
25
27
  get ':collection/:id/stripe_cards' => 'stripe#cards'
26
- get '(:collection)_stripe_subscriptions' => 'stripe#subscriptions'
28
+ get '(*collection)_stripe_cards' => 'stripe#card'
29
+ get '(*collection)_stripe_subscriptions' => 'stripe#subscriptions'
27
30
  get ':collection/:id/stripe_subscriptions' => 'stripe#subscriptions'
31
+ get '(*collection)_stripe_subscriptions/:subscription_id' => 'stripe#subscription'
28
32
  get ':collection/:id/stripe_bank_accounts' => 'stripe#bank_accounts'
33
+ get '(*collection)_stripe_bank_accounts' => 'stripe#bank_account'
29
34
 
30
35
  # Intercom Integration
31
36
  get ':collection/:id/intercom_conversations' => 'intercom#conversations'
@@ -269,7 +269,7 @@ module ForestLiana
269
269
 
270
270
  def setup_stripe_integration(collection_name_and_field)
271
271
  collection_name = collection_name_and_field.split('.')[0]
272
- model_name = collection_name.constantize.try(:table_name)
272
+ model_name = ForestLiana.name_for(collection_name.constantize)
273
273
  collection_display_name = model_name.capitalize
274
274
 
275
275
  ForestLiana.apimap << ForestLiana::Model::Collection.new({
@@ -1,3 +1,3 @@
1
1
  module ForestLiana
2
- VERSION = "1.9.7"
2
+ VERSION = "1.9.8"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: forest_liana
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.7
4
+ version: 1.9.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sandro Munda
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-30 00:00:00.000000000 Z
11
+ date: 2017-11-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -174,6 +174,7 @@ files:
174
174
  - app/services/forest_liana/has_many_associator.rb
175
175
  - app/services/forest_liana/has_many_dissociator.rb
176
176
  - app/services/forest_liana/has_many_getter.rb
177
+ - app/services/forest_liana/integration_base_getter.rb
177
178
  - app/services/forest_liana/intercom_attributes_getter.rb
178
179
  - app/services/forest_liana/intercom_conversation_getter.rb
179
180
  - app/services/forest_liana/intercom_conversations_getter.rb
@@ -189,11 +190,15 @@ files:
189
190
  - app/services/forest_liana/schema_utils.rb
190
191
  - app/services/forest_liana/search_query_builder.rb
191
192
  - app/services/forest_liana/stat_getter.rb
192
- - app/services/forest_liana/stripe_bank_accounts_getter.rb
193
- - app/services/forest_liana/stripe_cards_getter.rb
193
+ - app/services/forest_liana/stripe_base_getter.rb
194
+ - app/services/forest_liana/stripe_invoice_getter.rb
194
195
  - app/services/forest_liana/stripe_invoices_getter.rb
196
+ - app/services/forest_liana/stripe_payment_getter.rb
195
197
  - app/services/forest_liana/stripe_payment_refunder.rb
196
198
  - app/services/forest_liana/stripe_payments_getter.rb
199
+ - app/services/forest_liana/stripe_source_getter.rb
200
+ - app/services/forest_liana/stripe_sources_getter.rb
201
+ - app/services/forest_liana/stripe_subscription_getter.rb
197
202
  - app/services/forest_liana/stripe_subscriptions_getter.rb
198
203
  - app/services/forest_liana/value_stat_getter.rb
199
204
  - app/views/layouts/forest_liana/application.html.erb
@@ -1,86 +0,0 @@
1
- module ForestLiana
2
- class StripeCardsGetter
3
- attr_accessor :records
4
-
5
- def initialize(params, secret_key, reference)
6
- @params = params
7
- Stripe.api_key = ForestLiana.integrations[:stripe][:api_key]
8
- end
9
-
10
- def count
11
- @cards.try(:total_count) || 0
12
- end
13
-
14
- def perform
15
- params = {
16
- limit: limit,
17
- starting_after: starting_after,
18
- ending_before: ending_before,
19
- object: 'card'
20
- }
21
- params['include[]'] = 'total_count'
22
-
23
- resource = collection.find(@params[:id])
24
- customer = resource[field]
25
-
26
- if customer.blank?
27
- @records = []
28
- else
29
- fetch_cards(customer, params)
30
- end
31
- end
32
-
33
- def fetch_cards(customer, params)
34
- @cards = Stripe::Customer.retrieve(customer).sources.all(params)
35
- if @cards.blank?
36
- @records = []
37
- return
38
- end
39
-
40
- @records = @cards.data.map do |d|
41
- query = {}
42
- query[field] = d.customer
43
- d.customer = collection.find_by(query)
44
-
45
- d
46
- end
47
- end
48
-
49
- def starting_after
50
- if pagination? && @params[:starting_after]
51
- @params[:starting_after]
52
- end
53
- end
54
-
55
- def ending_before
56
- if pagination? && @params[:ending_before]
57
- @params[:ending_before]
58
- end
59
- end
60
-
61
- def limit
62
- return 10 unless pagination?
63
-
64
- if @params[:page][:size]
65
- @params[:page][:size].to_i
66
- else
67
- 10
68
- end
69
- end
70
-
71
- def pagination?
72
- @params[:page]
73
- end
74
-
75
- def collection
76
- @params[:collection].singularize.camelize.constantize
77
- end
78
-
79
- def field
80
- ForestLiana.integrations[:stripe][:mapping].select { |value|
81
- value.split('.')[0] == ForestLiana::SchemaUtils
82
- .find_model_from_collection_name(@params[:collection]).try(:name)
83
- }.first.split('.')[1]
84
- end
85
- end
86
- end