Class: MaxipagoApi::TransactionModel

Inherits:
Object
  • Object
show all
Defined in:
lib/maxipago_api/models/transaction_model.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ TransactionModel

Returns a new instance of TransactionModel.



5
6
7
8
9
10
11
12
# File 'lib/maxipago_api/models/transaction_model.rb', line 5

def initialize(options = {})
  self.customer_id = options[:customer_id]
  self.processor_id = options[:processor_id]
  self.token = options[:token]
  self.ip_address = options[:ip_address]
  self.reference_number = options[:reference_number]
  self.charge_total = options[:charge_total]
end

Instance Attribute Details

#charge_totalObject

Returns the value of attribute charge_total.



4
5
6
# File 'lib/maxipago_api/models/transaction_model.rb', line 4

def charge_total
  @charge_total
end

#customer_idObject

Returns the value of attribute customer_id.



4
5
6
# File 'lib/maxipago_api/models/transaction_model.rb', line 4

def customer_id
  @customer_id
end

#ip_addressObject

Returns the value of attribute ip_address.



4
5
6
# File 'lib/maxipago_api/models/transaction_model.rb', line 4

def ip_address
  @ip_address
end

#processor_idObject

Returns the value of attribute processor_id.



4
5
6
# File 'lib/maxipago_api/models/transaction_model.rb', line 4

def processor_id
  @processor_id
end

#reference_numberObject

Returns the value of attribute reference_number.



4
5
6
# File 'lib/maxipago_api/models/transaction_model.rb', line 4

def reference_number
  @reference_number
end

#tokenObject

Returns the value of attribute token.



4
5
6
# File 'lib/maxipago_api/models/transaction_model.rb', line 4

def token
  @token
end

Instance Method Details

#findObject



18
19
# File 'lib/maxipago_api/models/transaction_model.rb', line 18

def find
end

#saveObject



14
15
16
# File 'lib/maxipago_api/models/transaction_model.rb', line 14

def save
  MaxipagoApi::TransactionRequest.create(self)
end

#to_objectObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/maxipago_api/models/transaction_model.rb', line 21

def to_object
  {
    sale: {
      processorID: self.processor_id,
      referenceNum: self.reference_number,
      transactionDetail: {
        payType: {
          onFile: {
            customerId: self.customer_id,
            token: self.token,
          },
        }
      },
      payment: {
        currencyCode: 'BRL',
        chargeTotal: self.charge_total
      }
    }
  }.select{|k,v| v.present?}
end