Class: Workarea::Payment::Transaction

Inherits:
Object
  • Object
show all
Includes:
ApplicationDocument
Defined in:
app/models/workarea/payment/transaction.rb

Instance Method Summary collapse

Methods included from ApplicationDocument

#releasable?

Methods included from Sidekiq::Callbacks

add_worker, assert_valid_config!, async, caching_classes?, disable, enable, inline, #run_callbacks, workers, workers_list

Methods included from Mongoid::Document

#embedded_children

Instance Method Details

#authorize?Boolean

Returns:

  • (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

Returns:

  • (Boolean)


71
72
73
# File 'app/models/workarea/payment/transaction.rb', line 71

def canceled?
  !!canceled_at
end

#capture?Boolean

Returns:

  • (Boolean)


79
80
81
# File 'app/models/workarea/payment/transaction.rb', line 79

def capture?
  action == 'capture'
end

#captured_amountObject



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

#capturesObject



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

Returns:

  • (Boolean)


67
68
69
# File 'app/models/workarea/payment/transaction.rb', line 67

def failure?
  !success?
end

#messageObject



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

#nameString

For compatibility with admin features, models must respond to this method

Returns:



59
60
61
# File 'app/models/workarea/payment/transaction.rb', line 59

def name
  action
end

#success?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'app/models/workarea/payment/transaction.rb', line 63

def success?
  response.try(:success?) || super
end

#tenderObject



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