Class: Workarea::Payment::Transaction
- Inherits:
-
Object
- Object
- Workarea::Payment::Transaction
show all
- Includes:
- ApplicationDocument
- Defined in:
- app/models/workarea/payment/transaction.rb
Instance Method Summary
collapse
#releasable?
add_worker, assert_valid_config!, async, caching_classes?, disable, enable, inline, #run_callbacks, workers, workers_list
#embedded_children
Instance Method Details
#authorize? ⇒ Boolean
75
76
77
|
# File 'app/models/workarea/payment/transaction.rb', line 75
def authorize?
action == 'authorize'
end
|
#cancel!(options = {}) ⇒ Object
107
108
109
110
111
|
# File 'app/models/workarea/payment/transaction.rb', line 107
def cancel!(options = {})
operation(options).cancel!
self.canceled_at = Time.current
with(write: { w: "majority", j: true }) { save! }
end
|
#canceled? ⇒ Boolean
71
72
73
|
# File 'app/models/workarea/payment/transaction.rb', line 71
def canceled?
!!canceled_at
end
|
#capture? ⇒ Boolean
79
80
81
|
# File 'app/models/workarea/payment/transaction.rb', line 79
def capture?
action == 'capture'
end
|
#captured_amount ⇒ Object
97
98
99
100
|
# File 'app/models/workarea/payment/transaction.rb', line 97
def captured_amount
return amount if %w(purchase capture).include?(action)
captures.not_canceled.to_a.sum(&:amount)
end
|
#captures ⇒ Object
93
94
95
|
# File 'app/models/workarea/payment/transaction.rb', line 93
def captures
self.class.successful.captures.where(reference_id: id)
end
|
#complete!(options = {}) ⇒ Object
102
103
104
105
|
# File 'app/models/workarea/payment/transaction.rb', line 102
def complete!(options = {})
operation(options).complete!
with(write: { w: "majority", j: true }) { save! }
end
|
#failure? ⇒ Boolean
67
68
69
|
# File 'app/models/workarea/payment/transaction.rb', line 67
def failure?
!success?
end
|
#message ⇒ Object
113
114
115
116
117
118
119
120
121
|
# File 'app/models/workarea/payment/transaction.rb', line 113
def message
if success?
response.message
elsif failure? && response.present? && response.message.present?
I18n.t('workarea.payment.transaction_failure', message: response.message)
else
I18n.t('workarea.payment.transaction_error')
end
end
|
For compatibility with admin features, models must respond to this method
59
60
61
|
# File 'app/models/workarea/payment/transaction.rb', line 59
def name
action
end
|
#success? ⇒ Boolean
63
64
65
|
# File 'app/models/workarea/payment/transaction.rb', line 63
def success?
response.try(:success?) || super
end
|
#tender ⇒ Object
88
89
90
91
|
# File 'app/models/workarea/payment/transaction.rb', line 88
def tender
return @tender if defined?(@tender)
@tender = payment.tenders.detect { |t| t.id.to_s == tender_id }
end
|
#tender=(val) ⇒ Object
83
84
85
86
|
# File 'app/models/workarea/payment/transaction.rb', line 83
def tender=(val)
self.tender_id = val.try(:id)
@tender = val
end
|