Skip to content
This repository

Add Gateway for Moneris US #313

Merged
merged 1 commit into from about 2 years ago

2 participants

Michael Wood Nathaniel Talbott
Michael Wood

No description provided.

Nathaniel Talbott
Collaborator

Is Moneris US a completely different gateway than the other Moneris gateway we already support?

Michael Wood

Yes, it is a completely different gateway.

Nathaniel Talbott
Collaborator

I'm getting errors when running the unit tests:

  1) Error:
test_capture_is_valid_xml(MonerisUsTest):
NoMethodError: undefined method `each' for nil:NilClass
    /Users/ntalbott/git/active_merchant/lib/active_merchant/billing/gateways/moneris_us.rb:172:in `post_data'
    ./test/unit/gateways/moneris_us_test.rb:94:in `send'
    ./test/unit/gateways/moneris_us_test.rb:94:in `test_capture_is_valid_xml'
    /Users/ntalbott/.rbenv/versions/1.8.7-p352/lib/ruby/gems/1.8/gems/mocha-0.9.12/lib/mocha/integration/test_unit/ruby_version_186_and_above.rb:22:in `__send__'
    /Users/ntalbott/.rbenv/versions/1.8.7-p352/lib/ruby/gems/1.8/gems/mocha-0.9.12/lib/mocha/integration/test_unit/ruby_version_186_and_above.rb:22:in `run'

  2) Error:
test_purchase_is_valid_xml(MonerisUsTest):
NoMethodError: undefined method `each' for nil:NilClass
    /Users/ntalbott/git/active_merchant/lib/active_merchant/billing/gateways/moneris_us.rb:172:in `post_data'
    ./test/unit/gateways/moneris_us_test.rb:79:in `send'
    ./test/unit/gateways/moneris_us_test.rb:79:in `test_purchase_is_valid_xml'
    /Users/ntalbott/.rbenv/versions/1.8.7-p352/lib/ruby/gems/1.8/gems/mocha-0.9.12/lib/mocha/integration/test_unit/ruby_version_186_and_above.rb:22:in `__send__'
    /Users/ntalbott/.rbenv/versions/1.8.7-p352/lib/ruby/gems/1.8/gems/mocha-0.9.12/lib/mocha/integration/test_unit/ruby_version_186_and_above.rb:22:in `run'

I'm also getting a failure when running remote tests:

  1) Failure:
test_successful_authorization_and_void(MonerisUsRemoteTest)
    [test/remote/gateways/remote_moneris_us_test.rb:50:in `test_successful_authorization_and_void'
     /Users/ntalbott/.rbenv/versions/1.8.7-p352/lib/ruby/gems/1.8/gems/mocha-0.9.12/lib/mocha/integration/test_unit/ruby_version_186_and_above.rb:22:in `__send__'
     /Users/ntalbott/.rbenv/versions/1.8.7-p352/lib/ruby/gems/1.8/gems/mocha-0.9.12/lib/mocha/integration/test_unit/ruby_version_186_and_above.rb:22:in `run']:
Response failed: #<ActiveMerchant::Billing::Response:0x10a6f5440 @authorization=nil, @success=nil, @cvv_result={"code"=>nil, "message"=>nil}, @params={"trans_id"=>nil, "ticket"=>nil, "card_type"=>nil, "response_code"=>nil, "timed_out"=>nil, "iso"=>nil, "trans_time"=>nil, "receipt_id"=>nil, "trans_date"=>nil, "complete"=>false, "trans_amount"=>nil, "trans_type"=>nil, "auth_code"=>nil, "reference_num"=>nil, "bank_totals"=>nil, "message"=>"Invalid follow_up_amount number"}, @fraud_review=nil, @message="Invalid follow_up_amount number", @avs_result={"code"=>nil, "postal_match"=>nil, "street_match"=>nil, "message"=>nil}, @test=true>.
<nil> is not true.

The code looks solid, so if you can get me fixes for the tests, I'll be happy to merge. Thanks!

Michael Wood

Hi @ntalbott I've fixed up the Unit and Remote tests.

I also fixed a failing test for the Moneris Canada gateway. Recent changes to Moneris no longer allow a void on a preauthorization. You must capture a $0.00 on the auth to in effect void it.

The Moneris Canada remote test fix is also in this pull request if that is okay.

Nathaniel Talbott
Collaborator

Actually would be best to split the void change into another PR; I think we'll actually want to abstract away the zero-dollar capture behind the void method.

Michael Wood

One issue is the void method behaves differently depending on whether the original transaction was an auth or purchase/capture. And we only know the authorization of the transaction, not the type. One solution may be to create a void_authorization method that does the capture of $0.00.

Also, is it possible to remove/change a commit from a pull request?

Michael Wood

Another possibility is to remove that test altogether since only captures and purchases can be voided.

Nathaniel Talbott
Collaborator

The PR is based on the branch, so if you force push a different set of commits into the branch, the PR will update.

If the type of the transaction matters, maybe we should add additional info to the authorization string to indicate that?

Michael Wood

Done, void the authorization commit removed. I'll make a new pull request for these changes.

Nathaniel Talbott
Collaborator

Still getting a remote failure:

  1) Failure:
test_successful_authorization_and_void(MonerisUsRemoteTest)
    [test/remote/gateways/remote_moneris_us_test.rb:50:in `test_successful_authorization_and_void'
     /Users/ntalbott/.rbenv/versions/1.8.7-p358/lib/ruby/gems/1.8/gems/mocha-0.9.12/lib/mocha/integration/test_unit/ruby_version_186_and_above.rb:22:in `__send__'
     /Users/ntalbott/.rbenv/versions/1.8.7-p358/lib/ruby/gems/1.8/gems/mocha-0.9.12/lib/mocha/integration/test_unit/ruby_version_186_and_above.rb:22:in `run']:
Response failed: #<ActiveMerchant::Billing::Response:0x106929210 @fraud_review=nil, @avs_result={"street_match"=>nil, "message"=>nil, "postal_match"=>nil, "code"=>nil}, @test=true, @message="Invalid follow_up_amount number", @authorization=nil, @success=nil, @cvv_result={"message"=>nil, "code"=>nil}, @params={"message"=>"Invalid follow_up_amount number", "bank_totals"=>nil, "receipt_id"=>nil, "trans_type"=>nil, "trans_date"=>nil, "reference_num"=>nil, "trans_amount"=>nil, "response_code"=>nil, "timed_out"=>nil, "iso"=>nil, "auth_code"=>nil, "complete"=>false, "ticket"=>nil, "trans_time"=>nil, "card_type"=>nil, "trans_id"=>nil}>.
<nil> is not true.
Michael Wood

Fix added back in (curses that force push!)

Nathaniel Talbott
Collaborator

Working beautifully, just one last request: can you squash this all into a single commit? I'll merge ASAP once I have that. Thanks!

Michael Wood Add Gateway for Moneris US
Fix unit tests for Moneris US XML

Moneris US cannot void a preauthorization
Bring this in line with the way Moneris Canada does things.
2faffc1
Michael Wood

Hi, @ntalbott squashed them into a single commit! Interesting. I have never done something like that before, and was just wondering what the benefit is?

Nathaniel Talbott
Collaborator

With a large open source project with a lot of contributors, it's really handy to keep the history as clean as possible. Makes it much easier to see at a glance what's gone on and who has done what.

Nathaniel Talbott ntalbott merged commit a63697a into from March 23, 2012
Nathaniel Talbott ntalbott closed this March 23, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Mar 23, 2012
Michael Wood Add Gateway for Moneris US
Fix unit tests for Moneris US XML

Moneris US cannot void a preauthorization
Bring this in line with the way Moneris Canada does things.
2faffc1
This page is out of date. Refresh to see the latest.
1  README.md
Source Rendered
@@ -111,6 +111,7 @@ The [ActiveMerchant Wiki](http://github.com/Shopify/active_merchant/wikis) conta
111 111
 * [MerchantWare](http://merchantwarehouse.com/merchantware) - US
112 112
 * [Modern Payments](http://www.modpay.com) - US
113 113
 * [Moneris](http://www.moneris.com/) - CA
  114
+* [Moneris US](http://www.monerisusa.com/) - US
114 115
 * [NABTransact](http://www.nab.com.au/nabtransact/) - AU
115 116
 * [Netaxept](http://www.betalingsterminal.no/Netthandel-forside) - NO, DK, SE, FI
116 117
 * [NetRegistry](http://www.netregistry.com.au) - AU
211  lib/active_merchant/billing/gateways/moneris_us.rb
... ...
@@ -0,0 +1,211 @@
  1
+require 'rexml/document'
  2
+
  3
+module ActiveMerchant #:nodoc:
  4
+  module Billing #:nodoc:
  5
+
  6
+    # To learn more about the Moneris (US) gateway, please contact 
  7
+    # ussales@moneris.com for a copy of their integration guide. For 
  8
+    # information on remote testing, please see "Test Environment Penny Value 
  9
+    # Response Table", and "Test Environment eFraud (AVS and CVD) Penny 
  10
+    # Response Values", available at Moneris' {eSelect Plus Documentation 
  11
+    # Centre}[https://www3.moneris.com/connect/en/documents/index.html].
  12
+    class MonerisUsGateway < Gateway
  13
+      TEST_URL = 'https://esplusqa.moneris.com/gateway_us/servlet/MpgRequest'
  14
+      LIVE_URL = 'https://esplus.moneris.com/gateway_us/servlet/MpgRequest'
  15
+      
  16
+      self.supported_countries = ['US']
  17
+      self.supported_cardtypes = [:visa, :master, :american_express, :diners_club, :discover]
  18
+      self.homepage_url = 'http://www.monerisusa.com/'
  19
+      self.display_name = 'Moneris (US)'
  20
+  
  21
+      # login is your Store ID
  22
+      # password is your API Token
  23
+      def initialize(options = {})
  24
+        requires!(options, :login, :password)
  25
+        @options = { :crypt_type => 7 }.update(options)
  26
+        super      
  27
+      end      
  28
+    
  29
+      # Referred to as "PreAuth" in the Moneris integration guide, this action 
  30
+      # verifies and locks funds on a customer's card, which then must be 
  31
+      # captured at a later date.
  32
+      # 
  33
+      # Pass in +order_id+ and optionally a +customer+ parameter.
  34
+      def authorize(money, creditcard, options = {})
  35
+        debit_commit 'us_preauth', money, creditcard, options        
  36
+      end
  37
+      
  38
+      # This action verifies funding on a customer's card, and readies them for 
  39
+      # deposit in a merchant's account.
  40
+      # 
  41
+      # Pass in <tt>order_id</tt> and optionally a <tt>customer</tt> parameter
  42
+      def purchase(money, creditcard, options = {})
  43
+        debit_commit 'us_purchase', money, creditcard, options
  44
+      end
  45
+     
  46
+      # This method retrieves locked funds from a customer's account (from a 
  47
+      # PreAuth) and prepares them for deposit in a merchant's account.
  48
+      # 
  49
+      # Note: Moneris requires both the order_id and the transaction number of
  50
+      # the original authorization.  To maintain the same interface as the other
  51
+      # gateways the two numbers are concatenated together with a ; separator as
  52
+      # the authorization number returned by authorization
  53
+      def capture(money, authorization, options = {})
  54
+        commit 'us_completion', crediting_params(authorization, :comp_amount => amount(money))
  55
+      end
  56
+
  57
+      # Voiding requires the original transaction ID and order ID of some open 
  58
+      # transaction. Closed transactions must be refunded. Note that the only 
  59
+      # methods which may be voided are +capture+ and +purchase+.
  60
+      # 
  61
+      # Concatenate your transaction number and order_id by using a semicolon 
  62
+      # (';'). This is to keep the Moneris interface consistent with other 
  63
+      # gateways. (See +capture+ for details.)
  64
+      def void(authorization, options = {})
  65
+        commit 'us_purchasecorrection', crediting_params(authorization)
  66
+      end
  67
+      
  68
+      # Performs a refund. This method requires that the original transaction 
  69
+      # number and order number be included. Concatenate your transaction 
  70
+      # number and order_id by using a semicolon (';'). This is to keep the 
  71
+      # Moneris interface consistent with other gateways. (See +capture+ for 
  72
+      # details.)
  73
+      def credit(money, authorization, options = {})
  74
+        deprecated CREDIT_DEPRECATION_MESSAGE
  75
+        refund(money, authorization, options)
  76
+      end
  77
+   
  78
+      def refund(money, authorization, options = {})
  79
+        commit 'us_refund', crediting_params(authorization, :amount => amount(money))
  80
+      end
  81
+
  82
+      def test?
  83
+        @options[:test] || super
  84
+      end
  85
+    private # :nodoc: all
  86
+    
  87
+      def expdate(creditcard)
  88
+        sprintf("%.4i", creditcard.year)[-2..-1] + sprintf("%.2i", creditcard.month)
  89
+      end
  90
+      
  91
+      def debit_commit(commit_type, money, creditcard, options)
  92
+        requires!(options, :order_id)
  93
+        commit(commit_type, debit_params(money, creditcard, options))
  94
+      end
  95
+      
  96
+      # Common params used amongst the +purchase+ and +authorization+ methods
  97
+      def debit_params(money, creditcard, options = {})
  98
+        {
  99
+          :order_id   => options[:order_id],
  100
+          :cust_id    => options[:customer],
  101
+          :amount     => amount(money),
  102
+          :pan        => creditcard.number,
  103
+          :expdate    => expdate(creditcard),
  104
+          :crypt_type => options[:crypt_type] || @options[:crypt_type]
  105
+        }
  106
+      end
  107
+      
  108
+      # Common params used amongst the +credit+, +void+ and +capture+ methods
  109
+      def crediting_params(authorization, options = {})
  110
+        {
  111
+          :txn_number => split_authorization(authorization).first, 
  112
+          :order_id   => split_authorization(authorization).last, 
  113
+          :crypt_type => options[:crypt_type] || @options[:crypt_type]
  114
+        }.merge(options)
  115
+      end
  116
+      
  117
+      # Splits an +authorization+ param and retrives the order id and 
  118
+      # transaction number in that order.
  119
+      def split_authorization(authorization)
  120
+        if authorization.nil? || authorization.empty? || authorization !~ /;/
  121
+          raise ArgumentError, 'You must include a valid authorization code (e.g. "1234;567")' 
  122
+        else
  123
+          authorization.split(';')
  124
+        end
  125
+      end
  126
+  
  127
+      def commit(action, parameters = {})
  128
+        response = parse(ssl_post(test? ? TEST_URL : LIVE_URL, post_data(action, parameters)))
  129
+
  130
+        Response.new(successful?(response), message_from(response[:message]), response,
  131
+          :test          => test?,
  132
+          :authorization => authorization_from(response)
  133
+        )
  134
+      end
  135
+      
  136
+      # Generates a Moneris authorization string of the form 'trans_id;receipt_id'.
  137
+      def authorization_from(response = {})
  138
+        if response[:trans_id] && response[:receipt_id]
  139
+          "#{response[:trans_id]};#{response[:receipt_id]}"
  140
+        end
  141
+      end
  142
+      
  143
+      # Tests for a successful response from Moneris' servers
  144
+      def successful?(response)
  145
+        response[:response_code] && 
  146
+        response[:complete] && 
  147
+        (0..49).include?(response[:response_code].to_i)
  148
+      end
  149
+                                               
  150
+      def parse(xml)
  151
+        response = { :message => "Global Error Receipt", :complete => false }
  152
+        hashify_xml!(xml, response)
  153
+        response
  154
+      end
  155
+      
  156
+      def hashify_xml!(xml, response)
  157
+        xml = REXML::Document.new(xml)
  158
+        return if xml.root.nil?
  159
+        xml.elements.each('//receipt/*') do |node|
  160
+          response[node.name.underscore.to_sym] = normalize(node.text)
  161
+        end
  162
+      end
  163
+
  164
+      def post_data(action, parameters = {})
  165
+        xml   = REXML::Document.new
  166
+        root  = xml.add_element("request")
  167
+        root.add_element("store_id").text  = options[:login]
  168
+        root.add_element("api_token").text = options[:password]
  169
+        transaction = root.add_element(action)
  170
+
  171
+        # Must add the elements in the correct order
  172
+        actions[action].each do |key|
  173
+          transaction.add_element(key.to_s).text = parameters[key] unless parameters[key].blank?
  174
+        end
  175
+        
  176
+        xml.to_s
  177
+      end
  178
+    
  179
+      def message_from(message)
  180
+        return 'Unspecified error' if message.blank?
  181
+        message.gsub(/[^\w]/, ' ').split.join(" ").capitalize
  182
+      end
  183
+
  184
+      # Make a Ruby type out of the response string
  185
+      def normalize(field)
  186
+        case field
  187
+          when "true"     then true
  188
+          when "false"    then false
  189
+          when '', "null" then nil
  190
+          else field
  191
+        end        
  192
+      end
  193
+      
  194
+      def actions
  195
+        {
  196
+          "us_purchase"           => [:order_id, :cust_id, :amount, :pan, :expdate, :crypt_type],
  197
+          "us_preauth"            => [:order_id, :cust_id, :amount, :pan, :expdate, :crypt_type],
  198
+          "us_refund"             => [:order_id, :amount, :txn_number, :crypt_type],
  199
+          "us_ind_refund"         => [:order_id, :cust_id, :amount, :pan, :expdate, :crypt_type],
  200
+          "us_completion"         => [:order_id, :comp_amount, :txn_number, :crypt_type],
  201
+          "us_purchasecorrection" => [:order_id, :txn_number, :crypt_type],
  202
+          "us_cavv_purchase"      => [:order_id, :cust_id, :amount, :pan, :expdate, :cavv],
  203
+          "us_cavv_preauth"       => [:order_id, :cust_id, :amount, :pan, :expdate, :cavv],
  204
+          "us_batchcloseall"      => [],
  205
+          "us_opentotals"         => [:ecr_number],
  206
+          "us_batchclose"         => [:ecr_number]
  207
+        }
  208
+      end
  209
+    end
  210
+  end
  211
+end
4  test/fixtures.yml
@@ -168,6 +168,10 @@ moneris:
168 168
   login: store1
169 169
   password: yesguy
170 170
 
  171
+moneris_us:
  172
+  login: monusqa002
  173
+  password: qatoken
  174
+
171 175
 #Working credentials, no need to replace
172 176
 nab_transact:
173 177
   login: ABC0001
84  test/remote/gateways/remote_moneris_us_test.rb
... ...
@@ -0,0 +1,84 @@
  1
+require 'test_helper'
  2
+
  3
+class MonerisUsRemoteTest < Test::Unit::TestCase
  4
+  def setup
  5
+    Base.mode = :test
  6
+
  7
+    @gateway = MonerisUsGateway.new(fixtures(:moneris_us))
  8
+    @amount = 100
  9
+    @credit_card = credit_card('4242424242424242')
  10
+    @options = { 
  11
+      :order_id => generate_unique_id,
  12
+      :billing_address => address,
  13
+      :description => 'Store Purchase'
  14
+    }
  15
+  end
  16
+  
  17
+  def test_successful_purchase
  18
+    assert response = @gateway.purchase(@amount, @credit_card, @options)
  19
+    assert_success response
  20
+    assert_equal 'Approved', response.message
  21
+    assert_false response.authorization.blank?
  22
+  end
  23
+  
  24
+  def test_successful_authorization
  25
+    response = @gateway.authorize(@amount, @credit_card, @options)
  26
+    assert_success response
  27
+    assert_false response.authorization.blank?
  28
+  end
  29
+
  30
+  def test_failed_authorization
  31
+    response = @gateway.authorize(105, @credit_card, @options)
  32
+    assert_failure response
  33
+  end
  34
+
  35
+  def test_successful_authorization_and_capture
  36
+    response = @gateway.authorize(@amount, @credit_card, @options)
  37
+    assert_success response
  38
+    assert response.authorization
  39
+
  40
+    response = @gateway.capture(@amount, response.authorization)
  41
+    assert_success response
  42
+  end
  43
+  
  44
+  def test_successful_authorization_and_void
  45
+    response = @gateway.authorize(@amount, @credit_card, @options)
  46
+    assert_success response
  47
+    assert response.authorization
  48
+    
  49
+    # Moneris cannot void a preauthorization
  50
+    # You must capture the auth transaction with an amount of $0.00
  51
+    void = @gateway.capture(0, response.authorization)
  52
+    assert_success void
  53
+  end
  54
+  
  55
+  def test_successful_purchase_and_void
  56
+    purchase = @gateway.purchase(@amount, @credit_card, @options)
  57
+    assert_success purchase
  58
+    
  59
+    void = @gateway.void(purchase.authorization)
  60
+    assert_success void
  61
+  end
  62
+  
  63
+  def test_failed_purchase_and_void
  64
+    purchase = @gateway.purchase(101, @credit_card, @options)
  65
+    assert_failure purchase
  66
+    
  67
+    void = @gateway.void(purchase.authorization)
  68
+    assert_failure void
  69
+  end
  70
+  
  71
+  def test_successful_purchase_and_credit
  72
+    purchase = @gateway.purchase(@amount, @credit_card, @options)
  73
+    assert_success purchase
  74
+    
  75
+    credit = @gateway.credit(@amount, purchase.authorization)
  76
+    assert_success credit
  77
+  end
  78
+
  79
+  def test_failed_purchase_from_error
  80
+    assert response = @gateway.purchase(150, @credit_card, @options)
  81
+    assert_failure response
  82
+    assert_equal 'Declined', response.message
  83
+  end
  84
+end
3  test/unit/base_test.rb
@@ -11,7 +11,8 @@ def teardown
11 11
   
12 12
   def test_should_return_a_new_gateway_specified_by_symbol_name
13 13
     assert_equal BogusGateway,         Base.gateway(:bogus)
14  
-    assert_equal MonerisGateway,       Base.gateway(:moneris) 
  14
+    assert_equal MonerisGateway,       Base.gateway(:moneris)
  15
+    assert_equal MonerisUsGateway,     Base.gateway(:moneris_us)
15 16
     assert_equal AuthorizeNetGateway,  Base.gateway(:authorize_net)
16 17
     assert_equal UsaEpayGateway,       Base.gateway(:usa_epay)
17 18
     assert_equal LinkpointGateway,     Base.gateway(:linkpoint)
172  test/unit/gateways/moneris_us_test.rb
... ...
@@ -0,0 +1,172 @@
  1
+require 'test_helper'
  2
+
  3
+class MonerisUsTest < Test::Unit::TestCase
  4
+  def setup
  5
+    Base.mode = :test
  6
+    
  7
+    @gateway = MonerisUsGateway.new(
  8
+      :login => 'monusqa002',
  9
+      :password => 'qatoken'
  10
+    )
  11
+
  12
+    @amount = 100
  13
+    @credit_card = credit_card('4242424242424242')
  14
+    @options = { :order_id => '1', :billing_address => address }
  15
+  end
  16
+
  17
+  def test_successful_purchase
  18
+    @gateway.expects(:ssl_post).returns(successful_purchase_response)
  19
+    
  20
+    assert response = @gateway.authorize(100, @credit_card, @options)
  21
+    assert_success response
  22
+    assert_equal '58-0_3;1026.1', response.authorization
  23
+  end
  24
+
  25
+  def test_failed_purchase
  26
+    @gateway.expects(:ssl_post).returns(failed_purchase_response)
  27
+    
  28
+    assert response = @gateway.authorize(100, @credit_card, @options)
  29
+    assert_failure response
  30
+  end
  31
+  
  32
+  def test_deprecated_credit
  33
+    @gateway.expects(:ssl_post).with(anything, regexp_matches(/txn_number>123<\//), anything).returns("")
  34
+    @gateway.expects(:parse).returns({})
  35
+    assert_deprecation_warning(Gateway::CREDIT_DEPRECATION_MESSAGE, @gateway) do
  36
+      @gateway.credit(@amount, "123;456", @options)
  37
+    end
  38
+  end
  39
+
  40
+  def test_refund
  41
+    @gateway.expects(:ssl_post).with(anything, regexp_matches(/txn_number>123<\//), anything).returns("")
  42
+    @gateway.expects(:parse).returns({})
  43
+    @gateway.refund(@amount, "123;456", @options)
  44
+  end
  45
+
  46
+  def test_amount_style
  47
+   assert_equal '10.34', @gateway.send(:amount, 1034)
  48
+   
  49
+   assert_raise(ArgumentError) do
  50
+     @gateway.send(:amount, '10.34')
  51
+   end
  52
+  end
  53
+  
  54
+  def test_purchase_is_valid_xml
  55
+
  56
+   params = { 
  57
+     :order_id => "order1",
  58
+     :amount => "1.01",
  59
+     :pan => "4242424242424242",
  60
+     :expdate => "0303",
  61
+     :crypt_type => 7,
  62
+   }
  63
+
  64
+   assert data = @gateway.send(:post_data, 'us_preauth', params)
  65
+   assert REXML::Document.new(data)
  66
+   assert_equal xml_capture_fixture.size, data.size
  67
+  end  
  68
+
  69
+  def test_purchase_is_valid_xml
  70
+
  71
+   params = {
  72
+     :order_id => "order1",
  73
+     :amount => "1.01",
  74
+     :pan => "4242424242424242",
  75
+     :expdate => "0303",
  76
+     :crypt_type => 7,
  77
+   }
  78
+
  79
+   assert data = @gateway.send(:post_data, 'us_purchase', params)
  80
+   assert REXML::Document.new(data)
  81
+   assert_equal xml_purchase_fixture.size, data.size
  82
+  end
  83
+
  84
+  def test_capture_is_valid_xml
  85
+ 
  86
+   params = {
  87
+     :order_id => "order1",
  88
+     :amount => "1.01",
  89
+     :pan => "4242424242424242",
  90
+     :expdate => "0303",
  91
+     :crypt_type => 7,
  92
+   }
  93
+
  94
+   assert data = @gateway.send(:post_data, 'us_preauth', params)
  95
+   assert REXML::Document.new(data)
  96
+   assert_equal xml_capture_fixture.size, data.size
  97
+  end  
  98
+  
  99
+  def test_supported_countries
  100
+    assert_equal ['US'], MonerisUsGateway.supported_countries
  101
+  end
  102
+  
  103
+  def test_supported_card_types
  104
+    assert_equal [:visa, :master, :american_express, :diners_club, :discover], MonerisUsGateway.supported_cardtypes
  105
+  end
  106
+
  107
+  def test_should_raise_error_if_transaction_param_empty_on_credit_request
  108
+    [nil, '', '1234'].each do |invalid_transaction_param|
  109
+      assert_raise(ArgumentError) { @gateway.void(invalid_transaction_param) }
  110
+    end
  111
+  end
  112
+  
  113
+  private  
  114
+  def successful_purchase_response
  115
+    <<-RESPONSE
  116
+<?xml version="1.0"?>
  117
+<response>
  118
+  <receipt>
  119
+    <ReceiptId>1026.1</ReceiptId>
  120
+    <ReferenceNum>661221050010170010</ReferenceNum>
  121
+    <ResponseCode>027</ResponseCode>
  122
+    <ISO>01</ISO>
  123
+    <AuthCode>013511</AuthCode>
  124
+    <TransTime>18:41:13</TransTime>
  125
+    <TransDate>2008-01-05</TransDate>
  126
+    <TransType>00</TransType>
  127
+    <Complete>true</Complete>
  128
+    <Message>APPROVED * =</Message>
  129
+    <TransAmount>1.00</TransAmount>
  130
+    <CardType>V</CardType>
  131
+    <TransID>58-0_3</TransID>
  132
+    <TimedOut>false</TimedOut>
  133
+  </receipt>
  134
+</response>
  135
+    
  136
+    RESPONSE
  137
+  end
  138
+  
  139
+  def failed_purchase_response
  140
+    <<-RESPONSE
  141
+<?xml version="1.0"?>
  142
+<response>
  143
+  <receipt>
  144
+    <ReceiptId>1026.1</ReceiptId>
  145
+    <ReferenceNum>661221050010170010</ReferenceNum>
  146
+    <ResponseCode>481</ResponseCode>
  147
+    <ISO>01</ISO>
  148
+    <AuthCode>013511</AuthCode>
  149
+    <TransTime>18:41:13</TransTime>
  150
+    <TransDate>2008-01-05</TransDate>
  151
+    <TransType>00</TransType>
  152
+    <Complete>true</Complete>
  153
+    <Message>DECLINED * =</Message>
  154
+    <TransAmount>1.00</TransAmount>
  155
+    <CardType>V</CardType>
  156
+    <TransID>97-2-0</TransID>
  157
+    <TimedOut>false</TimedOut>
  158
+  </receipt>
  159
+</response>
  160
+    
  161
+    RESPONSE
  162
+  end  
  163
+
  164
+  def xml_purchase_fixture
  165
+   '<request><store_id>monusqa002</store_id><api_token>qatoken</api_token><us_purchase><amount>1.01</amount><pan>4242424242424242</pan><expdate>0303</expdate><crypt_type>7</crypt_type><order_id>order1</order_id></us_purchase></request>'
  166
+  end
  167
+
  168
+  def xml_capture_fixture
  169
+   '<request><store_id>monusqa002</store_id><api_token>qatoken</api_token><us_preauth><amount>1.01</amount><pan>4242424242424242</pan><expdate>0303</expdate><crypt_type>7</crypt_type><order_id>order1</order_id></us_preauth></request>'
  170
+  end
  171
+
  172
+end
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.