Class: MarkVoucherTransactionAsPaidService
- Inherits:
-
BaseOperationService
- Object
- BaseOperationService
- MarkVoucherTransactionAsPaidService
- Includes:
- DefaultErrorContainer
- Defined in:
- app/services/mark_voucher_transaction_as_paid_service.rb
Overview
typed: ignore Service to mark a reservation status to be 'Arrived'
Instance Attribute Summary collapse
-
#by_admin ⇒ Object
writeonly
Sets the attribute by_admin.
-
#charge_id ⇒ Object
readonly
Returns the value of attribute charge_id.
-
#reference_no ⇒ Object
readonly
Returns the value of attribute reference_no.
-
#transaction_id ⇒ Object
readonly
Returns the value of attribute transaction_id.
Attributes inherited from BaseOperationService
Instance Method Summary collapse
- #execute ⇒ Object
- #execute! ⇒ Object
-
#initialize(charge_id, transaction_id, reference_no = nil) ⇒ MarkVoucherTransactionAsPaidService
constructor
A new instance of MarkVoucherTransactionAsPaidService.
Methods included from DefaultErrorContainer
#error, #error_message_simple, #merge_errors
Methods inherited from BaseOperationService
Constructor Details
#initialize(charge_id, transaction_id, reference_no = nil) ⇒ MarkVoucherTransactionAsPaidService
Returns a new instance of MarkVoucherTransactionAsPaidService.
12 13 14 15 16 17 |
# File 'app/services/mark_voucher_transaction_as_paid_service.rb', line 12 def initialize(charge_id, transaction_id, reference_no = nil) @charge_id = charge_id @transaction_id = transaction_id @by_admin = transaction_id == 'by-admin' @reference_no = reference_no end |
Instance Attribute Details
#by_admin=(value) ⇒ Object
Sets the attribute by_admin
7 8 9 |
# File 'app/services/mark_voucher_transaction_as_paid_service.rb', line 7 def by_admin=(value) @by_admin = value end |
#charge_id ⇒ Object (readonly)
Returns the value of attribute charge_id.
6 7 8 |
# File 'app/services/mark_voucher_transaction_as_paid_service.rb', line 6 def charge_id @charge_id end |
#reference_no ⇒ Object (readonly)
Returns the value of attribute reference_no.
6 7 8 |
# File 'app/services/mark_voucher_transaction_as_paid_service.rb', line 6 def reference_no @reference_no end |
#transaction_id ⇒ Object (readonly)
Returns the value of attribute transaction_id.
6 7 8 |
# File 'app/services/mark_voucher_transaction_as_paid_service.rb', line 6 def transaction_id @transaction_id end |
Instance Method Details
#execute ⇒ Object
47 48 49 50 51 52 |
# File 'app/services/mark_voucher_transaction_as_paid_service.rb', line 47 def execute execute! rescue StandardError => e errors.add(:base, e.) false end |
#execute! ⇒ Object
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 |
# File 'app/services/mark_voucher_transaction_as_paid_service.rb', line 19 def execute! errors.clear charge = if reference_no.present? Externals::Omise::Charge.find_by(omise_charge_id: charge_id, reference_no: reference_no).presence || Externals::Omise::Charge.find_by(omise_charge_id: charge_id) else Externals::Omise::Charge.find_by(omise_charge_id: charge_id) end if charge.blank? errors.add(:base, "Charge ID #{charge_id} is not found") return false end result = update_attributes(charge) unless result APMErrorHandler.report('failed updating transaction voucher as active', charge: charge.attributes) raise StandardError, 'Failed updating transaction voucher data' end update_firebase(charge.voucher_transaction.reload) result rescue DuplicateChargeError true end |