activemerchant 1.3.2 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. data.tar.gz.sig +0 -0
  2. data/CHANGELOG +58 -0
  3. data/CONTRIBUTERS +25 -0
  4. data/MIT-LICENSE +3 -3
  5. data/README +16 -10
  6. data/Rakefile +4 -3
  7. data/lib/active_merchant.rb +7 -1
  8. data/lib/active_merchant/billing/check.rb +16 -9
  9. data/lib/active_merchant/billing/gateway.rb +1 -1
  10. data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +702 -0
  11. data/lib/active_merchant/billing/gateways/beanstream.rb +102 -0
  12. data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +233 -0
  13. data/lib/active_merchant/billing/gateways/beanstream_interac.rb +54 -0
  14. data/lib/active_merchant/billing/gateways/braintree.rb +10 -1
  15. data/lib/active_merchant/billing/gateways/cyber_source.rb +26 -2
  16. data/lib/active_merchant/billing/gateways/data_cash.rb +255 -59
  17. data/lib/active_merchant/billing/gateways/modern_payments.rb +36 -0
  18. data/lib/active_merchant/billing/gateways/modern_payments_cim.rb +214 -0
  19. data/lib/active_merchant/billing/gateways/net_registry.rb +1 -0
  20. data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +2 -2
  21. data/lib/active_merchant/billing/gateways/payflow_express.rb +3 -11
  22. data/lib/active_merchant/billing/gateways/payment_express.rb +2 -2
  23. data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +39 -21
  24. data/lib/active_merchant/billing/gateways/paypal_ca.rb +13 -0
  25. data/lib/active_merchant/billing/gateways/paypal_express.rb +3 -12
  26. data/lib/active_merchant/billing/gateways/paypal_express_common.rb +20 -0
  27. data/lib/active_merchant/billing/gateways/protx.rb +25 -25
  28. data/lib/active_merchant/billing/gateways/sage.rb +145 -0
  29. data/lib/active_merchant/billing/gateways/sage/sage_bankcard.rb +88 -0
  30. data/lib/active_merchant/billing/gateways/sage/sage_core.rb +110 -0
  31. data/lib/active_merchant/billing/gateways/sage/sage_virtual_check.rb +97 -0
  32. data/lib/active_merchant/billing/gateways/secure_pay_au.rb +3 -1
  33. data/lib/active_merchant/billing/gateways/skip_jack.rb +2 -0
  34. data/lib/active_merchant/billing/gateways/trust_commerce.rb +1 -1
  35. data/lib/active_merchant/billing/gateways/wirecard.rb +304 -0
  36. data/lib/active_merchant/billing/integrations.rb +8 -2
  37. data/lib/active_merchant/billing/integrations/action_view_helper.rb +18 -4
  38. data/lib/active_merchant/billing/integrations/hi_trust/notification.rb +4 -2
  39. data/lib/active_merchant/billing/integrations/notification.rb +10 -1
  40. data/lib/active_merchant/lib/posts_data.rb +12 -3
  41. data/script/destroy +0 -0
  42. data/script/generate +0 -0
  43. data/test/extra/binding_of_caller.rb +0 -0
  44. data/test/extra/breakpoint.rb +0 -0
  45. data/test/fixtures.yml +24 -0
  46. data/test/remote/gateways/remote_authorize_net_cim_test.rb +459 -0
  47. data/test/remote/gateways/remote_beanstream_interac_test.rb +53 -0
  48. data/test/remote/gateways/remote_beanstream_test.rb +150 -0
  49. data/test/remote/gateways/remote_braintree_test.rb +22 -0
  50. data/test/remote/gateways/remote_cyber_source_test.rb +28 -3
  51. data/test/remote/gateways/remote_data_cash_test.rb +250 -48
  52. data/test/remote/gateways/remote_modern_payments_cim_test.rb +58 -0
  53. data/test/remote/gateways/remote_modern_payments_test.rb +43 -0
  54. data/test/remote/gateways/remote_sage_bankcard_test.rb +109 -0
  55. data/test/remote/gateways/remote_sage_test.rb +87 -0
  56. data/test/remote/gateways/remote_sage_virtual_check_test.rb +62 -0
  57. data/test/remote/gateways/remote_wirecard_test.rb +76 -0
  58. data/test/remote/integrations/remote_paypal_integration_test.rb +15 -3
  59. data/test/test_helper.rb +31 -13
  60. data/test/unit/check_test.rb +14 -2
  61. data/test/unit/credit_card_methods_test.rb +18 -0
  62. data/test/unit/gateways/authorize_net_cim_test.rb +641 -0
  63. data/test/unit/gateways/beanstream_interac_test.rb +51 -0
  64. data/test/unit/gateways/beanstream_test.rb +108 -0
  65. data/test/unit/gateways/braintree_test.rb +2 -5
  66. data/test/unit/gateways/cyber_source_test.rb +18 -0
  67. data/test/unit/gateways/data_cash_test.rb +32 -4
  68. data/test/unit/gateways/gateway_test.rb +8 -1
  69. data/test/unit/gateways/modern_payments_cim_test.rb +171 -0
  70. data/test/unit/gateways/net_registry_test.rb +6 -0
  71. data/test/unit/gateways/payflow_express_test.rb +18 -2
  72. data/test/unit/gateways/paypal_express_test.rb +154 -0
  73. data/test/unit/gateways/paypal_test.rb +140 -0
  74. data/test/unit/gateways/sage_bankcard_test.rb +162 -0
  75. data/test/unit/gateways/sage_virtual_check_test.rb +71 -0
  76. data/test/unit/gateways/secure_pay_au_test.rb +58 -1
  77. data/test/unit/gateways/skip_jack_test.rb +8 -0
  78. data/test/unit/gateways/verifi_test.rb +0 -1
  79. data/test/unit/gateways/wirecard_test.rb +232 -0
  80. data/test/unit/integrations/action_view_helper_test.rb +3 -0
  81. data/test/unit/integrations/notifications/hi_trust_notification_test.rb +23 -2
  82. data/test/unit/integrations/notifications/notification_test.rb +13 -0
  83. data/test/unit/posts_data_test.rb +20 -6
  84. metadata +40 -5
  85. metadata.gz.sig +0 -0
@@ -0,0 +1,53 @@
1
+ require File.dirname(__FILE__) + '/../../test_helper'
2
+
3
+ class RemoteBeanstreamInteracTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @gateway = BeanstreamInteracGateway.new(fixtures(:beanstream_interac))
7
+
8
+ @amount = 100
9
+
10
+ @options = {
11
+ :order_id => generate_unique_id,
12
+ :billing_address => {
13
+ :name => 'xiaobo zzz',
14
+ :phone => '555-555-5555',
15
+ :address1 => '1234 Levesque St.',
16
+ :address2 => 'Apt B',
17
+ :city => 'Montreal',
18
+ :state => 'QC',
19
+ :country => 'CA',
20
+ :zip => 'H2C1X8'
21
+ },
22
+ :email => 'xiaobozzz@example.com',
23
+ :subtotal => 800,
24
+ :shipping => 100,
25
+ :tax1 => 100,
26
+ :tax2 => 100,
27
+ :custom => 'reference one'
28
+ }
29
+ end
30
+
31
+ def test_successful_purchase
32
+ assert response = @gateway.purchase(@amount, @options)
33
+ assert_success response
34
+ assert_equal "R", response.params["responseType"]
35
+ assert_false response.redirect.blank?
36
+ end
37
+
38
+ def test_failed_confirmation
39
+ assert response = @gateway.confirm("")
40
+ assert_failure response
41
+ end
42
+
43
+ def test_invalid_login
44
+ gateway = BeanstreamInteracGateway.new(
45
+ :merchant_id => '',
46
+ :login => '',
47
+ :password => ''
48
+ )
49
+ assert response = gateway.purchase(@amount, @options)
50
+ assert_failure response
51
+ assert_equal 'Invalid merchant id (merchant_id = 0)', response.message
52
+ end
53
+ end
@@ -0,0 +1,150 @@
1
+ require File.dirname(__FILE__) + '/../../test_helper'
2
+
3
+ # This test suite assumes that you have enabled username/password transaction validation in your Beanstream account.
4
+ # You will experience some test failures if username/password validation transaction validation is not enabled.
5
+ class RemoteBeanstreamTest < Test::Unit::TestCase
6
+
7
+ def setup
8
+ @gateway = BeanstreamGateway.new(fixtures(:beanstream))
9
+
10
+ # Beanstream test cards. Cards require a CVV of 123, which is the default of the credit card helper
11
+ @visa = credit_card('4030000010001234')
12
+ @declined_visa = credit_card('4003050500040005')
13
+
14
+ @mastercard = credit_card('5100000010001004')
15
+ @declined_mastercard = credit_card('5100000020002000')
16
+
17
+ @amex = credit_card('371100001000131')
18
+ @declined_amex = credit_card('342400001000180')
19
+
20
+ # Canadian EFT
21
+ @check = check(
22
+ :institution_number => '001',
23
+ :transit_number => '26729'
24
+ )
25
+
26
+ @amount = 1500
27
+
28
+ @options = {
29
+ :order_id => generate_unique_id,
30
+ :billing_address => {
31
+ :name => 'xiaobo zzz',
32
+ :phone => '555-555-5555',
33
+ :address1 => '1234 Levesque St.',
34
+ :address2 => 'Apt B',
35
+ :city => 'Montreal',
36
+ :state => 'QC',
37
+ :country => 'CA',
38
+ :zip => 'H2C1X8'
39
+ },
40
+ :email => 'xiaobozzz@example.com',
41
+ :subtotal => 800,
42
+ :shipping => 100,
43
+ :tax1 => 100,
44
+ :tax2 => 100,
45
+ :custom => 'reference one'
46
+ }
47
+ end
48
+
49
+ def test_successful_visa_purchase
50
+ assert response = @gateway.purchase(@amount, @visa, @options)
51
+ assert_success response
52
+ assert_false response.authorization.blank?
53
+ assert_equal "Approved", response.message
54
+ end
55
+
56
+ def test_unsuccessful_visa_purchase
57
+ assert response = @gateway.purchase(@amount, @declined_visa, @options)
58
+ assert_failure response
59
+ assert_equal 'DECLINE', response.message
60
+ end
61
+
62
+ def test_successful_mastercard_purchase
63
+ assert response = @gateway.purchase(@amount, @mastercard, @options)
64
+ assert_success response
65
+ assert_false response.authorization.blank?
66
+ assert_equal "Approved", response.message
67
+ end
68
+
69
+ def test_unsuccessful_mastercard_purchase
70
+ assert response = @gateway.purchase(@amount, @declined_mastercard, @options)
71
+ assert_failure response
72
+ assert_equal 'DECLINE', response.message
73
+ end
74
+
75
+ def test_successful_amex_purchase
76
+ assert response = @gateway.purchase(@amount, @amex, @options)
77
+ assert_success response
78
+ assert_false response.authorization.blank?
79
+ assert_equal "Approved", response.message
80
+ end
81
+
82
+ def test_unsuccessful_amex_purchase
83
+ assert response = @gateway.purchase(@amount, @declined_amex, @options)
84
+ assert_failure response
85
+ assert_equal 'DECLINE', response.message
86
+ end
87
+
88
+ def test_authorize_and_capture
89
+ assert auth = @gateway.authorize(@amount, @visa, @options)
90
+ assert_success auth
91
+ assert_equal "Approved", auth.message
92
+ assert_false auth.authorization.blank?
93
+
94
+ assert capture = @gateway.capture(@amount, auth.authorization)
95
+ assert_success capture
96
+ assert_false capture.authorization.blank?
97
+ end
98
+
99
+ def test_failed_capture
100
+ assert response = @gateway.capture(@amount, '')
101
+ assert_failure response
102
+ assert_no_match %r{You are not authorized}, response.message, "You need to enable username/password validation"
103
+ assert_match %r{Missing or invalid adjustment id.}, response.message
104
+ end
105
+
106
+ def test_successful_purchase_and_void
107
+ assert purchase = @gateway.purchase(@amount, @visa, @options)
108
+ assert_success purchase
109
+
110
+ assert void = @gateway.void(purchase.authorization)
111
+ assert_success void
112
+ end
113
+
114
+ def test_successful_purchase_and_credit_and_void_credit
115
+ assert purchase = @gateway.purchase(@amount, @visa, @options)
116
+ assert_success purchase
117
+
118
+ assert credit = @gateway.credit(@amount, purchase.authorization)
119
+ assert_success purchase
120
+
121
+ assert void = @gateway.void(credit.authorization)
122
+ assert_success void
123
+ end
124
+
125
+ def test_successful_check_purchase
126
+ assert response = @gateway.purchase(@amount, @check, @options)
127
+ assert_success response
128
+ assert response.test?
129
+ assert_false response.authorization.blank?
130
+ end
131
+
132
+ def test_successful_check_purchase_and_credit
133
+ assert purchase = @gateway.purchase(@amount, @check, @options)
134
+ assert_success purchase
135
+
136
+ assert credit = @gateway.credit(@amount, purchase.authorization)
137
+ assert_success credit
138
+ end
139
+
140
+ def test_invalid_login
141
+ gateway = BeanstreamGateway.new(
142
+ :merchant_id => '',
143
+ :login => '',
144
+ :password => ''
145
+ )
146
+ assert response = gateway.purchase(@amount, @visa, @options)
147
+ assert_failure response
148
+ assert_equal 'Invalid merchant id (merchant_id = 0)', response.message
149
+ end
150
+ end
@@ -46,6 +46,13 @@ class RemoteBraintreeTest < Test::Unit::TestCase
46
46
  assert_not_nil response.params["customer_vault_id"]
47
47
  end
48
48
 
49
+ def test_successful_add_to_vault_with_store_method
50
+ assert response = @gateway.store(@credit_card)
51
+ assert_equal 'This transaction has been approved', response.message
52
+ assert_success response
53
+ assert_not_nil response.params["customer_vault_id"]
54
+ end
55
+
49
56
  def test_successful_add_to_vault_and_use
50
57
  @options[:store] = true
51
58
  assert response = @gateway.purchase(@amount, @credit_card, @options)
@@ -66,6 +73,14 @@ class RemoteBraintreeTest < Test::Unit::TestCase
66
73
  assert_equal @options[:store], response.params["customer_vault_id"].to_i
67
74
  end
68
75
 
76
+ def test_add_to_vault_with_custom_vault_id_with_store_method
77
+ @options[:billing_id] = rand(100000)+10001
78
+ assert response = @gateway.store(@credit_card, @options.dup)
79
+ assert_equal 'This transaction has been approved', response.message
80
+ assert_success response
81
+ assert_equal @options[:billing_id], response.params["customer_vault_id"].to_i
82
+ end
83
+
69
84
  def test_update_vault
70
85
  test_add_to_vault_with_custom_vault_id
71
86
  @credit_card = credit_card('4111111111111111', :month => 10)
@@ -81,6 +96,13 @@ class RemoteBraintreeTest < Test::Unit::TestCase
81
96
  assert_equal 'Customer Deleted', response.message
82
97
  end
83
98
 
99
+ def test_delete_from_vault_with_unstore_method
100
+ test_add_to_vault_with_custom_vault_id
101
+ assert response = @gateway.unstore(@options[:store])
102
+ assert_success response
103
+ assert_equal 'Customer Deleted', response.message
104
+ end
105
+
84
106
  def test_declined_purchase
85
107
  assert response = @gateway.purchase(@declined_amount, @credit_card, @options)
86
108
  assert_equal 'This transaction has been declined', response.message
@@ -63,11 +63,24 @@ class RemoteCyberSourceTest < Test::Unit::TestCase
63
63
  end
64
64
 
65
65
  def test_successful_tax_calculation_with_nexus
66
- @gateway.options = @gateway.options.merge(:nexus => 'WI')
67
- assert response = @gateway.calculate_tax(@credit_card, @options)
66
+ total_line_items_value = @options[:line_items].inject(0) do |sum, item|
67
+ sum += item[:declared_value] * item[:quantity]
68
+ end
69
+
70
+ canada_gst_rate = 0.05
71
+ ontario_pst_rate = 0.08
72
+
73
+
74
+ total_pst = total_line_items_value.to_f * ontario_pst_rate / 100
75
+ total_gst = total_line_items_value.to_f * canada_gst_rate / 100
76
+ total_tax = total_pst + total_gst
77
+
78
+ assert response = @gateway.calculate_tax(@credit_card, @options.merge(:nexus => 'ON'))
68
79
  assert_equal 'Successful transaction', response.message
69
80
  assert response.params['totalTaxAmount']
70
- assert_equal "0", response.params['totalTaxAmount']
81
+ assert_equal total_pst, response.params['totalCountyTaxAmount'].to_f
82
+ assert_equal total_gst, response.params['totalStateTaxAmount'].to_f
83
+ assert_equal total_tax, response.params['totalTaxAmount'].to_f
71
84
  assert_success response
72
85
  assert response.test?
73
86
  end
@@ -102,6 +115,7 @@ class RemoteCyberSourceTest < Test::Unit::TestCase
102
115
 
103
116
  assert capture = @gateway.capture(@amount + 10, auth.authorization, @options)
104
117
  assert_failure capture
118
+ assert_equal "The requested amount exceeds the originally authorized amount", capture.message
105
119
  end
106
120
 
107
121
  def test_failed_capture_bad_auth_info
@@ -116,4 +130,15 @@ class RemoteCyberSourceTest < Test::Unit::TestCase
116
130
  assert_match /wsse:InvalidSecurity/, response.message
117
131
  assert_failure response
118
132
  end
133
+
134
+ def test_successful_credit
135
+ assert response = @gateway.purchase(@amount, @credit_card, @options)
136
+ assert_equal 'Successful transaction', response.message
137
+ assert_success response
138
+ assert response.test?
139
+ assert response = @gateway.credit(@amount, response.authorization)
140
+ assert_equal 'Successful transaction', response.message
141
+ assert_success response
142
+ assert response.test?
143
+ end
119
144
  end
@@ -2,58 +2,80 @@
2
2
  require File.dirname(__FILE__) + '/../../test_helper'
3
3
 
4
4
  class RemoteDataCashTest < Test::Unit::TestCase
5
+
5
6
  def setup
6
7
  # gateway to connect to Datacash
7
8
  @gateway = DataCashGateway.new(fixtures(:data_cash))
8
-
9
+
9
10
  @mastercard = CreditCard.new(
10
11
  :number => '5473000000000007',
11
12
  :month => 3,
12
- :year => 2010,
13
+ :year => Date.today.year + 2,
13
14
  :first_name => 'Mark',
14
15
  :last_name => 'McBride',
15
16
  :type => :master,
16
17
  :verification_value => '547'
17
18
  )
18
-
19
+
20
+ @mastercard_declined = CreditCard.new(
21
+ :number => '5473000000000106',
22
+ :month => 3,
23
+ :year => Date.today.year + 2,
24
+ :first_name => 'Mark',
25
+ :last_name => 'McBride',
26
+ :type => :master,
27
+ :verification_value => '547'
28
+ )
29
+
30
+ @visa_delta = CreditCard.new(
31
+ :number => '4539792100000003',
32
+ :month => 3,
33
+ :year => Date.today.year + 2,
34
+ :first_name => 'Mark',
35
+ :last_name => 'McBride',
36
+ :type => :visa,
37
+ :verification_value => '444'
38
+ )
39
+
19
40
  @solo = CreditCard.new(
20
41
  :first_name => 'Cody',
21
42
  :last_name => 'Fauser',
22
43
  :number => '633499100000000004',
23
44
  :month => 3,
24
- :year => 2010,
45
+ :year => Date.today.year + 2,
25
46
  :type => :solo,
26
47
  :issue_number => 5,
27
48
  :start_month => 12,
28
49
  :start_year => 2006,
29
50
  :verification_value => 444
30
51
  )
31
-
52
+
32
53
  @address = {
33
54
  :name => 'Mark McBride',
34
55
  :address1 => 'Flat 12/3',
35
56
  :address2 => '45 Main Road',
36
- :city => 'London',
37
- :state => 'None',
38
- :country => 'GBR',
57
+ :city => 'Sometown',
58
+ :state => 'Somecounty',
39
59
  :zip => 'A987AA',
40
60
  :phone => '(555)555-5555'
41
61
  }
42
-
62
+
43
63
  @params = {
44
64
  :order_id => generate_unique_id,
45
65
  :billing_address => @address
46
66
  }
67
+
68
+ @amount = 198
47
69
  end
48
-
70
+
49
71
  # Testing that we can successfully make a purchase in a one step
50
72
  # operation
51
73
  def test_successful_purchase
52
- response = @gateway.purchase(198, @mastercard, @params)
74
+ response = @gateway.purchase(@amount, @mastercard, @params)
53
75
  assert_success response
54
76
  assert response.test?
55
77
  end
56
-
78
+
57
79
  #the amount is changed to £1.99 - the DC test server won't check the
58
80
  #address details - this is more a check on the passed ExtendedPolicy
59
81
  def test_successful_purchase_without_address_check
@@ -61,95 +83,275 @@ class RemoteDataCashTest < Test::Unit::TestCase
61
83
  assert_success response
62
84
  assert response.test?
63
85
  end
64
-
86
+
87
+ # Note the Datacash test server regularly times out on switch requests
65
88
  def test_successful_purchase_with_solo_card
66
- response = @gateway.purchase(198, @solo, @params)
89
+ response = @gateway.purchase(@amount, @solo, @params)
67
90
  assert_success response
68
91
  assert response.test?
69
92
  end
70
-
93
+
71
94
  # this card number won't check the address details - testing extended
72
95
  # policy
73
96
  def test_successful_purchase_without_address_check2
74
97
  @solo.number = '633499110000000003'
75
-
76
- response = @gateway.purchase(198, @solo, @params)
98
+
99
+ response = @gateway.purchase(@amount, @solo, @params)
77
100
  assert_success response
78
101
  assert response.test?
79
102
  end
80
-
103
+
104
+ # Testing purchase with request to set up recurring payment account
105
+ def test_successful_purchase_without_account_set_up_and_repeat_payments
106
+ response = @gateway.purchase(@amount, @mastercard, @params)
107
+ assert_success response
108
+ assert response.authorization.to_s.split(';')[2].blank?
109
+ assert response.test?
110
+ end
111
+
112
+ # Testing purchase with request to set up recurring payment account
113
+ def test_successful_purchase_with_account_set_up_and_repeat_payments
114
+ @params[:set_up_continuous_authority] = true
115
+ response = @gateway.purchase(@amount, @mastercard, @params)
116
+ assert_success response
117
+ assert !response.authorization.to_s.split(';')[2].blank?
118
+ assert response.test?
119
+
120
+ #Make second payment on the continuous authorization that was set up in the first purchase
121
+ second_order_params = { :order_id => generate_unique_id }
122
+ purchase = @gateway.purchase(201, response.params['ca_reference'], second_order_params)
123
+ assert_success purchase
124
+ assert purchase.test?
125
+ end
126
+
127
+ def test_successful_purchase_with_account_set_up_and_repeat_payments_with_visa_delta_card
128
+ @params[:set_up_continuous_authority] = true
129
+ response = @gateway.purchase(@amount, @visa_delta, @params)
130
+ assert_success response
131
+ assert !response.authorization.to_s.split(';')[2].blank?
132
+ assert response.test?
133
+
134
+ #Make second payment on the continuous authorization that was set up in the first purchase
135
+ second_order_params = { :order_id => generate_unique_id }
136
+ purchase = @gateway.purchase(201, response.params['ca_reference'], second_order_params)
137
+ assert_success purchase
138
+ assert purchase.test?
139
+ end
140
+
141
+ def test_purchase_with_account_set_up_for_repeat_payments_fails_for_solo_card
142
+ @params[:set_up_continuous_authority] = true
143
+ response = @gateway.purchase(@amount, @solo, @params)
144
+ assert_equal '92', response.params['status'] # Error code for CA not supported
145
+ assert_equal 'CA Not Supported', response.message
146
+ assert response.test?
147
+ end
148
+
149
+ def test_successful_authorization_and_capture_with_account_set_up_and_second_purchase
150
+ #Authorize first payment
151
+ @params[:set_up_continuous_authority] = true
152
+ first_authorization = @gateway.authorize(@amount, @mastercard, @params)
153
+ assert_success first_authorization
154
+ assert !first_authorization.authorization.to_s.split(';')[2].blank?
155
+ assert first_authorization.test?
156
+
157
+ #Capture first payment
158
+ capture = @gateway.capture(@amount, first_authorization.authorization, @params)
159
+ assert_success capture
160
+ assert capture.test?
161
+
162
+ #Collect second purchase
163
+ second_order_params = { :order_id => generate_unique_id }
164
+ purchase = @gateway.purchase(201, first_authorization.authorization, second_order_params)
165
+ assert_success purchase
166
+ assert purchase.test?
167
+ end
168
+
169
+ def test_duplicate_order_id
170
+ response = @gateway.purchase(@amount, @mastercard, @params)
171
+ assert_success response
172
+
173
+ duplicate_response = @gateway.purchase(@amount, @mastercard, @params)
174
+ assert_failure duplicate_response
175
+ assert_equal 'Duplicate reference', duplicate_response.message
176
+ assert duplicate_response.test?
177
+ end
178
+
81
179
  def test_invalid_verification_number
82
180
  @mastercard.verification_value = 123
83
- response = @gateway.purchase(198, @mastercard, @params)
181
+ response = @gateway.purchase(@amount, @mastercard, @params)
84
182
  assert_failure response
183
+ assert_equal 'CV2AVS DECLINED', response.message
85
184
  assert response.test?
86
185
  end
87
-
186
+
88
187
  def test_invalid_expiry_month
89
188
  @mastercard.month = 13
90
- response = @gateway.purchase(198, @mastercard, @params)
189
+ response = @gateway.purchase(@amount, @mastercard, @params)
91
190
  assert_failure response
191
+ assert_equal 'Expiry date invalid', response.message
92
192
  assert response.test?
93
193
  end
94
-
194
+
95
195
  def test_invalid_expiry_year
96
196
  @mastercard.year = 1999
97
- response = @gateway.purchase(198, @mastercard, @params)
197
+ response = @gateway.purchase(@amount, @mastercard, @params)
98
198
  assert_failure response
199
+ assert_equal 'Card has already expired', response.message
99
200
  assert response.test?
100
201
  end
101
-
102
- def test_successful_authorization_and_capture
103
- amount = 198
104
-
105
- authorization = @gateway.authorize(amount, @mastercard, @params)
202
+
203
+ def test_declined_card
204
+ response = @gateway.purchase(@amount, @mastercard_declined, @params)
205
+ assert_failure response
206
+ assert_equal 'DECLINED', response.message
207
+ assert response.test?
208
+ end
209
+
210
+ def test_successful_authorization_and_capture
211
+ authorization = @gateway.authorize(@amount, @mastercard, @params)
106
212
  assert_success authorization
107
213
  assert authorization.test?
108
-
109
- capture = @gateway.capture(amount, authorization.authorization, @params)
214
+
215
+ capture = @gateway.capture(@amount, authorization.authorization, @params)
110
216
  assert_success capture
111
217
  assert capture.test?
112
218
  end
113
-
219
+
114
220
  def test_unsuccessful_capture
115
- response = @gateway.capture(198, '1234', @params)
221
+ response = @gateway.capture(@amount, ';1234', @params)
116
222
  assert_failure response
223
+ assert_equal 'AUTHCODE field required', response.message
117
224
  assert response.test?
118
225
  end
119
-
120
- def test_successful_authorization_and_void
121
- amount = 198
122
-
123
- authorization = @gateway.authorize(amount, @mastercard, @params)
226
+
227
+ def test_successful_authorization_and_void
228
+ authorization = @gateway.authorize(@amount, @mastercard, @params)
124
229
  assert_success authorization
125
230
  assert authorization.test?
126
-
231
+
127
232
  void = @gateway.void(authorization.authorization, @params)
128
233
  assert_success void
129
234
  assert void.test?
130
235
  end
131
-
132
- def test_successfuly_purchase_and_void
133
- purchase = @gateway.purchase(198, @mastercard, @params)
236
+
237
+ def test_successfully_purchase_and_void
238
+ purchase = @gateway.purchase(@amount, @mastercard, @params)
134
239
  assert_success purchase
135
240
  assert purchase.test?
136
-
241
+
137
242
  void = @gateway.void(purchase.authorization, @params)
138
243
  assert_success void
139
244
  assert void.test?
140
245
  end
141
246
 
247
+
248
+ def test_successful_refund
249
+ response = @gateway.credit(@amount, @mastercard, @params)
250
+ assert_success response
251
+ assert !response.params['datacash_reference'].blank?
252
+ assert !response.params['merchantreference'].blank?
253
+
254
+ assert response.test?
255
+ end
256
+
257
+ def test_successful_transaction_refund
258
+ purchase = @gateway.purchase(@amount, @mastercard, @params)
259
+ assert_success purchase
260
+ assert purchase.test?
261
+
262
+ refund = @gateway.credit(@amount, purchase.params['datacash_reference'])
263
+ assert_success refund
264
+ assert !refund.params['datacash_reference'].blank?
265
+ assert !refund.params['merchantreference'].blank?
266
+
267
+ assert refund.test?
268
+ end
269
+
270
+ def test_successful_transaction_refund_with_money_set_to_nil
271
+ purchase = @gateway.purchase(@amount, @mastercard, @params)
272
+ assert_success purchase
273
+ assert purchase.test?
274
+
275
+ refund = @gateway.credit(nil, purchase.params['datacash_reference'])
276
+ assert_success refund
277
+ assert refund.test?
278
+ end
279
+
280
+ def test_successful_transaction_refund_in_two_stages
281
+ purchase = @gateway.purchase(@amount, @mastercard, @params)
282
+ assert_success purchase
283
+ assert purchase.test?
284
+
285
+ first_partial_refund = @gateway.credit(100, purchase.params['datacash_reference'])
286
+ assert_success first_partial_refund
287
+ assert first_partial_refund.test?
288
+
289
+ second_partial_refund = @gateway.credit(98, purchase.params['datacash_reference'])
290
+ assert_success second_partial_refund
291
+ assert second_partial_refund.test?
292
+ end
293
+
294
+ def test_successful_partial_transaction_refund
295
+ purchase = @gateway.purchase(@amount, @mastercard, @params)
296
+ assert_success purchase
297
+ assert purchase.test?
298
+
299
+ partial_refund = @gateway.credit(100, purchase.params['datacash_reference'])
300
+ assert_success partial_refund
301
+ assert partial_refund.test?
302
+ end
303
+
304
+ def test_fail_to_refund_too_much
305
+ purchase = @gateway.purchase(@amount, @mastercard, @params)
306
+ assert_success purchase
307
+ assert purchase.test?
308
+
309
+ refund_too_much = @gateway.credit(500, purchase.params['datacash_reference'])
310
+ assert_failure refund_too_much
311
+ assert_equal 'Refund amount > orig 1.98', refund_too_much.message
312
+ assert refund_too_much.test?
313
+ end
314
+
315
+ def test_fail_to_refund_with_declined_purchase_reference
316
+ declined_purchase = @gateway.purchase(@amount, @mastercard_declined, @params)
317
+ assert_failure declined_purchase
318
+ assert declined_purchase.test?
319
+
320
+ refund = @gateway.credit(@amount, declined_purchase.params['datacash_reference'])
321
+ assert_failure refund
322
+ assert_equal 'Cannot refund transaction', refund.message
323
+ assert refund.test?
324
+ end
325
+
326
+ def test_fail_to_refund_purchase_which_is_already_refunded
327
+ purchase = @gateway.purchase(@amount, @mastercard, @params)
328
+ assert_success purchase
329
+ assert purchase.test?
330
+
331
+ first_refund = @gateway.credit(nil, purchase.params['datacash_reference'])
332
+ assert_success first_refund
333
+ assert first_refund.test?
334
+
335
+ second_refund = @gateway.credit(@amount, purchase.params['datacash_reference'])
336
+ assert_failure second_refund
337
+ assert_equal '1.98 > remaining funds 0.00', second_refund.message
338
+ assert second_refund.test?
339
+ end
340
+
341
+ # Check short merchant references are reformatted
142
342
  def test_merchant_reference_that_is_too_short
143
- @params[:order_id] = rand(10000)
144
- response = @gateway.purchase(198, @mastercard, @params)
343
+ @params[:order_id] = @params[:order_id].first(5)
344
+ response = @gateway.purchase(@amount, @mastercard, @params)
145
345
  assert_success response
146
346
  assert response.test?
147
347
  end
148
-
149
- def test_merchant_reference_containing_invalid_characters
150
- @params[:order_id] = "##{rand(1000) + 1000}.1"
151
- response = @gateway.purchase(198, @mastercard, @params)
348
+
349
+ # Check long merchant references are reformatted
350
+ def test_merchant_reference_that_is_too_long
351
+ @params[:order_id] = "#{@params[:order_id]}1234356"
352
+ response = @gateway.purchase(@amount, @mastercard, @params)
152
353
  assert_success response
153
354
  assert response.test?
154
355
  end
356
+
155
357
  end