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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'app/workers/workers/payments/general_check_status_worker.rb', line 9
def perform(external_charge_id, retry_check = 0)
charge = Externals::Omise::Charge.find_by omise_charge_id: external_charge_id
return if charge.blank?
transaction = charge.transaction
return if transaction.blank?
return if skip_process(charge)
check_status = GbPrimepay::CheckStatus.new
ref_no = charge.reference_no.presence || charge.reservation_id
check_status.check(ref_no)
data = check_status.data
retry_check += 1
return if check_status.invalid_card?
return if retry_check >= LIMIT_RETRY_CHECK
if check_status.success? && data.present?
success_payment = if data.is_a?(Array)
data.select { |txn| txn['status'] == 'S' || txn['status'] == 'A' }.first
elsif data['status'] == 'S' || data['status'] == 'A'
data
end
if success_payment.blank?
Workers::Payments::GeneralCheckStatusWorker.perform_in(RETRY_EVERY, external_charge_id, retry_check)
return
end
charge_id = success_payment['gbpReferenceNo']
service = if charge.reservation_id.present?
MarkReservationAsPaidService.new(charge_id, charge_id, ref_no)
elsif charge.voucher_transaction_id.present?
MarkVoucherTransactionAsPaidService.new(charge_id, charge_id, ref_no)
elsif charge.ticket_transaction_id.present?
PaymentProcessService::MarkAsPaid.new(charge_id, charge_id, ref_no)
else
raise NotImplementedError
end
unless service.execute!
HH_LOGGER.error(service.error_message_simple, {
id: transaction.id,
transaction: charge_id,
transaction_type: charge.transaction_product_type.to_s.camelize,
})
raise
end
else
Workers::Payments::GeneralCheckStatusWorker.perform_in(RETRY_EVERY, external_charge_id, retry_check)
end
end
|