Class: Braspag::Order

Inherits:
Object
  • Object
show all
Defined in:
lib/rbraspag/order.rb,
lib/rbraspag/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
36
# File 'lib/rbraspag/order.rb', line 6

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

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

  request = ::HTTPI::Request.new(self.status_url)
  request.body = {
    :loja => connection.merchant_id, :numeroPedido => order_id.to_s
  }

  response = ::HTTPI.post(request)

  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



38
39
40
41
# File 'lib/rbraspag/order.rb', line 38

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