Skip to content

Commit

Permalink
Add content-type header to requests,
Browse files Browse the repository at this point in the history
Changed Connection post/put body to be raw xml so that it isn't sent as url-encoded params
Added spec to test for Ronin::ResourceNotFound failure
  • Loading branch information
jkrall committed Feb 12, 2012
1 parent 8f510c6 commit de86dc6
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 10 deletions.
10 changes: 5 additions & 5 deletions lib/ronin/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ module Ronin::Connection
private

def get(uri, id)
request = HTTParty::Request.new(Net::HTTP::Get, "#{self.gateway.site}#{uri}/#{id}.xml", :format => :xml, :basic_auth => self.gateway.merchant_auth)
request = HTTParty::Request.new(Net::HTTP::Get, "#{self.gateway.site}#{uri}/#{id}.xml", :headers => {'content-type' => 'text/xml'}, :format => :xml, :basic_auth => self.gateway.merchant_auth)
request.perform
end

def post(uri, params)
request = HTTParty::Request.new(Net::HTTP::Post, "#{self.gateway.site}#{uri}.xml", :body => params, :format => :xml, :basic_auth => self.gateway.merchant_auth)
def post(uri, xml)
request = HTTParty::Request.new(Net::HTTP::Post, "#{self.gateway.site}#{uri}.xml", :headers => {'content-type' => 'text/xml'}, :body => xml, :format => :xml, :basic_auth => self.gateway.merchant_auth)
request.perform
end

def put(uri, id, params)
request = HTTParty::Request.new(Net::HTTP::Put, "#{self.gateway.site}#{uri}/#{id}.xml", :body => params, :format => :xml, :basic_auth => self.gateway.merchant_auth)
def put(uri, id, xml)
request = HTTParty::Request.new(Net::HTTP::Put, "#{self.gateway.site}#{uri}/#{id}.xml", :headers => {'content-type' => 'text/xml'}, :body => xml, :format => :xml, :basic_auth => self.gateway.merchant_auth)
request.perform
end

Expand Down
2 changes: 1 addition & 1 deletion lib/ronin/gateway.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def initialize(options={})
end

def create_payment_method(params={})
response = post('payment_methods', :payment_method => params)
response = post('payment_methods', params.to_xml(:root=>'payment_method'))
process_response(Ronin::PaymentMethod, 'payment_method', response)
end

Expand Down
4 changes: 2 additions & 2 deletions lib/ronin/models/payment_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ def token
end

def update(params={})
response = put('payment_methods', self.token, :payment_method => params)
response = put('payment_methods', self.token, params.to_xml(:root=>'payment_method'))
process_response(Ronin::PaymentMethod, 'payment_method', response)
end

private

def payment_method(method)
response = post("payment_methods/#{token}/#{method}", {})
response = post("payment_methods/#{token}/#{method}", '')
process_response(Ronin::PaymentMethod, 'payment_method', response)
end
end
2 changes: 1 addition & 1 deletion lib/ronin/models/processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def purchase(payment_method_token, amount, params={})

def create_transaction(payment_method_token, amount, method, params={})
transaction_params = params.merge(:payment_method_token => payment_method_token, :amount => amount)
response = post("processors/#{token}/#{method}", :transaction => transaction_params)
response = post("processors/#{token}/#{method}", transaction_params.to_xml(:root=>'transaction'))
process_response(Ronin::Transaction, 'transaction', response)
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/ronin/models/transaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def reverse(amount = self.amount)

def transaction_method(method, amount)
transaction_params = {:amount => amount}
response = post("transactions/#{self.token}/#{method}", :transaction => transaction_params)
response = post("transactions/#{self.token}/#{method}", transaction_params.to_xml(:root=>'transaction'))
process_response(Ronin::Transaction, 'transaction', response)
end
end
6 changes: 6 additions & 0 deletions spec/integration/processor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@
purchase.success.should be_false
purchase.errors['input.amount'].should == [ 'The transaction amount was invalid.' ]
end

it 'should raise Ronin::ResourceNotFound on invalid token' do
lambda {
@processor.purchase('bad_token', 1.10, :billing_reference=>rand(1000))
}.should raise_error(Ronin::ResourceNotFound, "Couldn't find PaymentMethod with token = bad_token")
end
end

describe 'cvv responses' do
Expand Down

0 comments on commit de86dc6

Please sign in to comment.