Module: CountryEmailHelper

Overview

CountryEmailHelper provides country-specific email routing functionality for merchant and finance emails based on restaurant country codes.

This module can be included in both controllers and mailers to provide consistent email routing logic across the application.

Examples:

Usage in a controller

class InventoriesController < ApplicationController
  include CountryEmailHelper

  def send_notification
    email = merchant_email_for_country(restaurant)
    StaffMailer.notify_error_staff(subject, body, { receivers: [email] }).deliver_later!
  end
end

Usage in a mailer

class StaffMailer < ApplicationMailer
  include CountryEmailHelper

  def notify_block_restaurant(restaurant_id, date, start_time, end_time, blocked_by)
    restaurant = Restaurant.fetch(restaurant_id)
    receiver = merchant_email_for_country(restaurant)
    mail(to: receiver, subject: subject)
  end
end

Instance Method Summary collapse

Instance Method Details

#merchant_email_for_country(restaurant) ⇒ String

Returns the appropriate merchant email based on the restaurant's country code

Examples:

merchant_email_for_country(restaurant) # => "merchant.sg@hungryhub.com" for SG
merchant_email_for_country(restaurant) # => "merchant@hungryhub.com" for TH/MY

Parameters:

  • restaurant (Restaurant)

    The restaurant object

Returns:

  • (String)

    The merchant email address for the country



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/my_lib/country_email_helper.rb', line 38

def merchant_email_for_country(restaurant)
  return MERCHANT_EMAIL if restaurant.blank?

  country_code = restaurant&.country&.alpha2 || restaurant&.city&.country&.alpha2

  case country_code
  when 'SG'
    MERCHANT_SG_EMAIL
  when 'MY'
    MERCHANT_MY_EMAIL
  else
    # Default to Thailand merchant email for 'TH' and any other country
    MERCHANT_EMAIL
  end
end