Class: Braspag::CreditCard

Inherits:
Object
  • Object
show all
Includes:
ActiveAttr::Model
Defined in:
lib/cbraspag/payment/credit_card.rb

Defined Under Namespace

Classes: ExpiratorValidator

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#aliasObject

Returns the value of attribute alias.



48
49
50
# File 'lib/cbraspag/payment/credit_card.rb', line 48

def alias
  @alias
end

#authenticated_numberObject

Returns the value of attribute authenticated_number.



50
51
52
# File 'lib/cbraspag/payment/credit_card.rb', line 50

def authenticated_number
  @authenticated_number
end

#autorization_numberObject

Returns the value of attribute autorization_number.



49
50
51
# File 'lib/cbraspag/payment/credit_card.rb', line 49

def autorization_number
  @autorization_number
end

#avsObject

Returns the value of attribute avs.



49
50
51
# File 'lib/cbraspag/payment/credit_card.rb', line 49

def avs
  @avs
end

#avs_responseObject

Returns the value of attribute avs_response.



50
51
52
# File 'lib/cbraspag/payment/credit_card.rb', line 50

def avs_response
  @avs_response
end

#checking_numberObject

Returns the value of attribute checking_number.



49
50
51
# File 'lib/cbraspag/payment/credit_card.rb', line 49

def checking_number
  @checking_number
end

#holder_nameObject

Returns the value of attribute holder_name.



48
49
50
# File 'lib/cbraspag/payment/credit_card.rb', line 48

def holder_name
  @holder_name
end

#idObject

Returns the value of attribute id.



48
49
50
# File 'lib/cbraspag/payment/credit_card.rb', line 48

def id
  @id
end

#issuingObject

Returns the value of attribute issuing.



50
51
52
# File 'lib/cbraspag/payment/credit_card.rb', line 50

def issuing
  @issuing
end

#monthObject

Returns the value of attribute month.



48
49
50
# File 'lib/cbraspag/payment/credit_card.rb', line 48

def month
  @month
end

#numberObject

Returns the value of attribute number.



48
49
50
# File 'lib/cbraspag/payment/credit_card.rb', line 48

def number
  @number
end

#transaction_numberObject

Returns the value of attribute transaction_number.



49
50
51
# File 'lib/cbraspag/payment/credit_card.rb', line 49

def transaction_number
  @transaction_number
end

#verification_valueObject

Returns the value of attribute verification_value.



48
49
50
# File 'lib/cbraspag/payment/credit_card.rb', line 48

def verification_value
  @verification_value
end

#yearObject

Returns the value of attribute year.



48
49
50
# File 'lib/cbraspag/payment/credit_card.rb', line 48

def year
  @year
end

Class Method Details

.from_authorize(connection, order, credit_card, params) ⇒ Object



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/cbraspag/payment/credit_card.rb', line 104

def self.from_authorize(connection, order, credit_card, params)
  response = Braspag::Converter::hash_from_xml(params.body, {
          :amount         => nil,
          :number         => "authorisationNumber",
          :message        => nil,
          :return_code    => 'returnCode',
          :status         => nil,
          :transaction_id => "transactionId"
  })
  
  order.gateway_authorization = response[:number]
  order.gateway_id = response[:transaction_id]
  order.gateway_return_code = response[:return_code]
  order.gateway_status = response[:status]
  order.gateway_message = response[:message]
  order.gateway_amount = Braspag::Converter::string_to_decimal(response[:amount])
  
  response
end

.from_capture(connection, order, params) ⇒ Object



131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/cbraspag/payment/credit_card.rb', line 131

def self.from_capture(connection, order, params)
  response = Braspag::Converter::hash_from_xml(params.body, {
          :amount => nil,
          :message => 'message',
          :return_code => 'returnCode',
          :status => 'status',
          :transaction_id => "transactionId"
  })
  
  #TODO: CHECK IF IS NECESSARY
  # order.gateway_capture_id = response[:transaction_id]
  order.gateway_capture_return_code = response[:return_code]
  order.gateway_capture_status = response[:status]
  order.gateway_capture_message = response[:message]
  order.gateway_capture_amount = Braspag::Converter::string_to_decimal(response[:amount])
  
  response
end

.from_void(connection, order, params) ⇒ Object



157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/cbraspag/payment/credit_card.rb', line 157

def self.from_void(connection, order, params)
  response = Braspag::Converter::hash_from_xml(params.body, {
          :order_id => "orderId",
          :amount => nil,
          :message => 'message',
          :return_code => 'returnCode',
          :status => 'status',
          :transaction_id => "transactionId"
  })
  
  #TODO: CHECK IF IS NECESSARY
  # order.gateway_void_id = response[:transaction_id]
  order.gateway_void_return_code = response[:return_code]
  order.gateway_void_status = response[:status]
  order.gateway_void_message = response[:message]
  order.gateway_void_amount = Braspag::Converter::string_to_decimal(response[:amount])
  
  response
end

.to_authorize(connection, order, credit_card) ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/cbraspag/payment/credit_card.rb', line 87

def self.to_authorize(connection, order, credit_card)
  year_normalize = credit_card.year.to_s[-2, 2]
  {
    "merchantId"     => connection.merchant_id,
    "holder"         => credit_card.holder_name.to_s,
    "cardNumber"     => credit_card.number.to_s,
    "expiration"     => "#{credit_card.month}/#{year_normalize}",
    "securityCode"   => credit_card.verification_value.to_s,
    "customerName"   => order.customer.name.to_s,
    "orderId"        => order.id.to_s,
    "amount"         => Braspag::Converter::decimal_to_string(order.amount),
    "paymentMethod"  => order.payment_method,
    "numberPayments" => order.installments,
    "typePayment"    => order.installments_type
  }
end

.to_capture(connection, order) ⇒ Object



124
125
126
127
128
129
# File 'lib/cbraspag/payment/credit_card.rb', line 124

def self.to_capture(connection, order)
  {
    "merchantId"  => connection.merchant_id,
    "orderId"     => order.id.to_s
  }
end

.to_void(connection, order) ⇒ Object



150
151
152
153
154
155
# File 'lib/cbraspag/payment/credit_card.rb', line 150

def self.to_void(connection, order)
  {
    "merchantId" => connection.merchant_id,
    "order"      => order.id.to_s
  }
end