Class: VoucherService::CreateTransaction
- Inherits:
-
ApplicationService
- Object
- ApplicationService
- VoucherService::CreateTransaction
- Includes:
- DefaultErrorContainer, ElasticAPM::SpanHelpers
- Defined in:
- app/services/voucher_service/create_transaction.rb
Defined Under Namespace
Classes: VoucherTransactionAdapter
Constant Summary collapse
- SUPPORTED_CURRENCIES =
Supported currencies for voucher transactions Using constants from Country model to ensure consistency
[ Country::THAI_CURRENCY_CODE, Country::SINGAPORE_CURRENCY_CODE, Country::MALAYSIA_CURRENCY_CODE, ].freeze
Instance Attribute Summary collapse
-
#params ⇒ Object
Returns the value of attribute params.
Attributes inherited from ApplicationService
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(params) ⇒ CreateTransaction
constructor
A new instance of CreateTransaction.
Methods included from DefaultErrorContainer
Methods inherited from ApplicationService
Constructor Details
#initialize(params) ⇒ CreateTransaction
Returns a new instance of CreateTransaction.
14 15 16 |
# File 'app/services/voucher_service/create_transaction.rb', line 14 def initialize(params) @params = params end |
Instance Attribute Details
#params ⇒ Object
Returns the value of attribute params.
4 5 6 |
# File 'app/services/voucher_service/create_transaction.rb', line 4 def params @params end |
Instance Method Details
#execute ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'app/services/voucher_service/create_transaction.rb', line 18 def execute ActiveRecord::Base.transaction do transaction_payload = { payment_type: payment_type_param, }.merge(voucher_owner_attr) transaction = VoucherTransaction.new transaction_payload transaction.vouchers << build_vouchers # Set currency before validation transaction.total_price_currency = currency_code validate return ServiceResult.new(errors: errors, message: ) if errors.present? transaction.set_total_price use_3d_secure = params[:use_3d_secure].to_s == 'true' reject_cc_payment unless use_3d_secure || omise_token_param.present? unless transaction.save merge_errors(transaction.errors) raise InvalidVoucherPurchase end # initialize firebase update_firebase(transaction) charge_transaction(transaction) unless transaction.save merge_errors(transaction.errors) raise InvalidVoucherPurchase end # update as paid if charge success update_firebase(transaction) update_transaction_status(transaction) return ServiceResult.new(errors: errors, message: ) if errors.present? ServiceResult.new data: transaction end rescue InvalidVoucherPurchase ServiceResult.new errors: errors, message: end |