Class: PaymentProcessService::MarkAsPaid

Inherits:
BaseOperationService show all
Includes:
DefaultErrorContainer
Defined in:
app/services/payment_process_service/mark_as_paid.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(charge_id, transaction_id, reference_no = nil) ⇒ MarkAsPaid

Returns a new instance of MarkAsPaid.

Parameters:

  • charge_id (String)

    Externals::Omise::Charge#omise_charge_id

  • transaction_id (String)

    Externals::Omise::Charge#transaction_id

  • reference_no (String) (defaults to: nil)

    Externals::Omise::Charge#transaction_id



12
13
14
15
16
17
# File 'app/services/payment_process_service/mark_as_paid.rb', line 12

def initialize(charge_id, transaction_id, reference_no = nil)
  @charge_id      = charge_id
  @transaction_id = transaction_id
  @by_admin       = transaction_id == 'by-admin'
  @reference_no   = reference_no
end

Instance Attribute Details

#by_admin=(value) ⇒ Object

Sets the attribute by_admin

Parameters:

  • value

    the value to set the attribute by_admin to.



7
8
9
# File 'app/services/payment_process_service/mark_as_paid.rb', line 7

def by_admin=(value)
  @by_admin = value
end

#charge_idObject (readonly)

Returns the value of attribute charge_id.



6
7
8
# File 'app/services/payment_process_service/mark_as_paid.rb', line 6

def charge_id
  @charge_id
end

#reference_noObject (readonly)

Returns the value of attribute reference_no.



6
7
8
# File 'app/services/payment_process_service/mark_as_paid.rb', line 6

def reference_no
  @reference_no
end

#transaction_idObject (readonly)

Returns the value of attribute transaction_id.



6
7
8
# File 'app/services/payment_process_service/mark_as_paid.rb', line 6

def transaction_id
  @transaction_id
end

Instance Method Details

#executeObject



40
41
42
43
44
45
# File 'app/services/payment_process_service/mark_as_paid.rb', line 40

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

#execute!Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/services/payment_process_service/mark_as_paid.rb', line 19

def execute!
  errors.clear
  raise StandardError, "Charge ID #{charge_id} is not found" if charge.blank?

  transaction     = charge.transaction
  transction_type = charge.transaction_product_type

  update_attributes(charge)

  payment_process = payment_process_class(transction_type).new(transaction.id, by_admin)
  unless payment_process.complete!
    merge_errors(payment_process.errors)
    APMErrorHandler.report("failed updating #{transction_type} as active", charge: charge.attributes)
    raise StandardError, 'Failed updating trasaction data'
  end

  true
rescue DuplicateChargeError
  true
end