Class: CreatePromptpayService
- Inherits:
-
Object
- Object
- CreatePromptpayService
- Includes:
- OmiseHelper
- Defined in:
- app/services/create_promptpay_service.rb
Overview
Service for creating QR code payments via Omise or GB PrimePay
Supports multiple payment types across Thailand, Singapore, and Malaysia:
-
PromptPay (Thailand) - via Omise or GB PrimePay
-
PayNow (Singapore) - via Omise
-
Alipay Plus (Thailand, Singapore, Malaysia) - via Omise or GB PrimePay
The service automatically configures the correct Omise keys based on the restaurant's country code (THA, SGP, MYS) to ensure payments are processed through the appropriate regional Omise account.
Omise Promptpay has 2 ID, charge ID and transaction ID
* charge ID is created when creating Promptpay
* transaction ID is received when Promptpay has been paid
GB Primepay only has 1 ID, gbpReferenceNo so charge ID and Transaction ID is same
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(reservation, provider, payment_type = nil) ⇒ CreatePromptpayService
constructor
Initialize the service with reservation and payment configuration.
Methods included from OmiseHelper
#configure_omise_keys, #omise_public_key
Constructor Details
#initialize(reservation, provider, payment_type = nil) ⇒ CreatePromptpayService
The service automatically configures Omise keys based on restaurant country:
-
Thailand (THA): Uses OMISE_SKEY_THA and OMISE_VAULT_KEY_THA
-
Singapore (SGP): Uses OMISE_SKEY_SGP and OMISE_VAULT_KEY_SGP
-
Malaysia (MYS): Uses OMISE_SKEY_MYS and OMISE_VAULT_KEY_MYS
Initialize the service with reservation and payment configuration
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'app/services/create_promptpay_service.rb', line 33 def initialize(reservation, provider, payment_type = nil) @reservation = reservation default_provider = case payment_type.to_s when Externals::Omise::Source::ALIPAYPLUS_SOURCE_TYPE reservation.restaurant.selected_alipay_payment_provider else reservation.restaurant.selected_promptpay_payment_provider || AdminSetting.selected_promptpay_payment_provider end @provider = provider.presence || default_provider @payment_type = payment_type # configure omise keys based on restaurant country code configure_omise_keys(reservation.restaurant.country.alpha3) if reservation.restaurant.present? BUSINESS_LOGGER.set_business_context({ reservation_id: reservation.id, provider: provider }) end |
Instance Method Details
#execute ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'app/services/create_promptpay_service.rb', line 53 def execute success = false ActiveRecord::Base.transaction do reservation.charges.build(charge_attribute(reservation, provider, payment_type)) success = true end if !success APMErrorHandler.report('Failed to process reservation with Promptpay', reservation_id: reservation.id) return false end BUSINESS_LOGGER.info 'Done processing reservation with Promptpay', reservation_id: reservation.id success end |