Skip to content

Commit

Permalink
Paymill: Add support for void
Browse files Browse the repository at this point in the history
  • Loading branch information
duff authored and ntalbott committed Sep 25, 2013
1 parent ae0cdc6 commit e7b079b
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Moneris: Add optional (off by default) verification_value support [duff]
* Spreedly: Pass country with other address fields [hoenth]
* SecureNet: Fix order of xml params [duff]
* Paymill: Add support for void [duff]

== Version 1.38.1 (September 16, 2013)

Expand Down
13 changes: 11 additions & 2 deletions lib/active_merchant/billing/gateways/paymill.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ def refund(money, authorization, options={})
commit(:post, "refunds/#{transaction_id(authorization)}", post)
end

def void(authorization, options={})
commit(:delete, "preauthorizations/#{preauth(authorization)}")
end

def store(credit_card, options={})
save_card(credit_card)
end
Expand Down Expand Up @@ -97,9 +101,12 @@ def response_from(raw_response)
end

def authorization_from(parsed_response)
parsed_data = parsed_response['data']
return '' unless parsed_data.kind_of?(Hash)

[
parsed_response['data']['id'],
parsed_response['data']['preauthorization'].try(:[], 'id')
parsed_data['id'],
parsed_data['preauthorization'].try(:[], 'id')
].join(";")
end

Expand Down Expand Up @@ -158,6 +165,8 @@ def save_card_url
end

def post_data(params)
return nil unless params

no_blanks = params.reject { |key, value| value.blank? }
no_blanks.map { |key, value| "#{key}=#{CGI.escape(value.to_s)}" }.join("&")
end
Expand Down
13 changes: 12 additions & 1 deletion test/remote/gateways/remote_paymill_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,18 @@ def test_failed_capture

assert capture_response = @gateway.capture(@amount, response.authorization)
assert_failure capture_response
assert_equal 'Preauthorization has already been used', capture_response.message
assert_equal 'Transaction duplicate', capture_response.message
end

def test_successful_authorize_and_void
assert response = @gateway.authorize(@amount, @credit_card)
assert_success response
assert_equal 'Transaction approved', response.message
assert response.authorization

assert void_response = @gateway.void(response.authorization)
assert_success void_response
assert_equal 'Transaction approved', void_response.message
end

def test_successful_refund
Expand Down
22 changes: 22 additions & 0 deletions test/unit/gateways/paymill_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,19 @@ def test_successful_authorize_and_capture
assert_equal "Transaction approved", response.message
end

def test_successful_authorize_and_void
@gateway.stubs(:raw_ssl_request).returns(successful_store_response, successful_authorize_response)

assert response = @gateway.authorize(@amount, @credit_card)
assert_success response

@gateway.expects(:raw_ssl_request).returns(successful_void_response)
response = @gateway.void(response.authorization)
assert_success response
assert response.test?
assert_equal "Transaction approved", response.message
end

def test_failed_capture
@gateway.stubs(:raw_ssl_request).returns(successful_store_response, successful_authorize_response)
assert response = @gateway.authorize(@amount, @credit_card)
Expand Down Expand Up @@ -378,6 +391,15 @@ def successful_capture_response
JSON
end

def successful_void_response
MockResponse.succeeded <<-JSON
{
"data":[],
"mode":"test"
}
JSON
end

def successful_refund_response
MockResponse.succeeded <<-JSON
{
Expand Down

0 comments on commit e7b079b

Please sign in to comment.