Class: ForestLiana::StripeController

Inherits:
ApplicationController show all
Defined in:
app/controllers/forest_liana/stripe_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#authenticate_user_from_jwt, #forest_user, #serialize_model, #serialize_models

Instance Method Details

#bank_accountsObject



67
68
69
70
71
72
73
74
75
76
77
78
# File 'app/controllers/forest_liana/stripe_controller.rb', line 67

def bank_accounts
  getter = StripeBankAccountsGetter.new(params,
                                 request.headers['Stripe-Secret-Key'],
                                 request.headers['Stripe-Reference'])
  getter.perform

  render serializer: nil, json: serialize_models(getter.records, {
    context: { type: get_serializer_type('stripe_bank_accounts') },
    count: getter.count,
    include: ['customer']
  })
end

#cardsObject



28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/controllers/forest_liana/stripe_controller.rb', line 28

def cards
  getter = StripeCardsGetter.new(params,
                                 request.headers['Stripe-Secret-Key'],
                                 request.headers['Stripe-Reference'])
  getter.perform

  render serializer: nil, json: serialize_models(getter.records, {
    context: { type: get_serializer_type('stripe_cards') },
    count: getter.count,
    include: ['customer']
  })
end

#get_serializer_type(suffix) ⇒ Object



80
81
82
# File 'app/controllers/forest_liana/stripe_controller.rb', line 80

def get_serializer_type(suffix)
  "#{params[:collection]}_#{suffix}"
end

#invoicesObject



41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/controllers/forest_liana/stripe_controller.rb', line 41

def invoices
  getter = StripeInvoicesGetter.new(params,
                                    request.headers['Stripe-Secret-Key'],
                                    request.headers['Stripe-Reference'])
  getter.perform

  render serializer: nil, json: serialize_models(getter.records, {
    context: { type: get_serializer_type('stripe_invoices') },
    count: getter.count,
    include: ['customer']
  })
end

#paymentsObject



4
5
6
7
8
9
10
11
12
13
14
15
# File 'app/controllers/forest_liana/stripe_controller.rb', line 4

def payments
  getter = StripePaymentsGetter.new(params,
                                    request.headers['Stripe-Secret-Key'],
                                    request.headers['Stripe-Reference'])
  getter.perform

  render serializer: nil, json: serialize_models(getter.records, {
    context: { type: get_serializer_type('stripe_payments') },
    count: getter.count,
    include: ['customer']
  })
end

#refundObject



17
18
19
20
21
22
23
24
25
26
# File 'app/controllers/forest_liana/stripe_controller.rb', line 17

def refund
  begin
    refunder = StripePaymentRefunder.new(params)
    refunder.perform

    render serializer: nil, json: {}
  rescue Stripe::InvalidRequestError => err
    render serializer: nil, json: { error: err.message }, status: 400
  end
end

#subscriptionsObject



54
55
56
57
58
59
60
61
62
63
64
65
# File 'app/controllers/forest_liana/stripe_controller.rb', line 54

def subscriptions
  getter = StripeSubscriptionsGetter.new(params,
                                 request.headers['Stripe-Secret-Key'],
                                 request.headers['Stripe-Reference'])
  getter.perform

  render serializer: nil, json: serialize_models(getter.records, {
    context: { type: get_serializer_type('stripe_subscriptions') },
    count: getter.count,
    include: ['customer']
  })
end