Class: Moiper::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/moiper/response.rb

Instance Method Summary collapse

Constructor Details

#initialize(body) ⇒ Response

Returns a new instance of Response.

Parameters:

  • body (String)

    the response body from Moip



4
5
6
# File 'lib/moiper/response.rb', line 4

def initialize(body)
  @body = body
end

Instance Method Details

#checkout_urlString?

Returns the URL which the user should be redirected to finish payment process or nil if the request was not successfully.

Returns:

  • (String, nil)

    the URL which the user should be redirected to finish payment process or nil if the request was not successfully



16
17
18
# File 'lib/moiper/response.rb', line 16

def checkout_url
  Moiper.api_entrypoint + "Instrucao.do?token=" + token if success?
end

#errorsArray<String>

List the possible errors returned by Moip

Returns:

  • (Array<String>)


27
28
29
# File 'lib/moiper/response.rb', line 27

def errors
  parsed_body.css("Erro").map(&:text)
end

#success?Boolean

Detects if the response was successfully

Returns:

  • (Boolean)


10
11
12
# File 'lib/moiper/response.rb', line 10

def success?
  parsed_body.css("Status").text == "Sucesso"
end

#tokenString

Returns the response token.

Returns:

  • (String)

    the response token



21
22
23
# File 'lib/moiper/response.rb', line 21

def token
  parsed_body.css("Token").text
end