Class: Workers::Payments::CancelLaterWorker
- Inherits:
-
ApplicationWorker
- Object
- ApplicationWorker
- Workers::Payments::CancelLaterWorker
- Defined in:
- app/workers/workers/payments/cancel_later_worker.rb
Overview
We use this worker to cancel TicketTransaction only right now But in the future it should be used for Reservation as well to replace app/workers/workers/reservations/cancel_later_worker.rb
Constant Summary collapse
- ALLOWED_TRANSACTION_TYPES =
['ticket_transaction', 'reservation'].freeze
Instance Method Summary collapse
Methods inherited from ApplicationWorker
Instance Method Details
#perform(transaction_type, transaction_id) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'app/workers/workers/payments/cancel_later_worker.rb', line 8 def perform(transaction_type, transaction_id) raise ArgumentError, "Invalid transaction type" unless ALLOWED_TRANSACTION_TYPES.include?(transaction_type) transaction = transaction_type.to_s.camelize.constantize.find_by(id: transaction_id) return if transaction.blank? # if admin or any process marked the transaction as paid before this worker has run # we don't need to cancel the transaction return if transaction.charges.success_scope.present? # transaction.audit_comment = 'cancel booking because didnt pay' # transaction.mark_as_canceled! # transaction.mark_voucher_as_inactive! # transaction.save!(validate: false) # service_class = "PaymentProcessService::Transactions::#{transaction_type.camelize}".constantize service = PaymentProcessService::Cancelled.new(transaction_type, transaction_id) service.execute # if transaction.shopee_pay_provider? && transaction.charges.success_scope.blank? # service = ShopeePayService::InvalidateInvoice.new(transaction) # service.execute # end [1, 5, 7, 10].each do |number| Workers::Payments::CheckPaymentWorker.perform_in(number.to_i.minutes, transaction_type, transaction_id) end end |