Method: WebpayOneClick#initInscription

Defined in:
lib/webpayoneclick.rb

#initInscription(username, email, urlReturn) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/webpayoneclick.rb', line 37

def initInscription(username, email, urlReturn)

  initInput ={
      "arg0" => {
            "username" => username,
            "email" => email,
            "responseURL" => urlReturn
      }
  }


  req = @client.build_request(:init_inscription, message: initInput)

  #Firmar documento

  document = sign_xml(req)
  puts document

  begin
    response = @client.call(:init_inscription) do
      xml document.to_xml(:save_with => 0)
    end
  rescue Exception, RuntimeError => e
    puts "Ocurrio un error en la llamada a Webpay: "+e.message
    response_array ={
        "error_desc" => "Ocurrio un error en la llamada a Webpay: "+e.message
    }
    return response_array
  end

  #Verificacion de certificado respuesta

  tbk_cert = OpenSSL::X509::Certificate.new(@webpay_cert)

  if !Verifier.verify(response, tbk_cert)
    puts "El Certificado de respuesta es Invalido."
    response_array ={
        "error_desc" => 'El Certificado de respuesta es Invalido'
    }
    return response_array
  else
    puts "El Certificado de respuesta es Valido."
  end


  token=''
  response_document = Nokogiri::HTML(response.to_s)
  response_document.xpath("//token").each do |token_value|
    token = token_value.text
  end
  url=''
  response_document.xpath("//urlwebpay").each do |url_value|
    url = url_value.text
  end

  puts 'token: '+token
  puts 'url: '+url

  response_array ={
      "token" => token.to_s,
      "url" => url.to_s,
      "error_desc" => 'TRX_OK'
  }

  return response_array
end