Class: Accountability::BillingConfigurationsController

Inherits:
AccountabilityController show all
Defined in:
app/controllers/accountability/billing_configurations_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



10
11
12
13
14
15
16
17
18
19
20
# File 'app/controllers/accountability/billing_configurations_controller.rb', line 10

def create
  bc_params = billing_configuration_params
  @billing_configuration = @account.build_billing_configuration_with_active_merchant_data(bc_params,
                                                                                          verify_card: true)
  if @billing_configuration.save
    message = 'Credit card successfully added.'
    render json: { status: :success, message: message, updated_elements: updated_billing_elements }
  else
    render json: { status: :error, errors: @billing_configuration.errors }
  end
end

#designate_as_primaryObject



46
47
48
49
50
51
52
53
# File 'app/controllers/accountability/billing_configurations_controller.rb', line 46

def designate_as_primary
  if @billing_configuration.primary!
    message = 'Payment Method Set As Primary'
    render json: { status: :success, message: message, updated_elements: updated_billing_elements }
  else
    render json: { status: :error, errors: @billing_configuration.errors }
  end
end

#destroyObject



35
36
37
38
39
40
41
42
43
44
# File 'app/controllers/accountability/billing_configurations_controller.rb', line 35

def destroy
  if @billing_configuration.destroy
    render json: {
      status: :success,
      message: 'Payment Method Destroyed'
    }
  else
    render json: { status: :error, errors: @billing_configuration.errors }
  end
end

#editObject



22
# File 'app/controllers/accountability/billing_configurations_controller.rb', line 22

def edit; end

#newObject



8
# File 'app/controllers/accountability/billing_configurations_controller.rb', line 8

def new; end

#showObject



6
# File 'app/controllers/accountability/billing_configurations_controller.rb', line 6

def show; end

#updateObject



24
25
26
27
28
29
30
31
32
33
# File 'app/controllers/accountability/billing_configurations_controller.rb', line 24

def update
  @billing_configuration.update billing_configuration_params

  if @billing_configuration.save
    message = 'Configuration Updated'
    render json: { status: :success, message: message, updated_elements: updated_billing_elements }
  else
    render json: { status: :error, errors: @billing_configuration.errors }
  end
end

#updated_billing_elementsObject



55
56
57
58
59
60
61
62
63
# File 'app/controllers/accountability/billing_configurations_controller.rb', line 55

def updated_billing_elements
  configurations_partial = 'accountability/accounts/billing_configurations/configurations'
  payment_form_partial = 'accountability/accounts/payment_form'

  {
    configurations: render_to_string(partial: configurations_partial, layout: false, locals: { account: @account }),
    payment_form: render_to_string(partial: payment_form_partial, layout: false, locals: { account: @account })
  }
end