Skip to content
Browse files

Merge pull request #36 from chargify/fusebox-auth-reversal

Add auth reversal capability to Fusebox gateway
  • Loading branch information...
2 parents 09b528d + d912f42 commit 1f394ca90a235808c1055ffccc9c6002a42c1f95 @andys andys committed Apr 28, 2016
View
21 lib/active_merchant/billing/gateways/fusebox.rb
@@ -37,11 +37,12 @@ class FuseboxGateway < Gateway
}
TRAN_TYPES = {
- :authorize => '01',
- :sale => '02',
- :refund => '09',
- :void => '11',
- :inquiry => '22'
+ :authorize => '01',
+ :sale => '02',
+ :refund => '09',
+ :void => '11',
+ :inquiry => '22',
+ :auth_reversal => '61'
}
GATEWAY_RETRYABLE_CODES = ['0003', '0004', '0015', '0016', '0017', '0155']
@@ -129,8 +130,10 @@ def inquiry(fields)
end
# Storing a card is done via an authorize for $0.00 with the string "ID:" in the token request field
+ # NB: Some cards/banks return an error for $0 auth, so you have to use $1 auth and then reverse it.
def store(creditcard, options = {})
- authorize(100, creditcard, options.merge(:token_request => 'ID:'))
+ auth_amount = options[:auth_amount] || 0
+ authorize(auth_amount, creditcard, options.merge(:token_request => 'ID:'))
end
# For a successful void, options must include same :reference of a
@@ -141,6 +144,12 @@ def void(money, creditcard, options = {})
)
end
+ def auth_reversal(money, creditcard, options = {})
+ commit(
+ transaction_details(money, creditcard, options).merge(:transaction_type => TRAN_TYPES[:auth_reversal])
+ )
+ end
+
# prior purchase, and the amount of money must be identical.
def refund(money, creditcard, options = {})
commit(
View
12 test/remote/gateways/remote_fusebox_test.rb
@@ -46,6 +46,18 @@ def test_unsuccessful_authorize
assert_match(/^0041 BAD ACCT NUMBER/, response.message)
end
+ def test_successful_auth_and_reverse
+ @reference = unique_reference
+ assert response = @gateway.store(@credit_card, reference: @reference, auth_amount: 100)
+ assert_success response
+ assert_match(/^0000, COMPLETE/, response.message)
+ @token = response.params['token']
+
+ assert response = @gateway.auth_reversal(100, @token, reference: @reference)
+ assert_success response
+ assert_match(/^0000, COMPLETE/, response.message)
+ end
+
def test_successful_store_and_refund
# Get a token
assert response = @gateway.store(@credit_card, reference: unique_reference)
View
66 test/unit/gateways/fusebox_test.rb
@@ -61,7 +61,7 @@ def test_unsuccessful_request
end
def test_successful_store
- @gateway.expects(:build_request).with(:token_request => 'ID:', :transaction_qualifier => '010', :transaction_amount => '1.00', :unique_reference => 8888888, :billing_zip_code => '', :billing_address => '', :cashier_id => '0', :customer_code => 8888888, :account_number => '4242424242424242', :expiration => '0917', :cvc => '123', :transaction_type => '01')
+ @gateway.expects(:build_request).with(:token_request => 'ID:', :transaction_qualifier => '010', :transaction_amount => '0.00', :unique_reference => 8888888, :billing_zip_code => '', :billing_address => '', :cashier_id => '0', :customer_code => 8888888, :account_number => '4242424242424242', :expiration => '0917', :cvc => '123', :transaction_type => '01')
@gateway.expects(:ssl_post).returns(successful_store_response)
assert response = @gateway.store(@credit_card, @options)
@@ -73,6 +73,25 @@ def test_successful_store
assert response.test?
end
+ def test_successful_store_and_auth_and_reverse
+ @gateway.expects(:build_request).with(:token_request => 'ID:', :transaction_qualifier => '010', :transaction_amount => '1.00', :unique_reference => 8888888, :billing_zip_code => '', :billing_address => '', :cashier_id => '0', :customer_code => 8888888, :account_number => '4242424242424242', :expiration => '0917', :cvc => '123', :transaction_type => '01')
+ @gateway.expects(:ssl_post).returns(successful_store_response)
+
+ assert response = @gateway.store(@credit_card, @options.merge(:auth_amount => 100))
+ assert_success response
+ assert_equal '074398711288593', response.params['transaction_id']
+ assert_equal '1115356246424627', response.params['gateway_id']
+ assert_equal @token, response.params['token']
+ assert_match /^0000, COMPLETE, DEMO90/, response.message
+ assert response.test?
+
+ @gateway.expects(:build_request).with(:transaction_qualifier => '010', :transaction_amount => '1.00', :unique_reference => 8888888, :billing_zip_code => '', :billing_address => '', :cashier_id => '0', :customer_code => 8888888, :account_number => '4242424242424242', :expiration => '0917', :cvc => '123', :transaction_type => '61')
+ @gateway.expects(:ssl_post).returns(successful_auth_reverse_response)
+ assert response = @gateway.auth_reversal(100, @credit_card, @options)
+ assert_match /^0000, COMPLETE, DEMO37/, response.message
+ assert response.test?
+ end
+
def test_successful_token_purchase
@gateway.expects(:build_request).with(:mail_order_indicator => '1', :transaction_type => '02', :tax1_indicator => '0', :tax1_amount => '0.00', :transaction_qualifier => '010', :transaction_amount => '1.00', :unique_reference => 8888888, :billing_zip_code => '', :billing_address => '', :cashier_id => '0', :customer_code => 8888888, :account_number => 'ID:7979582790001', :expiration => '0916')
@gateway.expects(:ssl_post).returns(successful_token_purchase_response)
@@ -357,4 +376,49 @@ def successful_void_response
</Transaction></ProtoBase_Transaction_Batch>
"
end
+
+ def successful_auth_reverse_response
+ "<ProtoBase_Transaction_Batch><Settlement_Batch>false</Settlement_Batch><Transaction>
+ <API_Field><Field_Number>0001</Field_Number><Field_Value>61</Field_Value></API_Field>
+ <API_Field><Field_Number>0002</Field_Number><Field_Value>1.00</Field_Value></API_Field>
+ <API_Field><Field_Number>0003</Field_Number><Field_Value>ID:7979582790001</Field_Value></API_Field>
+ <API_Field><Field_Number>0004</Field_Number><Field_Value>0917</Field_Value></API_Field>
+ <API_Field><Field_Number>0006</Field_Number><Field_Value>DEMO37</Field_Value></API_Field>
+ <API_Field><Field_Number>0007</Field_Number><Field_Value>11437951</Field_Value></API_Field>
+ <API_Field><Field_Number>0009</Field_Number><Field_Value>0021</Field_Value></API_Field>
+ <API_Field><Field_Number>0030</Field_Number><Field_Value>1</Field_Value></API_Field>
+ <API_Field><Field_Number>0032</Field_Number><Field_Value>042016</Field_Value></API_Field>
+ <API_Field><Field_Number>0033</Field_Number><Field_Value>051639</Field_Value></API_Field>
+ <API_Field><Field_Number>0034</Field_Number><Field_Value>E</Field_Value></API_Field>
+ <API_Field><Field_Number>0035</Field_Number><Field_Value>6F39</Field_Value></API_Field>
+ <API_Field><Field_Number>0036</Field_Number><Field_Value>075078762457213</Field_Value></API_Field>
+ <API_Field><Field_Number>0037</Field_Number><Field_Value>5</Field_Value></API_Field>
+ <API_Field><Field_Number>0040</Field_Number><Field_Value>N</Field_Value></API_Field>
+ <API_Field><Field_Number>0054</Field_Number><Field_Value>00</Field_Value></API_Field>
+ <API_Field><Field_Number>0070</Field_Number><Field_Value>11437951</Field_Value></API_Field>
+ <API_Field><Field_Number>0109</Field_Number><Field_Value>TERM1</Field_Value></API_Field>
+ <API_Field><Field_Number>0110</Field_Number><Field_Value>0</Field_Value></API_Field>
+ <API_Field><Field_Number>0112</Field_Number><Field_Value>400</Field_Value></API_Field>
+ <API_Field><Field_Number>0115</Field_Number><Field_Value>010</Field_Value></API_Field>
+ <API_Field><Field_Number>0126</Field_Number><Field_Value>0</Field_Value></API_Field>
+ <API_Field><Field_Number>0128</Field_Number><Field_Value>1.00</Field_Value></API_Field>
+ <API_Field><Field_Number>0130</Field_Number><Field_Value>1.00</Field_Value></API_Field>
+ <API_Field><Field_Number>0131</Field_Number><Field_Value>00</Field_Value></API_Field>
+ <API_Field><Field_Number>0132</Field_Number><Field_Value>0</Field_Value></API_Field>
+ <API_Field><Field_Number>0140</Field_Number><Field_Value>USD</Field_Value></API_Field>
+ <API_Field><Field_Number>0141</Field_Number><Field_Value>840</Field_Value></API_Field>
+ <API_Field><Field_Number>1000</Field_Number><Field_Value>VI</Field_Value></API_Field>
+ <API_Field><Field_Number>1001</Field_Number><Field_Value>VISA</Field_Value></API_Field>
+ <API_Field><Field_Number>1003</Field_Number><Field_Value>0000</Field_Value></API_Field>
+ <API_Field><Field_Number>1004</Field_Number><Field_Value>COMPLETE</Field_Value></API_Field>
+ <API_Field><Field_Number>1008</Field_Number><Field_Value>*********0001</Field_Value></API_Field>
+ <API_Field><Field_Number>1009</Field_Number><Field_Value>00000</Field_Value></API_Field>
+ <API_Field><Field_Number>1010</Field_Number><Field_Value>COMPLETE</Field_Value></API_Field>
+ <API_Field><Field_Number>1012</Field_Number><Field_Value>0021</Field_Value></API_Field>
+ <API_Field><Field_Number>7007</Field_Number><Field_Value>1116111333997614</Field_Value></API_Field>
+ <API_Field><Field_Number>8002</Field_Number><Field_Value>ETE MOTO</Field_Value></API_Field>
+ <API_Field><Field_Number>8006</Field_Number><Field_Value>TSTLA2</Field_Value></API_Field>
+ </Transaction></ProtoBase_Transaction_Batch>
+ "
+ end
end

0 comments on commit 1f394ca

Please sign in to comment.
Something went wrong with that request. Please try again.