Class: MarkReservationAsPaidService
- Inherits:
-
BaseOperationService
- Object
- BaseOperationService
- MarkReservationAsPaidService
- Includes:
- DefaultErrorContainer
- Defined in:
- app/services/mark_reservation_as_paid_service.rb
Defined Under Namespace
Classes: DuplicateChargeError
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) ⇒ MarkReservationAsPaidService
constructor
A new instance of MarkReservationAsPaidService.
Methods included from DefaultErrorContainer
#error, #error_message_simple, #merge_errors
Methods inherited from BaseOperationService
Constructor Details
#initialize(charge_id, transaction_id, reference_no = nil) ⇒ MarkReservationAsPaidService
Returns a new instance of MarkReservationAsPaidService.
15 16 17 18 19 20 21 |
# File 'app/services/mark_reservation_as_paid_service.rb', line 15 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 @need_to_run_loyalty_program_feature = false end |
Instance Attribute Details
#by_admin=(value) ⇒ Object
Sets the attribute by_admin
10 11 12 |
# File 'app/services/mark_reservation_as_paid_service.rb', line 10 def by_admin=(value) @by_admin = value end |
#charge_id ⇒ Object (readonly)
Returns the value of attribute charge_id.
9 10 11 |
# File 'app/services/mark_reservation_as_paid_service.rb', line 9 def charge_id @charge_id end |
#reference_no ⇒ Object (readonly)
Returns the value of attribute reference_no.
9 10 11 |
# File 'app/services/mark_reservation_as_paid_service.rb', line 9 def reference_no @reference_no end |
#transaction_id ⇒ Object (readonly)
Returns the value of attribute transaction_id.
9 10 11 |
# File 'app/services/mark_reservation_as_paid_service.rb', line 9 def transaction_id @transaction_id end |
Instance Method Details
#execute ⇒ Object
182 183 184 185 186 187 |
# File 'app/services/mark_reservation_as_paid_service.rb', line 182 def execute execute! rescue StandardError => e errors.add(:base, e.) false end |
#execute! ⇒ Object
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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 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 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'app/services/mark_reservation_as_paid_service.rb', line 23 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 raise StandardError, "Charge ID #{charge_id} is not found" if charge.blank? validate_supplier_reservation(charge) result = update_attributes(charge) unless result APMErrorHandler.report('failed updating reservation as active', charge: charge.attributes) raise StandardError, 'Failed updating reservation data' end reservation = charge.reservation.reload BUSINESS_LOGGER.set_business_context({ reservation_id: reservation.id }) BUSINESS_LOGGER.info("#{self.class}: Reservation found") if reservation.pay_now? && reservation.restaurant.eligible_for_rewards? GiveReservationRewardWorker.perform_in(1.minute, reservation.id) end send_notification(reservation) if @need_to_run_loyalty_program_feature time = reservation.reservation_time.twenty_four_hours_later if reservation.user_id.present? if reservation.id.blank? APMErrorHandler.report('Nil reservation id detected before enqueuing reward workers') else LoyaltyPrograms::TierQualificationWorker.perform_at(time, reservation.id) end end end MyPusher::ReservationDriver.broadcast_reservation(reservation, :update) if reservation.aoa_reservation.present? && reservation.aoa_channel? BUSINESS_LOGGER.info("#{self.class}: Aoa::WebhookWorker called from execute! method with status #{:pending_arrival}") Aoa::WebhookWorker.default_perform_async(reservation.id, :pending_arrival) end if reservation.by_marketplace? && reservation.tagthai_channel? status = ApiVendorV1::Constants::PENDING_ARRIVAL BUSINESS_LOGGER.info( "#{self.class}: Vendors::TagThai::WebhookWorker called from execute! method with status #{status}", status: status ) Vendors::TagThai::WebhookWorker.perform_async(reservation.id, status) end # update memo reservation [TableCheck] # update notes reservation [SevenRooms] if reservation.by_tablecheck? start_at = Time.use_zone reservation.restaurant.time_zone do Time.zone.parse(reservation.start_time_format, reservation.date) end update_params = { start_at: start_at, pax: reservation.party_size, pax_adult: reservation.adult, pax_child: reservation.kids, special_request: reservation., occasion: reservation.dining_occasion.present? ? reservation.dining_occasion.name_en : nil, } BUSINESS_LOGGER.info( "#{self.class}: Proceed to update payment info in Tablecheck memo", params: update_params ) tc_update_service = Tablecheck::Reservations::Update.new(reservation, reservation.vendor_reservation&.supplier_reservation_id, update_params) tc_update_service.execute elsif reservation.by_seven_rooms? update_params = { date: reservation.date, start_time: reservation.start_time, party_size: reservation.party_size, } BUSINESS_LOGGER.info( "#{self.class}: Proceed to update payment info in SevenRoom memo", params: update_params ) sr_update_service = SevenRooms::Reservations::Update.new(reservation, reservation.vendor_reservation&.supplier_reservation_id, update_params) sr_update_service.execute elsif reservation.by_weeloy? start_at = Time.use_zone reservation.restaurant.time_zone do Time.zone.parse(reservation.start_time_format, reservation.date) end update_params = { start_at: start_at, pax: reservation.party_size, pax_adult: reservation.adult, pax_child: reservation.kids, special_request: reservation., occasion: reservation.dining_occasion.present? ? reservation.dining_occasion.name_en : nil, } BUSINESS_LOGGER.info( "#{self.class}: Proceed to update payment info in Weeloy memo", params: update_params ) weeloy_update_service = Weeloy::Reservations::Update.new(reservation, reservation.vendor_reservation&.supplier_reservation_id, update_params) weeloy_update_service.execute elsif reservation.by_bistrochat? start_at = Time.use_zone reservation.restaurant.time_zone do Time.zone.parse(reservation.start_time_format, reservation.date) end update_params = { start_at: start_at, pax: reservation.party_size, pax_adult: reservation.adult, pax_child: reservation.kids, special_request: reservation., occasion: reservation.dining_occasion.present? ? reservation.dining_occasion.name_en : nil, } BUSINESS_LOGGER.info( "#{self.class}: Proceed to update payment info in BistroChat memo", params: update_params ) bc_update_service = Bistrochat::Reservations::Update.new(reservation, reservation.vendor_reservation&.supplier_reservation_id, update_params) bc_update_service.execute elsif reservation. start_at = Time.use_zone reservation.restaurant.time_zone do Time.zone.parse(reservation.start_time_format, reservation.date) end update_params = { start_at: start_at, pax: reservation.party_size, pax_adult: reservation.adult, pax_child: reservation.kids, special_request: reservation., occasion: reservation.dining_occasion.present? ? reservation.dining_occasion.name_en : nil, } BUSINESS_LOGGER.info( "#{self.class}: Proceed to update payment info in MyMenu memo", params: update_params ) mm_update_service = MyMenu::Reservations::Update.new(reservation, reservation.vendor_reservation&.supplier_reservation_id, update_params) mm_update_service.execute end result rescue DuplicateChargeError true end |