Class: VoidFailedReservationWorker

Inherits:
ApplicationWorker show all
Defined in:
app/workers/void_failed_reservation_worker.rb

Overview

this class will refund the payment if the booking status is not `pending_arrival` normally, for every transaction, system record the payment gateway's reference ID to Externals::Omise::Charge model so if the reference number has been recorded, we don't need to refund it if the reference number has not been recorded, we need to refund it this class will refund

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationWorker

unlimited_retry

Class Method Details

.void_later(provider, reference_no, gb_secret_key = nil) ⇒ Object



22
23
24
# File 'app/workers/void_failed_reservation_worker.rb', line 22

def self.void_later(provider, reference_no, gb_secret_key = nil)
  VoidFailedReservationWorker.perform_in(3.minutes, provider, reference_no, gb_secret_key)
end

Instance Method Details

#perform(provider, reference_no, gb_secret_key = nil) ⇒ Object



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

def perform(provider, reference_no, gb_secret_key = nil)
  # for GB Primepay we store the reference in `reference_no` column
  # but for Omise, we store it in `omise_charge_id` column
  hh_charge = Externals::Omise::Charge.where('reference_no = ? OR omise_charge_id = ?', reference_no,
                                             reference_no).first

  return if hh_charge.present?

  gateway = MyActiveMerchants::Gateway.new provider.to_sym
  gateway.void(reference_no: reference_no, gb_secret_key: gb_secret_key)
end