/test/unit/gateways/elavon_test.rb

https://github.com/Epictetus/Active-Merchant-Paypal-Recurring-payment-support-for-rails-2.x · Ruby · 139 lines · 115 code · 24 blank · 0 comment · 0 complexity · 55bc572fcd1639c6228bb9e61099083c MD5 · raw file

  1. require 'test_helper'
  2. class ElavonTest < Test::Unit::TestCase
  3. def setup
  4. @gateway = ElavonGateway.new(
  5. :login => 'login',
  6. :user => 'user',
  7. :password => 'password'
  8. )
  9. @credit_card = credit_card
  10. @amount = 100
  11. @options = {
  12. :order_id => '1',
  13. :billing_address => address,
  14. :description => 'Store Purchase'
  15. }
  16. end
  17. def test_successful_purchase
  18. @gateway.expects(:ssl_post).returns(successful_purchase_response)
  19. assert response = @gateway.purchase(@amount, @credit_card, @options)
  20. assert_success response
  21. assert_equal '123456', response.authorization
  22. assert response.test?
  23. end
  24. def test_successful_authorization
  25. @gateway.expects(:ssl_post).returns(successful_authorization_response)
  26. assert response = @gateway.authorize(@amount, @credit_card, @options)
  27. assert_instance_of Response, response
  28. assert_success response
  29. assert_equal '123456', response.authorization
  30. assert_equal "APPROVED", response.message
  31. assert response.test?
  32. end
  33. def test_failed_authorization
  34. @gateway.expects(:ssl_post).returns(failed_authorization_response)
  35. assert response = @gateway.authorize(@amount, @credit_card)
  36. assert_instance_of Response, response
  37. assert_failure response
  38. end
  39. def test_unsuccessful_purchase
  40. @gateway.expects(:ssl_post).returns(failed_purchase_response)
  41. assert response = @gateway.purchase(@amount, @credit_card, @options)
  42. assert_failure response
  43. assert response.test?
  44. end
  45. def test_invalid_login
  46. @gateway.expects(:ssl_post).returns(invalid_login_response)
  47. assert response = @gateway.purchase(@amount, @credit_card, @options)
  48. assert_equal '7000', response.params['result']
  49. assert_equal 'The VirtualMerchant ID and/or User ID supplied in the authorization request is invalid.', response.message
  50. assert_failure response
  51. end
  52. def test_supported_countries
  53. assert_equal ['US', 'CA'], ElavonGateway.supported_countries
  54. end
  55. def test_supported_card_types
  56. assert_equal [:visa, :master, :american_express, :discover], ElavonGateway.supported_cardtypes
  57. end
  58. def test_avs_result
  59. @gateway.expects(:ssl_post).returns(successful_purchase_response)
  60. response = @gateway.purchase(@amount, @credit_card)
  61. assert_equal 'X', response.avs_result['code']
  62. end
  63. def test_cvv_result
  64. @gateway.expects(:ssl_post).returns(successful_purchase_response)
  65. response = @gateway.purchase(@amount, @credit_card)
  66. assert_equal 'P', response.cvv_result['code']
  67. end
  68. private
  69. def successful_purchase_response
  70. "ssl_card_number=42********4242
  71. ssl_exp_date=0910
  72. ssl_amount=1.00
  73. ssl_invoice_number=
  74. ssl_description=Test Transaction
  75. ssl_result=0
  76. ssl_result_message=APPROVED
  77. ssl_txn_id=00000000-0000-0000-0000-00000000000
  78. ssl_approval_code=123456
  79. ssl_cvv2_response=P
  80. ssl_avs_response=X
  81. ssl_account_balance=0.00
  82. ssl_txn_time=08/07/2009 09:54:18 PM"
  83. end
  84. def failed_purchase_response
  85. "errorCode=5000
  86. errorName=Credit Card Number Invalid
  87. errorMessage=The Credit Card Number supplied in the authorization request appears to be invalid."
  88. end
  89. def invalid_login_response
  90. <<-RESPONSE
  91. ssl_result=7000\r
  92. ssl_result_message=The VirtualMerchant ID and/or User ID supplied in the authorization request is invalid.\r
  93. RESPONSE
  94. end
  95. def successful_authorization_response
  96. "ssl_card_number=42********4242
  97. ssl_exp_date=0910
  98. ssl_amount=1.00
  99. ssl_invoice_number=
  100. ssl_description=Test Transaction
  101. ssl_result=0
  102. ssl_result_message=APPROVED
  103. ssl_txn_id=00000000-0000-0000-0000-00000000000
  104. ssl_approval_code=123456
  105. ssl_cvv2_response=P
  106. ssl_avs_response=X
  107. ssl_account_balance=0.00
  108. ssl_txn_time=08/07/2009 09:56:11 PM"
  109. end
  110. def failed_authorization_response
  111. "errorCode=5000
  112. errorName=Credit Card Number Invalid
  113. errorMessage=The Credit Card Number supplied in the authorization request appears to be invalid."
  114. end
  115. end