Class: PaymentProcessService::Cancelled

Inherits:
BaseOperationService show all
Includes:
DefaultErrorContainer
Defined in:
app/services/payment_process_service/cancelled.rb

Overview

typed: ignore Service to handle after transaction payment

Defined Under Namespace

Classes: DuplicateChargeError

Instance Attribute Summary collapse

Attributes inherited from BaseOperationService

#outcome

Instance Method Summary collapse

Methods included from DefaultErrorContainer

#error, #error_message_simple, #merge_errors

Methods inherited from BaseOperationService

#success?

Constructor Details

#initialize(transaction_type, transaction_id, reason = nil) ⇒ Cancelled

Returns a new instance of Cancelled.



7
8
9
10
11
# File 'app/services/payment_process_service/cancelled.rb', line 7

def initialize(transaction_type, transaction_id, reason = nil)
  @transaction_type = transaction_type.to_s.camelize
  @transaction = @transaction_type.constantize.find_by(id: transaction_id)
  @reason = reason
end

Instance Attribute Details

#reasonObject

Returns the value of attribute reason.



5
6
7
# File 'app/services/payment_process_service/cancelled.rb', line 5

def reason
  @reason
end

#transactionObject

Returns the value of attribute transaction.



5
6
7
# File 'app/services/payment_process_service/cancelled.rb', line 5

def transaction
  @transaction
end

#transaction_typeObject

Returns the value of attribute transaction_type.



5
6
7
# File 'app/services/payment_process_service/cancelled.rb', line 5

def transaction_type
  @transaction_type
end

Instance Method Details

#executeObject



24
25
26
27
28
29
# File 'app/services/payment_process_service/cancelled.rb', line 24

def execute
  execute!
rescue StandardError => e
  errors.add(:base, e.message)
  false
end

#execute!Object



13
14
15
16
17
18
19
20
21
22
# File 'app/services/payment_process_service/cancelled.rb', line 13

def execute!
  errors.clear

  raise StandardError, "#{transaction_type} ID #{transaction.id} is not found" if transaction.blank?

  service = payment_process_class.new(transaction.id)
  service.cancelled!(reason)
rescue DuplicateChargeError
  true
end