Module: WirecardMapper::Model::Base

Extended by:
ActiveSupport::Concern
Included in:
MongoMapper
Defined in:
lib/wirecardmapper/models/base.rb

Defined Under Namespace

Modules: ClassMethods

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#card_idObject

Returns the value of attribute card_id.



58
59
60
# File 'lib/wirecardmapper/models/base.rb', line 58

def card_id
  @card_id
end

Class Method Details

.card_attr_reader(*args) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/wirecardmapper/models/base.rb', line 48

def self.card_attr_reader(*args)
  args.each do |arg|
    define_method(arg) do
      card_info.send(arg)
    end
  end
end

.status_reader(*args) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/wirecardmapper/models/base.rb', line 40

def self.status_reader(*args)
  args.each do |arg|
    define_method("#{arg}?") do
      status.to_s.eql?(arg.to_s.gsub('_', '-'))
    end
  end
end

.status_writer(*args) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/wirecardmapper/models/base.rb', line 25

def self.status_writer(*args)
  args.each do |arg|
    define_method("#{arg}!") do
      response = WirecardMapper.change_card_status(self.card_id, {:entity_id => self.class.entity_id, :status_code => arg})
      unless response.blank?
        reload_card_info_cache
        transaction_log("change_card_status", response)
        raise WirecardMapper::Exception, "Wirecard-System[ERROR]: #{response.return_message}" unless response.ok?
        update_status_cache
      end
      return response
    end
  end
end

Instance Method Details

#amountObject



106
107
108
# File 'lib/wirecardmapper/models/base.rb', line 106

def amount
  Money.euro(@amount)
end

#balanceObject



78
79
80
# File 'lib/wirecardmapper/models/base.rb', line 78

def balance
  Money.euro(card_info.balance)
end

#load_amount(amount = self.amount.cents, comment = "load") ⇒ Object



82
83
84
85
86
87
88
89
90
# File 'lib/wirecardmapper/models/base.rb', line 82

def load_amount(amount = self.amount.cents, comment = "load")
  response = WirecardMapper.submit_payment(self.card_id, {:entity_id => self.class.entity_id, :payment_data => {:amount => {:text => amount, :attributes => {:currency => Config.currency}}, :payment_comment => comment}})
  unless response.blank?
    reload_card_info_cache
    transaction_log("submit_payment - load_amount", response)
    return response.ok?
  end
  return false
end

#payment_info(start, stop) ⇒ Object



102
103
104
# File 'lib/wirecardmapper/models/base.rb', line 102

def payment_info(start, stop)
  WirecardMapper.payment_info(self.card_id, {:entity_id => self.class.entity_id, :time_range => {:from => start.iso8601, :to => stop.iso8601}})
end

#statusObject



74
75
76
# File 'lib/wirecardmapper/models/base.rb', line 74

def status
  self.respond_to?(:status_cache) && self.status_cache.present? ? self.status_cache : card_info.status_code
end

#transaction_log(method_name, response) ⇒ Object



71
72
# File 'lib/wirecardmapper/models/base.rb', line 71

def transaction_log(method_name, response)
end

#unload_amount(amount = self.balance.cents, comment = "unload") ⇒ Object



92
93
94
95
96
97
98
99
100
# File 'lib/wirecardmapper/models/base.rb', line 92

def unload_amount(amount = self.balance.cents, comment = "unload")
  response = WirecardMapper.submit_payment(self.card_id, {:entity_id => self.class.entity_id,:payment_data => {:amount => {:text => -amount, :attributes => {:currency => Config.currency}}, :payment_comment => comment}})
  unless response.blank?
    reload_card_info_cache
    transaction_log("submit_payment - unload_amount", response)
    return response.ok?
  end
  return false
end