Class: VendorsService::GoogleReserve::WebhookService

Inherits:
BaseOperationService show all
Includes:
ElasticAPM::SpanHelpers
Defined in:
app/services/vendors_service/google_reserve/webhook_service.rb

Constant Summary collapse

SCOPE =
['https://www.googleapis.com/auth/mapsbooking'].freeze
SERVICE_ACCOUNT_FILE =
ROUTE =
'bookings-notification'.freeze
MAX_RETRY_ATTEMPTS =
3
RETRY_DELAY_IN_SECONDS =
5

Instance Attribute Summary collapse

Attributes inherited from BaseOperationService

#outcome

Instance Method Summary collapse

Methods inherited from BaseOperationService

#success?

Constructor Details

#initialize(booking, status) ⇒ WebhookService

Returns a new instance of WebhookService.



50
51
52
53
54
55
56
57
58
59
# File 'app/services/vendors_service/google_reserve/webhook_service.rb', line 50

def initialize(booking, status)
  super()
  @booking = booking
  @status = status
  @reservation = booking&.decorate
  RequestStore.store[:reservation_id] ||= booking.id
  RequestStore.store[:restaurant_id] ||= booking.restaurant_id
  BUSINESS_LOGGER.set_business_context({ reservation_id: booking.id,
                                         vendor_name: ApiVendorV1::Constants::GOOGLE_RESERVE_VENDOR_NAME })
end

Instance Attribute Details

#bookingObject (readonly)

Returns the value of attribute booking.



45
46
47
# File 'app/services/vendors_service/google_reserve/webhook_service.rb', line 45

def booking
  @booking
end

#reservationObject (readonly)

Returns the value of attribute reservation.



45
46
47
# File 'app/services/vendors_service/google_reserve/webhook_service.rb', line 45

def reservation
  @reservation
end

#statusObject (readonly)

Returns the value of attribute status.



45
46
47
# File 'app/services/vendors_service/google_reserve/webhook_service.rb', line 45

def status
  @status
end

Instance Method Details

#send_webhookObject



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'app/services/vendors_service/google_reserve/webhook_service.rb', line 61

def send_webhook
  return unless valid_reservation?

  valid_statuses = [
    ApiVendorV1::Constants::RWG_CONFIRMED,
    ApiVendorV1::Constants::RWG_DECLINED_BY_MERCHANT,
    ApiVendorV1::Constants::RWG_CANCELED,
  ]

  unless valid_statuses.include?(status)
    log_error('GoogleReserve: Invalid reservation status', status: status)
    return
  end

  attempt_update_reservation
end