Module: OmiseHelper
- Included in:
- CreatePromptpayService, Externals::Omise::Charge, MyActiveMerchants::OmiseGateway, TicketService::Transaction, WechatPaymentService
- Defined in:
- app/helpers/omise_helper.rb
Overview
Helper module for Omise payment gateway configuration
This module provides methods to configure Omise API keys based on the country where the payment is being processed. Each country (Thailand, Singapore, Malaysia) has its own Omise account with separate API credentials.
Instance Method Summary collapse
-
#configure_omise_keys(country_code) ⇒ void
Configure Omise API keys based on country code.
-
#omise_public_key ⇒ String
Get the current Omise public key (vault key).
Instance Method Details
#configure_omise_keys(country_code) ⇒ void
If an invalid country code is provided, it defaults to Thailand (THA)
This method returns an undefined value.
Configure Omise API keys based on country code
This method sets the global Omise configuration to use the appropriate API credentials for the specified country. It reads credentials from environment variables in the format:
-
OMISE_SKEY_COUNTRY_CODE (secret key)
-
OMISE_VAULT_KEY_COUNTRY_CODE (public/vault key)
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 |
# File 'app/helpers/omise_helper.rb', line 52 def configure_omise_keys(country_code) # validate country code # default to TH if country code is not in the list country_code = ApiV5::Constants::COUNTRY_CODE_TH if ApiV5::Constants::COUNTRY_CODES.exclude?(country_code) # Handle Malaysia Omise keys with dual fallback mechanism to Singapore if country_code == ApiV5::Constants::COUNTRY_CODE_MY flag_enabled = Flipper.enabled?(:use_omise_malaysia_keys) # Fallback 1: Feature flag disabled - intentional fallback to Singapore if flag_enabled # Fallback 2: Feature flag enabled but keys missing - configuration issue api_key = Figaro.env.send("OMISE_SKEY_#{country_code}!") vault_key = Figaro.env.send("OMISE_VAULT_KEY_#{country_code}!") if api_key.blank? || vault_key.blank? error_context = { requested_country: country_code, fallback_reason: 'keys_not_configured', missing_api_key: api_key.blank?, missing_vault_key: vault_key.blank?, flipper_flag_enabled: true, fallback_country: ApiV5::Constants::COUNTRY_CODE_SG, action_required: 'Configure OMISE_SKEY_MYS and OMISE_VAULT_KEY_MYS environment variables', } BUSINESS_LOGGER.warn('Malaysia Omise keys missing despite feature flag enabled, falling back to Singapore', error_context) APMErrorHandler.report( RuntimeError.new('Malaysia Omise keys not configured'), error_context, ) country_code = ApiV5::Constants::COUNTRY_CODE_SG end else BUSINESS_LOGGER.info('Malaysia Omise keys feature flag disabled, using Singapore keys', requested_country: country_code, fallback_reason: 'feature_flag_disabled', flipper_flag: 'use_omise_malaysia_keys', fallback_country: ApiV5::Constants::COUNTRY_CODE_SG) country_code = ApiV5::Constants::COUNTRY_CODE_SG end end api_key = Figaro.env.send("OMISE_SKEY_#{country_code}!") vault_key = Figaro.env.send("OMISE_VAULT_KEY_#{country_code}!") ::Omise.api_key = api_key ::Omise.vault_key = vault_key end |
#omise_public_key ⇒ String
Get the current Omise public key (vault key)
24 25 26 |
# File 'app/helpers/omise_helper.rb', line 24 def omise_public_key ::Omise.vault_key end |