diff --git a/coverage/.resultset.json b/coverage/.resultset.json
index 3909332..79debcb 100644
--- a/coverage/.resultset.json
+++ b/coverage/.resultset.json
@@ -11,6 +11,7 @@
1,
1,
1,
+ 1,
null,
1,
1,
@@ -28,6 +29,7 @@
null,
null,
1,
+ 1,
null,
1,
null,
@@ -175,23 +177,23 @@
1,
null,
1,
- 71,
- 71,
- 71,
- 70,
- null,
- 68,
- 68,
- 68,
+ 69,
+ 69,
+ 69,
68,
null,
+ 66,
+ 66,
+ 66,
+ 66,
+ null,
null,
1,
89,
null,
null,
1,
- 23,
+ 21,
null,
null,
1,
@@ -622,9 +624,6 @@
1,
1,
4,
- 4,
- 4,
- null,
null,
4,
null,
@@ -635,20 +634,8 @@
null,
null,
null,
- null,
- null,
- null,
- null,
- null,
4,
null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
4,
null,
4,
@@ -663,20 +650,8 @@
null,
null,
1,
- null,
3,
null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
3,
null,
null,
@@ -825,11 +800,11 @@
null,
null,
1,
- 4,
+ 2,
null,
- 4,
+ 2,
null,
- 4,
+ 2,
null,
null,
null,
@@ -2653,296 +2628,14 @@
1,
null,
1,
- 3,
- 3,
- null,
- 1,
- 1,
- 1,
- null,
- null,
- null,
- null,
- 1,
- null,
- 1,
- null,
- 1,
- 1,
- 1,
- 1,
- null,
- null,
- 1,
1,
- null,
- null,
- null,
- null,
- 1,
- null,
- 1,
- null,
1,
null,
- null,
- null,
1,
- 0,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- 0,
- null,
- null,
- 0,
- 0,
- null,
- null,
- 0,
- null,
- 0,
- null,
- 0,
- 0,
- null,
- null,
- 0,
- 0,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- 0,
- null,
- null,
- 0,
- 0,
- null,
- null,
- 0,
- 0,
- 0,
- null,
- 0,
- 0,
- null,
- 0,
- null,
- null,
- 0,
- 0,
- null,
- null,
- null,
- 0,
- null,
- null,
- null,
- 0,
- 0,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- 0,
- null,
- null,
- 0,
- 0,
- null,
- null,
- 0,
- 0,
- null,
- 0,
- null,
- 0,
- 0,
- null,
- 0,
- null,
- null,
- 0,
- 0,
- null,
- null,
- null,
- 0,
- null,
- null,
- null,
null,
1,
- 0,
- null,
- 0,
- 0,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- 0,
- 0,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- 0,
- 0,
- null,
- null,
- null,
- 0,
- 0,
- null,
- null,
- null,
- 0,
- 0,
- null,
- 0,
- null,
- null,
- 0,
- 0,
- null,
- null,
- null,
- 0,
- 0,
- null,
- 0,
- null,
- null,
- 0,
- 0,
- null,
- null,
- null,
- null,
- null,
- null,
- 0,
- null,
- null,
- null,
null,
1,
- 0,
- 0,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- 0,
- null,
- 0,
- 0,
- 0,
- null,
- 0,
- 0,
- 0,
- null,
- 0,
- null,
- null,
- 0,
- 0,
- null,
- null,
- null,
- 0,
- 0,
- 0,
- 0,
- null,
- null,
- 0,
- 0,
- null,
- null,
- 0,
- 0,
- 0,
- null,
- null,
- 0,
- 0,
- 0,
- null,
- null,
- 0,
- 0,
- 0,
- null,
- null,
- 0,
- 0,
- 0,
- null,
- null,
- 0,
- 0,
- 0,
- null,
- null,
- 0,
- 0,
- 0,
- null,
- null,
- 0,
- 0,
- 0,
- null,
- null,
- 0,
- 0,
- 0,
- null,
- null,
- 0,
- 0,
- 0,
- null,
- null,
- 0,
- 0,
- 0,
- null,
- null,
- null,
null,
null,
1,
@@ -3034,6 +2727,6 @@
null
]
},
- "timestamp": 1352840553
+ "timestamp": 1352924674
}
}
diff --git a/coverage/index.html b/coverage/index.html
index dfc2d4e..b0c8999 100644
--- a/coverage/index.html
+++ b/coverage/index.html
@@ -23,27 +23,27 @@
-
Generated
2012-11-13T19:02:33-02:00
+
Generated
2012-11-14T18:24:34-02:00
All Files
- (91.49%
+ (99.18%
covered at
- 4.34
+ 4.39
hits/line)
22 files in total.
- 1340 relevant lines.
- 1226 lines covered and
- 114 lines missed
+ 1222 relevant lines.
+ 1212 lines covered and
+ 10 lines missed
@@ -62,9 +62,9 @@
lib/cbraspag.rb |
100.0 % |
- 92 |
- 24 |
- 24 |
+ 94 |
+ 26 |
+ 26 |
0 |
1.0 |
@@ -76,7 +76,7 @@
52 |
52 |
0 |
- 17.2 |
+ 16.8 |
@@ -132,9 +132,9 @@
lib/cbraspag/crypto/webservice.rb |
100.0 % |
- 92 |
- 31 |
- 31 |
+ 65 |
+ 29 |
+ 29 |
0 |
2.8 |
@@ -156,7 +156,7 @@
73 |
73 |
0 |
- 9.4 |
+ 9.3 |
@@ -271,12 +271,12 @@
spec/payment/recurrency_credit_card_spec.rb |
- 42.86 % |
- 382 |
- 182 |
- 78 |
- 104 |
- 1.0 |
+ 100.0 % |
+ 100 |
+ 64 |
+ 64 |
+ 0 |
+ 2.6 |
@@ -292,7 +292,7 @@
covered at
- 11.46
+ 11.38
hits/line)
@@ -324,7 +324,7 @@
52 |
52 |
0 |
- 17.2 |
+ 16.8 |
@@ -386,8 +386,8 @@
2 files in total.
- 34 relevant lines.
- 34 lines covered and
+ 32 relevant lines.
+ 32 lines covered and
0 lines missed
@@ -417,9 +417,9 @@
lib/cbraspag/crypto/webservice.rb |
100.0 % |
- 92 |
- 31 |
- 31 |
+ 65 |
+ 29 |
+ 29 |
0 |
2.8 |
@@ -436,7 +436,7 @@
covered at
- 4.5
+ 4.47
hits/line)
@@ -478,7 +478,7 @@
73 |
73 |
0 |
- 9.4 |
+ 9.3 |
@@ -536,20 +536,20 @@
Spec
- (87.46%
+ (98.85%
covered at
- 1.81
+ 1.95
hits/line)
11 files in total.
- 901 relevant lines.
- 788 lines covered and
- 113 lines missed
+ 783 relevant lines.
+ 774 lines covered and
+ 9 lines missed
@@ -667,12 +667,12 @@
spec/payment/recurrency_credit_card_spec.rb |
- 42.86 % |
- 382 |
- 182 |
- 78 |
- 104 |
- 1.0 |
+ 100.0 % |
+ 100 |
+ 64 |
+ 64 |
+ 0 |
+ 2.6 |
@@ -694,8 +694,8 @@
1 files in total.
- 24 relevant lines.
- 24 lines covered and
+ 26 relevant lines.
+ 26 lines covered and
0 lines missed
@@ -715,9 +715,9 @@
lib/cbraspag.rb |
100.0 % |
- 92 |
- 24 |
- 24 |
+ 94 |
+ 26 |
+ 26 |
0 |
1.0 |
@@ -742,8 +742,8 @@
lib/cbraspag.rb
100.0 % covered
- 24 relevant lines.
- 24 lines covered and
+ 26 relevant lines.
+ 26 lines covered and
0 lines missed.
@@ -805,499 +805,511 @@ 100.0 % covered
require 'active_merchant'
-
+
+ 1
+
+ require 'erb'
+
+
+
-
+
1
require "cbraspag/version"
-
+
1
require 'cbraspag/core/converter'
-
+
1
require 'cbraspag/core/connection'
-
+
1
require 'cbraspag/core/poster'
-
+
1
require 'cbraspag/core/customer'
-
+
1
require 'cbraspag/core/order'
-
+
-
+
1
require 'cbraspag/crypto/no_crypto'
-
+
1
require 'cbraspag/crypto/webservice'
-
+
-
+
1
require 'cbraspag/payment/billet'
-
+
1
require 'cbraspag/payment/credit_card'
-
+
1
require 'cbraspag/payment/eft'
-
+
-
+
-
+
1
module Braspag
-
+
+ 1
+
+ PATH = File.dirname(__FILE__)
+
+
+
-
+
1
INTEREST = {
-
+
:no => 0,
-
+
:merchant => 1,
-
+
:customer => 2,
-
+
:merchant_iata => 3,
-
+
:customer_iata => 4,
-
+
:no_iata => 5
-
+
}
-
+
-
+
1
STATUS_PAYMENT = {
-
+
:starting => 1,
-
+
:close => 2,
-
+
:paid => 3,
-
+
:cancelled => 4
-
+
}
-
+
-
+
1
PAYMENT_METHOD = {
-
+
#BILLET
-
+
:billet_bradesco => 6, #Boleto Bradesco
-
+
:billet_cef => 7, #Boleto Caixa Economica Federal
-
+
:billet_hsbc => 8, #Boleto HSBC
-
+
:billet_banco_do_brasil => 9, #Boleto Banco do Brasil
-
+
:billet_santader => 10, #Boleto Banco Santader
-
+
:billet_citibank => 13, #Boleto Citibank
-
+
:billet_itau => 14, #Boleto Itau
-
+
:billet_unibanco => 26, #Boleto Unibanco
-
+
#EFT
-
+
:eft_bradesco => 11, #EFT Bradesco
-
+
:eft_itau => 12, #EFT Itau Shopline
-
+
:eft_banco_do_brasil => 15, #EFT Banco do Brasil
-
+
:eft_banco_real => 16, #EFT Banco Real
-
+
:eft_banrisul => 30, #EFT Banrisul
-
+
:eft_unibanco => 31, #EFT Unibanco
-
+
#CARDS - BRASIL
-
+
:amex_2p => 18, # American Express 2 Party
-
+
:cielo_noauth_visa => 71, # Cielo webservice captura automática sem autenticação - Visa
-
+
:cielo_preauth_visa => 73, # Cielo webservice preauth sem autenticação - Visa
-
+
:cielo_noauth_mastercard => 120, # Cielo webservice captura automática sem autenticação - Mastercard
-
+
:cielo_preauth_mastercard => 122, # Cielo webservice preauth sem autenticação - Mastercard
-
+
:cielo_noauth_elo => 126, # Cielo webservice captura automática sem autenticação - ELO
-
+
:cielo_noauth_diners => 130, # Cielo webservice captura automática sem autenticação - Diners
-
+
:redecard => 20, # Redecard Mastercard/Diners/Visa
-
+
:redecard_preauth => 42, # Redecard preauth Mastercard/Diners/Visa
-
+
:cielo_sitef => 57, # Cielo SITEF
-
+
:hipercard_sitef => 62, # Hipercard SITEF
-
+
:hipercard_moip => 90, # Hipercard MOIP
-
+
:oi_paggo => 55, # OiPaggo
-
+
:amex_sitef => 58, # Amex SITEF
-
+
:aura_dtef => 37, # Aura DTEF
-
+
:redecard_sitef => 44, # Redecard SITEF - Mastercard/Diners
-
+
#CARDS - MEXICO
-
+
:mex_amex_2p => 45, # American Express 2 Party
-
+
:mex_banorte_visa => 50, # Banorte Visa
-
+
:mex_banorte_diners => 52, # Banorte Diners
-
+
:mex_banorte_mastercard => 53, # Banorte Mastercard
-
+
#CARDS - COLOMBIA
-
+
:col_visa => 63, # Visa
-
+
:col_amex => 65, # Amex
-
+
:col_diners => 66, # Diners
-
+
# INTERNACIONAL
-
+
:paypal_express => 35, # PayPal Express Checkout
-
+
# HOMOLOGATION
-
+
:braspag => 997
-
+
}
-
+
end
@@ -1405,26 +1417,26 @@ 100.0 % covered
def initialize(params = {})
-
- 71
+
+ 69
merchant_id = params[:merchant_id]
-
- 71
+
+ 69
env = params[:environment]
-
- 71
+
+ 69
raise InvalidMerchantId unless merchant_id =~ /\{[a-z0-9]{8}-([a-z0-9]{4}-){3}[a-z0-9]{12}\}/i
-
- 70
+
+ 68
raise InvalidEnvironment unless (env == :homologation || env == :production)
@@ -1435,26 +1447,26 @@ 100.0 % covered
-
- 68
+
+ 66
@merchant_id = merchant_id
-
- 68
+
+ 66
@env = env
-
- 68
+
+ 66
@logger = params[:logger]
-
- 68
+
+ 66
@proxy_address = params[:proxy_address]
@@ -1501,8 +1513,8 @@ 100.0 % covered
def homologation?
-
- 23
+
+ 21
@env == :homologation
@@ -4474,8 +4486,8 @@ 100.0 % covered
lib/cbraspag/crypto/webservice.rb
100.0 % covered
- 31 relevant lines.
- 31 lines covered and
+ 29 relevant lines.
+ 29 lines covered and
0 lines missed.
@@ -4510,526 +4522,364 @@ 100.0 % covered
4
- fields = "\n"
+ data = ERB.new(File.read(Braspag::PATH + '/cbraspag/templates/crypto/encrypt.xml.erb'))
-
- 4
+
- map.each do |key, value|
+
+
4
- fields.concat(" <tns:string>#{key}=#{value}</tns:string>\n")
+ response = Braspag::Poster.new(
- end
+ connection,
-
+ connection.url_for(:encrypt)
-
- 4
+
- data = <<-STRING
+
+ ).do_post(
- <?xml version="1.0" encoding="utf-8"?>
+ :encrypt,
- <env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope">
+ data.result(binding),
- <env:Header />
+ {"Content-Type" => "text/xml"}
- <env:Body>
+ )
- <tns:EncryptRequest xmlns:tns="https://www.pagador.com.br/webservice/BraspagGeneralService">
+
-
-
+
+ 4
- <tns:merchantId>#{connection.merchant_id}</tns:merchantId>
+ binding.pry
- <tns:request>
+
-
-
+
+ 4
- #{fields}
+ document = Nokogiri::XML(response.body)
- </tns:request>
+
-
-
+
+ 4
- </tns:EncryptRequest>
+ raise 'UnknownError' if document.children.empty?
- </env:Body>
+
- </env:Envelope>
-
-
-
-
-
- STRING
+ #melhorar este parser cof cof
-
- 4
+
+ 3
- response = Braspag::Poster.new(
+ response = document.children.children.children.children.children.to_s
-
+
- connection,
+
-
-
+
+ 3
- connection.url_for(:encrypt)
+ raise 'InvalidMerchantId' if (response == 'Erro BP 011' || response == 'Erro BP 012')
-
-
-
- ).do_post(
-
-
-
-
-
- :encrypt,
-
-
-
-
-
- data,
-
-
-
-
-
- {"Content-Type" => "text/xml"}
-
-
-
-
-
- )
-
-
-
-
-
-
-
-
-
- 4
-
- document = Nokogiri::XML(response.body)
-
-
-
-
-
-
-
-
-
- 4
-
- raise 'UnknownError' if document.children.empty?
-
-
-
-
-
-
-
-
-
-
-
- #melhorar este parser cof cof
-
-
-
- 3
-
- response = document.children.children.children.children.children.to_s
-
-
-
-
-
-
-
-
-
- 3
-
- raise 'InvalidMerchantId' if (response == 'Erro BP 011' || response == 'Erro BP 012')
-
-
-
+
2
raise 'InvalidIP' if (response == 'Erro BP 067' || response == 'Erro BP 068')
-
+
-
+
1
response
-
+
end
-
+
-
+
1
def decrypt(connection, encripted_text)
-
-
-
-
-
-
-
+
3
- data = <<-STRING
-
-
-
-
-
- <?xml version="1.0" encoding="utf-8"?>
-
-
-
-
-
- <env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope">
-
-
-
-
-
- <env:Header />
-
-
-
-
-
- <env:Body>
-
-
-
-
-
- <tns:DecryptRequest xmlns:tns="https://www.pagador.com.br/webservice/BraspagGeneralService">
-
-
-
-
-
- <tns:merchantId>#{connection.merchant_id}</tns:merchantId>
+ data = ERB.new(File.read(Braspag::PATH + '/cbraspag/templates/crypto/decrypt.xml.erb'))
-
-
-
- <tns:cryptString>#{encripted_text}</tns:cryptString>
-
-
-
-
-
- </tns:DecryptRequest>
-
-
-
-
-
- </env:Body>
-
-
-
-
-
- </env:Envelope>
-
-
-
-
-
- STRING
-
-
-
+
-
+
3
response = Braspag::Poster.new(
-
+
connection,
-
+
connection.url_for(:decrypt)
-
+
).do_post(
-
+
:decrypt,
-
+
- data,
+ data.result(binding),
-
+
{"Content-Type" => "text/xml"}
-
+
)
-
+
-
+
-
+
3
document = Nokogiri::XML(response.body)
-
+
3
raise 'UnknownError' if document.children.empty?
-
+
-
+
2
result_error = document.children.children.children.children.children.first.content.to_s
-
+
-
+
2
raise 'InvalidMerchantId' if (result_error == 'Erro BP 011' || result_error == 'Erro BP 012')
-
+
2
raise 'InvalidIP' if (result_error == 'Erro BP 067' || result_error == 'Erro BP 068')
-
+
-
+
1
convert_request_to_map document
-
+
end
-
+
-
+
1
protected
-
+
1
def convert_request_to_map(document)
-
+
1
map = {}
-
+
1
document.children.children.children.children.children.each do |n|
-
+
11
values = n.content.to_s.split("=")
-
+
11
map[values[0].downcase.to_sym] = values[1] if values.size == 2
-
+
end
-
+
1
map
-
+
end
-
+
end
-
+
end
-
+
end
@@ -5743,8 +5593,8 @@ 100.0 % covered
def void(order, partial=nil)
-
- 4
+
+ 2
response = self.post(:void, order)
@@ -5755,8 +5605,8 @@ 100.0 % covered
-
- 4
+
+ 2
status = (response[:status] == "0")
@@ -5767,8 +5617,8 @@ 100.0 % covered
-
- 4
+
+ 2
ActiveMerchant::Billing::Response.new(status,
@@ -16748,11 +16598,11 @@ 100.0 % covered
@@ -16777,14 +16627,14 @@
42.86 % covered
describe Braspag::Connection do
-
- 3
+
+ 1
let(:merchant_id) { "{12345678-1234-1234-1234-123456789000}" }
-
- 3
+
+ 1
let(:connection) { Braspag::Connection.new(:merchant_id => merchant_id, :environment => :homologation)}
@@ -16798,2254 +16648,562 @@
42.86 % covered
1
- context ".void" do
+ pending 'archive'
-
- 1
+
- it "should return response" do
+
+
1
- void = {
+ pending 'get_recurrency'
- :status => "1",
+
-
-
+
+ 1
- :message => "BLA"
+ pending 'recurrency'
- }
+ end
-
+
1
- connection.should_receive(:post).and_return(void)
+ describe Braspag::CreditCard do
-
+
1
- response = connection.void(mock)
+ [:purchase, :authorize, :archive].each do |context_type|
-
-
-
-
-
-
-
- 1
-
- response.success?.should eq(false)
-
-
-
- 1
-
- response.message.should eq(void[:message])
-
-
-
- 1
-
- response.params.should eq({"status"=>"1", "message"=>"BLA"})
-
-
-
- 1
-
- response.test.should eq(true)
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
- 1
-
- it "should return success when status is zero" do
-
-
-
- 1
-
- void = {
-
-
-
-
-
- :status => "0",
-
-
-
-
-
- :message => "BLA"
-
-
-
-
-
- }
-
-
-
-
-
-
-
-
-
- 1
-
- connection.should_receive(:post).and_return(void)
-
-
-
-
-
-
-
-
-
- 1
-
- response = connection.void(mock)
-
-
-
-
-
-
-
-
-
- 1
-
- response.success?.should eq(true)
-
-
-
-
-
- end
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
- 1
-
- pending ".save" do
-
-
-
-
-
- let(:params) do
-
-
-
-
-
- {
-
-
-
-
-
- :customer_name => "W" * 21,
-
-
-
-
-
- :holder => "Joao Maria Souza",
-
-
-
-
-
- :card_number => "9" * 10,
-
-
-
-
-
- :expiration => "10/12",
-
-
-
-
-
- :order_id => "um order id",
-
-
-
-
-
- :request_id => "00000000-0000-0000-0000-000000000044"
-
-
-
-
-
- }
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
-
-
- let(:params_with_merchant_id) do
-
-
-
-
-
- params.merge!(:merchant_id => merchant_id)
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
-
-
- let(:save_protected_card_url) { "http://braspag.com/bla" }
-
-
-
-
-
-
-
-
-
-
-
- let(:savon_double) { double('Savon') }
-
-
-
-
-
-
-
-
-
-
-
- before do
-
-
-
-
-
- @connection.should_receive(:merchant_id)
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
-
-
- context "with valid params" do
-
-
-
-
-
- let(:valid_hash) do
-
-
-
-
-
- {
-
-
-
-
-
- :save_credit_card_response => {
-
-
-
-
-
- :save_credit_card_result => {
-
-
-
-
-
- :just_click_key => 'SAVE-PROTECTED-CARD-TOKEN',
-
-
-
-
-
- :success => true
-
-
-
-
-
- }
-
-
-
-
-
- }
-
-
-
-
-
- }
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
-
-
- let(:response) do
-
-
-
-
-
- double('Response', :to_hash => valid_hash)
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
-
-
- before do
-
-
-
-
-
- Braspag::ProtectedCreditCard.should_receive(:save_protected_card_url)
-
-
-
-
-
- Braspag::ProtectedCreditCard.should_receive(:check_protected_card_params)
-
-
-
-
-
- .and_return(true)
-
-
-
-
-
- Savon::Client.should_receive(:new).and_return(savon_double)
-
-
-
-
-
- savon_double.should_receive(:request).and_return(response)
-
-
-
-
-
-
-
-
-
-
-
- @response = Braspag::ProtectedCreditCard.save(params)
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
-
-
- it "should return a Hash" do
-
-
-
-
-
- @response.should be_kind_of Hash
-
-
-
-
-
- @response.should == {
-
-
-
-
-
- :just_click_key => "SAVE-PROTECTED-CARD-TOKEN",
-
-
-
-
-
- :success => true
-
-
-
-
-
- }
-
-
-
-
-
- end
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
-
-
- context "with invalid params" do
-
-
-
-
-
- let(:invalid_hash) do
-
-
-
-
-
- {
-
-
-
-
-
- :save_credit_card_response => {
-
-
-
-
-
- :save_credit_card_result => {
-
-
-
-
-
- :just_click_key => nil,
-
-
-
-
-
- :success => false
-
-
-
-
-
- }
-
-
-
-
-
- }
-
-
-
-
-
- }
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
-
-
- let(:response) do
-
-
-
-
-
- double('Response', :to_hash => invalid_hash)
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
-
-
- before do
-
-
-
-
-
- Braspag::ProtectedCreditCard.should_receive(:check_protected_card_params)
-
-
-
-
-
- .and_return(true)
-
-
-
-
-
- Braspag::ProtectedCreditCard.should_receive(:save_protected_card_url)
-
-
-
-
-
- .and_return(save_protected_card_url)
-
-
-
-
-
- Savon::Client.should_receive(:new).and_return(savon_double)
-
-
-
-
-
- savon_double.should_receive(:request).and_return(response)
-
-
-
-
-
-
-
-
-
-
-
- @response = Braspag::ProtectedCreditCard.save(params)
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
-
-
- it "should return a Hash" do
-
-
-
-
-
- @response.should be_kind_of Hash
-
-
-
-
-
- @response.should == {
-
-
-
-
-
- :just_click_key => nil,
-
-
-
-
-
- :success => false
-
-
-
-
-
- }
-
-
-
-
-
- end
-
-
-
-
-
- end
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
- 1
-
- pending ".get" do
-
-
-
-
-
- let(:get_protected_card_url) { "http://braspag/bla" }
-
-
-
-
-
-
-
-
-
-
-
- let(:invalid_xml) do
-
-
-
-
-
- <<-EOXML
-
-
-
-
-
- <CartaoProtegidoReturn xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-
-
-
-
-
- xmlns:xsd="http://www.w3.org/2001/XMLSchema"
-
-
-
-
-
- xmlns="http://www.pagador.com.br/">
-
-
-
-
-
- <CardHolder>Joao Maria Souza</CardHolder>
-
-
-
-
-
- <CardNumber></CardNumber>
-
-
-
-
-
- <CardExpiration>10/12</CardExpiration>
-
-
-
-
-
- <MaskedCardNumber>******9999</MaskedCardNumber>
-
-
-
-
-
- </CartaoProtegidoReturn>
-
-
-
-
-
- EOXML
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
-
-
- let(:valid_xml) do
-
-
-
-
-
- <<-EOXML
-
-
-
-
-
- <CartaoProtegidoReturn xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-
-
-
-
-
- xmlns:xsd="http://www.w3.org/2001/XMLSchema"
-
-
-
-
-
- xmlns="http://www.pagador.com.br/">
-
-
-
-
-
- <CardHolder>Joao Maria Souza</CardHolder>
-
-
-
-
-
- <CardNumber>9999999999</CardNumber>
-
-
-
-
-
- <CardExpiration>10/12</CardExpiration>
-
-
-
-
-
- <MaskedCardNumber>******9999</MaskedCardNumber>
-
-
-
-
-
- </CartaoProtegidoReturn>
-
-
-
-
-
- EOXML
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
-
-
- it "should raise an error when just click key is not valid" do
-
-
-
-
-
- Braspag::ProtectedCreditCard.should_receive(:valid_just_click_key?)
-
-
-
-
-
- .with("bla")
-
-
-
-
-
- .and_return(false)
-
-
-
-
-
-
-
-
-
-
-
- expect {
-
-
-
-
-
- Braspag::ProtectedCreditCard.get "bla"
-
-
-
-
-
- }.to raise_error(Braspag::InvalidJustClickKey)
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
-
-
- it "should raise an error when Braspag returned an invalid xml as response" do
-
-
-
-
-
- FakeWeb.register_uri(:post, get_protected_card_url, :body => invalid_xml)
-
-
-
-
-
-
-
-
-
-
-
- Braspag::ProtectedCreditCard.should_receive(:get_protected_card_url)
-
-
-
-
-
- .and_return(get_protected_card_url)
-
-
-
-
-
-
-
-
-
-
-
- expect {
-
-
-
-
-
- Braspag::ProtectedCreditCard.get("b0b0b0b0-bbbb-4d4d-bd27-f1f1f1ededed")
-
-
-
-
-
- }.to raise_error(Braspag::UnknownError)
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
-
-
- it "should return a Hash when Braspag returned a valid xml as response" do
-
-
-
-
-
- FakeWeb.register_uri(:post, get_protected_card_url, :body => valid_xml)
-
-
-
-
-
-
-
-
-
-
-
- Braspag::ProtectedCreditCard.should_receive(:get_protected_card_url)
-
-
-
-
-
- .and_return(get_protected_card_url)
-
-
-
-
-
-
-
-
-
-
-
- response = Braspag::ProtectedCreditCard.get("b0b0b0b0-bbbb-4d4d-bd27-f1f1f1ededed")
-
-
-
-
-
- response.should be_kind_of Hash
-
-
-
-
-
-
-
-
-
-
-
- response.should == {
-
-
-
-
-
- :holder => "Joao Maria Souza",
-
-
-
-
-
- :expiration => "10/12",
-
-
-
-
-
- :card_number => "9" * 10,
-
-
-
-
-
- :masked_card_number => "*" * 6 + "9" * 4
-
-
-
-
-
- }
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
- 1
-
- pending ".just_click_shop" do
-
-
-
-
-
- context "body" do
-
-
-
-
-
- let(:params) { {
-
-
-
-
-
- :request_id => "123",
-
-
-
-
-
- :customer_name => "Joao Silva",
-
-
-
-
-
- :order_id => "999",
-
-
-
-
-
- :amount => 10.50,
-
-
-
-
-
- :payment_method => :redecard,
-
-
-
-
-
- :number_installments => 3,
-
-
-
-
-
- :payment_type => "test",
-
-
-
-
-
- :just_click_key => "key",
-
-
-
-
-
- :security_code => "123"
-
-
-
-
-
- } }
-
-
-
-
-
-
-
-
-
-
-
- class SavonClientTest
-
-
-
-
-
- attr_accessor :response
-
-
-
-
-
- attr_reader :method
-
-
-
-
-
-
-
-
-
-
-
- def request(web, method, &block)
-
-
-
-
-
- @method = method
-
-
-
-
-
- instance_eval &block
-
-
-
-
-
-
-
-
-
-
-
- @response
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
-
-
- def soap
-
-
-
-
-
- @soap ||= OpenStruct.new
-
-
-
-
-
- end
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
-
-
- before :each do
-
-
-
-
-
- @savon_client_test = SavonClientTest.new
-
-
-
-
-
- @savon_client_test.response = {:just_click_shop_response => {}}
-
-
-
-
-
- Savon::Client.stub(:new).with('https://www.cartaoprotegido.com.br/Services/TestEnvironment/CartaoProtegido.asmx?wsdl').and_return(@savon_client_test)
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
-
-
- after :each do
-
-
-
-
-
- Savon::Client.unstub(:new)
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
-
-
- it "should have RequestId" do
-
-
-
-
-
- described_class.just_click_shop(params)
-
-
-
-
-
- @savon_client_test.soap.body['justClickShopRequestWS']['RequestId'].should eq '123'
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
-
-
- it "should have MerchantKey" do
-
-
-
-
-
- described_class.just_click_shop(params)
-
-
-
-
-
- @savon_client_test.soap.body['justClickShopRequestWS']['MerchantKey'].should eq 'um id qualquer'
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
-
-
- it "should have CustomerName" do
-
-
-
-
-
- described_class.just_click_shop(params)
-
-
-
-
-
- @savon_client_test.soap.body['justClickShopRequestWS']['CustomerName'].should eq 'Joao Silva'
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
-
-
- it "should have OrderId" do
-
-
-
-
-
- described_class.just_click_shop(params)
-
-
-
-
-
- @savon_client_test.soap.body['justClickShopRequestWS']['OrderId'].should eq '999'
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
-
-
- it "should have Amount" do
-
-
-
-
-
- described_class.just_click_shop(params)
-
-
-
-
-
- @savon_client_test.soap.body['justClickShopRequestWS']['Amount'].should eq 10.50
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
-
-
- it "should have PaymentMethod" do
-
-
-
-
-
- described_class.just_click_shop(params)
-
-
-
-
-
- @savon_client_test.soap.body['justClickShopRequestWS']['PaymentMethod'].should eq 20
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
-
-
- it "should have PaymentType" do
-
-
-
-
-
- described_class.just_click_shop(params)
-
-
-
-
-
- @savon_client_test.soap.body['justClickShopRequestWS']['PaymentType'].should eq 'test'
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
-
-
- it "should have NumberInstallments" do
-
-
-
-
-
- described_class.just_click_shop(params)
-
-
-
-
-
- @savon_client_test.soap.body['justClickShopRequestWS']['NumberInstallments'].should eq 3
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
-
-
- it "should have JustClickKey" do
-
-
-
-
-
- described_class.just_click_shop(params)
-
-
-
-
-
- @savon_client_test.soap.body['justClickShopRequestWS']['JustClickKey'].should eq 'key'
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
-
-
- it "should have SecurityCode" do
-
-
-
-
-
- described_class.just_click_shop(params)
-
-
-
-
-
- @savon_client_test.soap.body['justClickShopRequestWS']['SecurityCode'].should eq '123'
-
-
-
-
-
- end
-
-
-
-
-
- end
-
-
-
-
-
- end
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
- 1
-
- describe Braspag::CreditCard do
-
-
-
-
-
-
-
-
-
- 1
-
- [:purchase, :authorize, :archive].each do |context_type|
-
-
-
- 3
+
+ 3
context "on #{context_type}" do
-
+
3
it "should validate minimum 1 length of holder_name" do
-
+
3
subject.holder_name = ''
-
+
3
subject.valid?(context_type)
-
+
3
subject.errors.messages[:holder_name].should include("is too short (minimum is 1 characters)")
-
+
end
-
+
-
+
3
it "should validate maximum 100 length of holder_name" do
-
+
3
subject.holder_name = '*' * 110
-
+
3
subject.valid?(context_type)
-
+
3
subject.errors.messages[:holder_name].should include("is too long (maximum is 100 characters)")
-
+
end
-
+
-
+
3
it "should not allow blank for number" do
-
+
3
subject.number = ''
-
+
3
subject.valid?(context_type)
-
+
3
subject.errors.messages[:number].should include("can't be blank")
-
+
end
-
+
-
+
3
it "should not allow blank for month" do
-
+
3
subject.month = ''
-
+
3
subject.valid?(context_type)
-
+
3
subject.errors.messages[:month].should include("can't be blank")
-
+
end
-
+
-
+
3
it "should not allow blank for year" do
-
+
3
subject.year = ''
-
+
3
subject.valid?(context_type)
-
+
3
subject.errors.messages[:year].should include("can't be blank")
-
+
end
-
+
-
+
3
it "should not allow invalid date for month & year" do
-
+
3
subject.month = "14"
-
+
3
subject.year = "2012"
-
+
3
subject.valid?(context_type)
-
+
3
subject.errors.messages[:month].should include("invalid date")
-
+
3
subject.errors.messages[:year].should include("invalid date")
-
+
end
-
+
-
+
3
it "should allow valid date for month & year" do
-
+
3
subject.month = "09"
-
+
3
subject.year = "12"
-
+
3
subject.valid?(context_type)
-
+
3
subject.errors.messages[:month].should be(nil)
-
+
3
subject.errors.messages[:year].should be(nil)
-
+
end
-
+
-
+
3
it "should allow valid date for month & year" do
-
+
3
subject.month = 12
-
+
3
subject.year = 2014
-
+
3
subject.valid?(context_type)
-
+
3
subject.errors.messages[:month].should be(nil)
-
+
3
subject.errors.messages[:year].should be(nil)
-
+
end
-
+
end
-
+
end
-
+
-
+
1
[:purchase, :authorize, :recurrency].each do |context_type|
-
+
3
context "on #{context_type}" do
-
+
3
it "should validate minimum 1 length of verification_value" do
-
+
3
subject.verification_value = ''
-
+
3
subject.valid?(context_type)
-
+
3
subject.errors.messages[:verification_value].should include("is too short (minimum is 1 characters)")
-
+
end
-
+
-
+
3
it "should validate maximum 4 length of verification_value" do
-
+
3
subject.verification_value = '*' * 5
-
+
3
subject.valid?(context_type)
-
+
3
subject.errors.messages[:verification_value].should include("is too long (maximum is 4 characters)")
-
+
end
-
+
end
-
+
end
-
+
-
+
1
[:get_recurrency, :recurrency].each do |context_type|
-
+
2
context "on #{context_type}" do
-
+
2
it "should validate length of id" do
-
+
2
subject.id = '*' * 37
-
+
2
subject.valid?(context_type)
-
+
2
subject.errors.messages[:id].should include("is the wrong length (should be 36 characters)")
-
+
end
-
+
end
-
+
end
-
+
-
+
end
diff --git a/lib/cbraspag.rb b/lib/cbraspag.rb
index 27911ba..e3335f0 100644
--- a/lib/cbraspag.rb
+++ b/lib/cbraspag.rb
@@ -7,6 +7,7 @@
require 'savon'
require 'bigdecimal'
require 'active_merchant'
+require 'erb'
require "cbraspag/version"
require 'cbraspag/core/converter'
@@ -24,6 +25,7 @@
module Braspag
+ PATH = File.dirname(__FILE__)
INTEREST = {
:no => 0,
diff --git a/lib/cbraspag/crypto/webservice.rb b/lib/cbraspag/crypto/webservice.rb
index aceb8ea..0515b47 100644
--- a/lib/cbraspag/crypto/webservice.rb
+++ b/lib/cbraspag/crypto/webservice.rb
@@ -2,34 +2,17 @@ module Braspag
module Crypto
class Webservice
def encrypt(connection, map)
- fields = "\n"
- map.each do |key, value|
- fields.concat(" #{key}=#{value}\n")
- end
+ data = ERB.new(File.read(Braspag::PATH + '/cbraspag/templates/crypto/encrypt.xml.erb'))
- data = <<-STRING
-
-
-
-
-
- #{connection.merchant_id}
-
- #{fields}
-
-
-
-
-STRING
response = Braspag::Poster.new(
connection,
connection.url_for(:encrypt)
).do_post(
:encrypt,
- data,
+ data.result(binding),
{"Content-Type" => "text/xml"}
)
-
+
document = Nokogiri::XML(response.body)
raise 'UnknownError' if document.children.empty?
@@ -44,29 +27,17 @@ def encrypt(connection, map)
end
def decrypt(connection, encripted_text)
-
- data = <<-STRING
-
-
-
-
-
- #{connection.merchant_id}
- #{encripted_text}
-
-
-
-STRING
+ data = ERB.new(File.read(Braspag::PATH + '/cbraspag/templates/crypto/decrypt.xml.erb'))
response = Braspag::Poster.new(
connection,
connection.url_for(:decrypt)
).do_post(
:decrypt,
- data,
+ data.result(binding),
{"Content-Type" => "text/xml"}
)
-
+
document = Nokogiri::XML(response.body)
raise 'UnknownError' if document.children.empty?
diff --git a/lib/cbraspag/payment/recurrency_credit_card.rb b/lib/cbraspag/payment/recurrency_credit_card.rb
index cd668a3..3540ce9 100644
--- a/lib/cbraspag/payment/recurrency_credit_card.rb
+++ b/lib/cbraspag/payment/recurrency_credit_card.rb
@@ -1,99 +1,18 @@
module Braspag
class Connection
- PROTECTED_CARD_MAPPING = {
- :request_id => "RequestId",
- :merchant_id => "MerchantKey",
- :customer_name => "CustomerName",
- :holder => "CardHolder",
- :card_number => "CardNumber",
- :expiration => "CardExpiration"
- }
-
- JUST_CLICK_MAPPING = {
- :request_id => "RequestId",
- :merchant_id => "MerchantKey",
- :customer_name => "CustomerName",
- :order_id => "OrderId",
- :amount => "Amount",
- :payment_method => "PaymentMethod",
- :number_installments => "NumberInstallments",
- :payment_type => "PaymentType",
- :just_click_key => "JustClickKey",
- :security_code => "SecurityCode"
- }
-
-
- # saves credit card in Braspag PCI Compliant
def archive(credit_card, customer, request_id)
-
- self.check_protected_card_params(params)
-
- data = { 'saveCreditCardRequestWS' => {} }
-
- PROTECTED_CARD_MAPPING.each do |k, v|
- data['saveCreditCardRequestWS'][v] = params[k] || ""
- end
-
-
- client = Savon::Client.new(self.save_protected_card_url)
- response = client.request(:web, :save_credit_card) do
- soap.body = data
- end
-
- response.to_hash[:save_credit_card_response][:save_credit_card_result]
-
+ year_normalize = credit_card.year.to_s[-2, 2]
+
+ template = ERB.new 'save_credit'
+ puts template.result(binding)
end
-
# request the credit card info in Braspag PCI Compliant
def get_recurrency(credit_card)
- raise InvalidJustClickKey unless valid_just_click_key?(just_click_key)
-
- data = { 'getCreditCardRequestWS' => {:loja => connection.merchant_id, :justClickKey => just_click_key} }
-
- request = ::HTTPI::Request.new(self.get_protected_card_url)
- request.body = { 'getCreditCardRequestWS' => {:loja => connection.merchant_id, :justClickKey => just_click_key} }
-
- response = ::HTTPI.post(request)
-
- response = Utils::convert_to_map(response.body, {
- :holder => "CardHolder",
- :card_number => "CardNumber",
- :expiration => "CardExpiration",
- :masked_card_number => "MaskedCardNumber"
- })
-
- raise UnknownError if response[:card_number].nil?
- response
end
def recurrency(order, credit_card, request_id)
-
- self.check_just_click_shop_params(params)
-
- order_id = params[:order_id]
- raise InvalidOrderId unless self.valid_order_id?(order_id)
-
- data = { 'justClickShopRequestWS' => {} }
-
- JUST_CLICK_MAPPING.each do |k, v|
- case k
- when :payment_method
- data['justClickShopRequestWS'][v] = Braspag::Connection.instance.homologation? ? PAYMENT_METHODS[:braspag] : PAYMENT_METHODS[params[:payment_method]]
- else
- data['justClickShopRequestWS'][v] = params[k] || ""
- end
- end
-
- client = Savon::Client.new(self.just_click_shop_url)
- response = client.request(:web, :just_click_shop) do
- soap.body = data
- end
-
- response.to_hash[:just_click_shop_response][:just_click_shop_result]
-
+
end
-
-
end
end
diff --git a/lib/cbraspag/templates/crypto/decrypt.xml.erb b/lib/cbraspag/templates/crypto/decrypt.xml.erb
new file mode 100644
index 0000000..956d38f
--- /dev/null
+++ b/lib/cbraspag/templates/crypto/decrypt.xml.erb
@@ -0,0 +1,10 @@
+
+
+
+
+
+ <%= connection.merchant_id %>
+ <%= encripted_text %>
+
+
+
\ No newline at end of file
diff --git a/lib/cbraspag/templates/crypto/encrypt.xml.erb b/lib/cbraspag/templates/crypto/encrypt.xml.erb
new file mode 100644
index 0000000..009c7aa
--- /dev/null
+++ b/lib/cbraspag/templates/crypto/encrypt.xml.erb
@@ -0,0 +1,14 @@
+
+
+
+
+
+ <%= connection.merchant_id %>
+
+ <% map.each do |key, value| %>
+ <%= key %>=<%= value %>
+ <% end %>
+
+
+
+
\ No newline at end of file
diff --git a/lib/cbraspag/templates/justclick/archive.xml.erb b/lib/cbraspag/templates/justclick/archive.xml.erb
new file mode 100644
index 0000000..1534428
--- /dev/null
+++ b/lib/cbraspag/templates/justclick/archive.xml.erb
@@ -0,0 +1,16 @@
+
+
+
+
+
+ <%= merchant_id %>
+ <%= customer.cpf%>
+ <%= customer.name %>
+ <%= credit_card.holder_name %>
+ <%= credit_card.number %>
+ <%= credit_card.year + credit_card.month %>
+ <%= creditcard_alias%>
+
+
+
+
\ No newline at end of file
diff --git a/lib/cbraspag/templates/justclick/get_recurrency.xml.erb b/lib/cbraspag/templates/justclick/get_recurrency.xml.erb
new file mode 100644
index 0000000..a69acbf
--- /dev/null
+++ b/lib/cbraspag/templates/justclick/get_recurrency.xml.erb
@@ -0,0 +1,12 @@
+
+
+
+
+
+ <%= merchant_id %>
+ guid
+ string
+
+
+
+
\ No newline at end of file
diff --git a/lib/cbraspag/templates/justclick/recurrency.xml.erb b/lib/cbraspag/templates/justclick/recurrency.xml.erb
new file mode 100644
index 0000000..1515acd
--- /dev/null
+++ b/lib/cbraspag/templates/justclick/recurrency.xml.erb
@@ -0,0 +1,23 @@
+
+
+
+
+
+ guid
+ string
+ string
+ string
+ int
+ short
+ short
+ short
+ guid
+ string
+ string
+ string
+ guid
+ string
+
+
+
+
\ No newline at end of file
diff --git a/spec/payment/recurrency_credit_card_spec.rb b/spec/payment/recurrency_credit_card_spec.rb
index 580ee1a..7893314 100644
--- a/spec/payment/recurrency_credit_card_spec.rb
+++ b/spec/payment/recurrency_credit_card_spec.rb
@@ -4,293 +4,11 @@
let(:merchant_id) { "{12345678-1234-1234-1234-123456789000}" }
let(:connection) { Braspag::Connection.new(:merchant_id => merchant_id, :environment => :homologation)}
- context ".void" do
- it "should return response" do
- void = {
- :status => "1",
- :message => "BLA"
- }
-
- connection.should_receive(:post).and_return(void)
-
- response = connection.void(mock)
-
- response.success?.should eq(false)
- response.message.should eq(void[:message])
- response.params.should eq({"status"=>"1", "message"=>"BLA"})
- response.test.should eq(true)
- end
-
- it "should return success when status is zero" do
- void = {
- :status => "0",
- :message => "BLA"
- }
-
- connection.should_receive(:post).and_return(void)
-
- response = connection.void(mock)
-
- response.success?.should eq(true)
- end
- end
-
- pending ".save" do
- let(:params) do
- {
- :customer_name => "W" * 21,
- :holder => "Joao Maria Souza",
- :card_number => "9" * 10,
- :expiration => "10/12",
- :order_id => "um order id",
- :request_id => "00000000-0000-0000-0000-000000000044"
- }
- end
-
- let(:params_with_merchant_id) do
- params.merge!(:merchant_id => merchant_id)
- end
-
- let(:save_protected_card_url) { "http://braspag.com/bla" }
-
- let(:savon_double) { double('Savon') }
-
- before do
- @connection.should_receive(:merchant_id)
- end
-
- context "with valid params" do
- let(:valid_hash) do
- {
- :save_credit_card_response => {
- :save_credit_card_result => {
- :just_click_key => 'SAVE-PROTECTED-CARD-TOKEN',
- :success => true
- }
- }
- }
- end
-
- let(:response) do
- double('Response', :to_hash => valid_hash)
- end
-
- before do
- Braspag::ProtectedCreditCard.should_receive(:save_protected_card_url)
- Braspag::ProtectedCreditCard.should_receive(:check_protected_card_params)
- .and_return(true)
- Savon::Client.should_receive(:new).and_return(savon_double)
- savon_double.should_receive(:request).and_return(response)
-
- @response = Braspag::ProtectedCreditCard.save(params)
- end
-
- it "should return a Hash" do
- @response.should be_kind_of Hash
- @response.should == {
- :just_click_key => "SAVE-PROTECTED-CARD-TOKEN",
- :success => true
- }
- end
- end
-
- context "with invalid params" do
- let(:invalid_hash) do
- {
- :save_credit_card_response => {
- :save_credit_card_result => {
- :just_click_key => nil,
- :success => false
- }
- }
- }
- end
-
- let(:response) do
- double('Response', :to_hash => invalid_hash)
- end
-
- before do
- Braspag::ProtectedCreditCard.should_receive(:check_protected_card_params)
- .and_return(true)
- Braspag::ProtectedCreditCard.should_receive(:save_protected_card_url)
- .and_return(save_protected_card_url)
- Savon::Client.should_receive(:new).and_return(savon_double)
- savon_double.should_receive(:request).and_return(response)
-
- @response = Braspag::ProtectedCreditCard.save(params)
- end
-
- it "should return a Hash" do
- @response.should be_kind_of Hash
- @response.should == {
- :just_click_key => nil,
- :success => false
- }
- end
- end
- end
-
- pending ".get" do
- let(:get_protected_card_url) { "http://braspag/bla" }
-
- let(:invalid_xml) do
- <<-EOXML
-
- Joao Maria Souza
-
- 10/12
- ******9999
-
- EOXML
- end
-
- let(:valid_xml) do
- <<-EOXML
-
- Joao Maria Souza
- 9999999999
- 10/12
- ******9999
-
- EOXML
- end
-
- it "should raise an error when just click key is not valid" do
- Braspag::ProtectedCreditCard.should_receive(:valid_just_click_key?)
- .with("bla")
- .and_return(false)
-
- expect {
- Braspag::ProtectedCreditCard.get "bla"
- }.to raise_error(Braspag::InvalidJustClickKey)
- end
-
- it "should raise an error when Braspag returned an invalid xml as response" do
- FakeWeb.register_uri(:post, get_protected_card_url, :body => invalid_xml)
-
- Braspag::ProtectedCreditCard.should_receive(:get_protected_card_url)
- .and_return(get_protected_card_url)
-
- expect {
- Braspag::ProtectedCreditCard.get("b0b0b0b0-bbbb-4d4d-bd27-f1f1f1ededed")
- }.to raise_error(Braspag::UnknownError)
- end
-
- it "should return a Hash when Braspag returned a valid xml as response" do
- FakeWeb.register_uri(:post, get_protected_card_url, :body => valid_xml)
-
- Braspag::ProtectedCreditCard.should_receive(:get_protected_card_url)
- .and_return(get_protected_card_url)
-
- response = Braspag::ProtectedCreditCard.get("b0b0b0b0-bbbb-4d4d-bd27-f1f1f1ededed")
- response.should be_kind_of Hash
-
- response.should == {
- :holder => "Joao Maria Souza",
- :expiration => "10/12",
- :card_number => "9" * 10,
- :masked_card_number => "*" * 6 + "9" * 4
- }
- end
-
- end
-
- pending ".just_click_shop" do
- context "body" do
- let(:params) { {
- :request_id => "123",
- :customer_name => "Joao Silva",
- :order_id => "999",
- :amount => 10.50,
- :payment_method => :redecard,
- :number_installments => 3,
- :payment_type => "test",
- :just_click_key => "key",
- :security_code => "123"
- } }
-
- class SavonClientTest
- attr_accessor :response
- attr_reader :method
-
- def request(web, method, &block)
- @method = method
- instance_eval &block
-
- @response
- end
-
- def soap
- @soap ||= OpenStruct.new
- end
- end
-
- before :each do
- @savon_client_test = SavonClientTest.new
- @savon_client_test.response = {:just_click_shop_response => {}}
- Savon::Client.stub(:new).with('https://www.cartaoprotegido.com.br/Services/TestEnvironment/CartaoProtegido.asmx?wsdl').and_return(@savon_client_test)
- end
-
- after :each do
- Savon::Client.unstub(:new)
- end
-
- it "should have RequestId" do
- described_class.just_click_shop(params)
- @savon_client_test.soap.body['justClickShopRequestWS']['RequestId'].should eq '123'
- end
-
- it "should have MerchantKey" do
- described_class.just_click_shop(params)
- @savon_client_test.soap.body['justClickShopRequestWS']['MerchantKey'].should eq 'um id qualquer'
- end
-
- it "should have CustomerName" do
- described_class.just_click_shop(params)
- @savon_client_test.soap.body['justClickShopRequestWS']['CustomerName'].should eq 'Joao Silva'
- end
-
- it "should have OrderId" do
- described_class.just_click_shop(params)
- @savon_client_test.soap.body['justClickShopRequestWS']['OrderId'].should eq '999'
- end
-
- it "should have Amount" do
- described_class.just_click_shop(params)
- @savon_client_test.soap.body['justClickShopRequestWS']['Amount'].should eq 10.50
- end
-
- it "should have PaymentMethod" do
- described_class.just_click_shop(params)
- @savon_client_test.soap.body['justClickShopRequestWS']['PaymentMethod'].should eq 20
- end
-
- it "should have PaymentType" do
- described_class.just_click_shop(params)
- @savon_client_test.soap.body['justClickShopRequestWS']['PaymentType'].should eq 'test'
- end
-
- it "should have NumberInstallments" do
- described_class.just_click_shop(params)
- @savon_client_test.soap.body['justClickShopRequestWS']['NumberInstallments'].should eq 3
- end
-
- it "should have JustClickKey" do
- described_class.just_click_shop(params)
- @savon_client_test.soap.body['justClickShopRequestWS']['JustClickKey'].should eq 'key'
- end
-
- it "should have SecurityCode" do
- described_class.just_click_shop(params)
- @savon_client_test.soap.body['justClickShopRequestWS']['SecurityCode'].should eq '123'
- end
- end
- end
+ pending 'archive'
+
+ pending 'get_recurrency'
+
+ pending 'recurrency'
end
describe Braspag::CreditCard do