Class: Workarea::Payment::Operation

Inherits:
Object
  • Object
show all
Defined in:
app/models/workarea/payment/operation.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(transactions, options = {}) ⇒ Operation

Returns a new instance of Operation.



6
7
8
9
10
# File 'app/models/workarea/payment/operation.rb', line 6

def initialize(transactions, options = {})
  @transactions = transactions
  @options = options
  @errors = []
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



4
5
6
# File 'app/models/workarea/payment/operation.rb', line 4

def errors
  @errors
end

#transactionsObject (readonly)

Returns the value of attribute transactions.



4
5
6
# File 'app/models/workarea/payment/operation.rb', line 4

def transactions
  @transactions
end

Instance Method Details

#complete!Object



16
17
18
19
20
21
22
23
24
25
# File 'app/models/workarea/payment/operation.rb', line 16

def complete!
  begin
    complete_each_transaction!
  rescue Exception => e
    rollback!
    raise e
  ensure
    add_transaction_errors
  end
end

#rollback!Object



27
28
29
30
31
32
# File 'app/models/workarea/payment/operation.rb', line 27

def rollback!
  transactions
    .select(&:success?)
    .reject(&:canceled?)
    .each { |t| t.cancel!(@options) }
end

#success?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'app/models/workarea/payment/operation.rb', line 12

def success?
  errors.empty?
end