Class: Braspag::Order

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

Defined Under Namespace

Classes: AssociationValidator, InstallmentsTypeValidator, PaymentMethodValidator

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#amountObject

Returns the value of attribute amount.



111
112
113
# File 'lib/cbraspag/core/order.rb', line 111

def amount
  @amount
end

#customerObject

Returns the value of attribute customer.



111
112
113
# File 'lib/cbraspag/core/order.rb', line 111

def customer
  @customer
end

#gateway_amountObject

Returns the value of attribute gateway_amount.



112
113
114
# File 'lib/cbraspag/core/order.rb', line 112

def gateway_amount
  @gateway_amount
end

#gateway_authorizationObject

Returns the value of attribute gateway_authorization.



112
113
114
# File 'lib/cbraspag/core/order.rb', line 112

def gateway_authorization
  @gateway_authorization
end

#gateway_capture_amountObject

Returns the value of attribute gateway_capture_amount.



113
114
115
# File 'lib/cbraspag/core/order.rb', line 113

def gateway_capture_amount
  @gateway_capture_amount
end

#gateway_capture_messageObject

Returns the value of attribute gateway_capture_message.



113
114
115
# File 'lib/cbraspag/core/order.rb', line 113

def gateway_capture_message
  @gateway_capture_message
end

#gateway_capture_return_codeObject

Returns the value of attribute gateway_capture_return_code.



113
114
115
# File 'lib/cbraspag/core/order.rb', line 113

def gateway_capture_return_code
  @gateway_capture_return_code
end

#gateway_capture_statusObject

Returns the value of attribute gateway_capture_status.



113
114
115
# File 'lib/cbraspag/core/order.rb', line 113

def gateway_capture_status
  @gateway_capture_status
end

#gateway_idObject

Returns the value of attribute gateway_id.



112
113
114
# File 'lib/cbraspag/core/order.rb', line 112

def gateway_id
  @gateway_id
end

#gateway_messageObject

Returns the value of attribute gateway_message.



112
113
114
# File 'lib/cbraspag/core/order.rb', line 112

def gateway_message
  @gateway_message
end

#gateway_return_codeObject

Returns the value of attribute gateway_return_code.



112
113
114
# File 'lib/cbraspag/core/order.rb', line 112

def gateway_return_code
  @gateway_return_code
end

#gateway_statusObject

Returns the value of attribute gateway_status.



112
113
114
# File 'lib/cbraspag/core/order.rb', line 112

def gateway_status
  @gateway_status
end

#gateway_void_amountObject

Returns the value of attribute gateway_void_amount.



114
115
116
# File 'lib/cbraspag/core/order.rb', line 114

def gateway_void_amount
  @gateway_void_amount
end

#gateway_void_messageObject

Returns the value of attribute gateway_void_message.



114
115
116
# File 'lib/cbraspag/core/order.rb', line 114

def gateway_void_message
  @gateway_void_message
end

#gateway_void_return_codeObject

Returns the value of attribute gateway_void_return_code.



114
115
116
# File 'lib/cbraspag/core/order.rb', line 114

def gateway_void_return_code
  @gateway_void_return_code
end

#gateway_void_statusObject

Returns the value of attribute gateway_void_status.



114
115
116
# File 'lib/cbraspag/core/order.rb', line 114

def gateway_void_status
  @gateway_void_status
end

#idObject

Returns the value of attribute id.



111
112
113
# File 'lib/cbraspag/core/order.rb', line 111

def id
  @id
end

#installmentsObject

Returns the value of attribute installments.



111
112
113
# File 'lib/cbraspag/core/order.rb', line 111

def installments
  @installments
end

#installments_typeObject

Returns the value of attribute installments_type.



111
112
113
# File 'lib/cbraspag/core/order.rb', line 111

def installments_type
  @installments_type
end

#payment_methodObject

Returns the value of attribute payment_method.



111
112
113
# File 'lib/cbraspag/core/order.rb', line 111

def payment_method
  @payment_method
end

Instance Method Details

#convert_to(method) ⇒ Object



149
150
151
152
153
154
# File 'lib/cbraspag/core/order.rb', line 149

def convert_to(method)
  data = {}
  data = self.send("to_#{method}") if self.respond_to?("to_#{method}")
  data.merge!(self.customer.convert_to(method)) if self.customer
  data
end

#no_interest?Boolean

Returns:

  • (Boolean)


141
142
143
144
145
146
147
# File 'lib/cbraspag/core/order.rb', line 141

def no_interest?
  case installments_type
  when Braspag::INTEREST[:no],
       Braspag::INTEREST[:no_iata]
    true
  end
end

#populate!(method, response) ⇒ Object



186
187
188
# File 'lib/cbraspag/core/order.rb', line 186

def populate!(method, response)
  self.send("populate_#{method}!", response)
end

#populate_authorize!(response) ⇒ Object



190
191
192
193
194
195
196
197
# File 'lib/cbraspag/core/order.rb', line 190

def populate_authorize!(response)
  self.gateway_authorization = response[:number]
  self.gateway_id = response[:transaction_id]
  self.gateway_return_code = response[:return_code]
  self.gateway_status = response[:status]
  self.gateway_message = response[:message]
  self.gateway_amount = Converter::string_to_decimal(response[:amount])
end

#populate_capture!(response) ⇒ Object



199
200
201
202
203
204
205
206
# File 'lib/cbraspag/core/order.rb', line 199

def populate_capture!(response)
  #TODO: CHECK IF IS NECESSARY
  # self.gateway_capture_id = response[:transaction_id]
  self.gateway_capture_return_code = response[:return_code]
  self.gateway_capture_status = response[:status]
  self.gateway_capture_message = response[:message]
  self.gateway_capture_amount = Converter::string_to_decimal(response[:amount])
end

#populate_generate_billet!(response) ⇒ Object



217
218
219
220
221
# File 'lib/cbraspag/core/order.rb', line 217

def populate_generate_billet!(response)
  self.gateway_return_code = response[:return_code]
  self.gateway_status = response[:status]
  self.gateway_amount = BigDecimal.new(response[:amount].to_s) if response[:amount]
end

#populate_void!(response) ⇒ Object



208
209
210
211
212
213
214
215
# File 'lib/cbraspag/core/order.rb', line 208

def populate_void!(response)
  #TODO: CHECK IF IS NECESSARY
  # self.gateway_void_id = response[:transaction_id]
  self.gateway_void_return_code = response[:return_code]
  self.gateway_void_status = response[:status]
  self.gateway_void_message = response[:message]
  self.gateway_void_amount = Converter::string_to_decimal(response[:amount])
end

#to_authorizeObject



156
157
158
159
160
161
162
163
164
# File 'lib/cbraspag/core/order.rb', line 156

def to_authorize
  {
    :order_id        => self.id.to_s,
    :amount          => self.amount,
    :payment_method  => self.payment_method,
    :number_payments => self.installments,
    :type            => self.installments_type,
  }
end

#to_captureObject



166
167
168
169
170
# File 'lib/cbraspag/core/order.rb', line 166

def to_capture
  {
    :order_id        => self.id.to_s
  }
end

#to_generate_billetObject



178
179
180
181
182
183
184
# File 'lib/cbraspag/core/order.rb', line 178

def to_generate_billet
  {
    :order_id        => self.id.to_s,
    :amount          => self.amount,
    :payment_method  => self.payment_method
  }
end

#to_voidObject



172
173
174
175
176
# File 'lib/cbraspag/core/order.rb', line 172

def to_void
  {
    :order_id        => self.id.to_s
  }
end