Class: Workarea::Payment::Operation
- Inherits:
-
Object
- Object
- Workarea::Payment::Operation
- Defined in:
- app/models/workarea/payment/operation.rb
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#transactions ⇒ Object
readonly
Returns the value of attribute transactions.
Instance Method Summary collapse
- #complete! ⇒ Object
-
#initialize(transactions, options = {}) ⇒ Operation
constructor
A new instance of Operation.
- #rollback! ⇒ Object
- #success? ⇒ Boolean
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, = {}) @transactions = transactions @options = @errors = [] end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
4 5 6 |
# File 'app/models/workarea/payment/operation.rb', line 4 def errors @errors end |
#transactions ⇒ Object (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
12 13 14 |
# File 'app/models/workarea/payment/operation.rb', line 12 def success? errors.empty? end |