Class: Api::V5::TicketTransactionsController
- Inherits:
-
BaseController
- Object
- ActionController::API
- BaseController
- Api::V5::TicketTransactionsController
show all
- Includes:
- Concerns::Authorization
- Defined in:
- app/controllers/api/v5/ticket_transactions_controller.rb
Overview
typed: ignore frozen_string_literal: true
Constant Summary
BaseController::CACHE_NAMESPACE, BaseController::INTERNAL_SERVER_ERROR_MESSAGE, BaseController::ResponseSchema
Instance Method Summary
collapse
#identity_cache_memoization
#append_info_to_payload
#my_response_cache
Instance Method Details
#cancel ⇒ Object
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'app/controllers/api/v5/ticket_transactions_controller.rb', line 58
def cancel
if @ticket_transaction.active?
reason = if @ticket_transaction.for_locking_system?
'cancel lock system by user'
else
'cancel payment by user'
end
service = ::PaymentProcessService::Cancelled.new(:ticket_transaction, @ticket_transaction.id, reason)
service.execute
end
render json: {
success: true,
message: 'cancel transaction success',
}
end
|
#create ⇒ Object
old flow, without Locking System we should remove this action after Locking System is implemented
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'app/controllers/api/v5/ticket_transactions_controller.rb', line 12
def create
render json: { success: false, message: I18n.t('ticket_transaction.prevent_booking_old_version') }
end
|
#extend_session ⇒ Object
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
# File 'app/controllers/api/v5/ticket_transactions_controller.rb', line 99
def extend_session
if @ticket_transaction.active? && @ticket_transaction.for_locking_system?
new_session = @ticket_transaction.renew_session_id
@ticket_transaction.save(validate: false)
count_down = Time.zone.now + AdminSetting.reservation_session_timeout.to_i.minutes
Workers::TicketTransactions::CancelTemporaryWorker.perform_in(count_down, @ticket_transaction.id, new_session)
(true)
render json: {
data: {
transaction_id: @ticket_transaction.id,
expired_at: count_down.utc.iso8601,
},
success: true,
message: 'Extend session transaction success',
}
else
render json: {
data: nil,
success: false,
message: 'Extend session transaction failed',
}
end
end
|
#lock ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'app/controllers/api/v5/ticket_transactions_controller.rb', line 35
def lock
user = params.key?(:access_token) && params[:access_token].present? && authorize! && user_signed_in? ? current_user : nil
service = ::TicketService::Transaction.new(params, user, request.remote_ip)
if service.lock && service.outcome
(true)
render json: {
data: {
transaction_id: service.outcome.id,
expired_at: service.expiry_time,
},
success: true,
message: 'lock transaction success',
}
elsif service.errors.present?
(false)
render json: { success: false, message: service.error_message_simple, data: nil }
else
(false)
message = service.error_message_simple.presence || I18n.t('errors.too_many_requests')
render json: { success: false, message: message, data: nil }
end
end
|
#mark_as_paid ⇒ Object
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
# File 'app/controllers/api/v5/ticket_transactions_controller.rb', line 126
def mark_as_paid
charge = @ticket_transaction.charges.pending_scope.last
if charge.blank? || ENV['RAILS_ENV_REAL'] == 'production'
render json: { success: false }
return
end
charge_id = charge.omise_charge_id
service = PaymentProcessService::MarkAsPaid.new(charge_id, 'by-admin')
if service.execute
render json: { success: true }
else
render json: { success: false }
end
end
|
#show ⇒ Object
30
31
32
33
|
# File 'app/controllers/api/v5/ticket_transactions_controller.rb', line 30
def show
options = { include: DEFAULT_INCLUDE }
render json: resource_as_json(@ticket_transaction, Api::V5::TicketTransactionSerializer, options)
end
|
#submit ⇒ Object
same as #create action, but this one is for Locking System
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
# File 'app/controllers/api/v5/ticket_transactions_controller.rb', line 77
def submit
transaction = TicketTransaction.find_by(id: params[:ticket_transaction_id])
return render json: { success: false, message: 'Transaction not found', data: nil } if transaction.blank?
user = params.key?(:access_token) && params[:access_token].present? && params.key?(:provider) && authorize! && user_signed_in? ? current_user : nil
transaction_id = params.require(:ticket_transaction_id)
service = ::TicketService::Transaction.new(params, user, request.remote_ip)
service.set_transaction(transaction_id)
if service.create
(true)
options = { include: DEFAULT_INCLUDE }
render json: resource_as_json(service.outcome, Api::V5::TicketTransactionSerializer, options).
merge(
success: true,
message: 'Purchase vouchers success',
)
else
(false)
render json: { success: false, message: service.error_message_simple, data: nil }
end
end
|