Class: Braspag::Order

Inherits:
Object
  • Object
show all
Defined in:
lib/baby-braspag/order.rb,
lib/baby-braspag/errors.rb

Defined Under Namespace

Classes: InvalidData

Constant Summary collapse

PRODUCTION_INFO_URI =
"/webservices/pagador/pedido.asmx/GetDadosPedido"
HOMOLOGATION_INFO_URI =
"/pagador/webservice/pedido.asmx/GetDadosPedido"

Class Method Summary collapse

Class Method Details

.status(order_id) ⇒ Object

Raises:


6
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
# File 'lib/baby-braspag/order.rb', line 6

def self.status(order_id)
  connection = Braspag::Connection.instance

  raise InvalidOrderId unless Braspag::PaymentMethod.valid_order_id?(order_id)

  data = {
    :loja => connection.merchant_id, :numeroPedido => order_id.to_s
  }

  response = Braspag::Poster.new(self.status_url).do_post(:order_status, data)

  response = Utils::convert_to_map(response.body, {
    :authorization => "CodigoAutorizacao",
    :error_code => "CodigoErro",
    :error_message => "MensagemErro",
    :payment_method => "CodigoPagamento",
    :payment_method_name => "FormaPagamento",
    :installments => "NumeroParcelas",
    :status => "Status",
    :amount => "Valor",
    :cancelled_at => "DataCancelamento",
    :paid_at => "DataPagamento",
    :order_date => "DataPedido",
    :transaction_id => "TransId",
    :tid => "BraspagTid"
  })

  raise InvalidData if response[:authorization].nil?
  response
end

.status_urlObject


37
38
39
40
# File 'lib/baby-braspag/order.rb', line 37

def self.status_url
  connection = Braspag::Connection.instance
  connection.braspag_url + (connection.production? ? PRODUCTION_INFO_URI : HOMOLOGATION_INFO_URI)
end