Module: MoIP

Includes:
HTTParty
Defined in:
lib/moip.rb,
lib/direct_payment.rb

Defined Under Namespace

Classes: DirectPayment

Constant Summary collapse

STATUS =

Status de retorno

{ 1 => "authorized", 2 => "started", 3 => "printed", 4 => "completed", 5 => "canceled", 6 => "analysing" }
@@uri =
'https://www.moip.com.br'

Class Method Summary collapse

Class Method Details

.checkout(attributes = {}) ⇒ Object

Envia uma instrução para pagamento único



34
35
36
37
38
# File 'lib/moip.rb', line 34

def checkout(attributes = {})
  full_data = peform_action!(:post, 'EnviarInstrucao/Unica', :body => DirectPayment.body(attributes))

  get_response!(full_data["EnviarInstrucaoUnicaResponse"]["Resposta"])
end

.moip_page(token) ⇒ Object

Retorna a URL de acesso ao MoIP

Raises:

  • (StandardError)


48
49
50
51
# File 'lib/moip.rb', line 48

def moip_page(token)
  raise(StandardError, "É necessário informar um token para retornar os dados da transação") if token.nil?
  "#{self.uri}/Instrucao.do?token=#{token}"
end

.notification(params) ⇒ Object

Monta o NASP



54
55
56
57
58
59
60
61
62
63
# File 'lib/moip.rb', line 54

def notification(params)
  notification = {}
  notification[:transaction_id] = params["id_transacao"]
  notification[:amount]         = params["valor"]
  notification[:status]         = STATUS[params["status_pagamento"].to_i]
  notification[:code]           = params["cod_moip"]
  notification[:payment_type]   = params["tipo_pagamento"]
  notification[:email]          = params["email_consumidor"]
  notification
end

.query(token) ⇒ Object

Consulta dos dados das autorizações e pagamentos associados à Instrução



41
42
43
44
45
# File 'lib/moip.rb', line 41

def query(token)
  full_data = peform_action!(:get, "ConsultarInstrucao/#{token}")

  get_response!(full_data["ConsultarTokenResponse"]["RespostaConsultar"])
end

.setup {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:

  • _self (MoIP)

    the object that the method was called on



22
23
24
# File 'lib/moip.rb', line 22

def self.setup
  yield self
end