Class: VoucherService::CreateTransaction::VoucherTransactionAdapter

Inherits:
Object
  • Object
show all
Includes:
ElasticAPM::SpanHelpers
Defined in:
app/services/voucher_service/create_transaction.rb

Overview

Adapter class to make VoucherTransaction compatible with MyActiveMerchants::Gateway which expects reservation-like interface (similar to TicketTransactionAdapter)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(voucher_transaction, omise_token) ⇒ VoucherTransactionAdapter

Returns a new instance of VoucherTransactionAdapter.



556
557
558
559
# File 'app/services/voucher_service/create_transaction.rb', line 556

def initialize(voucher_transaction, omise_token)
  @voucher_transaction = voucher_transaction
  @omise_token = omise_token
end

Instance Attribute Details

#omise_tokenObject (readonly)

Returns the value of attribute omise_token.



554
555
556
# File 'app/services/voucher_service/create_transaction.rb', line 554

def omise_token
  @omise_token
end

#voucher_transactionObject (readonly)

Returns the value of attribute voucher_transaction.



554
555
556
# File 'app/services/voucher_service/create_transaction.rb', line 554

def voucher_transaction
  @voucher_transaction
end

Instance Method Details

#cc_providerObject



591
592
593
# File 'app/services/voucher_service/create_transaction.rb', line 591

def cc_provider
  voucher_transaction.cc_provider&.to_sym
end

#chargesObject



604
605
606
# File 'app/services/voucher_service/create_transaction.rb', line 604

def charges
  voucher_transaction.charges
end

#countryObject

For OmiseGateway compatibility - delegate to voucher_transaction



637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
# File 'app/services/voucher_service/create_transaction.rb', line 637

def country
  # VoucherTransaction doesn't have direct country association
  # Determine country from total_price_currency
  currency_code = voucher_transaction.total_price_currency

  if currency_code.present?
    # Find country by currency code
    case currency_code.upcase
    when Country::MALAYSIA_CURRENCY_CODE
      Country.find_malaysia
    when Country::SINGAPORE_CURRENCY_CODE
      Country.find_singapore
    when Country::THAI_CURRENCY_CODE
      Country.find_thailand
    else
      # Try to find country by currency code, fallback to Thailand
      Country.find_by(currency_code: currency_code.downcase) || Country.find_thailand
    end
  else
    # Fallback to Thailand
    Country.find_thailand
  end
end

#customerObject



595
596
597
598
# File 'app/services/voucher_service/create_transaction.rb', line 595

def customer
  # For voucher transactions, we don't pre-create customers like reservations
  nil
end

#emailObject



566
567
568
# File 'app/services/voucher_service/create_transaction.rb', line 566

def email
  voucher_transaction.email
end

#errorsObject



600
601
602
# File 'app/services/voucher_service/create_transaction.rb', line 600

def errors
  voucher_transaction.errors
end

#firebase_tracking_keyObject

Firebase tracking key for voucher transactions



631
632
633
# File 'app/services/voucher_service/create_transaction.rb', line 631

def firebase_tracking_key
  "voucher_transaction/#{voucher_transaction.id}"
end

#idObject

Delegate methods that MyActiveMerchants::Gateway expects



562
563
564
# File 'app/services/voucher_service/create_transaction.rb', line 562

def id
  voucher_transaction.id
end

Returns:

  • (Boolean)


626
627
628
# File 'app/services/voucher_service/create_transaction.rb', line 626

def paid_cc?
  false # New voucher transaction, not paid yet
end

#payment_success_urlObject



616
617
618
619
620
621
622
623
# File 'app/services/voucher_service/create_transaction.rb', line 616

def payment_success_url
  # Return webhook URL for payment confirmation
  hh_host_url = Figaro.env.HH_HOST_URL!
  success_response_url = Rails.application.routes.url_helpers.cc_response_api_webhook_path(
    transaction_id: voucher_transaction.encrypted_id,
  )
  "#{hh_host_url}#{success_response_url}".gsub('http:', 'https:')
end

#restaurantObject



587
588
589
# File 'app/services/voucher_service/create_transaction.rb', line 587

def restaurant
  voucher_transaction.restaurant
end

#userObject



583
584
585
# File 'app/services/voucher_service/create_transaction.rb', line 583

def user
  voucher_transaction.user
end

#user_idObject



579
580
581
# File 'app/services/voucher_service/create_transaction.rb', line 579

def user_id
  voucher_transaction.user_id
end

#usernameObject



570
571
572
573
574
575
576
# File 'app/services/voucher_service/create_transaction.rb', line 570

def username
  guest = voucher_transaction.guest
  user = voucher_transaction.user
  guest_name = guest&.name if guest
  user_name = user&.name if user
  guest_name || user_name || 'Guest'
end

#using_charge_directly_channel?Boolean

Returns:

  • (Boolean)


608
609
610
# File 'app/services/voucher_service/create_transaction.rb', line 608

def using_charge_directly_channel?
  true # Vouchers are always charged immediately
end

#using_on_hold_channel?Boolean

Returns:

  • (Boolean)


612
613
614
# File 'app/services/voucher_service/create_transaction.rb', line 612

def using_on_hold_channel?
  false # Vouchers don't use on-hold pattern
end