Module: VendorsService::GoogleReserve::Concerns::PackageUtils

Extended by:
ActiveSupport::Concern
Included in:
AvailabilityFeeds::ProcessorService, PackageService
Defined in:
app/services/vendors_service/google_reserve/concerns/package_utils.rb

Overview

Utility methods for Google Reserve package integrations.

This concern provides common helper methods used across Google Reserve services for package validation, filtering, and eligibility checks, particularly focusing on Phase-II payment redirect compatibility, Google Reserve requirements, and handling the three package payment types: pay-at-restaurant, require_cc, and pay_now.

Instance Method Summary collapse

Instance Method Details

#determine_admin_force_payment_settings(package, google_reserve_package = nil) ⇒ Hash

Returns admin force payment settings for a package. Provides a hash with :is_force_prepayment and :can_edit_force_prepayment keys for UI and API logic.

Payment logic by package type:

  • Pay-at-restaurant packages: Cannot be forced to prepay (no advance payment accepted)

  • require_cc packages: Must prepay (mandatory advance payment)

  • pay_now packages: Configurable prepayment settings (optional advance payment)

Parameters:

  • package (HhPackage::Package)

    The package to evaluate

  • google_reserve_package (Object, nil) (defaults to: nil)

    Optional Google Reserve package object

Returns:

  • (Hash)

    force payment settings



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'app/services/vendors_service/google_reserve/concerns/package_utils.rb', line 54

def determine_admin_force_payment_settings(package, google_reserve_package = nil)
  can_edit_force_prepayment = false

  if pay_at_restaurant_package?(package)
    is_force_prepayment = false
  elsif package.require_cc
    # Require pre-payment package (mandatory advance payment)
    is_force_prepayment = true
  else
    # Pay now package (optional advance payment)
    is_force_prepayment = google_reserve_package&.force_prepayment.nil? ? true : google_reserve_package.force_prepayment
    can_edit_force_prepayment = true
  end
  { is_force_prepayment: is_force_prepayment, can_edit_force_prepayment: can_edit_force_prepayment }
end

#format_pkg_name(default_package_name, package_type) ⇒ String

Formats the package name for display in Google Reserve UI. Adds “(Buffet)” for Ayce package types, otherwise returns the name as-is.

Parameters:

  • default_package_name (String)

    The default package name

  • package_type (String)

    The package type (e.g., 'Ayce')

Returns:

  • (String)

    Formatted package name



76
77
78
79
80
81
82
# File 'app/services/vendors_service/google_reserve/concerns/package_utils.rb', line 76

def format_pkg_name(default_package_name, package_type)
  if package_type == 'Ayce'
    "#{default_package_name} (Buffet)"
  else
    default_package_name.to_s
  end
end

#rwg_prepaid_package?(package, rwg_package = nil) ⇒ Boolean

Returns true if a package should be uploaded to Google Reserve as prepaid.

In Phase-II payment redirect, eligible for prepayment:

  • require_cc packages: Always prepaid (mandatory advance payment)

  • pay_now packages: Only if admin has not disabled force_prepayment

  • All per_pax packages (require_cc or pay_now types only)

  • Single quantity per_pack packages (require_cc or pay_now types only)

Pay-at-restaurant packages are excluded as they don't accept advance payment.

Parameters:

  • package (HhPackage::Package)

    The package to evaluate

  • google_reserve_package (Object, nil)

    Optional Google Reserve package object

Returns:

  • (Boolean)

    true if package should be uploaded as prepaid



97
98
99
100
101
102
103
104
# File 'app/services/vendors_service/google_reserve/concerns/package_utils.rb', line 97

def rwg_prepaid_package?(package, rwg_package = nil)
  return false if pay_at_restaurant_package?(package)

  # For pay_now packages, check admin's force_prepayment setting (defaults to true if not set)
  return false if package.pay_now && rwg_package&.force_prepayment == false

  true
end

#skip_package_upload?(package, restaurant) ⇒ Boolean

Returns true if a package should be excluded from Google Reserve upload.

pay-at-restaurant packages for third-party inventory restaurants should be excluded because of inventory mismatch issue

Parameters:

  • package (HhPackage::Package)

    The package to evaluate

  • restaurant (Restaurant)

    Restaurant object to check third-party inventory status

Returns:

  • (Boolean)

    true if package should be excluded from upload



34
35
36
37
38
39
40
41
# File 'app/services/vendors_service/google_reserve/concerns/package_utils.rb', line 34

def skip_package_upload?(package, restaurant)
  # Skip all package upload for Malaysia restaurants until prepayment processing is enabled for Malaysia
  return true if restaurant.country&.alpha3 == ApiV5::Constants::COUNTRY_CODE_MY
  # Skip pay-at-restaurant packages for third-party inventory restaurants
  return true if restaurant.use_third_party_inventory? && pay_at_restaurant_package?(package)

  false
end