Class: Webhooks::Vendors::Tablecheck::CallbackController
- Inherits:
-
ApplicationV2Controller
- Object
- ActionController::Base
- ApplicationV2Controller
- Webhooks::Vendors::Tablecheck::CallbackController
- Defined in:
- app/controllers/webhooks/vendors/tablecheck/callback_controller.rb
Instance Method Summary collapse
Methods inherited from ApplicationV2Controller
Methods included from LogrageCustomLogger
Instance Method Details
#callback ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'app/controllers/webhooks/vendors/tablecheck/callback_controller.rb', line 40 def callback syncable_type = params[:syncable_type] syncable_id = params[:syncable_id] reservation = VendorReservation.find_by(supplier_reservation_id: syncable_id)&.reservation BUSINESS_LOGGER.set_business_context({ vendor_reference_id: syncable_id, reservation_id: reservation&.id, vendor_name: ApiVendorV1::Constants::TABLECHECK_INV_SOURCE_NAME }) VendorLogger.log_event(:webhook_in, params[:route], payload: params) if syncable_type.present? && syncable_id.present? && reservation.present? ::Vendors::Tablecheck::WebhookWorker.perform_async(reservation.id, syncable_id) end render json: { success: true, message: nil } rescue StandardError => e = "Tablecheck Webhook processing error: #{e.}" APMErrorHandler.report render json: { success: false, message: } end |
#oauth2_tablecheck ⇒ Object
8 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 |
# File 'app/controllers/webhooks/vendors/tablecheck/callback_controller.rb', line 8 def oauth2_tablecheck BUSINESS_LOGGER.set_business_context({ vendor_name: ApiVendorV1::Constants::TABLECHECK_INV_SOURCE_NAME }) VendorLogger.log_event(:request, params[:route]) client_id = params[:client_id] client_secret = params[:client_secret] if client_id.blank? || client_secret.blank? return render json: { success: false, message: 'client_id or client_secret is missing' }, status: :unauthorized end application = Doorkeeper::Application.find_by(uid: client_id, secret: client_secret) if application.blank? return render json: { success: false, message: 'Invalid client_id or client_secret' }, status: :unauthorized end access_token = Doorkeeper::AccessToken.create( resource_owner: application, refresh_token: generate_refresh_token, expires_in: Doorkeeper.configuration.access_token_expires_in.to_i, scopes: 'default', ) render json: { token_type: access_token.token_type, scope: access_token.scopes.to_s, created_at: access_token.created_at.to_i, access_token: access_token.token, expires_at: access_token.expires_at.to_i, refresh_token: access_token.refresh_token, } end |