Class: Easypay::PaymentReference

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/easypay/payment_reference.rb

Instance Method Summary collapse

Instance Method Details

#modify(action, options = {}) ⇒ Object

Update or delete payment reference



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'app/models/easypay/payment_reference.rb', line 40

def modify(action, options = {})
  @object = self
  
  response = Easypay::Client.new(options).modify_payment_reference(self, action)
  
  if action.to_s.match("delete")
    self.update_attributes(:ep_status => "deleted") if response[:ep_status].starts_with? "ok"
  else
    self.update_attributes(:item_description => self.item_description,
                           :item_quantity => self.item_quantity,
                           :o_name  => self.o_name,
                           :o_description  => self.o_description, 
                           :o_obs => self.o_obs,
                           :o_email => self.o_email,
                           :o_mobile  => self.o_mobile)
  end                       
    
  return response
end

#process(object, options = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/models/easypay/payment_reference.rb', line 7

def process(object, options = {})
  @object = object
  payable_type = @object.class.to_s
  
  if compliant?
    self.update_attributes(handle_model_methods)
    
    payment_reference = Easypay::Client.new(options).create_reference(self)
    
    self.update_attributes( :payable_type => payable_type,
                            :ep_message => payment_reference[:ep_message],
                            :ep_reference => payment_reference[:ep_reference],
                            :ep_cin => payment_reference[:ep_cin],
                            :ep_user => payment_reference[:ep_user],
                            :ep_entity => payment_reference[:ep_entity],
                            :ep_link => payment_reference[:payment_link],
                            :ep_last_status => payment_reference[:ep_status],
                            :request_log => payment_reference[:raw],
                            :item_description => self.item_description,
                            :item_quantity => self.item_quantity,
                            :o_name  => self.o_name,
                            :o_description  => self.o_description, 
                            :o_obs => self.o_obs,
                            :o_email => self.o_email,
                            :o_mobile  => self.o_mobile)
                            
    return payment_reference
  else
    nil
  end
end