transbank-oneclick 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 95fbfd070c19da9f643fcf4832ae3d72e41bc05e
4
- data.tar.gz: 8b385a733da276b16e2a2f513c1eeb2ba7c174a1
3
+ metadata.gz: c98d91cef3e41e3a727cade1e309670a35f1c2d2
4
+ data.tar.gz: 4cde9397e226cf9bc276806abb259ce7c23f9786
5
5
  SHA512:
6
- metadata.gz: 1d563893975c9fa28cd0404541ccf0742acc7b909e16e072600a9e2fbdd19c01ed9000e80f2039b3756c845b34d276079f485f862d3c7bfe5b72620801501128
7
- data.tar.gz: 3a47c91275f88f0c5c64fac1f7320457a296611138f20574eb911e3d01c6cf582f7893308310ff8868f189a9fdada50ed04cb3670e05535b71be41fe9bcf375e
6
+ metadata.gz: 62b93da646c847a6d14b6eedcaabc4b6fc9c3a00d60665ad4f8a1bb9ee6ab5de9e165339453d8a00c46e0a9f4bfa63e621f7b18b7fb863f2d9ceeeb652eebdfd
7
+ data.tar.gz: c6c7f23e17ee36f7b66e335956c29d564d3b29477f8cec7f981176e6cc8418ee98571f7ac250ebaa3a2d38c5a6b1593a04f3507a5090ce865c5c8a2e4f7afa82
data/Gemfile CHANGED
@@ -2,3 +2,9 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in transbank-oneclick.gemspec
4
4
  gemspec
5
+
6
+ group :development, :test do
7
+ # only for generators
8
+ gem 'activesupport', '>= 3.0.0'
9
+ gem 'railties', '>= 3.0.0'
10
+ end
data/README.md CHANGED
@@ -138,9 +138,6 @@ Transbank::Oneclick.configure do |config|
138
138
  config.key_path = "RELATIVE_PATH_TO_KEY_FILE"
139
139
  end
140
140
  ```
141
- ## TODO
142
- - Testing, testing, testing
143
- - Refactoring
144
141
 
145
142
  ## Contributing
146
143
 
data/Rakefile CHANGED
@@ -1,2 +1,12 @@
1
1
  require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new(:spec) do |s|
5
+ s.libs << 'spec'
6
+ s.pattern = 'spec/**/*_spec.rb'
7
+ end
8
+
9
+ task default: :spec
10
+
11
+
2
12
 
@@ -10,7 +10,9 @@ module Transbank
10
10
  self.http = Net::HTTP.new uri.host, uri.port
11
11
 
12
12
  # load options
13
- opt.each {|attr, value| http.__send__("#{attr}=", value)}
13
+ set_options(opt)
14
+
15
+ # default options
14
16
  http.use_ssl = true
15
17
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
16
18
  end
@@ -18,6 +20,11 @@ module Transbank
18
20
  def post(xml_canonicalize)
19
21
  http.post(uri.path, xml_canonicalize, HEADER)
20
22
  end
23
+
24
+ private
25
+ def set_options(opt = {})
26
+ opt.each {|attr, value| http.__send__("#{attr}=", value)}
27
+ end
21
28
  end
22
29
  end
23
30
  end
@@ -8,7 +8,7 @@ module Transbank
8
8
  attr_accessor :http_options
9
9
 
10
10
  def initialize
11
- self.rescue_exceptions = [Net::ReadTimeout, Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError,
11
+ self.rescue_exceptions = [Net::ReadTimeout, Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError, Net::HTTPBadGateway,
12
12
  Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError]
13
13
  self.http_options = {}
14
14
  end
@@ -1,3 +1,5 @@
1
+ require "base64"
2
+
1
3
  module Transbank
2
4
  module Oneclick
3
5
  class Document
@@ -4,18 +4,24 @@ module Transbank
4
4
  attr_accessor :content, :action, :attributes, :errors, :exception
5
5
 
6
6
  RESPONSE_CODE = {
7
- '0' => 'aprobado',
8
- '-1' => 'rechazo',
9
- '-2' => 'rechazo',
10
- '-3' => 'rechazo',
11
- '-4' => 'rechazo',
12
- '-5' => 'rechazo',
13
- '-6' => 'rechazo',
14
- '-7' => 'rechazo',
15
- '-8' => 'rechazo',
16
- '-97' => 'limites Oneclick, máximo monto diario de pago excedido',
17
- '-98' => 'limites Oneclick, máximo monto de pago excedido',
18
- '-99' => 'limites Oneclick, máxima cantidad de pagos diarios excedido'
7
+ authorize: {
8
+ '0' => 'aprobado',
9
+ '-1' => 'rechazo',
10
+ '-2' => 'rechazo',
11
+ '-3' => 'rechazo',
12
+ '-4' => 'rechazo',
13
+ '-5' => 'rechazo',
14
+ '-6' => 'rechazo',
15
+ '-7' => 'rechazo',
16
+ '-8' => 'rechazo',
17
+ '-97' => 'limites Oneclick, máximo monto diario de pago excedido',
18
+ '-98' => 'limites Oneclick, máximo monto de pago excedido',
19
+ '-99' => 'limites Oneclick, máxima cantidad de pagos diarios excedido'
20
+ },
21
+ default: {
22
+ '0' => 'aprobado',
23
+ '-98' => 'Error'
24
+ }
19
25
  }
20
26
 
21
27
  def initialize(content, action)
@@ -55,7 +61,11 @@ module Transbank
55
61
  end
56
62
 
57
63
  def response_code_display
58
- RESPONSE_CODE.fetch(response_code, response_code)
64
+ if respond_to?(:response_code)
65
+ # key = RESPONSE_CODE.keys.include?(action) ? action : :default
66
+ # RESPONSE_CODE[key].fetch(response_code, response_code)
67
+ RESPONSE_CODE[action] && RESPONSE_CODE[action][response_code] || RESPONSE_CODE[:default][response_code] || response_code
68
+ end
59
69
  end
60
70
 
61
71
  def inspect
@@ -87,7 +97,7 @@ module Transbank
87
97
  end
88
98
 
89
99
  def validate!
90
- if action =~ /finishInscription|Authorize/ and respond_to?(:response_code) and response_code != '0'
100
+ if action =~ /finishInscription|Authorize|/ and respond_to?(:response_code) and response_code != '0'
91
101
  self.errors << response_code_display
92
102
  end
93
103
 
@@ -101,6 +111,7 @@ module Transbank
101
111
 
102
112
  if content.class != Net::HTTPOK
103
113
  self.errors += xml_error.map(&:text)
114
+ self.errors << content.message if content.respond_to?(:message)
104
115
  end
105
116
  end
106
117
  end
@@ -1,5 +1,5 @@
1
1
  module Transbank
2
2
  module Oneclick
3
- VERSION = "0.0.3"
3
+ VERSION = "0.0.4"
4
4
  end
5
5
  end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+ class TransbankOneclickGeneratorSpec < Rails::Generators::TestCase
3
+ tests TransbankOneclick::Generators::InstallGenerator
4
+ destination File.expand_path("../tmp", File.dirname(__FILE__))
5
+ setup :prepare_destination
6
+ teardown { rm_rf(destination_root) }
7
+
8
+ test "Assert all files are properly created" do
9
+ run_generator
10
+ assert_file 'config/initializers/transbank_oneclick.rb'
11
+ end
12
+ end
@@ -0,0 +1,20 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIDWjCCAkICCQD+dO80PPmJQzANBgkqhkiG9w0BAQUFADBvMQswCQYDVQQGEwJD
3
+ TDETMBEGA1UECBMKU29tZS1TdGF0ZTERMA8GA1UEBxMIU0FOVElBR08xITAfBgNV
4
+ BAoTGEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDEVMBMGA1UEAxMMNTk3MDI5MTI0
5
+ NDU2MB4XDTE1MDIyNTE3MjAxNVoXDTE5MDIyNDE3MjAxNVowbzELMAkGA1UEBhMC
6
+ Q0wxEzARBgNVBAgTClNvbWUtU3RhdGUxETAPBgNVBAcTCFNBTlRJQUdPMSEwHwYD
7
+ VQQKExhJbnRlcm5ldCBXaWRnaXRzIFB0eSBMdGQxFTATBgNVBAMTDDU5NzAyOTEy
8
+ NDQ1NjCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBANgchO1+f/ByFIhd
9
+ AeGTro97D9qR4pXDL/hpF87qx8ip52+GUxKzTJrwhWkjA+7IN53zK5Usl5tsGlVq
10
+ aXN10QNa97mzpPPXFpVKMQfLtv5t21CTmLVRi2lTP/HCIFukyfeawmhav7DVHPqA
11
+ itCyCZ1wuCy/7kp5cqNnpVa82KWDZFsx0yKXipUYYxP7S386G/Vp4fFPFrPCW3t3
12
+ /Mm3G/57YXYAqYTAqlMfe7NcTlzGaVvhzDYUN7CdCCwfZuIxrIciDr+SxN1jb1Zg
13
+ iIdA3TyEUvvKeeIfpr+YrwqE3JuJ05YRfwxM9WiI2oZQKXGozxroacXal4DAad59
14
+ n1hfkbsCAwEAATANBgkqhkiG9w0BAQUFAAOCAQEAaJM1/P/ke+BwUe7MhaZTWXVl
15
+ LKxMCII2v/Leov/E1AKoIfrtm3cLbWY44IaaC43uwHcMvrq72hKG9t9b9Z5BJu/2
16
+ Rsy3RSNCzu7x+89Af2KvwKypWBjpyfWxmnDr4VN7Lq4vcvA8ba/+u59wWDCAa5Pq
17
+ xWg727XQSuDkJS7KiIhFfGYUZwaLBfGybeo+KYYsJ3IQHZ5U6lsBoRo5OWYqmnZb
18
+ aqY6UiI5lCilR7q3bdNhGpvygyxl16ZlIKU0TG1EsvwuZuWTN5gZNkCjxM5VhZHg
19
+ NdojvzDd3dtk0jQpR0WvLxk35Cw9NItWe6sGGLpBrMddFuEenNHZHL+ftYJMCg==
20
+ -----END CERTIFICATE-----
@@ -0,0 +1,27 @@
1
+ -----BEGIN RSA PRIVATE KEY-----
2
+ MIIEowIBAAKCAQEA2ByE7X5/8HIUiF0B4ZOuj3sP2pHilcMv+GkXzurHyKnnb4ZT
3
+ ErNMmvCFaSMD7sg3nfMrlSyXm2waVWppc3XRA1r3ubOk89cWlUoxB8u2/m3bUJOY
4
+ tVGLaVM/8cIgW6TJ95rCaFq/sNUc+oCK0LIJnXC4LL/uSnlyo2elVrzYpYNkWzHT
5
+ IpeKlRhjE/tLfzob9Wnh8U8Ws8Jbe3f8ybcb/nthdgCphMCqUx97s1xOXMZpW+HM
6
+ NhQ3sJ0ILB9m4jGshyIOv5LE3WNvVmCIh0DdPIRS+8p54h+mv5ivCoTcm4nTlhF/
7
+ DEz1aIjahlApcajPGuhpxdqXgMBp3n2fWF+RuwIDAQABAoIBAHlhI0Pk3eTlniSs
8
+ 4GabNNr/inr/nxzwgRvrouSjt0w8KXHZJwWE0Qzg9H2FniraJ2q+bocdgZVY1T2O
9
+ Q+YGkTtqN2MExCv0bYmyHvG6+G/Use6Cx61nPH8OtAaMOvJeDtXUBUbpWWrvd5Q2
10
+ 6ECpDn9wFPGFZ0hLCBlBGHssHB5xMiz5tVnkOzQf+SJWg4h+nXls10HQPAynXidV
11
+ mlTilXzRVf1qjSmDo914OcJ57bbcYrvRCjnTV+JwNW9jC+o/+PLmTKQe7R9RmyS+
12
+ G0EIzKMCdH0AseYOrRdhskX/pcCBEG33K19LRkVIr527O+a8agdYhX1Tl//JTNsi
13
+ OyRjAjkCgYEA+EO+pE6Adh+KTlt3kxo5mmVv8ALRI8113fmhA/nJCTbenH2ku0SE
14
+ AnFwW7MNQlV6k3hqiE+iK3Cex5yPk3iFZY885RrAZRLFhLUulhf+z6LxxKvQiJKA
15
+ AnuU5lUvzzkiQ2j/bK8LiwfxSNgyhqtRHTeqtrMYZCtKOjuHGnsAPsUCgYEA3thO
16
+ 0+r3q9lpPUzLM+0O3/6jpt7hx37O4zWoh6r1b5iSOiytLECwvG6r7Jfe0pqgX8mN
17
+ xU85DhvCBjoAEU06gH4X+lA4Kcrj1kqVwXNo4JGaA9Tv9MiAWAwiX6v6gltBmq9A
18
+ 86tf4XQw6N6s5M+eO3g3ZksJU0D6RkdIrmwlln8CgYBa/tGgfZl+Mj9KSyI/y6vz
19
+ WFy39wBbBBLAop+Oyn4SH4dminLXpNxR3OxW4ADrIFOGO+uoPK/vBh9cgJjrb5BN
20
+ Ujv6qVx9b2zwIEyL/Q2LY2kEMgmEFVZQEqXX6r9UT9esJ47/cgVkFywsC/ow/BgG
21
+ AoJS5r/47xkM0QbLAOxtFQKBgCZ+pTdUWo5UEyrkriF9LNmiyjBURhpJHIIBTeiJ
22
+ rrYlW/UyrIN9dUpHr+lB3trwnQ2O6q+P3OJEB0M+F67lcVqq7Ydu/hSyGKN25OGz
23
+ BwXsAPfye7UEQa90ASgXtEF6dB29cnHlQ73VbXF8rc8k0kehn6hLBAResB0dyT9g
24
+ LSoPAoGBALNZN9e0Ed/ybaq5ltl+QFaLjF2zRm2FjCI/pDxyaiRjfFPxw6zmV6ix
25
+ 7ElODI6crpeAkJB0+hfGK+8mXGY3bCezNj3DEpxe6A+6CITn501GFTEten/6/N4j
26
+ i5rY1EiLoiuPJYywLi0wzUHPL//Ou3C4fQ9gXJqTEm3IXJeG6yyy
27
+ -----END RSA PRIVATE KEY-----
@@ -0,0 +1,24 @@
1
+ require 'bundler/setup'
2
+ require 'minitest/autorun'
3
+ require 'minitest/unit'
4
+ require 'mocha/mini_test'
5
+ require 'webmock/minitest'
6
+ require 'active_support'
7
+ require 'rails/generators'
8
+ require 'rails/generators/test_case'
9
+ require 'generators/transbank_oneclick/install/install_generator'
10
+ require 'transbank-oneclick'
11
+
12
+ INIT_INSCRIPTION_XML = %q{<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header><wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" SOAP-ENV:mustUnderstand="1"><ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#"><ds:SignedInfo><ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"></ds:CanonicalizationMethod><ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"></ds:SignatureMethod><ds:Reference URI="#dge763trgad"><ds:Transforms><ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"></ds:Transform></ds:Transforms><ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"></ds:DigestMethod><ds:DigestValue>0BrXmTm2mc2ZRtl/MItcP95fKRg=</ds:DigestValue></ds:Reference></ds:SignedInfo><ds:SignatureValue>sMXYD7Y5UiuBqHcZNAQYASx4pS0iv2szapjCIlAxyj/VLGfyuHHiKeIannYxcdE4FSL7ubOyKTDW46m3F4xvimYqBAxT6XmoWIpRTohsUL0yVcXlcd3tsyw34ik0+ESDtWxsfYEVoYktW5IceIb3ZcZyCCInvy0ef7aQxFR0tluejqFF9w2TtLcqgwdTDR2n/Xb2sRr+Propdc2rgSElWvz/EYA4yquAKQP/Lw+9+7u6twEM0o6axY+ZQq2VG8ydUjazoZ/25GyPGibQ7OmJ0FnisqpkLDMbgkSJcNcTlpqFTM9Ces0SEx1aTGMiSvP8/Kes0ceWgQgyvCoE/2vDKw==</ds:SignatureValue><ds:KeyInfo><wsse:SecurityTokenReference><ds:X509Data><ds:X509IssuerSerial><ds:X509IssuerName>C=CL,ST=Some-State,L=SANTIAGO,O=Internet Widgits Pty Ltd,CN=597029124456</ds:X509IssuerName><ds:X509SerialNumber>18335542990572456259</ds:X509SerialNumber></ds:X509IssuerSerial></ds:X509Data></wsse:SecurityTokenReference></ds:KeyInfo></ds:Signature></wsse:Security></SOAP-ENV:Header><SOAP-ENV:Body xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="dge763trgad"><ns1:init_inscription xmlns:ns1="http://webservices.webpayserver.transbank.com/"><arg0><email>username@domain</email><username>username</username><response_url>http://domain/card</response_url></arg0></ns1:init_inscription></SOAP-ENV:Body></SOAP-ENV:Envelope>}
13
+ FINISH_INSCRIPTION_XML = %q{<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header><wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" SOAP-ENV:mustUnderstand="1"><ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#"><ds:SignedInfo><ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"></ds:CanonicalizationMethod><ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"></ds:SignatureMethod><ds:Reference URI="#dge763trgad"><ds:Transforms><ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"></ds:Transform></ds:Transforms><ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"></ds:DigestMethod><ds:DigestValue>IHwQM0OmsM6YCyFNI1kG5RdMtk4=</ds:DigestValue></ds:Reference></ds:SignedInfo><ds:SignatureValue>AGO75Nn0u5YrmRaLeN055X1WBj1Ikzb1sgP4chOsMNTQDmG7fAW/FTE7ldTzHNmHolrLD2Scmb2H7Xu9k3OqfjGTM0883zyKLXZiyNPBqpW2CqiTcb+i1O490BVZcsRMVWd8P/EGoWpcuLwDYlq0j1Ym6486OZ0V0+E9Rj5U4tc3ShjHd7rJRiO2J8+rq9CmUhn++Yd+v+LGDev54UQHFp574CmWPC3s5u7JXJ1Bf2zZN4jZR1LGvtDDRWw+CRmm/k9XNpgw57+9bJQYN7xwg248vztvCX/mtPqwayNiqhXwo3cAKgCFP6WoK0XNTWWqxUVRrf6fNSxc8JqWPKBGoA==</ds:SignatureValue><ds:KeyInfo><wsse:SecurityTokenReference><ds:X509Data><ds:X509IssuerSerial><ds:X509IssuerName>C=CL,ST=Some-State,L=SANTIAGO,O=Internet Widgits Pty Ltd,CN=597029124456</ds:X509IssuerName><ds:X509SerialNumber>18335542990572456259</ds:X509SerialNumber></ds:X509IssuerSerial></ds:X509Data></wsse:SecurityTokenReference></ds:KeyInfo></ds:Signature></wsse:Security></SOAP-ENV:Header><SOAP-ENV:Body xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="dge763trgad"><ns1:finish_inscription xmlns:ns1="http://webservices.webpayserver.transbank.com/"><arg0><token>fyegwyufgi3289rheowifewfiasocgh2e78c</token></arg0></ns1:finish_inscription></SOAP-ENV:Body></SOAP-ENV:Envelope>}
14
+ AUTHORIZE_XML = %q{<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header><wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" SOAP-ENV:mustUnderstand="1"><ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#"><ds:SignedInfo><ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"></ds:CanonicalizationMethod><ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"></ds:SignatureMethod><ds:Reference URI="#dge763trgad"><ds:Transforms><ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"></ds:Transform></ds:Transforms><ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"></ds:DigestMethod><ds:DigestValue>5Cly+K17xLkr7oiICa7phcdvbos=</ds:DigestValue></ds:Reference></ds:SignedInfo><ds:SignatureValue>m7UKJYImHNr0jWN3dOqfXmOXzqNQ4UZ4wII6R/XwtZmJp1dLV71WXvABBP35mTIgKD1Bd3FbDXxrPndVw/FjliotujOBGeUk+qJKGLhm+uET1Mr5acNPtmQE2Kw7Ls4qrWkqbyIEOv8skJfnhy6qZeJgmHsgjPqARW3QTUPSfqL2Z3ysNqriRw92c8ZrKF518e/B/f1ua8ruaIz4srEcMD+4RVE0DP4ao/iNHJA5rVB4mbb9JW2Hb+isyDjCXCfZzx5K2szJksBV/BagFdF7+No44bpH37tL6H3jHw1hAkWjST/1WN1RC+1IflQIZUVBQh0IXw+AmjDQ/AceYqef7A==</ds:SignatureValue><ds:KeyInfo><wsse:SecurityTokenReference><ds:X509Data><ds:X509IssuerSerial><ds:X509IssuerName>C=CL,ST=Some-State,L=SANTIAGO,O=Internet Widgits Pty Ltd,CN=597029124456</ds:X509IssuerName><ds:X509SerialNumber>18335542990572456259</ds:X509SerialNumber></ds:X509IssuerSerial></ds:X509Data></wsse:SecurityTokenReference></ds:KeyInfo></ds:Signature></wsse:Security></SOAP-ENV:Header><SOAP-ENV:Body xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="dge763trgad"><ns1:authorize xmlns:ns1="http://webservices.webpayserver.transbank.com/"><arg0><amount>99999</amount><tbk_user>35700491-cb03-4bbb-8ab7-29dd7b0771ab</tbk_user><username>user_1</username><buy_order>20110715115550003</buy_order></arg0></ns1:authorize></SOAP-ENV:Body></SOAP-ENV:Envelope>}
15
+ REVERSE_XML = %q{<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header><wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" SOAP-ENV:mustUnderstand="1"><ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#"><ds:SignedInfo><ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"></ds:CanonicalizationMethod><ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"></ds:SignatureMethod><ds:Reference URI="#dge763trgad"><ds:Transforms><ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"></ds:Transform></ds:Transforms><ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"></ds:DigestMethod><ds:DigestValue>9B2Jhrmw13cLqSMKfCGj3XU3W8k=</ds:DigestValue></ds:Reference></ds:SignedInfo><ds:SignatureValue>Mr3W82xULZwHOCuwperpcJNJUEJMH7nMoiDeDE9JeSz9CSIDyUTz/fWhe5nCIzTuzx8JpYSgPiqbPv4WYkKuPOcZeWnhE3v6ewL/xw732XpBkwlFgA1zRPi9tI+y3YgPbPxuklvbHuMgq771YKwJAM5tN6xHyd1Oj2wiOXAw/DA6j5vpch74ruHiucbI3UB4FMOpTTagQlcvBvz+a9ZP27cJ2V/3PYNd6Bz12bcdUhm5GvORGdqVRC0KB0vA11E4lCjXzzjZenf/4KHE6Zh7gYboUNstDrinQZkF7XnUn8mw4qjP7gi8jkzoJS3jPW9Ctkx2RrxG/eMUJ4NsY73jNA==</ds:SignatureValue><ds:KeyInfo><wsse:SecurityTokenReference><ds:X509Data><ds:X509IssuerSerial><ds:X509IssuerName>C=CL,ST=Some-State,L=SANTIAGO,O=Internet Widgits Pty Ltd,CN=597029124456</ds:X509IssuerName><ds:X509SerialNumber>18335542990572456259</ds:X509SerialNumber></ds:X509IssuerSerial></ds:X509Data></wsse:SecurityTokenReference></ds:KeyInfo></ds:Signature></wsse:Security></SOAP-ENV:Header><SOAP-ENV:Body xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="dge763trgad"><ns1:code_reverse_one_click xmlns:ns1="http://webservices.webpayserver.transbank.com/"><arg0><buy_order>20110715115550003</buy_order></arg0></ns1:code_reverse_one_click></SOAP-ENV:Body></SOAP-ENV:Envelope>}
16
+ REMOVE_USER_XML = %q{<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header><wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" SOAP-ENV:mustUnderstand="1"><ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#"><ds:SignedInfo><ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"></ds:CanonicalizationMethod><ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"></ds:SignatureMethod><ds:Reference URI="#dge763trgad"><ds:Transforms><ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"></ds:Transform></ds:Transforms><ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"></ds:DigestMethod><ds:DigestValue>ky84GGpUNWifeLGMvHARCkYnH/A=</ds:DigestValue></ds:Reference></ds:SignedInfo><ds:SignatureValue>uA/FBTbofW1GHUU6wjldJ0WShUARW6zLxQMUiXXwKWb+BoTvDDB7Hk6cRb5iC0n+LjqWAKuoTkyT/6CYFDWNOP7s0Cb/TrPI/Qw9gTTF1UCA3wWLaDwwMfDNyniWtIwfM9sTwrsh7sRL9qtEetjZVR/CejUePLTLtkQSdNnTO23mKUhBlyWQav2MwuYJntVB8LghdqFyvFo/IncA9cF6wmhBVqJvCvma7+Kn9kQjmgRCzxGGej75lJ4/GG5tgk6TJUxtwRzV73uk3bB/nZGjnOIB4qvrCgU0NPoaUkn3/k1JBPE4BmKmBo36/JRn1dj9JNJG65KSeHktNhDOjVryow==</ds:SignatureValue><ds:KeyInfo><wsse:SecurityTokenReference><ds:X509Data><ds:X509IssuerSerial><ds:X509IssuerName>C=CL,ST=Some-State,L=SANTIAGO,O=Internet Widgits Pty Ltd,CN=597029124456</ds:X509IssuerName><ds:X509SerialNumber>18335542990572456259</ds:X509SerialNumber></ds:X509IssuerSerial></ds:X509Data></wsse:SecurityTokenReference></ds:KeyInfo></ds:Signature></wsse:Security></SOAP-ENV:Header><SOAP-ENV:Body xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="dge763trgad"><ns1:remove_user xmlns:ns1="http://webservices.webpayserver.transbank.com/"><arg0><tbk_user>35700491-cb03-4bbb-8ab7-29dd7b0771ab</tbk_user><username>user_1</username></arg0></ns1:remove_user></SOAP-ENV:Body></SOAP-ENV:Envelope>}
17
+
18
+ ActiveSupport.test_order = :sorted
19
+
20
+ Transbank::Oneclick.configure do |config|
21
+ config.url = 'https://transbank-example.cl/oneclick'
22
+ config.cert_path = 'spec/keys/597029124456.crt'
23
+ config.key_path = 'spec/keys/597029124456.key'
24
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ module Transbank
4
+ module Oneclick
5
+ describe Api do
6
+
7
+ let(:api){ Api.new }
8
+
9
+ describe '#build_params' do
10
+ it { api.send( :build_params, {email: 'email'} ).keys.must_include :email }
11
+ it { api.send( :build_params, {response_url: 'response_url'} ).keys.must_include :responseURL }
12
+ it { api.send( :build_params, {token: 'token'} ).keys.must_include :token }
13
+ it { api.send( :build_params, {amount: 'amount'} ).keys.must_include :amount }
14
+ it { api.send( :build_params, {tbk_user: 'tbk_user'} ).keys.must_include :tbkUser }
15
+ it { api.send( :build_params, {buy_order: 'buy_order'} ).keys.must_include :buyOrder }
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ module Transbank
4
+ module Oneclick
5
+
6
+ describe Client do
7
+ let(:client) { Client.new read_timeout: 55, open_timeout: 55}
8
+
9
+ describe 'check default options' do
10
+ it { client.http.use_ssl?.must_equal true }
11
+ it { client.http.verify_mode.must_equal OpenSSL::SSL::VERIFY_NONE }
12
+ end
13
+
14
+ describe 'check options' do
15
+ it { client.http.read_timeout.must_equal 55 }
16
+ it { client.http.open_timeout.must_equal 55 }
17
+ end
18
+
19
+ describe '#post' do
20
+ it 'init incription'do
21
+ stub_request(:post, 'https://transbank-example.cl/oneclick')
22
+ .with(body: INIT_INSCRIPTION_XML, headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type'=>'application/soap+xml; charset=utf-8', 'User-Agent'=>'Ruby'})
23
+ .to_return(status: 200, body: "", headers:{})
24
+
25
+ client.post(INIT_INSCRIPTION_XML).code.must_equal '200'
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,40 @@
1
+ require 'spec_helper'
2
+
3
+ module Transbank
4
+ module Oneclick
5
+ describe Document do
6
+ before { Document.any_instance.stubs(:body_id).returns('dge763trgad') }
7
+
8
+ it 'action init inscription' do
9
+ doc = Document.new :init_inscription, email: "username@domain",
10
+ username: "username",
11
+ response_url: "http://domain/card"
12
+ doc.canonicalize.to_s.must_equal INIT_INSCRIPTION_XML
13
+ end
14
+
15
+ it 'action finish inscription' do
16
+ doc = Document.new :finish_inscription, token: 'fyegwyufgi3289rheowifewfiasocgh2e78c'
17
+ doc.canonicalize.to_s.must_equal FINISH_INSCRIPTION_XML
18
+ end
19
+
20
+ it 'action authorize' do
21
+ doc = Document.new :authorize, amount: 99999,
22
+ tbk_user: '35700491-cb03-4bbb-8ab7-29dd7b0771ab',
23
+ username: 'user_1',
24
+ buy_order: '20110715115550003'
25
+ doc.canonicalize.to_s.must_equal AUTHORIZE_XML
26
+ end
27
+
28
+ it 'action reverse' do
29
+ doc = Document.new :code_reverse_one_click, buy_order: '20110715115550003'
30
+ doc.canonicalize.to_s.must_equal REVERSE_XML
31
+ end
32
+
33
+ it 'action remove user' do
34
+ doc = Document.new :remove_user, tbk_user: '35700491-cb03-4bbb-8ab7-29dd7b0771ab',
35
+ username: 'user_1'
36
+ doc.canonicalize.to_s.must_equal REMOVE_USER_XML
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ module Transbank
4
+ module Oneclick
5
+ describe ExceptionResponse do
6
+ let(:raise_error) { URI::InvalidURIError.new 'the scheme http does not accept registry part: :80 (or bad hostname?)>' }
7
+ let(:exception_response) { ExceptionResponse.new raise_error, :initi_inscription}
8
+
9
+ it{ exception_response.valid?.must_equal false }
10
+
11
+ it{ exception_response.errors.must_include 'the scheme http does not accept registry part: :80 (or bad hostname?)>' }
12
+
13
+ it { exception_response.exception?.must_equal true }
14
+
15
+ it { exception_response.errors_display.must_equal 'URI::InvalidURIError, the scheme http does not accept registry part: :80 (or bad hostname?)>' }
16
+
17
+ it { exception_response.errors_display.inspect.must_equal '"URI::InvalidURIError, the scheme http does not accept registry part: :80 (or bad hostname?)>"'}
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ module Transbank
4
+ module Oneclick
5
+ describe Request do
6
+
7
+ # Mocks
8
+ before do
9
+ client = mock()
10
+ client.expects(:post).with(INIT_INSCRIPTION_XML).returns(:post_result)
11
+ Client.stubs(:new).returns(client)
12
+
13
+ document = mock()
14
+ document.expects(:canonicalize).returns(INIT_INSCRIPTION_XML)
15
+ Document.stubs(:new).returns(document)
16
+
17
+ ExceptionResponse.stubs(:new).returns(:exception_response)
18
+ end
19
+
20
+ let(:request) { Request.new :init_inscription }
21
+
22
+ describe '#response' do
23
+
24
+ describe 'without error' do
25
+ before { Response.stubs(:new).with(:post_result, :init_inscription).returns(:response) }
26
+ it { request.response.must_equal :response }
27
+ end
28
+
29
+ describe 'with error' do
30
+ before { Response.stubs(:new).with(:post_result, :init_inscription).raises(Net::ReadTimeout) }
31
+ it { request.response.must_equal :exception_response }
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,474 @@
1
+ require 'spec_helper'
2
+
3
+ module Transbank
4
+ module Oneclick
5
+ describe Response do
6
+
7
+ describe 'init inscription' do
8
+
9
+ describe 'with raise error' do
10
+ let(:content) do
11
+ Net::HTTPBadGateway.new("1.1", "502", "Bad Gateway").tap do |n|
12
+ n.instance_variable_set(:@read, true)
13
+ end
14
+ end
15
+ let(:response) { Response.new content, :initInscription}
16
+
17
+ it { response.http_code.must_equal '502' }
18
+ it { response.xml_result.must_equal [] }
19
+ it { response.xml_error.must_be_empty }
20
+ it { response.errors_display.must_equal 'Bad Gateway' }
21
+ it { response.valid?.must_equal false }
22
+ it { response.response_code_display.must_be_nil }
23
+ it { response.inspect.must_equal '#<Transbank::Oneclick::Response valid: false, error: "Bad Gateway" >' }
24
+ it { response.exception?.must_equal false }
25
+ it { response.exception.must_be_nil }
26
+ it { response.attributes.size.must_equal 0 }
27
+ end
28
+
29
+ describe 'with response valid' do
30
+ let(:body) { %q{<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Header><wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" soap:mustUnderstand="1"><ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#" Id="SIG-8350"><ds:SignedInfo><ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"><ec:InclusiveNamespaces xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#" PrefixList="soap"/></ds:CanonicalizationMethod><ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/><ds:Reference URI="#id-8349"><ds:Transforms><ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"><ec:InclusiveNamespaces xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#" PrefixList=""/></ds:Transform></ds:Transforms><ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/><ds:DigestValue>dsJH15MYSVxtlBewmw7XtFm3/oM=</ds:DigestValue></ds:Reference></ds:SignedInfo><ds:SignatureValue>Cq1ROc9mNYV1KKzMDEK6HypOfzF0o2z4TPjyaapxF14LUO5HkvxD4mPsZ/kjAkOdhr9CRIN6IZR5\nvDf9Q+IZueZylue40Yqy4k/a+g/yzGUOw2p2uGai9beKibBhhmJX2ORrAv8g0bHv+qoSYiZzG0mK\nwdgCTlYr361EWQrWqeQ4mQdhDgVhlBDt2Q9VyUepjWj4Cd30rw6bAKdRIAmGByglYTleG5Pinz4E\nLGKtjyDFAUZb8t3/Aya0cTA2NIypysKqUMw7Our9vF/ml7KNyaMF9AAPdcKzv0cAQ4Ebh8O9lUTP\n5mzcMM3fcWaR8vrPNproMzLOVLWDWoCgF4pijXFtWZWGDzqB1xzKembbdvEPAhtIgOw1z5Qyxhjq\nWrJWctIa2R4SyGbGZC3uOmfurDle/D74D5BlpyfeU84k7T+J5YObYYmIXAFPlxgmL5p5Zck1V+BB\n32O3LXMmi88PeXVO1eo8KKB/igqc0PAxYbMme4pHlidQgqUJpO2Dyd5F2+LOGKpRlMcjejzoutB2\nDX4eREUkTF/nAqcjeEm+08QR0cjsfo5iqZAKyXidzw+bIXcvFSwnTvK1xhzj3eNIkn/r1tf7uFGj\niVvXbdy+HOajwPFEUkcDddwmtLlSZ+pzTcn1FSsgxfjdzlLCp1t40IJaKOZJ0gBJbFG7lKdFuUs=</ds:SignatureValue><ds:KeyInfo Id="KI-F6DDC585AC5A582DD2142559657168312524"><wsse:SecurityTokenReference wsu:Id="STR-F6DDC585AC5A582DD2142559657168312525"><ds:X509Data><ds:X509IssuerSerial><ds:X509IssuerName>CN=10,OU=ExperTI,O=ExperTI,L=Santiago,ST=Santiago,C=CL,1.2.840.113549.1.9.1=#16116a636572646140657870657274692e636c</ds:X509IssuerName><ds:X509SerialNumber>1401281826</ds:X509SerialNumber></ds:X509IssuerSerial></ds:X509Data></wsse:SecurityTokenReference></ds:KeyInfo></ds:Signature></wsse:Security></soap:Header><soap:Body xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="id-8349"><ns2:initInscriptionResponse xmlns:ns2="http://webservices.webpayserver.transbank.com/"><return><token>e7667c5f871fa39e6c05549eeddd1ff07a520a769fa84cc6994465cdb06cbb4b</token><urlWebpay>https://webpay3g.orangepeople.cl/webpayserver/bp_inscription.cgi</urlWebpay></return></ns2:initInscriptionResponse></soap:Body></soap:Envelope>} }
31
+ let(:content) { mock_content(body, '200') }
32
+ let(:response) { Response.new content, :initInscription}
33
+
34
+ it { response.body.must_equal body }
35
+ it { response.http_code.must_equal '200' }
36
+ it { response.doc.to_xml.must_equal Nokogiri::XML(body).to_xml }
37
+ it { response.xml_result.to_xml.must_equal '<token>e7667c5f871fa39e6c05549eeddd1ff07a520a769fa84cc6994465cdb06cbb4b</token><urlWebpay>https://webpay3g.orangepeople.cl/webpayserver/bp_inscription.cgi</urlWebpay>'}
38
+ it { response.xml_error.must_be_empty }
39
+ it { response.errors_display.must_be_empty }
40
+ it { response.valid?.must_equal true }
41
+ it { response.response_code_display.must_be_nil }
42
+ it { response.inspect.must_equal '#<Transbank::Oneclick::Response valid: true, token: "e7667c5f871fa39e6c05549eeddd1ff07a520a769fa84cc6994465cdb06cbb4b", url_webpay: "https://webpay3g.orangepeople.cl/webpayserver/bp_inscription.cgi" >' }
43
+ it { response.exception?.must_equal false }
44
+ it { response.exception.must_be_nil }
45
+ it { response.token.must_equal 'e7667c5f871fa39e6c05549eeddd1ff07a520a769fa84cc6994465cdb06cbb4b'}
46
+ it { response.url_webpay.must_equal 'https://webpay3g.orangepeople.cl/webpayserver/bp_inscription.cgi' }
47
+ it { response.attributes.size.must_equal 2 }
48
+ end
49
+
50
+ describe 'with email not valid' do
51
+ let(:body) { %q{<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><soap:Fault><faultcode>soap:Server</faultcode><faultstring>Invalid email</faultstring></soap:Fault></soap:Body></soap:Envelope>} }
52
+ let(:content) { mock_content(body, '500') }
53
+ let(:response) { Response.new content, :initInscription}
54
+
55
+ it { response.body.must_equal body }
56
+ it { response.http_code.must_equal '500' }
57
+ it { response.doc.to_xml.must_equal Nokogiri::XML(body).to_xml }
58
+ it { response.xml_result.must_equal [] }
59
+ it { response.xml_error.to_xml.must_equal '<faultstring>Invalid email</faultstring>' }
60
+ it { response.errors_display.must_equal 'Invalid email' }
61
+ it { response.valid?.must_equal false }
62
+ it { response.response_code_display.must_be_nil }
63
+ it { response.inspect.must_equal '#<Transbank::Oneclick::Response valid: false, error: "Invalid email" >' }
64
+ it { response.exception?.must_equal false }
65
+ it { response.exception.must_be_nil }
66
+ it { response.attributes.size.must_equal 0 }
67
+ end
68
+
69
+ describe 'with username not valid' do
70
+ let(:body) { %q{<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><soap:Fault><faultcode>soap:Server</faultcode><faultstring>Username is required</faultstring></soap:Fault></soap:Body></soap:Envelope>} }
71
+ let(:content) { mock_content(body, '500') }
72
+ let(:response) { Response.new content, :initInscription}
73
+
74
+ it { response.body.must_equal body }
75
+ it { response.http_code.must_equal '500' }
76
+ it { response.doc.to_xml.must_equal Nokogiri::XML(body).to_xml }
77
+ it { response.xml_result.must_equal [] }
78
+ it { response.xml_error.to_xml.must_equal '<faultstring>Username is required</faultstring>' }
79
+ it { response.errors_display.must_equal 'Username is required' }
80
+ it { response.valid?.must_equal false }
81
+ it { response.response_code_display.must_be_nil }
82
+ it { response.inspect.must_equal '#<Transbank::Oneclick::Response valid: false, error: "Username is required" >' }
83
+ it { response.exception?.must_equal false }
84
+ it { response.exception.must_be_nil }
85
+ it { response.attributes.size.must_equal 0 }
86
+ end
87
+
88
+ describe 'with url not valid' do
89
+ let(:body) { %q{<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><soap:Fault><faultcode>soap:Server</faultcode><faultstring>URL is required</faultstring></soap:Fault></soap:Body></soap:Envelope>} }
90
+ let(:content) { mock_content(body, '500') }
91
+ let(:response) { Response.new content, :initInscription}
92
+
93
+ it { response.body.must_equal body }
94
+ it { response.http_code.must_equal '500' }
95
+ it { response.doc.to_xml.must_equal Nokogiri::XML(body).to_xml }
96
+ it { response.xml_result.must_equal [] }
97
+ it { response.xml_error.to_xml.must_equal '<faultstring>URL is required</faultstring>' }
98
+ it { response.errors_display.must_equal 'URL is required' }
99
+ it { response.valid?.must_equal false }
100
+ it { response.response_code_display.must_be_nil }
101
+ it { response.inspect.must_equal '#<Transbank::Oneclick::Response valid: false, error: "URL is required" >' }
102
+ it { response.exception?.must_equal false }
103
+ it { response.exception.must_be_nil }
104
+ it { response.attributes.size.must_equal 0 }
105
+ end
106
+ end
107
+
108
+ describe 'finish inscription' do
109
+ describe 'with response valid' do
110
+ let(:body) { %q{<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Header><wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" soap:mustUnderstand="1"><ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#" Id="SIG-8366"><ds:SignedInfo><ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"><ec:InclusiveNamespaces xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#" PrefixList="soap"/></ds:CanonicalizationMethod><ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/><ds:Reference URI="#id-8365"><ds:Transforms><ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"><ec:InclusiveNamespaces xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#" PrefixList=""/></ds:Transform></ds:Transforms><ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/><ds:DigestValue>fJP2u/9YdHinVin6lld9n4nEAvo=</ds:DigestValue></ds:Reference></ds:SignedInfo><ds:SignatureValue>Nh8Pvf8QK20OKZ7Fa2lsPBClWvcCTTENIChbHui/sPJwUibVIT4V65kJ4oB2aMS3IhPpKdg7kLuv\nKoEZLIzTeERXC9DJgmrQdaSGr1E0Z/ML3cAapoxEDyZ2g0xpRdKND2mrLTXiXLYd1ZcLI4fod6v8\nxGt21rLABQpVIa/PUyhr4ZjqJ8aNxnds5k1FRkhECMJwLovMCn63jlcezc0Q0VtYULpm2wymThBx\nDxs0EuaqZ4uUJWRK/hhL0j9WR0rqTenN8Ok97Ko4HDvg/NL5PUH7xJKnByhKpqPOBqzLr07AZoCO\nTQc7a0dUN/Edw2DvDSlaM33eVoVzzONDnV40S7vIlaXi3U3WzebcDcXV+KF/TSwM7bSSVEDSGrdV\nvthCjv+XuoYnepqWoMTesDEo/bZ46l2gkVenn90APv7KSv0iem2dMcvUq7ftY//RTruHaUh0P3bi\nlosdu4zF5AxvY804t6fKWfoAwqZlhyt2s1HcSaOKX3Hck44NnSGwJBiGKwE1tEBs/jjb8VhkLkyW\nI9S09VaHlzwSW0PfAFdX4SrGq9fd0OlO35wQ2U31D5usBHvrDHfHBU0oLW/9li8rkroH8UgSnHbA\nyC7ktl+p9qABaioBCh3IF8JLcuXkElDCuCQmWYUaGv8mJ/4aYRhPh/rgdNRhcV5OuTWVQK43s94=</ds:SignatureValue><ds:KeyInfo Id="KI-F6DDC585AC5A582DD2142564457877312548"><wsse:SecurityTokenReference wsu:Id="STR-F6DDC585AC5A582DD2142564457877312549"><ds:X509Data><ds:X509IssuerSerial><ds:X509IssuerName>CN=10,OU=ExperTI,O=ExperTI,L=Santiago,ST=Santiago,C=CL,1.2.840.113549.1.9.1=#16116a636572646140657870657274692e636c</ds:X509IssuerName><ds:X509SerialNumber>1401281826</ds:X509SerialNumber></ds:X509IssuerSerial></ds:X509Data></wsse:SecurityTokenReference></ds:KeyInfo></ds:Signature></wsse:Security></soap:Header><soap:Body xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="id-8365"><ns2:finishInscriptionResponse xmlns:ns2="http://webservices.webpayserver.transbank.com/"><return><authCode>1213</authCode><creditCardType>Visa</creditCardType><last4CardDigits>6623</last4CardDigits><responseCode>0</responseCode><tbkUser>d2f27f36-b038-4937-8ea6-182b3de38cfd</tbkUser></return></ns2:finishInscriptionResponse></soap:Body></soap:Envelope>} }
111
+ let(:content) { mock_content(body, '200') }
112
+ let(:response) { Response.new content, :finishInscription}
113
+
114
+ it { response.body.must_equal body }
115
+ it { response.http_code.must_equal '200' }
116
+ it { response.doc.to_xml.must_equal Nokogiri::XML(body).to_xml }
117
+ it { response.xml_result.to_xml.must_equal '<authCode>1213</authCode><creditCardType>Visa</creditCardType><last4CardDigits>6623</last4CardDigits><responseCode>0</responseCode><tbkUser>d2f27f36-b038-4937-8ea6-182b3de38cfd</tbkUser>'}
118
+ it { response.xml_error.must_be_empty }
119
+ it { response.errors_display.must_be_empty }
120
+ it { response.valid?.must_equal true }
121
+ it { response.response_code_display.must_equal 'aprobado' }
122
+ it { response.inspect.must_equal '#<Transbank::Oneclick::Response valid: true, auth_code: "1213", credit_card_type: "Visa", last4_card_digits: "6623", response_code: "0", tbk_user: "d2f27f36-b038-4937-8ea6-182b3de38cfd" >' }
123
+ it { response.exception?.must_equal false }
124
+ it { response.exception.must_be_nil }
125
+ it { response.attributes.size.must_equal 5 }
126
+ it { response.auth_code.must_equal '1213' }
127
+ it { response.credit_card_type.must_equal 'Visa' }
128
+ it { response.last4_card_digits.must_equal '6623' }
129
+ it { response.response_code.must_equal '0' }
130
+ it { response.tbk_user.must_equal 'd2f27f36-b038-4937-8ea6-182b3de38cfd' }
131
+ end
132
+
133
+ describe 'with token not valid' do
134
+ let(:body) { %q{<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><soap:Fault><faultcode>soap:Server</faultcode><faultstring>Can't finish user inscription</faultstring></soap:Fault></soap:Body></soap:Envelope>} }
135
+ let(:content) { mock_content(body, '500') }
136
+ let(:response) { Response.new content, :finishInscription}
137
+
138
+ it { response.body.must_equal body }
139
+ it { response.http_code.must_equal '500' }
140
+ it { response.doc.to_xml.must_equal Nokogiri::XML(body).to_xml }
141
+ it { response.xml_result.must_equal []}
142
+ it { response.xml_error.to_xml.must_equal '<faultstring>Can\'t finish user inscription</faultstring>'}
143
+ it { response.errors_display.must_equal 'Can\'t finish user inscription' }
144
+ it { response.valid?.must_equal false }
145
+ it { response.response_code_display.must_be_nil }
146
+ it { response.inspect.must_equal '#<Transbank::Oneclick::Response valid: false, error: "Can\'t finish user inscription" >' }
147
+ it { response.exception?.must_equal false }
148
+ it { response.exception.must_be_nil }
149
+ it { response.attributes.size.must_equal 0 }
150
+ end
151
+
152
+ describe 'with card unregistered' do
153
+ let(:body) { %q{<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Header><wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" soap:mustUnderstand="1"><ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#" Id="SIG-8356"><ds:SignedInfo><ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"><ec:InclusiveNamespaces xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#" PrefixList="soap"/></ds:CanonicalizationMethod><ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/><ds:Reference URI="#id-8355"><ds:Transforms><ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"><ec:InclusiveNamespaces xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#" PrefixList=""/></ds:Transform></ds:Transforms><ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/><ds:DigestValue>jnlzX73k8Sgqj8z3h8X92UFF/OQ=</ds:DigestValue></ds:Reference></ds:SignedInfo><ds:SignatureValue>U95EZ+m8b1Adg1wxpBuWkr1PqneEKbZ3vgaRioF2Fsnwa0thuf4ZvesbIKdhol2EoVxsa5aWAhf1\nGez3+z1kselbyQQHlnE6zo7O8QOE6t1z1dUDQZS13KmqHW8bW30xlRii809kmPfvszWnIkCjcCUg\nPUX3pK2pAmYuEIkJ1GXUtCob4h2a6m+YZkOTsK8hDyWKOY2LvosNIWnI209GCePZioA6e6FW4l83\nB2ZJzbXG7DxhQ45ePR98PwelF23U4GaaLLnHR+QdDOQG267+vm76cAETIbO+AMEzQOWNhFixSioJ\nCtg+hvszOrwwYlSsjEM2siY+yhZ92U1moh2peouvx59KB5VBKn+LTVv7xOZRnnhze+k4KP5I8ZV5\naJ8Xlkp8HqZbnEFlEukCODaQYscDWD9kGGZzEX33Ln1i4qI64c6VlGRHD6YAi9fgaNq+khAqUdcD\n+1HcNmDy2Jv0tP0ura6n8TqSHJ3agm9LaFr5b7K0u5WTsHWxk999HRkYz+ZhstnwNbTzrmE4/Mw/\nU10qdaonIGSkhWLqQigvD304a+SFqB4MBC/z3YsI0aNv4QrDnaZnJANyoJtiaq8lmcHD7ygZbT7L\n2us0rbudFbidqdj/yPS9TCkrD3XRxCMmhwjELzt3WJ0037SVNvdWKJ/QdgPgnDlTpuApDCLpK0U=</ds:SignatureValue><ds:KeyInfo Id="KI-F6DDC585AC5A582DD2142564333510612533"><wsse:SecurityTokenReference wsu:Id="STR-F6DDC585AC5A582DD2142564333510612534"><ds:X509Data><ds:X509IssuerSerial><ds:X509IssuerName>CN=10,OU=ExperTI,O=ExperTI,L=Santiago,ST=Santiago,C=CL,1.2.840.113549.1.9.1=#16116a636572646140657870657274692e636c</ds:X509IssuerName><ds:X509SerialNumber>1401281826</ds:X509SerialNumber></ds:X509IssuerSerial></ds:X509Data></wsse:SecurityTokenReference></ds:KeyInfo></ds:Signature></wsse:Security></soap:Header><soap:Body xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="id-8355"><ns2:finishInscriptionResponse xmlns:ns2="http://webservices.webpayserver.transbank.com/"><return><responseCode>-98</responseCode></return></ns2:finishInscriptionResponse></soap:Body></soap:Envelope>} }
154
+ let(:content) { mock_content(body, '500') }
155
+ let(:response) { Response.new content, :finishInscription}
156
+
157
+ it { response.body.must_equal body }
158
+ it { response.http_code.must_equal '500' }
159
+ it { response.doc.to_xml.must_equal Nokogiri::XML(body).to_xml }
160
+ it { response.xml_result.to_xml.must_equal '<responseCode>-98</responseCode>'}
161
+ it { response.xml_error.to_xml.must_be_empty }
162
+ it { response.errors_display.must_equal 'Error' }
163
+ it { response.valid?.must_equal false }
164
+ it { response.response_code_display.must_equal 'Error' }
165
+ it { response.inspect.must_equal '#<Transbank::Oneclick::Response valid: false, response_code: "-98", error: "Error" >' }
166
+ it { response.exception?.must_equal false }
167
+ it { response.exception.must_be_nil }
168
+ it { response.attributes.size.must_equal 1 }
169
+ it { response.response_code.must_equal '-98' }
170
+ end
171
+ end
172
+
173
+ describe 'Authorize' do
174
+ describe 'with response valid' do
175
+ let(:body) { %q{<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Header><wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" soap:mustUnderstand="1"><ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#" Id="SIG-8376"><ds:SignedInfo><ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"><ec:InclusiveNamespaces xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#" PrefixList="soap"/></ds:CanonicalizationMethod><ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/><ds:Reference URI="#id-8375"><ds:Transforms><ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"><ec:InclusiveNamespaces xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#" PrefixList=""/></ds:Transform></ds:Transforms><ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/><ds:DigestValue>IC08S2+O4xGJRy9RPz1u51eTpOs=</ds:DigestValue></ds:Reference></ds:SignedInfo><ds:SignatureValue>R9E7xvZEAWU4GPOksR6bws6dcEyLAeC1Rb0be511NGsSwXNbLdMsDMkEPT0CSGh4kT+sdG9JjGJJ\n8KnAWrqUYCBUwwniyxhHxcA1pfYrwE8lIdcd2dSHAWPeblrfuOWJqxl1gYJ1aVCMSrbzIyH+5WYl\nvQVUM5uJrMJaR88RydNNDAF4S8yp+4y1F3f5UhSP4KBOftDIPhixrQTEAcypZaTMQVf3+wqfQ1ME\nbsScaXmXitDZVkUSmSkLcif5IZex7b6tvDGeCtIxZtNZZRcPSifewztB/lD/0pp4A/ouVln7G67w\nd/PjXM4DPLKEN0AYv7ysKsOQ/kn9ress/mYSweSXJ3lTcfnD4zV1Fq4rBEU4aOu2PpOAU/Ye7E1M\nW14dIzJ8eRow9EFsb2tuPL9gixPSlAepV2zgSFNJ5vPlXJhsa3DhMph46sX7Ueqv+lZkAvz/EMSc\nGtw/N1m6Z64x+kVGyZuq3G52/NlmEx5WR/RmZmWYOF+O3pUWOjR82Wa1Gpb9YEbgHEMnNj+AcTZE\n2JemINg9FZNiwz+yMHxNAKUQsoRdB5DFPYi38YJqDyCwZAH/KPgHC+PgnrgeePUhAz5vvJo7a0qv\nU2CDdYWFx2OGdVsHRUbIOpdR7Wz3K4lQRxBP6AxA2fURV024Uw9hoihU1OtAUt9dQDnSgpURBpg=</ds:SignatureValue><ds:KeyInfo Id="KI-F6DDC585AC5A582DD2142566381917212563"><wsse:SecurityTokenReference wsu:Id="STR-F6DDC585AC5A582DD2142566381917212564"><ds:X509Data><ds:X509IssuerSerial><ds:X509IssuerName>CN=10,OU=ExperTI,O=ExperTI,L=Santiago,ST=Santiago,C=CL,1.2.840.113549.1.9.1=#16116a636572646140657870657274692e636c</ds:X509IssuerName><ds:X509SerialNumber>1401281826</ds:X509SerialNumber></ds:X509IssuerSerial></ds:X509Data></wsse:SecurityTokenReference></ds:KeyInfo></ds:Signature></wsse:Security></soap:Header><soap:Body xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="id-8375"><ns2:authorizeResponse xmlns:ns2="http://webservices.webpayserver.transbank.com/"><return><authorizationCode>1213</authorizationCode><creditCardType>Visa</creditCardType><last4CardDigits>6623</last4CardDigits><responseCode>0</responseCode><transactionId>71498</transactionId></return></ns2:authorizeResponse></soap:Body></soap:Envelope>} }
176
+ let(:content) { mock_content(body, '200') }
177
+ let(:response) { Response.new content, :authorize}
178
+
179
+ it { response.body.must_equal body }
180
+ it { response.http_code.must_equal '200' }
181
+ it { response.doc.to_xml.must_equal Nokogiri::XML(body).to_xml }
182
+ it { response.xml_result.to_xml.must_equal '<authorizationCode>1213</authorizationCode><creditCardType>Visa</creditCardType><last4CardDigits>6623</last4CardDigits><responseCode>0</responseCode><transactionId>71498</transactionId>'}
183
+ it { response.xml_error.must_be_empty }
184
+ it { response.errors_display.must_be_empty }
185
+ it { response.valid?.must_equal true }
186
+ it { response.response_code_display.must_equal 'aprobado' }
187
+ it { response.inspect.must_equal '#<Transbank::Oneclick::Response valid: true, authorization_code: "1213", credit_card_type: "Visa", last4_card_digits: "6623", response_code: "0", transaction_id: "71498" >' }
188
+ it { response.exception?.must_equal false }
189
+ it { response.exception.must_be_nil }
190
+ it { response.attributes.size.must_equal 5 }
191
+ it { response.authorization_code.must_equal '1213' }
192
+ it { response.credit_card_type.must_equal 'Visa' }
193
+ it { response.last4_card_digits.must_equal '6623' }
194
+ it { response.response_code.must_equal '0' }
195
+ it { response.transaction_id.must_equal '71498' }
196
+ end
197
+
198
+ describe 'with amount not valid' do
199
+ let(:body) { %q{<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><soap:Fault><faultcode>soap:Server</faultcode><faultstring>Invalid amount</faultstring></soap:Fault></soap:Body></soap:Envelope>} }
200
+ let(:content) { mock_content(body, '500') }
201
+ let(:response) { Response.new content, :authorize}
202
+
203
+ it { response.body.must_equal body }
204
+ it { response.http_code.must_equal '500' }
205
+ it { response.doc.to_xml.must_equal Nokogiri::XML(body).to_xml }
206
+ it { response.xml_result.must_equal [] }
207
+ it { response.xml_error.to_xml.must_equal '<faultstring>Invalid amount</faultstring>' }
208
+ it { response.errors_display.must_equal 'Invalid amount' }
209
+ it { response.valid?.must_equal false }
210
+ it { response.response_code_display.must_be_nil }
211
+ it { response.inspect.must_equal '#<Transbank::Oneclick::Response valid: false, error: "Invalid amount" >' }
212
+ it { response.exception?.must_equal false }
213
+ it { response.exception.must_be_nil }
214
+ it { response.attributes.size.must_equal 0 }
215
+ end
216
+
217
+ describe 'with tbkUser blank' do
218
+ let(:body) { %q{<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><soap:Fault><faultcode>soap:Server</faultcode><faultstring>Tbk User is required</faultstring></soap:Fault></soap:Body></soap:Envelope>} }
219
+ let(:content) { mock_content(body, '500') }
220
+ let(:response) { Response.new content, :authorize}
221
+
222
+ it { response.body.must_equal body }
223
+ it { response.http_code.must_equal '500' }
224
+ it { response.doc.to_xml.must_equal Nokogiri::XML(body).to_xml }
225
+ it { response.xml_result.must_equal [] }
226
+ it { response.xml_error.to_xml.must_equal '<faultstring>Tbk User is required</faultstring>' }
227
+ it { response.errors_display.must_equal 'Tbk User is required' }
228
+ it { response.valid?.must_equal false }
229
+ it { response.response_code_display.must_be_nil }
230
+ it { response.inspect.must_equal '#<Transbank::Oneclick::Response valid: false, error: "Tbk User is required" >' }
231
+ it { response.exception?.must_equal false }
232
+ it { response.exception.must_be_nil }
233
+ it { response.attributes.size.must_equal 0 }
234
+ end
235
+
236
+ describe 'when tbkUser is not valid' do
237
+ let(:body) { %q{<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><soap:Fault><faultcode>soap:Server</faultcode><faultstring>Authorization failed</faultstring></soap:Fault></soap:Body></soap:Envelope>} }
238
+ let(:content) { mock_content(body, '500') }
239
+ let(:response) { Response.new content, :authorize}
240
+
241
+ it { response.body.must_equal body }
242
+ it { response.http_code.must_equal '500' }
243
+ it { response.doc.to_xml.must_equal Nokogiri::XML(body).to_xml }
244
+ it { response.xml_result.must_equal [] }
245
+ it { response.xml_error.to_xml.must_equal '<faultstring>Authorization failed</faultstring>' }
246
+ it { response.errors_display.must_equal 'Authorization failed' }
247
+ it { response.valid?.must_equal false }
248
+ it { response.response_code_display.must_be_nil }
249
+ it { response.inspect.must_equal '#<Transbank::Oneclick::Response valid: false, error: "Authorization failed" >' }
250
+ it { response.exception?.must_equal false }
251
+ it { response.exception.must_be_nil }
252
+ it { response.attributes.size.must_equal 0 }
253
+ end
254
+
255
+ describe 'with username blank' do
256
+ let(:body) { %q{<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><soap:Fault><faultcode>soap:Client</faultcode><faultstring>Unmarshalling Error: For input string: "" </faultstring></soap:Fault></soap:Body></soap:Envelope>} }
257
+ let(:content) { mock_content(body, '500') }
258
+ let(:response) { Response.new content, :authorize}
259
+
260
+ it { response.body.must_equal body }
261
+ it { response.http_code.must_equal '500' }
262
+ it { response.doc.to_xml.must_equal Nokogiri::XML(body).to_xml }
263
+ it { response.xml_result.must_equal [] }
264
+ it { response.xml_error.to_xml.must_equal '<faultstring>Unmarshalling Error: For input string: "" </faultstring>' }
265
+ it { response.errors_display.must_equal 'Unmarshalling Error: For input string: "" ' }
266
+ it { response.valid?.must_equal false }
267
+ it { response.response_code_display.must_be_nil }
268
+ it { response.inspect.must_equal '#<Transbank::Oneclick::Response valid: false, error: "Unmarshalling Error: For input string: "" " >' }
269
+ it { response.exception?.must_equal false }
270
+ it { response.exception.must_be_nil }
271
+ it { response.attributes.size.must_equal 0 }
272
+ end
273
+
274
+ describe 'with maximum amount exceeded' do
275
+ let(:body) { %q{<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Header><wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" soap:mustUnderstand="1"><ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#" Id="SIG-8418"><ds:SignedInfo><ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"><ec:InclusiveNamespaces xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#" PrefixList="soap"/></ds:CanonicalizationMethod><ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/><ds:Reference URI="#id-8417"><ds:Transforms><ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"><ec:InclusiveNamespaces xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#" PrefixList=""/></ds:Transform></ds:Transforms><ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/><ds:DigestValue>OGBAVz4h7um3+DFrHvBzahVmsDE=</ds:DigestValue></ds:Reference></ds:SignedInfo><ds:SignatureValue>ZPg+X9p6U6cArwO93sZsU/c+FhKk0iiE6nLeS6gZZjsEvMDMpOjU6g5FJVUMVcXDJB2CkSBzOrEI\nD4awwE6vUWQ7jxlgchiME5HeQqok1wI9fMmNo3UfVt52/In6aCNrYeHlbYi+Zeod/05DUbTyznQS\nNax6v/WT2MUBs6usNe3aT3ryzY7WRuGdrP2lS3tmUQasfJBuZzCn7BqZULjWmi2+nlsmiVafIK0W\nOmNEV9XyUhsOKtrVEF7JGuJ9dJZP7cdYKVUOzFRnt/rdqHflghA4mr/WzEHVpVliA1MvgzJ0XvOw\nCRb4slH6EuSYNKmMZUoKDe3ShbcsBd0fz6RJwSoL5RN6mD+EA5KudbPimXD90WrqJCGbu1nIfXtr\n9DlmbEjobPApaRJ2e+m9of5KhoFNF76OXXumrrGgp8N/k/+jMyfX0abbLtzZfebvyWbeqO14XCzw\nyFO22RfVff9cpYS6vadUuu7dNe67QmbuZk8uTu+QNqSozO7wuDL336fNkMBafohKcSCzmZuXTqKp\nt4OJWYzINMKaypT06IWrGL83P3GBcqadKKo19IiZtiaQ9XJIhrZixYtHzDGV1cKKI7v+bBhZed+1\n2MR6e5ro6VdsMQCZ7C/BRT0sPd/0tinV4eJdNAquWT/a62c4HlCUAw/9iSbVzAhNV9QaCKGPX6Q=</ds:SignatureValue><ds:KeyInfo Id="KI-F6DDC585AC5A582DD2142573691238412626"><wsse:SecurityTokenReference wsu:Id="STR-F6DDC585AC5A582DD2142573691238412627"><ds:X509Data><ds:X509IssuerSerial><ds:X509IssuerName>CN=10,OU=ExperTI,O=ExperTI,L=Santiago,ST=Santiago,C=CL,1.2.840.113549.1.9.1=#16116a636572646140657870657274692e636c</ds:X509IssuerName><ds:X509SerialNumber>1401281826</ds:X509SerialNumber></ds:X509IssuerSerial></ds:X509Data></wsse:SecurityTokenReference></ds:KeyInfo></ds:Signature></wsse:Security></soap:Header><soap:Body xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="id-8417"><ns2:authorizeResponse xmlns:ns2="http://webservices.webpayserver.transbank.com/"><return><creditCardType>Visa</creditCardType><last4CardDigits>6623</last4CardDigits><responseCode>-98</responseCode><transactionId>71686</transactionId></return></ns2:authorizeResponse></soap:Body></soap:Envelope>} }
276
+ let(:content) { mock_content(body, '200') }
277
+ let(:response) { Response.new content, :authorize}
278
+
279
+ it { response.body.must_equal body }
280
+ it { response.http_code.must_equal '200' }
281
+ it { response.doc.to_xml.must_equal Nokogiri::XML(body).to_xml }
282
+ it { response.xml_result.to_xml.must_equal '<creditCardType>Visa</creditCardType><last4CardDigits>6623</last4CardDigits><responseCode>-98</responseCode><transactionId>71686</transactionId>' }
283
+ it { response.xml_error.to_xml.must_equal '' }
284
+ it { response.errors_display.must_equal 'limites Oneclick, máximo monto de pago excedido' }
285
+ it { response.valid?.must_equal false }
286
+ it { response.response_code_display.must_equal 'limites Oneclick, máximo monto de pago excedido' }
287
+ it { response.inspect.must_equal '#<Transbank::Oneclick::Response valid: false, credit_card_type: "Visa", last4_card_digits: "6623", response_code: "-98", transaction_id: "71686", error: "limites Oneclick, máximo monto de pago excedido" >' }
288
+ it { response.exception?.must_equal false }
289
+ it { response.exception.must_be_nil }
290
+ it { response.attributes.size.must_equal 4 }
291
+ it { response.credit_card_type.must_equal 'Visa' }
292
+ it { response.last4_card_digits.must_equal '6623' }
293
+ it { response.response_code.must_equal '-98' }
294
+ it { response.transaction_id.must_equal '71686' }
295
+ end
296
+
297
+ describe 'with maximum payments exceeded' do
298
+ let(:body) { %q{<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Header><wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" soap:mustUnderstand="1"><ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#" Id="SIG-8418"><ds:SignedInfo><ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"><ec:InclusiveNamespaces xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#" PrefixList="soap"/></ds:CanonicalizationMethod><ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/><ds:Reference URI="#id-8417"><ds:Transforms><ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"><ec:InclusiveNamespaces xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#" PrefixList=""/></ds:Transform></ds:Transforms><ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/><ds:DigestValue>OGBAVz4h7um3+DFrHvBzahVmsDE=</ds:DigestValue></ds:Reference></ds:SignedInfo><ds:SignatureValue>ZPg+X9p6U6cArwO93sZsU/c+FhKk0iiE6nLeS6gZZjsEvMDMpOjU6g5FJVUMVcXDJB2CkSBzOrEI\nD4awwE6vUWQ7jxlgchiME5HeQqok1wI9fMmNo3UfVt52/In6aCNrYeHlbYi+Zeod/05DUbTyznQS\nNax6v/WT2MUBs6usNe3aT3ryzY7WRuGdrP2lS3tmUQasfJBuZzCn7BqZULjWmi2+nlsmiVafIK0W\nOmNEV9XyUhsOKtrVEF7JGuJ9dJZP7cdYKVUOzFRnt/rdqHflghA4mr/WzEHVpVliA1MvgzJ0XvOw\nCRb4slH6EuSYNKmMZUoKDe3ShbcsBd0fz6RJwSoL5RN6mD+EA5KudbPimXD90WrqJCGbu1nIfXtr\n9DlmbEjobPApaRJ2e+m9of5KhoFNF76OXXumrrGgp8N/k/+jMyfX0abbLtzZfebvyWbeqO14XCzw\nyFO22RfVff9cpYS6vadUuu7dNe67QmbuZk8uTu+QNqSozO7wuDL336fNkMBafohKcSCzmZuXTqKp\nt4OJWYzINMKaypT06IWrGL83P3GBcqadKKo19IiZtiaQ9XJIhrZixYtHzDGV1cKKI7v+bBhZed+1\n2MR6e5ro6VdsMQCZ7C/BRT0sPd/0tinV4eJdNAquWT/a62c4HlCUAw/9iSbVzAhNV9QaCKGPX6Q=</ds:SignatureValue><ds:KeyInfo Id="KI-F6DDC585AC5A582DD2142573691238412626"><wsse:SecurityTokenReference wsu:Id="STR-F6DDC585AC5A582DD2142573691238412627"><ds:X509Data><ds:X509IssuerSerial><ds:X509IssuerName>CN=10,OU=ExperTI,O=ExperTI,L=Santiago,ST=Santiago,C=CL,1.2.840.113549.1.9.1=#16116a636572646140657870657274692e636c</ds:X509IssuerName><ds:X509SerialNumber>1401281826</ds:X509SerialNumber></ds:X509IssuerSerial></ds:X509Data></wsse:SecurityTokenReference></ds:KeyInfo></ds:Signature></wsse:Security></soap:Header><soap:Body xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="id-8417"><ns2:authorizeResponse xmlns:ns2="http://webservices.webpayserver.transbank.com/"><return><creditCardType>Visa</creditCardType><last4CardDigits>6623</last4CardDigits><responseCode>-97</responseCode><transactionId>71686</transactionId></return></ns2:authorizeResponse></soap:Body></soap:Envelope>} }
299
+ let(:content) { mock_content(body, '200') }
300
+ let(:response) { Response.new content, :authorize}
301
+
302
+ it { response.body.must_equal body }
303
+ it { response.http_code.must_equal '200' }
304
+ it { response.doc.to_xml.must_equal Nokogiri::XML(body).to_xml }
305
+ it { response.xml_result.to_xml.must_equal '<creditCardType>Visa</creditCardType><last4CardDigits>6623</last4CardDigits><responseCode>-97</responseCode><transactionId>71686</transactionId>' }
306
+ it { response.xml_error.to_xml.must_equal '' }
307
+ it { response.errors_display.must_equal 'limites Oneclick, máximo monto diario de pago excedido' }
308
+ it { response.valid?.must_equal false }
309
+ it { response.response_code_display.must_equal 'limites Oneclick, máximo monto diario de pago excedido' }
310
+ it { response.inspect.must_equal '#<Transbank::Oneclick::Response valid: false, credit_card_type: "Visa", last4_card_digits: "6623", response_code: "-97", transaction_id: "71686", error: "limites Oneclick, máximo monto diario de pago excedido" >' }
311
+ it { response.exception?.must_equal false }
312
+ it { response.exception.must_be_nil }
313
+ it { response.attributes.size.must_equal 4 }
314
+ it { response.credit_card_type.must_equal 'Visa' }
315
+ it { response.last4_card_digits.must_equal '6623' }
316
+ it { response.response_code.must_equal '-97' }
317
+ it { response.transaction_id.must_equal '71686' }
318
+ end
319
+
320
+ describe 'with maximum number of payments per day exceeded' do
321
+ let(:body) { %q{<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Header><wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" soap:mustUnderstand="1"><ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#" Id="SIG-8418"><ds:SignedInfo><ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"><ec:InclusiveNamespaces xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#" PrefixList="soap"/></ds:CanonicalizationMethod><ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/><ds:Reference URI="#id-8417"><ds:Transforms><ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"><ec:InclusiveNamespaces xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#" PrefixList=""/></ds:Transform></ds:Transforms><ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/><ds:DigestValue>OGBAVz4h7um3+DFrHvBzahVmsDE=</ds:DigestValue></ds:Reference></ds:SignedInfo><ds:SignatureValue>ZPg+X9p6U6cArwO93sZsU/c+FhKk0iiE6nLeS6gZZjsEvMDMpOjU6g5FJVUMVcXDJB2CkSBzOrEI\nD4awwE6vUWQ7jxlgchiME5HeQqok1wI9fMmNo3UfVt52/In6aCNrYeHlbYi+Zeod/05DUbTyznQS\nNax6v/WT2MUBs6usNe3aT3ryzY7WRuGdrP2lS3tmUQasfJBuZzCn7BqZULjWmi2+nlsmiVafIK0W\nOmNEV9XyUhsOKtrVEF7JGuJ9dJZP7cdYKVUOzFRnt/rdqHflghA4mr/WzEHVpVliA1MvgzJ0XvOw\nCRb4slH6EuSYNKmMZUoKDe3ShbcsBd0fz6RJwSoL5RN6mD+EA5KudbPimXD90WrqJCGbu1nIfXtr\n9DlmbEjobPApaRJ2e+m9of5KhoFNF76OXXumrrGgp8N/k/+jMyfX0abbLtzZfebvyWbeqO14XCzw\nyFO22RfVff9cpYS6vadUuu7dNe67QmbuZk8uTu+QNqSozO7wuDL336fNkMBafohKcSCzmZuXTqKp\nt4OJWYzINMKaypT06IWrGL83P3GBcqadKKo19IiZtiaQ9XJIhrZixYtHzDGV1cKKI7v+bBhZed+1\n2MR6e5ro6VdsMQCZ7C/BRT0sPd/0tinV4eJdNAquWT/a62c4HlCUAw/9iSbVzAhNV9QaCKGPX6Q=</ds:SignatureValue><ds:KeyInfo Id="KI-F6DDC585AC5A582DD2142573691238412626"><wsse:SecurityTokenReference wsu:Id="STR-F6DDC585AC5A582DD2142573691238412627"><ds:X509Data><ds:X509IssuerSerial><ds:X509IssuerName>CN=10,OU=ExperTI,O=ExperTI,L=Santiago,ST=Santiago,C=CL,1.2.840.113549.1.9.1=#16116a636572646140657870657274692e636c</ds:X509IssuerName><ds:X509SerialNumber>1401281826</ds:X509SerialNumber></ds:X509IssuerSerial></ds:X509Data></wsse:SecurityTokenReference></ds:KeyInfo></ds:Signature></wsse:Security></soap:Header><soap:Body xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="id-8417"><ns2:authorizeResponse xmlns:ns2="http://webservices.webpayserver.transbank.com/"><return><creditCardType>Visa</creditCardType><last4CardDigits>6623</last4CardDigits><responseCode>-99</responseCode><transactionId>71686</transactionId></return></ns2:authorizeResponse></soap:Body></soap:Envelope>} }
322
+ let(:content) { mock_content(body, '200') }
323
+ let(:response) { Response.new content, :authorize}
324
+
325
+ it { response.body.must_equal body }
326
+ it { response.http_code.must_equal '200' }
327
+ it { response.doc.to_xml.must_equal Nokogiri::XML(body).to_xml }
328
+ it { response.xml_result.to_xml.must_equal '<creditCardType>Visa</creditCardType><last4CardDigits>6623</last4CardDigits><responseCode>-99</responseCode><transactionId>71686</transactionId>' }
329
+ it { response.xml_error.to_xml.must_equal '' }
330
+ it { response.errors_display.must_equal 'limites Oneclick, máxima cantidad de pagos diarios excedido' }
331
+ it { response.valid?.must_equal false }
332
+ it { response.response_code_display.must_equal 'limites Oneclick, máxima cantidad de pagos diarios excedido' }
333
+ it { response.inspect.must_equal '#<Transbank::Oneclick::Response valid: false, credit_card_type: "Visa", last4_card_digits: "6623", response_code: "-99", transaction_id: "71686", error: "limites Oneclick, máxima cantidad de pagos diarios excedido" >' }
334
+ it { response.exception?.must_equal false }
335
+ it { response.exception.must_be_nil }
336
+ it { response.attributes.size.must_equal 4 }
337
+ it { response.credit_card_type.must_equal 'Visa' }
338
+ it { response.last4_card_digits.must_equal '6623' }
339
+ it { response.response_code.must_equal '-99' }
340
+ it { response.transaction_id.must_equal '71686' }
341
+ end
342
+ end
343
+
344
+ describe 'Reverse' do
345
+ describe 'with response ok' do
346
+ let(:body) { %q{<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Header><wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" soap:mustUnderstand="1"><ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#" Id="SIG-8432"><ds:SignedInfo><ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"><ec:InclusiveNamespaces xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#" PrefixList="soap"/></ds:CanonicalizationMethod><ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/><ds:Reference URI="#id-8431"><ds:Transforms><ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"><ec:InclusiveNamespaces xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#" PrefixList=""/></ds:Transform></ds:Transforms><ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/><ds:DigestValue>d5eiiC8lU9K+RwEa1fYFuCK2uOI=</ds:DigestValue></ds:Reference></ds:SignedInfo><ds:SignatureValue>R075K3Tm1onQwi7Oxcw+Ha/31BQ0r4of5cNqOg6e/D3539aDw9m7LEFaMZoqtZ+G8aNlf/Nm1l12\ntG7bglfVO+/HrP6MxfC/VVLLFUO4EK7MCvAWa0qO4YaGXAE76rzN6ouO3W3e7mDXfeb3ChVSEobT\nX1LEOlB7ICW3YZXOYhnqyCxjoIkX8PdxDTEc4f3k9PjNaaXuVCzHg4X0KkPFOnRT1wXLLmgJoSOP\nnPjzVch2b+Z3QHYMIgd2d4intjz2XfwVj7SdjhCixpUa0foJR83NMykbSLFgxkJqYeYhhDLl8hvJ\nBd5vt2/Wx6R60Ctxgk3+NyKiuWXyYqMv5E4wzuXh+WSYQKccApE+6S4+E9V/zVO21F6cClhCEHxZ\nTH9ZikfBKUm5KSh9B7FqbH7DbnF4BhJDNEZXOvgBKvQNwt9hhsa07e/Kk9ZF+8vW5LpNTzf1sBJO\ndpiEZW+cKCOM8/xTscobqoIg3eRZOKdHe/gWoyyvc7PHHKQcc7bjRIUR53Pc0VYAXSB2MrV8GxL7\n13OxX4m/MrNX/M/6982n/QDW/X1EDHOrvKyknIjZ4IVkqpAm5QRZvlmmeWCL1zDiaIZkW4achjkZ\n1KVfhIwypN3MAgDa5a1JJxs00fKuDRTHs9BFrNxIm6UrR+isy+MD4j473hJUnvNT7xqZv0Ljvfg=</ds:SignatureValue><ds:KeyInfo Id="KI-F6DDC585AC5A582DD2142573852294212647"><wsse:SecurityTokenReference wsu:Id="STR-F6DDC585AC5A582DD2142573852294212648"><ds:X509Data><ds:X509IssuerSerial><ds:X509IssuerName>CN=10,OU=ExperTI,O=ExperTI,L=Santiago,ST=Santiago,C=CL,1.2.840.113549.1.9.1=#16116a636572646140657870657274692e636c</ds:X509IssuerName><ds:X509SerialNumber>1401281826</ds:X509SerialNumber></ds:X509IssuerSerial></ds:X509Data></wsse:SecurityTokenReference></ds:KeyInfo></ds:Signature></wsse:Security></soap:Header><soap:Body xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="id-8431"><ns2:codeReverseOneClickResponse xmlns:ns2="http://webservices.webpayserver.transbank.com/"><return><reverseCode>3619160862457231902</reverseCode><reversed>true</reversed></return></ns2:codeReverseOneClickResponse></soap:Body></soap:Envelope>} }
347
+ let(:content) { mock_content(body, '200') }
348
+ let(:response) { Response.new content, :codeReverseOneClick}
349
+
350
+ it { response.body.must_equal body }
351
+ it { response.http_code.must_equal '200' }
352
+ it { response.doc.to_xml.must_equal Nokogiri::XML(body).to_xml }
353
+ it { response.xml_result.to_xml.must_equal '<reverseCode>3619160862457231902</reverseCode><reversed>true</reversed>'}
354
+ it { response.xml_error.must_be_empty }
355
+ it { response.errors_display.must_be_empty }
356
+ it { response.valid?.must_equal true }
357
+ it { response.response_code_display.must_be_nil }
358
+ it { response.inspect.must_equal '#<Transbank::Oneclick::Response valid: true, reverse_code: "3619160862457231902", reversed: "true" >' }
359
+ it { response.exception?.must_equal false }
360
+ it { response.exception.must_be_nil }
361
+ it { response.attributes.size.must_equal 2 }
362
+ it { response.reverse_code.must_equal '3619160862457231902'}
363
+ it { response.reversed.must_equal 'true' }
364
+ end
365
+
366
+ describe 'with buyorder blank' do
367
+ let(:body) { %q{<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><soap:Fault><faultcode>soap:Client</faultcode><faultstring>Unmarshalling Error: For input string: "" </faultstring></soap:Fault></soap:Body></soap:Envelope>} }
368
+ let(:content) { mock_content(body, '500') }
369
+ let(:response) { Response.new content, :codeReverseOneClick}
370
+
371
+ it { response.body.must_equal body }
372
+ it { response.http_code.must_equal '500' }
373
+ it { response.doc.to_xml.must_equal Nokogiri::XML(body).to_xml }
374
+ it { response.xml_result.must_equal [] }
375
+ it { response.xml_error.to_xml.must_equal '<faultstring>Unmarshalling Error: For input string: "" </faultstring>' }
376
+ it { response.errors_display.must_equal 'Unmarshalling Error: For input string: "" ' }
377
+ it { response.valid?.must_equal false }
378
+ it { response.response_code_display.must_be_nil }
379
+ it { response.inspect.must_equal '#<Transbank::Oneclick::Response valid: false, error: "Unmarshalling Error: For input string: "" " >' }
380
+ it { response.exception?.must_equal false }
381
+ it { response.exception.must_be_nil }
382
+ it { response.attributes.size.must_equal 0 }
383
+ end
384
+
385
+ describe 'with buyorder blank' do
386
+ let(:body) { %q{<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Header><wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" soap:mustUnderstand="1"><ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#" Id="SIG-8434"><ds:SignedInfo><ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"><ec:InclusiveNamespaces xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#" PrefixList="soap"/></ds:CanonicalizationMethod><ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/><ds:Reference URI="#id-8433"><ds:Transforms><ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"><ec:InclusiveNamespaces xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#" PrefixList=""/></ds:Transform></ds:Transforms><ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/><ds:DigestValue>/j2dFcNHzkq8gRjQkeA3DznM0h4=</ds:DigestValue></ds:Reference></ds:SignedInfo><ds:SignatureValue>fJa28EFXMD+IS5FOVnPFFKEpJSqXAh8sG5A6prDMFg7RmffO3Seg0kGbnsCl1MaCw5lXoHa0DLHo\nNoX6BIgxNU/7jK+O9Z91VB7jKV4gO2fJKJN/dp30xxhctpFCmO+YYGuAwvsI0qwKUEWrVs6ZApnY\nuLAgyZO0xCp9DselwxkNanyIG7rekmpjYEs3nLFifyGH0w5DBNRPPgDtrBbYS6IIqqCmHuoBcel0\nCqsGFPJeC7Wtu3rZlZ2r9GWaVm6T2Dykg+Glnpr9sviHAwcPCkb2qpM5MiTnx3v39Mh7403j3U9k\nYJ9Lr26RV3zbPx5l+KBh4703sQ3kQzf1hwxP5IKvXsvkd9XLNBDthMJS1ghD/OPt+NcT8pgnCyV0\nJNOo0LpZt4ehHjVtfa68gIg+2T7sQ2+bpsBPgzAOSl6+n6VO2NPHEAGb/A9YOzQwizdCsrHrrPPW\nSJ39Pa9M2Ia7vj+K5xm1UnWpnNj3N5Ax6JrDkGchGsqp70TmSzjlsNFYuvHJd8akWK3KGolyISzW\nsqqJNo2oqb616s6hW4JbacxUS4zQ127jHikCqzqxI3zxgf1Qi5giF8FRIwPf5wbH9lDWke8+QOZI\nHdKW5EDx+mrN7Umf9brxnBGGNS3qhyl5P5HMRYPHBHc821iW0qkQ/E0KAHdLaEcb+Bj8Yt66lgg=</ds:SignatureValue><ds:KeyInfo Id="KI-F6DDC585AC5A582DD2142573918866412650"><wsse:SecurityTokenReference wsu:Id="STR-F6DDC585AC5A582DD2142573918866412651"><ds:X509Data><ds:X509IssuerSerial><ds:X509IssuerName>CN=10,OU=ExperTI,O=ExperTI,L=Santiago,ST=Santiago,C=CL,1.2.840.113549.1.9.1=#16116a636572646140657870657274692e636c</ds:X509IssuerName><ds:X509SerialNumber>1401281826</ds:X509SerialNumber></ds:X509IssuerSerial></ds:X509Data></wsse:SecurityTokenReference></ds:KeyInfo></ds:Signature></wsse:Security></soap:Header><soap:Body xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="id-8433"><ns2:codeReverseOneClickResponse xmlns:ns2="http://webservices.webpayserver.transbank.com/"><return><reversed>false</reversed></return></ns2:codeReverseOneClickResponse></soap:Body></soap:Envelope>} }
387
+ let(:content) { mock_content(body, '500') }
388
+ let(:response) { Response.new content, :codeReverseOneClick}
389
+
390
+ it { response.body.must_equal body }
391
+ it { response.http_code.must_equal '500' }
392
+ it { response.doc.to_xml.must_equal Nokogiri::XML(body).to_xml }
393
+ it { response.xml_result.to_xml.must_equal '<reversed>false</reversed>' }
394
+ it { response.xml_error.to_xml.must_equal '' }
395
+ it { response.errors_display.must_equal 'imposible revertir la compra' }
396
+ it { response.valid?.must_equal false }
397
+ it { response.response_code_display.must_be_nil }
398
+ it { response.inspect.must_equal '#<Transbank::Oneclick::Response valid: false, reversed: "false", error: "imposible revertir la compra" >' }
399
+ it { response.exception?.must_equal false }
400
+ it { response.exception.must_be_nil }
401
+ it { response.attributes.size.must_equal 1 }
402
+ it { response.reversed.must_equal 'false' }
403
+ end
404
+ end
405
+
406
+ describe 'Remove user' do
407
+ describe 'with ok response' do
408
+ let(:body) { %q{<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Header><wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" soap:mustUnderstand="1"><ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#" Id="SIG-8436"><ds:SignedInfo><ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"><ec:InclusiveNamespaces xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#" PrefixList="soap"/></ds:CanonicalizationMethod><ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/><ds:Reference URI="#id-8435"><ds:Transforms><ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"><ec:InclusiveNamespaces xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#" PrefixList=""/></ds:Transform></ds:Transforms><ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/><ds:DigestValue>BtK1c6IQQt90kV7NJUMfdDFWdjU=</ds:DigestValue></ds:Reference></ds:SignedInfo><ds:SignatureValue>VEH0ndx62nnFZYDmXfF9vnAksQbIn/epOBQhomEOfLOrTv0Zzi7q71uCQbUYUyF49z2MM56vzdI8\n2LVqSUY/ahsBgc/9L1+yK6TjuqxR/2nVRIil9QbyPjquCWYxnQbu4Pw442xf2savBgGQFyS+0NLJ\nqeKPaztSysUgJ2TKXFOeS7H3DgHIggz1har94US8WTFSgCOzfBeVhX+wNxZNgGUj4y/UO/4kuR1y\nAd/om6FX8EAre3EsawCOrVqLNSCG8kOW57ujcQQlgXKL0hI71C7HT62ysph5+hKmwAiyMAWaERr4\nsYxVI3tc3A/92NyWy6cg52xVSjJARLfLiqV/Dc1EoJqMFu6KLri3PdR9muIIUNp2heUVInaW6Xh6\n/7TnZSIXqwF0v0eMckTLU2amr9iRR4ipYHk/AmmInYMGtULXgNlHhRhk0UgvHqn0rsjVueDfHLtb\na+kNNExBqI1gazz0EV3NvhOBeFsu04YvyR2y4PTZokWLk3zfsmxTVbN9QIBGfKoK+E6ty4RlWOTH\nIIUzhDsP3yrjgC4UH2Zs7Kl/HYMXPkfZ0LoMNmJW2C5+BIYs8WDxXkpLkbtaEcfDpXfXTSsIyH3Y\nCQ2PguHy8NOcnETXlLieALLMVXvCmq3O0DoE6SWHq9URwqFnataMbHZhLOecDp3XmwMex7uNLac=</ds:SignatureValue><ds:KeyInfo Id="KI-F6DDC585AC5A582DD2142573978894412653"><wsse:SecurityTokenReference wsu:Id="STR-F6DDC585AC5A582DD2142573978894412654"><ds:X509Data><ds:X509IssuerSerial><ds:X509IssuerName>CN=10,OU=ExperTI,O=ExperTI,L=Santiago,ST=Santiago,C=CL,1.2.840.113549.1.9.1=#16116a636572646140657870657274692e636c</ds:X509IssuerName><ds:X509SerialNumber>1401281826</ds:X509SerialNumber></ds:X509IssuerSerial></ds:X509Data></wsse:SecurityTokenReference></ds:KeyInfo></ds:Signature></wsse:Security></soap:Header><soap:Body xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="id-8435"><ns2:removeUserResponse xmlns:ns2="http://webservices.webpayserver.transbank.com/"><return>true</return></ns2:removeUserResponse></soap:Body></soap:Envelope>} }
409
+ let(:content) { mock_content(body, '200') }
410
+ let(:response) { Response.new content, :removeUser}
411
+
412
+ it { response.body.must_equal body }
413
+ it { response.http_code.must_equal '200' }
414
+ it { response.doc.to_xml.must_equal Nokogiri::XML(body).to_xml }
415
+ it { response.xml_result.to_xml.must_equal 'true'}
416
+ it { response.xml_error.must_be_empty }
417
+ it { response.errors_display.must_be_empty }
418
+ it { response.valid?.must_equal true }
419
+ it { response.response_code_display.must_be_nil }
420
+ it { response.inspect.must_equal '#<Transbank::Oneclick::Response valid: true, text: "true" >' }
421
+ it { response.exception?.must_equal false }
422
+ it { response.exception.must_be_nil }
423
+ it { response.attributes.size.must_equal 1 }
424
+ it { response.text.must_equal 'true' }
425
+ end
426
+
427
+ describe 'with tbkUser blank ' do
428
+ let(:body) { %q{<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><soap:Fault><faultcode>soap:Server</faultcode><faultstring>Tbk User is required</faultstring></soap:Fault></soap:Body></soap:Envelope>} }
429
+ let(:content) { mock_content(body, '500') }
430
+ let(:response) { Response.new content, :removeUser}
431
+
432
+ it { response.body.must_equal body }
433
+ it { response.http_code.must_equal '500' }
434
+ it { response.doc.to_xml.must_equal Nokogiri::XML(body).to_xml }
435
+ it { response.xml_result.must_equal [] }
436
+ it { response.xml_error.to_xml.must_equal '<faultstring>Tbk User is required</faultstring>'}
437
+ it { response.errors_display.must_equal 'Tbk User is required' }
438
+ it { response.valid?.must_equal false }
439
+ it { response.response_code_display.must_be_nil }
440
+ it { response.inspect.must_equal '#<Transbank::Oneclick::Response valid: false, error: "Tbk User is required" >' }
441
+ it { response.exception?.must_equal false }
442
+ it { response.exception.must_be_nil }
443
+ it { response.attributes.size.must_equal 0 }
444
+ end
445
+
446
+ describe 'with username blank' do
447
+ let(:body) { %q{<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><soap:Fault><faultcode>soap:Server</faultcode><faultstring>Username is required</faultstring></soap:Fault></soap:Body></soap:Envelope>} }
448
+ let(:content) { mock_content(body, '500') }
449
+ let(:response) { Response.new content, :removeUser}
450
+
451
+ it { response.body.must_equal body }
452
+ it { response.http_code.must_equal '500' }
453
+ it { response.doc.to_xml.must_equal Nokogiri::XML(body).to_xml }
454
+ it { response.xml_result.must_equal [] }
455
+ it { response.xml_error.to_xml.must_equal '<faultstring>Username is required</faultstring>'}
456
+ it { response.errors_display.must_equal 'Username is required' }
457
+ it { response.valid?.must_equal false }
458
+ it { response.response_code_display.must_be_nil }
459
+ it { response.inspect.must_equal '#<Transbank::Oneclick::Response valid: false, error: "Username is required" >' }
460
+ it { response.exception?.must_equal false }
461
+ it { response.exception.must_be_nil }
462
+ it { response.attributes.size.must_equal 0 }
463
+ end
464
+ end
465
+
466
+ def mock_content(body, code)
467
+ mock do |m|
468
+ stubs(:body).returns(body)
469
+ stubs(:code).returns(code)
470
+ end
471
+ end
472
+ end
473
+ end
474
+ end
@@ -19,8 +19,12 @@ Gem::Specification.new do |spec|
19
19
 
20
20
  spec.required_ruby_version = '>= 1.9'
21
21
 
22
- spec.add_development_dependency "bundler", "~> 1.7"
23
- spec.add_development_dependency "rake", "~> 10.0"
22
+ spec.add_development_dependency 'bundler', '~> 1.7'
23
+ spec.add_development_dependency 'rake', '~> 10.0'
24
+ spec.add_development_dependency 'minitest', '>= 4.0'
25
+ spec.add_development_dependency 'mocha', '>= 1.1.0'
26
+ spec.add_development_dependency 'webmock', '>= 1.20'
24
27
 
25
- spec.add_dependency "nokogiri", ">= 1.4.0"
28
+
29
+ spec.add_dependency 'nokogiri', '>= 1.4.0'
26
30
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: transbank-oneclick
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ramón Soto
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-29 00:00:00.000000000 Z
11
+ date: 2015-03-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,6 +38,48 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '4.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '4.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: mocha
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 1.1.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 1.1.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '1.20'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '1.20'
41
83
  - !ruby/object:Gem::Dependency
42
84
  name: nokogiri
43
85
  requirement: !ruby/object:Gem::Requirement
@@ -76,6 +118,16 @@ files:
76
118
  - lib/transbank/oneclick/request.rb
77
119
  - lib/transbank/oneclick/response.rb
78
120
  - lib/transbank/oneclick/version.rb
121
+ - spec/generators/transbank_oneclick_generator_spec.rb
122
+ - spec/keys/597029124456.crt
123
+ - spec/keys/597029124456.key
124
+ - spec/spec_helper.rb
125
+ - spec/transbank/oneclick/api_spec.rb
126
+ - spec/transbank/oneclick/client_spec.rb
127
+ - spec/transbank/oneclick/document_spec.rb
128
+ - spec/transbank/oneclick/exception_response_spec.rb
129
+ - spec/transbank/oneclick/request_spec.rb
130
+ - spec/transbank/oneclick/response_spec.rb
79
131
  - transbank-oneclick.gemspec
80
132
  homepage: ''
81
133
  licenses:
@@ -101,4 +153,14 @@ rubygems_version: 2.4.3
101
153
  signing_key:
102
154
  specification_version: 4
103
155
  summary: transbank oneclick.
104
- test_files: []
156
+ test_files:
157
+ - spec/generators/transbank_oneclick_generator_spec.rb
158
+ - spec/keys/597029124456.crt
159
+ - spec/keys/597029124456.key
160
+ - spec/spec_helper.rb
161
+ - spec/transbank/oneclick/api_spec.rb
162
+ - spec/transbank/oneclick/client_spec.rb
163
+ - spec/transbank/oneclick/document_spec.rb
164
+ - spec/transbank/oneclick/exception_response_spec.rb
165
+ - spec/transbank/oneclick/request_spec.rb
166
+ - spec/transbank/oneclick/response_spec.rb