Class: Braspag::Order
- Inherits:
-
Object
- Object
- Braspag::Order
- Includes:
- ActiveAttr::Model
- Defined in:
- lib/cbraspag/core/order.rb
Defined Under Namespace
Classes: AssociationValidator, InstallmentsTypeValidator, PaymentMethodValidator
Instance Attribute Summary collapse
-
#amount ⇒ Object
Returns the value of attribute amount.
-
#authorization ⇒ Object
Returns the value of attribute authorization.
-
#billet ⇒ Object
Returns the value of attribute billet.
-
#credit_card ⇒ Object
Returns the value of attribute credit_card.
-
#customer ⇒ Object
Returns the value of attribute customer.
-
#gateway_amount ⇒ Object
Returns the value of attribute gateway_amount.
-
#gateway_authorization ⇒ Object
Returns the value of attribute gateway_authorization.
-
#gateway_cancelled_at ⇒ Object
Returns the value of attribute gateway_cancelled_at.
-
#gateway_capture_amount ⇒ Object
Returns the value of attribute gateway_capture_amount.
-
#gateway_capture_message ⇒ Object
Returns the value of attribute gateway_capture_message.
-
#gateway_capture_return_code ⇒ Object
Returns the value of attribute gateway_capture_return_code.
-
#gateway_capture_status ⇒ Object
Returns the value of attribute gateway_capture_status.
-
#gateway_created_at ⇒ Object
Returns the value of attribute gateway_created_at.
-
#gateway_id ⇒ Object
Returns the value of attribute gateway_id.
-
#gateway_message ⇒ Object
Returns the value of attribute gateway_message.
-
#gateway_paid_at ⇒ Object
Returns the value of attribute gateway_paid_at.
-
#gateway_return_code ⇒ Object
Returns the value of attribute gateway_return_code.
-
#gateway_status ⇒ Object
Returns the value of attribute gateway_status.
-
#gateway_void_amount ⇒ Object
Returns the value of attribute gateway_void_amount.
-
#gateway_void_message ⇒ Object
Returns the value of attribute gateway_void_message.
-
#gateway_void_return_code ⇒ Object
Returns the value of attribute gateway_void_return_code.
-
#gateway_void_status ⇒ Object
Returns the value of attribute gateway_void_status.
-
#id ⇒ Object
Returns the value of attribute id.
-
#installments ⇒ Object
Returns the value of attribute installments.
-
#installments_type ⇒ Object
Returns the value of attribute installments_type.
-
#payment_method ⇒ Object
Returns the value of attribute payment_method.
-
#payment_method_name ⇒ Object
Returns the value of attribute payment_method_name.
-
#status ⇒ Object
Returns the value of attribute status.
-
#transaction_id ⇒ Object
Returns the value of attribute transaction_id.
Class Method Summary collapse
- .from_info(connection, order, params) ⇒ Object
- .from_info_billet(connection, order, params) ⇒ Object
- .from_info_credit_card(connection, order, params) ⇒ Object
- .to_info(connection, order) ⇒ Object
- .to_info_billet(connection, order) ⇒ Object
- .to_info_credit_card(connection, order) ⇒ Object
Instance Method Summary collapse
- #build_billet ⇒ Object
- #build_credit_card ⇒ Object
- #build_customer ⇒ Object
- #no_interest? ⇒ Boolean
- #payment_method_type? ⇒ Boolean
Instance Attribute Details
#amount ⇒ Object
Returns the value of attribute amount.
57 58 59 |
# File 'lib/cbraspag/core/order.rb', line 57 def amount @amount end |
#authorization ⇒ Object
Returns the value of attribute authorization.
61 62 63 |
# File 'lib/cbraspag/core/order.rb', line 61 def @authorization end |
#billet ⇒ Object
Returns the value of attribute billet.
62 63 64 |
# File 'lib/cbraspag/core/order.rb', line 62 def billet @billet end |
#credit_card ⇒ Object
Returns the value of attribute credit_card.
62 63 64 |
# File 'lib/cbraspag/core/order.rb', line 62 def credit_card @credit_card end |
#customer ⇒ Object
Returns the value of attribute customer.
57 58 59 |
# File 'lib/cbraspag/core/order.rb', line 57 def customer @customer end |
#gateway_amount ⇒ Object
Returns the value of attribute gateway_amount.
58 59 60 |
# File 'lib/cbraspag/core/order.rb', line 58 def gateway_amount @gateway_amount end |
#gateway_authorization ⇒ Object
Returns the value of attribute gateway_authorization.
58 59 60 |
# File 'lib/cbraspag/core/order.rb', line 58 def @gateway_authorization end |
#gateway_cancelled_at ⇒ Object
Returns the value of attribute gateway_cancelled_at.
61 62 63 |
# File 'lib/cbraspag/core/order.rb', line 61 def gateway_cancelled_at @gateway_cancelled_at end |
#gateway_capture_amount ⇒ Object
Returns the value of attribute gateway_capture_amount.
59 60 61 |
# File 'lib/cbraspag/core/order.rb', line 59 def gateway_capture_amount @gateway_capture_amount end |
#gateway_capture_message ⇒ Object
Returns the value of attribute gateway_capture_message.
59 60 61 |
# File 'lib/cbraspag/core/order.rb', line 59 def @gateway_capture_message end |
#gateway_capture_return_code ⇒ Object
Returns the value of attribute gateway_capture_return_code.
59 60 61 |
# File 'lib/cbraspag/core/order.rb', line 59 def gateway_capture_return_code @gateway_capture_return_code end |
#gateway_capture_status ⇒ Object
Returns the value of attribute gateway_capture_status.
59 60 61 |
# File 'lib/cbraspag/core/order.rb', line 59 def gateway_capture_status @gateway_capture_status end |
#gateway_created_at ⇒ Object
Returns the value of attribute gateway_created_at.
62 63 64 |
# File 'lib/cbraspag/core/order.rb', line 62 def gateway_created_at @gateway_created_at end |
#gateway_id ⇒ Object
Returns the value of attribute gateway_id.
58 59 60 |
# File 'lib/cbraspag/core/order.rb', line 58 def gateway_id @gateway_id end |
#gateway_message ⇒ Object
Returns the value of attribute gateway_message.
58 59 60 |
# File 'lib/cbraspag/core/order.rb', line 58 def @gateway_message end |
#gateway_paid_at ⇒ Object
Returns the value of attribute gateway_paid_at.
61 62 63 |
# File 'lib/cbraspag/core/order.rb', line 61 def gateway_paid_at @gateway_paid_at end |
#gateway_return_code ⇒ Object
Returns the value of attribute gateway_return_code.
58 59 60 |
# File 'lib/cbraspag/core/order.rb', line 58 def gateway_return_code @gateway_return_code end |
#gateway_status ⇒ Object
Returns the value of attribute gateway_status.
58 59 60 |
# File 'lib/cbraspag/core/order.rb', line 58 def gateway_status @gateway_status end |
#gateway_void_amount ⇒ Object
Returns the value of attribute gateway_void_amount.
60 61 62 |
# File 'lib/cbraspag/core/order.rb', line 60 def gateway_void_amount @gateway_void_amount end |
#gateway_void_message ⇒ Object
Returns the value of attribute gateway_void_message.
60 61 62 |
# File 'lib/cbraspag/core/order.rb', line 60 def @gateway_void_message end |
#gateway_void_return_code ⇒ Object
Returns the value of attribute gateway_void_return_code.
60 61 62 |
# File 'lib/cbraspag/core/order.rb', line 60 def gateway_void_return_code @gateway_void_return_code end |
#gateway_void_status ⇒ Object
Returns the value of attribute gateway_void_status.
60 61 62 |
# File 'lib/cbraspag/core/order.rb', line 60 def gateway_void_status @gateway_void_status end |
#id ⇒ Object
Returns the value of attribute id.
57 58 59 |
# File 'lib/cbraspag/core/order.rb', line 57 def id @id end |
#installments ⇒ Object
Returns the value of attribute installments.
57 58 59 |
# File 'lib/cbraspag/core/order.rb', line 57 def installments @installments end |
#installments_type ⇒ Object
Returns the value of attribute installments_type.
57 58 59 |
# File 'lib/cbraspag/core/order.rb', line 57 def installments_type @installments_type end |
#payment_method ⇒ Object
Returns the value of attribute payment_method.
57 58 59 |
# File 'lib/cbraspag/core/order.rb', line 57 def payment_method @payment_method end |
#payment_method_name ⇒ Object
Returns the value of attribute payment_method_name.
61 62 63 |
# File 'lib/cbraspag/core/order.rb', line 61 def payment_method_name @payment_method_name end |
#status ⇒ Object
Returns the value of attribute status.
61 62 63 |
# File 'lib/cbraspag/core/order.rb', line 61 def status @status end |
#transaction_id ⇒ Object
Returns the value of attribute transaction_id.
62 63 64 |
# File 'lib/cbraspag/core/order.rb', line 62 def transaction_id @transaction_id end |
Class Method Details
.from_info(connection, order, params) ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/cbraspag/core/order.rb', line 122 def self.from_info(connection, order, params) response = Braspag::Converter::hash_from_xml(params.body, { :authorization => "CodigoAutorizacao", :error_code => "CodigoErro", :error_message => "MensagemErro", :payment_method => "CodigoPagamento", :payment_method_name => "FormaPagamento", :installments => "NumeroParcelas", :status => "Status", :amount => "Valor", :cancelled_at => Proc.new { |document| begin Time.parse(document.search("DataCancelamento").first.to_s) rescue nil end }, :paid_at => Proc.new { |document| begin Time.parse(document.search("DataPagamento").first.to_s) rescue nil end }, :order_date => Proc.new { |document| begin Time.parse(document.search("DataPedido").first.to_s) rescue nil end }, :transaction_id => "TransId", :tid => "BraspagTid" }) order. = response[:authorization] order.payment_method_name = response[:payment_method_name] order.payment_method = response[:payment_method] order.installments = response[:installments] order.status = response[:status] order.amount = Braspag::Converter::string_to_decimal(response[:amount], :eua) order.gateway_cancelled_at = response[:cancelled_at] order.gateway_paid_at = response[:paid_at] order.gateway_created_at = response[:order_date] order.transaction_id = response[:transaction_id] order.gateway_id = response[:tid] response end |
.from_info_billet(connection, order, params) ⇒ Object
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 |
# File 'lib/cbraspag/core/order.rb', line 213 def self.from_info_billet(connection, order, params) response = Braspag::Converter::hash_from_xml(params.body, { :document_number => "NumeroDocumento", :payer => "Sacado", :our_number => "NossoNumero", :bill_line => "LinhaDigitavel", :document_date => Proc.new { |document| begin Date.parse(document.search("DataDocumento").first.to_s) rescue nil end }, :expiration_date => Proc.new { |document| begin Date.parse(document.search("DataVencimento").first.to_s) rescue nil end }, :receiver => "Cedente", :bank => "Banco", :agency => "Agencia", :account => "Conta", :wallet => "Carteira", :amount => "ValorDocumento", :amount_invoice => "ValorPago", :invoice_date => Proc.new { |document| begin Date.parse(document.search("DataCredito").first.to_s) rescue nil end } }) order.build_customer if order.customer.nil? order.customer.name = response[:payer] order.build_billet if order.billet.nil? order.billet.id = response[:our_number] order.billet.code = response[:bill_line] order.billet.created_at = response[:document_date] order.billet.due_date_on = response[:expiration_date] order.billet.receiver = response[:receiver] order.billet.bank = response[:bank] order.billet.agency = response[:agency] order.billet.account = response[:account] order.billet.wallet = response[:wallet] order.billet.amount = Braspag::Converter::string_to_decimal(response[:amount]) order.billet.amount_paid = Braspag::Converter::string_to_decimal(response[:amount_invoice]) order.billet.paid_at = response[:invoice_date] response end |
.from_info_credit_card(connection, order, params) ⇒ Object
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/cbraspag/core/order.rb', line 179 def self.from_info_credit_card(connection, order, params) response = Braspag::Converter::hash_from_xml(params.body, { :checking_number => "NumeroComprovante", :certified => "Autenticada", :autorization_number => "NumeroAutorizacao", :card_number => "NumeroCartao", :transaction_number => "NumeroTransacao", :avs_response => "RetornoAVS", :issuing => "Emissor", :authenticated_number => "NumeroAutenticacao" }) order.build_credit_card if order.credit_card.nil? order.credit_card.checking_number = response[:checking_number] order.credit_card.avs = response[:certified] order.credit_card.autorization_number = response[:autorization_number] order.credit_card.number = response[:card_number] order.credit_card.transaction_number = response[:transaction_number] order.credit_card.avs_response = response[:avs_response] order.credit_card.issuing = response[:issuing] order.credit_card.authenticated_number = response[:authenticated_number] response end |
.to_info(connection, order) ⇒ Object
115 116 117 118 119 120 |
# File 'lib/cbraspag/core/order.rb', line 115 def self.to_info(connection, order) { "loja" => connection.merchant_id, "numeroPedido" => order.id.to_s } end |
.to_info_billet(connection, order) ⇒ Object
206 207 208 209 210 211 |
# File 'lib/cbraspag/core/order.rb', line 206 def self.to_info_billet(connection, order) { "loja" => connection.merchant_id, "numeroPedido" => order.id.to_s } end |
.to_info_credit_card(connection, order) ⇒ Object
172 173 174 175 176 177 |
# File 'lib/cbraspag/core/order.rb', line 172 def self.to_info_credit_card(connection, order) { "loja" => connection.merchant_id, "numeroPedido" => order.id.to_s } end |
Instance Method Details
#build_billet ⇒ Object
107 108 109 |
# File 'lib/cbraspag/core/order.rb', line 107 def build_billet self.billet = Billet.new end |
#build_credit_card ⇒ Object
111 112 113 |
# File 'lib/cbraspag/core/order.rb', line 111 def build_credit_card self.credit_card = CreditCard.new end |
#build_customer ⇒ Object
103 104 105 |
# File 'lib/cbraspag/core/order.rb', line 103 def build_customer self.customer = Customer.new end |
#no_interest? ⇒ Boolean
89 90 91 92 93 94 95 96 97 |
# File 'lib/cbraspag/core/order.rb', line 89 def no_interest? case installments_type when Braspag::INTEREST[:no], Braspag::INTEREST[:no_iata] true else false end end |
#payment_method_type? ⇒ Boolean
99 100 101 |
# File 'lib/cbraspag/core/order.rb', line 99 def payment_method_type? Converter.payment_method_type?(self.payment_method) end |