Class: Admin::CreditCardsController

Inherits:
BaseController show all
Defined in:
app/controllers/admin/credit_cards_controller.rb

Constant Summary

Constants inherited from BaseController

BaseController::INTERNAL_SERVER_ERROR_MESSAGE

Instance Method Summary collapse

Methods inherited from BaseController

#destroy_session, #identity_cache_memoization, #sign_in_page, #user_developer_session

Methods included from LogrageCustomLogger

#append_info_to_payload

Methods included from AdminHelper

#dynamic_pricings_formatter, #link_to_admin_reservations_path_by_id, #link_to_admin_restaurants_path_by_id, #link_to_log, #optional_locales, #optional_locales_with_labels, #staff_signed_in?

Methods included from UpdateLocaleConcern

#setup_locale

Methods inherited from ApplicationController

#after_sign_in_path_for, #after_sign_out_path_for, #default_url_options, #identity_cache_memoization, #render_not_found, #routing_error, search_params_key=

Methods included from ControllerHelpers

#check_boolean_param, #get_banners, #inventory_params, #reservation_params

Instance Method Details

#check_statusObject



73
74
75
76
77
78
# File 'app/controllers/admin/credit_cards_controller.rb', line 73

def check_status
  @check_status = GbPrimepay::CheckStatus.new
  @check_status.check(params[:reference_no])

  render 'admin/credit_cards/_check_status', layout: false
end

#downloadObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'app/controllers/admin/credit_cards_controller.rb', line 50

def download
  permitted_parameters = params.require(:credit_card).permit(
    :start_date, :end_date, :restaurant_id
  )
  if permitted_parameters[:start_date].blank? || permitted_parameters[:end_date].blank?
    return redirect_back(fallback_location: back_fallback_location,
                         alert: 'Start date and End date must be present')
  end

  start_date = Date.strptime(permitted_parameters.require(:start_date), '%m/%d/%Y')
  end_date = Date.strptime(permitted_parameters.require(:end_date), '%m/%d/%Y')

  download_link = ExportCreditCardService.new(start_date, end_date, permitted_parameters[:restaurant_id]).download
  respond_to do |format|
    format.xls do
      filename = "CreditCard-reports-#{Time.current_time.strftime('%Y-%m-%d %H:%M:%S')}.xls"
      data = open(download_link)
      send_data data.read, filename: filename, type: 'application/xls', disposition: 'inline', stream: 'true',
                           buffer_size: '4096'
    end
  end
end

#editObject



23
24
25
# File 'app/controllers/admin/credit_cards_controller.rb', line 23

def edit
  @credit_card = ::Externals::Omise::Charge.find params.require(:id)
end

#indexObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/controllers/admin/credit_cards_controller.rb', line 6

def index
  if params[:credit_cards_grid].blank?
    params[:credit_cards_grid] = {}
    if params[:credit_cards_grid][:order].blank?
      params[:credit_cards_grid][:order] = 'id'
      params[:credit_cards_grid][:descending] = true
    end
  end
  @grid = ::CreditCardsGrid.new(params[:credit_cards_grid]) do |scope|
    scope.page(params[:page])
  end

  @page_title = 'Credit Card Data'

  return unless stale_etag? @grid.assets
end

#showObject



27
28
29
# File 'app/controllers/admin/credit_cards_controller.rb', line 27

def show
  @charge = ::Externals::Omise::Charge.find(params[:id])
end

#updateObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/controllers/admin/credit_cards_controller.rb', line 31

def update
  @credit_card = ::Externals::Omise::Charge.find params.require(:id)

  permitted_params = params.require(:externals_omise_charge).permit(:amount_v2_cents).tap do |param|
    if param[:amount_v2_cents].present?
      currency = @credit_card.amount_v2_currency || 'THB'
      param[:amount_v2_cents] = HhMoney.from_amount(param[:amount_v2_cents].to_f, currency).amount_cents
    end
  end
  if @credit_card.update permitted_params
    update_reservation_charge_price

    redirect_to edit_admin_credit_card_path(@credit_card),
                notice: "Transaction ID #{@credit_card.id} updated successfully"
  else
    render :edit
  end
end