Skip to content
This repository has been archived by the owner on Jul 5, 2023. It is now read-only.

Commit

Permalink
Savon to use SOAP instead of REST in BRASPAG save method
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaeltimbo committed Jul 20, 2012
1 parent 723e103 commit aa9e7d5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 26 deletions.
1 change: 1 addition & 0 deletions lib/rbraspag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
require 'httpi'
require 'nokogiri'
require 'json'
require 'savon'

require "rbraspag/version"
require 'rbraspag/connection'
Expand Down
17 changes: 9 additions & 8 deletions lib/rbraspag/credit_card.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,14 +177,15 @@ def self.save(params = {})
data['saveCreditCardRequestWS'][v] = params[k] || ""
end

request = ::HTTPI::Request.new(self.save_protected_card_url)
request.body = data

response = ::HTTPI.post(request)
client = Savon::Client.new('https://cartaoprotegido.braspag.com.br/Services/CartaoProtegido.asmx?wsdl')
puts self.save_protected_card_url
response = client.request(:web, :save_credit_card) do
soap.body = data
end

Utils::convert_to_map(response.body, {
:just_click_key => "JustClickKey"
})
})

end

Expand Down Expand Up @@ -348,15 +349,15 @@ def self.cancellation_url
end

def self.save_protected_card_url
Braspag::Connection.instance.braspag_url + SAVE_PROTECTED_CARD_URI
Braspag::Connection.instance.protected_card_url + SAVE_PROTECTED_CARD_URI
end

def self.get_protected_card_url
Braspag::Connection.instance.braspag_url + GET_PROTECTED_CARD_URI
Braspag::Connection.instance.protected_card_url + GET_PROTECTED_CARD_URI
end

def self.just_click_shop_url
Braspag::Connection.instance.braspag_url + JUST_CLICK_SHOP_URI
Braspag::Connection.instance.protected_card_url + JUST_CLICK_SHOP_URI
end

end
Expand Down
38 changes: 20 additions & 18 deletions spec/credit_card_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -203,50 +203,52 @@
:holder => "Joao Maria Souza",
:card_number => "9" * 10,
:expiration => "10/12",
:order_id => "um order id"
: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/bla" }
let(:save_protected_card_url) { "http://braspag.com/bla" }

let(:savon) { double('Savon') }

before do
@connection.should_receive(:merchant_id)

Braspag::CreditCard.should_receive(:save_protected_card_url)
.and_return(save_protected_card_url)

Braspag::CreditCard.should_receive(:check_protected_card_params)
.and_return(true)
end

context "with invalid params"

context "with valid params" do
let(:valid_xml) do
<<-EOXML
<?xml version="1.0" encoding="utf-8"?>
<CartaoProtegidoReturn xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="https://www.pagador.com.br/webservice/pagador">
xmlns="https://cartaoprotegido.braspag.com.br/Services/CartaoProtegido.asmx">
<JustClickKey>SAVE-PROTECTED-CARD-TOKEN</JustClickKey>
</CartaoProtegidoReturn>
EOXML
end

let(:response) do
double('Response', :body => valid_xml)
end
before do
FakeWeb.register_uri(:post, save_protected_card_url, :body => valid_xml)
Braspag::CreditCard.should_receive(:save_protected_card_url)
.and_return(save_protected_card_url)
Braspag::CreditCard.should_receive(:check_protected_card_params)
.and_return(true)
Savon::Client.should_receive(:new).and_return(savon)
savon.should_receive(:request).and_return(response)

@response = Braspag::CreditCard.save(params)
end

it "should return a Hash" do
@response.should be_kind_of Hash
@response.should == {
:just_click_key => "SAVE-PROTECTED-CARD-TOKEN"
}
@response.should == { :just_click_key => "SAVE-PROTECTED-CARD-TOKEN" }
end
end
end
Expand Down Expand Up @@ -601,8 +603,8 @@
end

it ".save_protected_card_url .get_protected_card_url" do
@connection.stub(:braspag_url => braspag_homologation_protected_card_url)
@connection.stub(:protected_card_url => braspag_homologation_protected_card_url)

Braspag::CreditCard.save_protected_card_url.should == "#{braspag_homologation_protected_card_url}/CartaoProtegido.asmx/SaveCreditCard"
Braspag::CreditCard.get_protected_card_url.should == "#{braspag_homologation_protected_card_url}/CartaoProtegido.asmx/GetCreditCard"
end
Expand All @@ -617,7 +619,7 @@
end

it "should return the correct protected credit card url when connection environment is production" do
@connection.stub(:braspag_url => braspag_production_protected_card_url)
@connection.stub(:protected_card_url => braspag_production_protected_card_url)

Braspag::CreditCard.save_protected_card_url.should == "#{braspag_production_protected_card_url}/CartaoProtegido.asmx/SaveCreditCard"
Braspag::CreditCard.get_protected_card_url.should == "#{braspag_production_protected_card_url}/CartaoProtegido.asmx/GetCreditCard"
Expand Down

0 comments on commit aa9e7d5

Please sign in to comment.