diff --git a/CHANGELOG b/CHANGELOG index bae438126d3..acc08d5578f 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -7,7 +7,9 @@ * PayU: Fix a major bug with status types [melari] * SecureNet: Allow production transactions [duff] * Stripe: Allow a card_not_present_fee to be specified [melari] - +* Moneris: Add verification_value support [duff] +* SecureNet: Add INVOICENUM and INVOICEDESC optional fields [duff] +* Balanced: Make BalancedGateway::Error inherit from ActiveMerchantError [duff] == Version 1.36.0 (August 2, 2013) diff --git a/README.md b/README.md index 27c7805bc95..52409cbfb2e 100644 --- a/README.md +++ b/README.md @@ -166,7 +166,7 @@ The [ActiveMerchant Wiki](http://github.com/Shopify/active_merchant/wikis) conta * [SecurePayTech](http://www.securepaytech.com/) - NZ * [SkipJack](http://www.skipjack.com/) - US, CA * [Spreedly Core](https://spreedlycore.com/) - AD, AE, AT, AU, BD, BE, BG, BN, CA, CH, CY, CZ, DE, DK, EE, EG, ES, FI, FR, GB, GI, GR, HK, HU, ID, IE, IL, IM, IN, IS, IT, JO, KW, LB, LI, LK, LT, LU, LV, MC, MT, MU, MV, MX, MY, NL, NO, NZ, OM, PH, PL, PT, QA, RO, SA, SE, SG, SI, SK, SM, TR, TT, UM, US, VA, VN, ZA -* [Stripe](https://stripe.com/) - US +* [Stripe](https://stripe.com/) - US, CA, GB * [TransFirst](http://www.transfirst.com/) - US * [Transnational](http://www.tnbci.com/) - US * [TrustCommerce](http://www.trustcommerce.com/) - US diff --git a/activemerchant.gemspec b/activemerchant.gemspec index fbd4c89ab4a..e8edc9ea796 100644 --- a/activemerchant.gemspec +++ b/activemerchant.gemspec @@ -24,7 +24,7 @@ Gem::Specification.new do |s| s.add_dependency('builder', '>= 2.1.2', '< 4.0.0') s.add_dependency('json', '~> 1.8') s.add_dependency('active_utils', '~> 2.0') - s.add_dependency('nokogiri', "~> 1.6") + s.add_dependency('nokogiri', "~> 1.4") s.add_development_dependency('rake') s.add_development_dependency('mocha', '~> 0.13.0') diff --git a/lib/active_merchant/billing/gateways/balanced.rb b/lib/active_merchant/billing/gateways/balanced.rb index 5ff114a607d..49ea3019d78 100644 --- a/lib/active_merchant/billing/gateways/balanced.rb +++ b/lib/active_merchant/billing/gateways/balanced.rb @@ -69,7 +69,7 @@ class BalancedGateway < Gateway self.display_name = 'Balanced' self.money_format = :cents - class Error < StandardError + class Error < ActiveMerchant::ActiveMerchantError attr_reader :response def initialize(response, msg=nil) diff --git a/lib/active_merchant/billing/gateways/firstdata_e4.rb b/lib/active_merchant/billing/gateways/firstdata_e4.rb index ee9f6b4b445..1915ca758cc 100644 --- a/lib/active_merchant/billing/gateways/firstdata_e4.rb +++ b/lib/active_merchant/billing/gateways/firstdata_e4.rb @@ -116,7 +116,7 @@ def build_sale_or_authorization_request(money, credit_card_or_store_authorizatio if credit_card_or_store_authorization.is_a? String add_credit_card_token(xml, credit_card_or_store_authorization) else - add_credit_card(xml, credit_card_or_store_authorization) + add_credit_card(xml, credit_card_or_store_authorization, options) end add_customer_data(xml, options) @@ -138,7 +138,7 @@ def build_capture_or_credit_request(money, identification, options) def build_store_request(credit_card, options) xml = Builder::XmlMarkup.new - add_credit_card(xml, credit_card) + add_credit_card(xml, credit_card, options) add_customer_data(xml, options) xml.target! @@ -164,12 +164,23 @@ def add_amount(xml, money) xml.tag! "DollarAmount", amount(money) end - def add_credit_card(xml, credit_card) + def add_credit_card(xml, credit_card, options) xml.tag! "Card_Number", credit_card.number xml.tag! "Expiry_Date", expdate(credit_card) xml.tag! "CardHoldersName", credit_card.name xml.tag! "CardType", credit_card.brand + add_credit_card_verification_strings(xml, credit_card, options) + end + + def add_credit_card_verification_strings(xml, credit_card, options) + address = options[:billing_address] || options[:address] + if address + address_values = [] + [:address1, :zip, :city, :state, :country].each { |part| address_values << address[part].to_s } + xml.tag! "VerificationStr1", address_values.join("|") + end + if credit_card.verification_value? xml.tag! "CVD_Presence_Ind", "1" xml.tag! "VerificationStr2", credit_card.verification_value diff --git a/lib/active_merchant/billing/gateways/litle.rb b/lib/active_merchant/billing/gateways/litle.rb index f666266e639..83ce2bc28dc 100755 --- a/lib/active_merchant/billing/gateways/litle.rb +++ b/lib/active_merchant/billing/gateways/litle.rb @@ -112,11 +112,16 @@ def void(identification, options = {}) end end - def credit(money, identification_or_token, options = {}) - to_pass = build_credit_request(money, identification_or_token, options) + def refund(money, authorization, options = {}) + to_pass = build_credit_request(money, authorization, options) build_response(:credit, @litle.credit(to_pass)) end + def credit(money, authorization, options = {}) + deprecated CREDIT_DEPRECATION_MESSAGE + refund(money, authorization, options) + end + def store(creditcard_or_paypage_registration_id, options = {}) to_pass = create_token_hash(creditcard_or_paypage_registration_id, options) build_response(:registerToken, @litle.register_token_request(to_pass), %w(000 801 802)) diff --git a/lib/active_merchant/billing/gateways/moneris.rb b/lib/active_merchant/billing/gateways/moneris.rb index f6bc8bec1fd..74b3732d14f 100644 --- a/lib/active_merchant/billing/gateways/moneris.rb +++ b/lib/active_merchant/billing/gateways/moneris.rb @@ -128,6 +128,7 @@ def add_payment_source(post, source) else post[:pan] = source.number post[:expdate] = expdate(source) + post[:cvd_value] = source.verification_value if source.verification_value? end end @@ -155,6 +156,7 @@ def commit(action, parameters = {}) Response.new(successful?(response), message_from(response[:message]), response, :test => test?, + :cvv_result => response[:cvd_result_code].try(:last), :authorization => authorization_from(response) ) end @@ -192,14 +194,35 @@ def post_data(action, parameters = {}) root = xml.add_element("request") root.add_element("store_id").text = options[:login] root.add_element("api_token").text = options[:password] - transaction = root.add_element(action) + root.add_element(transaction_element(action, parameters)) + + xml.to_s + end + + def transaction_element(action, parameters) + transaction = REXML::Element.new(action) # Must add the elements in the correct order actions[action].each do |key| - transaction.add_element(key.to_s).text = parameters[key] unless parameters[key].blank? + if key == :cvd_info + transaction.add_element(cvd_element(parameters[:cvd_value])) + else + transaction.add_element(key.to_s).text = parameters[key] unless parameters[key].blank? + end end - xml.to_s + transaction + end + + def cvd_element(cvd_value) + element = REXML::Element.new('cvd_info') + if cvd_value + element.add_element('cvd_indicator').text = "1" + element.add_element('cvd_value').text = cvd_value + else + element.add_element('cvd_indicator').text = "0" + end + element end def message_from(message) @@ -219,8 +242,8 @@ def normalize(field) def actions { - "purchase" => [:order_id, :cust_id, :amount, :pan, :expdate, :crypt_type], - "preauth" => [:order_id, :cust_id, :amount, :pan, :expdate, :crypt_type], + "purchase" => [:order_id, :cust_id, :amount, :pan, :expdate, :crypt_type, :cvd_info], + "preauth" => [:order_id, :cust_id, :amount, :pan, :expdate, :crypt_type, :cvd_info], "command" => [:order_id], "refund" => [:order_id, :amount, :txn_number, :crypt_type], "indrefund" => [:order_id, :cust_id, :amount, :pan, :expdate, :crypt_type], diff --git a/lib/active_merchant/billing/gateways/secure_net.rb b/lib/active_merchant/billing/gateways/secure_net.rb index 4ee4a23a669..fd2aad4e282 100644 --- a/lib/active_merchant/billing/gateways/secure_net.rb +++ b/lib/active_merchant/billing/gateways/secure_net.rb @@ -182,8 +182,9 @@ def add_address(xml, creditcard, options) end def add_invoice(xml, options) - xml.tag! 'INVOICEDESC', options[:description] - xml.tag! 'INVOICENUM', 'inv-8' + xml.tag! 'NOTE', options[:description] if options[:description] + xml.tag! 'INVOICEDESC', options[:invoice_description] if options[:invoice_description] + xml.tag! 'INVOICENUM', options[:invoice_number] if options[:invoice_number] end def add_merchant_key(xml, options) diff --git a/lib/active_merchant/billing/gateways/stripe.rb b/lib/active_merchant/billing/gateways/stripe.rb index 95f97ad7ba6..10d6637c2ab 100644 --- a/lib/active_merchant/billing/gateways/stripe.rb +++ b/lib/active_merchant/billing/gateways/stripe.rb @@ -21,7 +21,7 @@ class StripeGateway < Gateway 'unchecked' => 'P' } - self.supported_countries = ['US', 'CA'] + self.supported_countries = ['US', 'CA', 'GB'] self.default_currency = 'USD' self.money_format = :cents self.supported_cardtypes = [:visa, :master, :american_express, :discover, :jcb, :diners_club] @@ -71,7 +71,7 @@ def refund(money, identification, options = {}) post = {:amount => amount(money)} commit_options = generate_meta(options) - MultiResponse.run do |r| + MultiResponse.run(:first) do |r| r.process { commit(:post, "charges/#{CGI.escape(identification)}/refund", post, commit_options) } return r unless options[:refund_fee_amount] diff --git a/lib/active_merchant/billing/gateways/webpay.rb b/lib/active_merchant/billing/gateways/webpay.rb index c291e94c222..07f8a82f500 100644 --- a/lib/active_merchant/billing/gateways/webpay.rb +++ b/lib/active_merchant/billing/gateways/webpay.rb @@ -21,10 +21,33 @@ def capture(money, credit_card, options = {}) raise NotImplementedError.new end + def refund(money, identification, options = {}) + post = {:amount => localized_amount(money)} + commit_options = generate_meta(options) + + MultiResponse.run do |r| + r.process { commit(:post, "charges/#{CGI.escape(identification)}/refund", post, commit_options) } + + return r unless options[:refund_fee_amount] + + r.process { fetch_application_fees(identification, commit_options) } + r.process { refund_application_fee(options[:refund_fee_amount], application_fee_from_response(r), commit_options) } + end + end + def refund_fee(identification, options, meta) raise NotImplementedError.new end + def localized_amount(money, currency = self.default_currency) + non_fractional_currency?(currency) ? (amount(money).to_f / 100).floor : amount(money) + end + + def add_amount(post, money, options) + post[:currency] = (options[:currency] || currency(money)).downcase + post[:amount] = localized_amount(money, post[:currency].upcase) + end + def json_error(raw_response) msg = 'Invalid response received from the WebPay API. Please contact support@webpay.jp if you continue to receive this message.' msg += " (The raw response returned by the API was #{raw_response.inspect})" diff --git a/lib/active_merchant/billing/response.rb b/lib/active_merchant/billing/response.rb index c02a22e7cd7..715855511bc 100644 --- a/lib/active_merchant/billing/response.rb +++ b/lib/active_merchant/billing/response.rb @@ -39,14 +39,18 @@ def initialize(success, message, params = {}, options = {}) end class MultiResponse < Response - def self.run(&block) - new.tap(&block) + def self.run(primary_response = :last, &block) + response = new.tap(&block) + response.primary_response = primary_response + response end attr_reader :responses + attr_writer :primary_response def initialize @responses = [] + @primary_response = :last end def process @@ -65,10 +69,14 @@ def success? @responses.all?{|r| r.success?} end + def primary_response + success? && @primary_response == :first ? @responses.first : @responses.last + end + %w(params message test authorization avs_result cvv_result test? fraud_review?).each do |m| class_eval %( def #{m} - (@responses.empty? ? nil : @responses.last.#{m}) + (@responses.empty? ? nil : primary_response.#{m}) end ) end diff --git a/test/fixtures.yml b/test/fixtures.yml index 14bdee08288..814be2c77f9 100644 --- a/test/fixtures.yml +++ b/test/fixtures.yml @@ -626,7 +626,7 @@ vindicia: password: PASSWORD webpay: - login: "vtUQeOtUnYr7PGCLQ96Ul4zqpDUO4sOE" + login: "test_secret_eHn4TTgsGguBcW764a2KA8Yd" # Working test credentials, no need to replace wirecard: diff --git a/test/remote/gateways/remote_authorize_net_test.rb b/test/remote/gateways/remote_authorize_net_test.rb index 7676e10286d..a18b04e3d36 100644 --- a/test/remote/gateways/remote_authorize_net_test.rb +++ b/test/remote/gateways/remote_authorize_net_test.rb @@ -106,6 +106,7 @@ def test_bad_login assert_equal Response, response.class assert_equal ["action", + "authorization_code", "avs_result_code", "card_code", "response_code", @@ -128,6 +129,7 @@ def test_using_test_request assert_equal Response, response.class assert_equal ["action", + "authorization_code", "avs_result_code", "card_code", "response_code", diff --git a/test/remote/gateways/remote_firstdata_e4_test.rb b/test/remote/gateways/remote_firstdata_e4_test.rb index 026e480fa65..6b402bb2968 100644 --- a/test/remote/gateways/remote_firstdata_e4_test.rb +++ b/test/remote/gateways/remote_firstdata_e4_test.rb @@ -78,4 +78,12 @@ def test_invalid_login assert_match /Unauthorized Request/, response.message assert_failure response end + + def test_response_contains_cvv_and_avs_results + response = @gateway.purchase(@amount, @credit_card, @options) + assert_success response + assert_equal 'M', response.cvv_result["code"] + assert_equal '1', response.avs_result["code"] + end + end diff --git a/test/remote/gateways/remote_litle_test.rb b/test/remote/gateways/remote_litle_test.rb index ef4a146017a..44bcdca4542 100755 --- a/test/remote/gateways/remote_litle_test.rb +++ b/test/remote/gateways/remote_litle_test.rb @@ -88,7 +88,7 @@ def test_unsuccessful_purchase assert_equal 'Insufficient Funds', response.message end - def test_authorization_capture_credit_void + def test_authorization_capture_refund_void #Auth assert auth_response = @gateway.authorize(10010, @credit_card1, @options) @@ -102,7 +102,7 @@ def test_authorization_capture_credit_void #Credit against the Capture capture_litle_txn_id = capture_response.params['litleOnlineResponse']['captureResponse']['litleTxnId'] - assert credit_response = @gateway.credit(10010, capture_litle_txn_id) + assert credit_response = @gateway.refund(10010, capture_litle_txn_id) assert_success credit_response assert_equal 'Approved', credit_response.message @@ -119,8 +119,8 @@ def test_capture_unsuccessful assert_equal 'No transaction found with specified litleTxnId', capture_response.message end - def test_credit_unsuccessful - assert credit_response = @gateway.credit(10010, 123456789012345360) + def test_refund_unsuccessful + assert credit_response = @gateway.refund(10010, 123456789012345360) assert_failure credit_response assert_equal 'No transaction found with specified litleTxnId', credit_response.message end diff --git a/test/remote/gateways/remote_moneris_test.rb b/test/remote/gateways/remote_moneris_test.rb index 45525b337e6..760a0e18b34 100644 --- a/test/remote/gateways/remote_moneris_test.rb +++ b/test/remote/gateways/remote_moneris_test.rb @@ -49,12 +49,12 @@ def test_successful_authorization_and_void assert_success void end - def test_successful_purchase_and_credit + def test_successful_purchase_and_refund purchase = @gateway.purchase(@amount, @credit_card, @options) assert_success purchase - credit = @gateway.credit(@amount, purchase.authorization) - assert_success credit + refund = @gateway.refund(@amount, purchase.authorization) + assert_success refund end def test_failed_purchase_from_error @@ -108,4 +108,16 @@ def test_failed_authorization_with_vault assert_failure response end + def test_cvv_match + assert response = @gateway.purchase(1039, @credit_card, @options) + assert_success response + assert_equal({'code' => 'M', 'message' => 'Match'}, response.cvv_result) + end + + def test_cvv_no_match + assert response = @gateway.purchase(1053, @credit_card, @options) + assert_success response + assert_equal({'code' => 'N', 'message' => 'No Match'}, response.cvv_result) + end + end diff --git a/test/remote/gateways/remote_webpay_test.rb b/test/remote/gateways/remote_webpay_test.rb index 53295eccec4..3aa0edf27ea 100644 --- a/test/remote/gateways/remote_webpay_test.rb +++ b/test/remote/gateways/remote_webpay_test.rb @@ -6,7 +6,8 @@ class RemoteWebpayTest < Test::Unit::TestCase def setup @gateway = WebpayGateway.new(fixtures(:webpay)) - @amount = 100 + @amount = 10000 + @refund_amount = 2000 @credit_card = credit_card('4242424242424242') @declined_card = credit_card('4000') @new_credit_card = credit_card('5105105105105100') @@ -24,6 +25,12 @@ def test_successful_purchase assert response.params["paid"] end + def test_appropriate_purchase_amount + assert response = @gateway.purchase(@amount, @credit_card, @options) + assert_success response + assert_equal @amount / 100, response.params["amount"] + end + def test_purchase_description assert response = @gateway.purchase(@amount, @credit_card, { :description => "TheDescription", :email => "email@example.com" }) assert_equal "TheDescription", response.params["description"], "Use the description if it's specified." @@ -59,8 +66,17 @@ def test_successful_refund assert response = @gateway.purchase(@amount, @credit_card, @options) assert_success response assert response.authorization - assert void = @gateway.refund(@amount - 20, response.authorization) + assert void = @gateway.refund(@refund_amount, response.authorization) + assert_success void + end + + def test_appropriate_refund_amount + assert response = @gateway.purchase(@amount, @credit_card, @options) + assert_success response + assert response.authorization + assert void = @gateway.refund(@refund_amount, response.authorization) assert_success void + assert_equal @refund_amount / 100, void.params["amount_refunded"] end def test_unsuccessful_refund @@ -97,7 +113,7 @@ def test_invalid_login gateway = WebpayGateway.new(:login => 'active_merchant_test') assert response = gateway.purchase(@amount, @credit_card, @options) assert_failure response - assert_equal "Invalid API key provided: active_merchant_test", response.message + assert_equal "Invalid API key provided. Check your API key is correct.", response.message end end diff --git a/test/unit/gateways/firstdata_e4_test.rb b/test/unit/gateways/firstdata_e4_test.rb index 622ea5c00a1..c6d387f3a4c 100644 --- a/test/unit/gateways/firstdata_e4_test.rb +++ b/test/unit/gateways/firstdata_e4_test.rb @@ -2,6 +2,8 @@ require 'yaml' class FirstdataE4Test < Test::Unit::TestCase + include CommStub + def setup @gateway = FirstdataE4Gateway.new( :login => "A00427-01", @@ -107,6 +109,14 @@ def test_cvv_result assert_equal 'M', response.cvv_result['code'] end + def test_requests_include_verification_string + stub_comms(:ssl_post) do + @gateway.purchase(@amount, @credit_card, @options) + end.check_request do |endpoint, data, headers| + assert_match "1234 My Street|K1C2N6|Ottawa|ON|CA", data + end.respond_with(successful_purchase_response) + end + private def successful_purchase_response diff --git a/test/unit/gateways/litle_test.rb b/test/unit/gateways/litle_test.rb index d43e295c744..e3166870e8f 100755 --- a/test/unit/gateways/litle_test.rb +++ b/test/unit/gateways/litle_test.rb @@ -593,31 +593,31 @@ def test_void_authorization_fail_schema assert_equal 'Error validating xml data against the schema', responseFrom.message end - def test_credit_pass + def test_refund_pass creditResponseObj = {'response' => '000', 'message' => 'pass', 'litleTxnId'=>'123456789012345678'} retObj = {'response'=>'0','creditResponse'=>creditResponseObj} LitleOnline::Communications.expects(:http_post => retObj.to_xml(:root => 'litleOnlineResponse')) identification = "1234;credit" - responseFrom = @gateway.credit(0, identification) + responseFrom = @gateway.refund(0, identification) assert_equal true, responseFrom.success? assert_equal '123456789012345678;credit', responseFrom.authorization end - def test_credit_fail + def test_refund_fail creditResponseObj = {'response' => '111', 'message' => 'fail', 'litleTxnId'=>'123456789012345678'} retObj = {'response'=>'0','creditResponse'=>creditResponseObj} LitleOnline::Communications.expects(:http_post => retObj.to_xml(:root => 'litleOnlineResponse')) identification = "1234;credit" - responseFrom = @gateway.credit(0, identification) + responseFrom = @gateway.refund(0, identification) assert_equal false, responseFrom.success? assert_equal '123456789012345678;credit', responseFrom.authorization end - def test_credit_fail_schema + def test_refund_fail_schema retObj = {'response'=>'1','message'=>'Error validating xml data against the schema'} LitleOnline::Communications.expects(:http_post => retObj.to_xml(:root => 'litleOnlineResponse')) identification = '1234;credit' - responseFrom = @gateway.credit(0, identification) + responseFrom = @gateway.refund(0, identification) assert_equal false, responseFrom.success? assert_equal 'Error validating xml data against the schema', responseFrom.message end @@ -736,6 +736,13 @@ def test_that_setting_a_wiredump_device_on_the_gateway_sets_the_little_logger_up end end + def test_deprecated_credit + @gateway.expects(:refund).returns true + assert_deprecation_warning(Gateway::CREDIT_DEPRECATION_MESSAGE, @gateway) do + assert response = @gateway.credit(0, '123') + end + end + private def with_litle_configuration_restoration(&block) diff --git a/test/unit/gateways/moneris_test.rb b/test/unit/gateways/moneris_test.rb index 74e263948fa..fbd0ef4f366 100644 --- a/test/unit/gateways/moneris_test.rb +++ b/test/unit/gateways/moneris_test.rb @@ -1,6 +1,8 @@ require 'test_helper' class MonerisTest < Test::Unit::TestCase + include CommStub + def setup Base.mode = :test @@ -165,6 +167,26 @@ def test_failed_authorization_with_vault assert_failure response end + def test_passing_cvv + @credit_card.verification_value = "452" + stub_comms do + @gateway.purchase(@amount, @credit_card, @options) + end.check_request do |endpoint, data, headers| + assert_match(%r{cvd_indicator>1<}, data) + assert_match(%r{cvd_value>452<}, data) + end.respond_with(successful_purchase_response) + end + + def test_no_cvv_specified + @credit_card.verification_value = "" + stub_comms do + @gateway.purchase(@amount, @credit_card, @options) + end.check_request do |endpoint, data, headers| + assert_match(%r{cvd_indicator>0<}, data) + assert_no_match(%r{cvd_value>}, data) + end.respond_with(successful_purchase_response) + end + private def successful_purchase_response @@ -262,10 +284,10 @@ def successful_update_response def xml_purchase_fixture - 'store1yesguy1.01424242424242424203037order1' + 'store1yesguy1.01424242424242424203037order10' end def xml_capture_fixture - 'store1yesguy1.01424242424242424203037order1' + 'store1yesguy1.01424242424242424203037order10' end end diff --git a/test/unit/gateways/secure_net_test.rb b/test/unit/gateways/secure_net_test.rb index 1a14fc1a4bd..4221f602f19 100644 --- a/test/unit/gateways/secure_net_test.rb +++ b/test/unit/gateways/secure_net_test.rb @@ -1,6 +1,8 @@ require 'test_helper' class SecureNetTest < Test::Unit::TestCase + include CommStub + def setup @gateway = SecureNetGateway.new( :login => 'X', @@ -126,6 +128,27 @@ def test_failure_without_response_reason_text end end + def test_passes_optional_fields + options = { description: "Good Stuff", invoice_description: "Sweet Invoice", invoice_number: "48" } + stub_comms do + @gateway.purchase(@amount, @credit_card, options) + end.check_request do |endpoint, data, headers| + assert_match(%r{NOTE>Good Stuff<}, data) + assert_match(%r{INVOICEDESC>Sweet Invoice<}, data) + assert_match(%r{INVOICENUM>48<}, data) + end.respond_with(successful_purchase_response) + end + + def test_only_passes_optional_fields_if_specified + stub_comms do + @gateway.purchase(@amount, @credit_card, {}) + end.check_request do |endpoint, data, headers| + assert_no_match(%r{NOTE}, data) + assert_no_match(%r{INVOICEDESC}, data) + assert_no_match(%r{INVOICENUM}, data) + end.respond_with(successful_purchase_response) + end + private diff --git a/test/unit/gateways/stripe_test.rb b/test/unit/gateways/stripe_test.rb index 4e7cfacfbcb..bf579bd4883 100644 --- a/test/unit/gateways/stripe_test.rb +++ b/test/unit/gateways/stripe_test.rb @@ -87,6 +87,17 @@ def test_successful_refund_with_refund_fee_amount assert_success response end + def test_refund_with_fee_response_gives_a_charge_authorization + s = sequence("request") + @gateway.expects(:ssl_request).returns(successful_partially_refunded_response).in_sequence(s) + @gateway.expects(:ssl_request).returns(successful_application_fee_list_response).in_sequence(s) + @gateway.expects(:ssl_request).returns(successful_refunded_application_fee_response).in_sequence(s) + + assert response = @gateway.refund(@refund_amount, 'ch_test_charge', :refund_fee_amount => 100) + assert_success response + assert_equal 'ch_test_charge', response.authorization + end + def test_unsuccessful_refund_with_refund_fee_amount_when_application_fee_id_not_found s = sequence("request") @gateway.expects(:ssl_request).returns(successful_partially_refunded_response).in_sequence(s) diff --git a/test/unit/gateways/webpay_test.rb b/test/unit/gateways/webpay_test.rb index 885691e0083..1e6d9406c9c 100644 --- a/test/unit/gateways/webpay_test.rb +++ b/test/unit/gateways/webpay_test.rb @@ -5,8 +5,8 @@ def setup @gateway = WebpayGateway.new(:login => 'login') @credit_card = credit_card() - @amount = 400 - @refund_amount = 200 + @amount = 40000 + @refund_amount = 20000 @options = { :billing_address => address(), @@ -26,6 +26,17 @@ def test_successful_purchase assert response.test? end + def test_appropiate_purchase_amount + @gateway.expects(:ssl_request).returns(successful_purchase_response) + + response = @gateway.purchase(@amount, @credit_card, @options) + assert_instance_of Response, response + assert_success response + + assert_equal @amount / 100, response.params["amount"] + end + + def test_successful_void @gateway.expects(:ssl_request).returns(successful_purchase_response(true)) diff --git a/test/unit/multi_response_test.rb b/test/unit/multi_response_test.rb index 93542d0acef..18a3b34dd88 100644 --- a/test/unit/multi_response_test.rb +++ b/test/unit/multi_response_test.rb @@ -72,6 +72,65 @@ def test_proxies_last_request assert !m.fraud_review? end + def test_proxies_first_request_if_marked + m = MultiResponse.new + m.primary_response = :first + + r1 = Response.new( + true, + "1", + {"one" => 1}, + :test => true, + :authorization => "auth1", + :avs_result => {:code => "AVS1"}, + :cvv_result => "CVV1", + :fraud_review => true + ) + m.process{r1} + assert_equal({"one" => 1}, m.params) + assert_equal "1", m.message + assert m.test + assert_equal "auth1", m.authorization + assert_equal "AVS1", m.avs_result["code"] + assert_equal "CVV1", m.cvv_result["code"] + assert m.test? + assert m.fraud_review? + + r2 = Response.new( + true, + "2", + {"two" => 2}, + :test => false, + :authorization => "auth2", + :avs_result => {:code => "AVS2"}, + :cvv_result => "CVV2", + :fraud_review => false + ) + m.process{r2} + assert_equal({"one" => 1}, m.params) + assert_equal "1", m.message + assert m.test + assert_equal "auth1", m.authorization + assert_equal "AVS1", m.avs_result["code"] + assert_equal "CVV1", m.cvv_result["code"] + assert m.test? + assert m.fraud_review? + end + + def test_primary_response_always_returns_the_last_response_on_failure + m = MultiResponse.new + m.primary_response = :first + + r1 = Response.new(true, "1", {}, {}) + r2 = Response.new(false, "2", {}, {}) + r3 = Response.new(false, "3", {}, {}) + m.process{r1} + m.process{r2} + m.process{r3} + assert_equal r2, m.primary_response + assert_equal '2', m.message + end + def test_stops_processing_upon_failure r1 = Response.new(false, "1", {}) r2 = Response.new(true, "2", {})