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
@@ -39,12 +39,16 @@ module ActiveMerchant #:nodoc:
39
39
  # <% service.cancel_return_url 'http://mystore.com' %>
40
40
  # <% end %>
41
41
  #
42
- def payment_service_for(order, account, options = {}, &proc)
42
+ def payment_service_for(order, account, options = {}, &proc)
43
43
  raise ArgumentError, "Missing block" unless block_given?
44
44
 
45
- integration_module = ActiveMerchant::Billing::Integrations.const_get(Inflector.classify("#{options.delete(:service)}"))
45
+ integration_module = ActiveMerchant::Billing::Integrations.const_get(options.delete(:service).to_s.classify)
46
46
 
47
- concat(form_tag(integration_module.service_url, options.delete(:html) || {}), proc.binding)
47
+ if ignore_binding?
48
+ concat(form_tag(integration_module.service_url, options.delete(:html) || {}))
49
+ else
50
+ concat(form_tag(integration_module.service_url, options.delete(:html) || {}), proc.binding)
51
+ end
48
52
  result = "\n"
49
53
 
50
54
  service_class = integration_module.const_get('Helper')
@@ -57,7 +61,17 @@ module ActiveMerchant #:nodoc:
57
61
 
58
62
  result << "\n"
59
63
  result << '</form>'
60
- concat(result, proc.binding)
64
+
65
+ if ignore_binding?
66
+ concat(result)
67
+ else
68
+ concat(result, proc.binding)
69
+ end
70
+ end
71
+
72
+ private
73
+ def ignore_binding?
74
+ ActionPack::VERSION::MAJOR >= 2 && ActionPack::VERSION::MINOR >= 2
61
75
  end
62
76
  end
63
77
  end
@@ -7,6 +7,8 @@ module ActiveMerchant #:nodoc:
7
7
  class Notification < ActiveMerchant::Billing::Integrations::Notification
8
8
  SUCCESS = '00'
9
9
 
10
+ self.production_ips = [ '203.75.242.8' ]
11
+
10
12
  def complete?
11
13
  status == 'Completed'
12
14
  end
@@ -28,11 +30,11 @@ module ActiveMerchant #:nodoc:
28
30
  end
29
31
 
30
32
  def gross
31
- params['approveamount']
33
+ sprintf("%.2f", gross_cents.to_f / 100)
32
34
  end
33
35
 
34
36
  def gross_cents
35
- gross.to_i
37
+ params['approveamount'].to_i
36
38
  end
37
39
 
38
40
  def account
@@ -4,6 +4,9 @@ module ActiveMerchant #:nodoc:
4
4
  class Notification
5
5
  attr_accessor :params
6
6
  attr_accessor :raw
7
+
8
+ # set this to an array in the subclass, to specify which IPs are allowed to send requests
9
+ class_inheritable_accessor :production_ips
7
10
 
8
11
  def initialize(post, options = {})
9
12
  @options = options
@@ -36,7 +39,13 @@ module ActiveMerchant #:nodoc:
36
39
  @params = Hash.new
37
40
  @raw = ""
38
41
  end
39
-
42
+
43
+ # Check if the request comes from an official IP
44
+ def valid_sender?(ip)
45
+ return true if ActiveMerchant::Billing::Base.integration_mode == :test || production_ips.blank?
46
+ production_ips.include?(ip)
47
+ end
48
+
40
49
  private
41
50
 
42
51
  # Take the posted data and move the relevant data into a hash
@@ -11,7 +11,7 @@ module ActiveMerchant #:nodoc:
11
11
  READ_TIMEOUT = 60
12
12
 
13
13
  def self.included(base)
14
- base.class_inheritable_accessor :ssl_strict
14
+ base.superclass_delegating_accessor :ssl_strict
15
15
  base.ssl_strict = true
16
16
 
17
17
  base.class_inheritable_accessor :pem_password
@@ -19,14 +19,23 @@ module ActiveMerchant #:nodoc:
19
19
 
20
20
  base.class_inheritable_accessor :retry_safe
21
21
  base.retry_safe = false
22
+
23
+ base.superclass_delegating_accessor :open_timeout
24
+ base.open_timeout = OPEN_TIMEOUT
25
+
26
+ base.superclass_delegating_accessor :read_timeout
27
+ base.read_timeout = READ_TIMEOUT
22
28
  end
23
29
 
24
30
  def ssl_post(url, data, headers = {})
31
+ # Ruby 1.8.4 doesn't automatically set this header
32
+ headers['Content-Type'] ||= "application/x-www-form-urlencoded"
33
+
25
34
  uri = URI.parse(url)
26
35
 
27
36
  http = Net::HTTP.new(uri.host, uri.port)
28
- http.open_timeout = OPEN_TIMEOUT
29
- http.read_timeout = READ_TIMEOUT
37
+ http.open_timeout = self.class.open_timeout
38
+ http.read_timeout = self.class.read_timeout
30
39
  http.use_ssl = true
31
40
 
32
41
  if ssl_strict
File without changes
File without changes
File without changes
File without changes
@@ -14,6 +14,16 @@ authorize_net:
14
14
  login: X
15
15
  password: Y
16
16
 
17
+ beanstream:
18
+ login: merchant id
19
+ user: username
20
+ password: password
21
+
22
+ beanstream_interac:
23
+ login: merchant id
24
+ user: username
25
+ password: password
26
+
17
27
  braintree:
18
28
  login: demo
19
29
  password: password
@@ -54,6 +64,10 @@ linkpoint:
54
64
  pem: |--
55
65
  PASTE YOUR PEM FILE HERE
56
66
 
67
+ modern_payments:
68
+ login: login
69
+ password: password
70
+
57
71
  # Working credentials, no need to replace
58
72
  moneris:
59
73
  login: store1
@@ -236,6 +250,10 @@ realex_mastercard_coms_error:
236
250
  year: '2020'
237
251
  verification_value: '123'
238
252
 
253
+ sage:
254
+ login: login
255
+ password: password
256
+
239
257
  secure_pay:
240
258
  login: LOGIN
241
259
  password: PASSWORD
@@ -275,3 +293,9 @@ viaklix:
275
293
  login: LOGIN
276
294
  password: PASSWORD
277
295
  user: USER
296
+
297
+ # Working test credentials, no need to replace
298
+ wirecard:
299
+ login: 56500
300
+ password: TestXAPTER
301
+
@@ -0,0 +1,459 @@
1
+ require File.dirname(__FILE__) + '/../../test_helper'
2
+ require 'pp'
3
+
4
+ class AuthorizeNetCimTest < Test::Unit::TestCase
5
+ def setup
6
+ Base.mode = :test
7
+
8
+ @gateway = AuthorizeNetCimGateway.new(fixtures(:authorize_net))
9
+ @amount = 100
10
+ @credit_card = credit_card('4242424242424242')
11
+ @payment = {
12
+ :credit_card => @credit_card
13
+ }
14
+ @profile = {
15
+ :merchant_customer_id => 'Up to 20 chars', # Optional
16
+ :description => 'Up to 255 Characters', # Optional
17
+ :email => 'Up to 255 Characters', # Optional
18
+ :payment_profiles => { # Optional
19
+ :customer_type => 'individual', # Optional
20
+ :bill_to => @address,
21
+ :payment => @payment
22
+ },
23
+ :ship_to_list => {
24
+ :first_name => 'John',
25
+ :last_name => 'Doe',
26
+ :company => 'Widgets, Inc',
27
+ :address1 => '1234 Fake Street',
28
+ :city => 'Anytown',
29
+ :state => 'MD',
30
+ :zip => '12345',
31
+ :country => 'USA',
32
+ :phone_number => '(123)123-1234', # Optional - Up to 25 digits (no letters)
33
+ :fax_number => '(123)123-1234' # Optional - Up to 25 digits (no letters)
34
+ }
35
+ }
36
+ @options = {
37
+ :ref_id => '1234', # Optional
38
+ :profile => @profile
39
+ }
40
+ end
41
+
42
+ def teardown
43
+ if @customer_profile_id
44
+ assert response = @gateway.delete_customer_profile(:customer_profile_id => @customer_profile_id)
45
+ assert_success response
46
+ @customer_profile_id = nil
47
+ end
48
+ end
49
+
50
+ def test_successful_profile_create_get_update_and_delete
51
+ assert response = @gateway.create_customer_profile(@options)
52
+ @customer_profile_id = response.authorization
53
+
54
+ assert_success response
55
+ assert response.test?
56
+
57
+ assert response = @gateway.get_customer_profile(:customer_profile_id => @customer_profile_id)
58
+ assert response.test?
59
+ assert_success response
60
+ assert_equal @customer_profile_id, response.authorization
61
+ assert_equal 'Successful.', response.message
62
+ assert response.params['profile']['payment_profiles']['customer_payment_profile_id'] =~ /\d+/, 'The customer_payment_profile_id should be a number'
63
+ assert_equal "XXXX#{@credit_card.last_digits}", response.params['profile']['payment_profiles']['payment']['credit_card']['card_number'], "The card number should contain the last 4 digits of the card we passed in #{@credit_card.last_digits}"
64
+ assert_equal @profile[:merchant_customer_id], response.params['profile']['merchant_customer_id']
65
+ assert_equal @profile[:description], response.params['profile']['description']
66
+ assert_equal @profile[:email], response.params['profile']['email']
67
+ assert_equal @profile[:payment_profiles][:customer_type], response.params['profile']['payment_profiles']['customer_type']
68
+ assert_equal @profile[:ship_to_list][:phone_number], response.params['profile']['ship_to_list']['phone_number']
69
+ assert_equal @profile[:ship_to_list][:company], response.params['profile']['ship_to_list']['company']
70
+
71
+ assert response = @gateway.update_customer_profile(:profile => {:customer_profile_id => @customer_profile_id, :email => 'new email address'})
72
+ assert response.test?
73
+ assert_success response
74
+ assert_nil response.authorization
75
+ assert response = @gateway.get_customer_profile(:customer_profile_id => @customer_profile_id)
76
+ assert_nil response.params['profile']['merchant_customer_id']
77
+ assert_nil response.params['profile']['description']
78
+ assert_equal 'new email address', response.params['profile']['email']
79
+ end
80
+
81
+ def test_successful_create_customer_profile_transaction_auth_only_and_then_capture_only_requests
82
+ assert response = @gateway.create_customer_profile(@options)
83
+ @customer_profile_id = response.authorization
84
+
85
+ assert response = @gateway.get_customer_profile(:customer_profile_id => @customer_profile_id)
86
+ @customer_payment_profile_id = response.params['profile']['payment_profiles']['customer_payment_profile_id']
87
+
88
+ assert response = @gateway.create_customer_profile_transaction(
89
+ :transaction => {
90
+ :customer_profile_id => @customer_profile_id,
91
+ :customer_payment_profile_id => @customer_payment_profile_id,
92
+ :type => :auth_only,
93
+ :amount => @amount
94
+ }
95
+ )
96
+
97
+ assert response.test?
98
+ assert_success response
99
+ assert_nil response.authorization
100
+ assert_equal "This transaction has been approved.", response.params['direct_response']['message']
101
+ assert response.params['direct_response']['approval_code'] =~ /\w{6}/
102
+ assert_equal "auth_only", response.params['direct_response']['transaction_type']
103
+ assert_equal "100.00", response.params['direct_response']['amount']
104
+
105
+ approval_code = response.params['direct_response']['approval_code']
106
+
107
+ # Capture the previously authorized funds
108
+
109
+ assert response = @gateway.create_customer_profile_transaction(
110
+ :transaction => {
111
+ :customer_profile_id => @customer_profile_id,
112
+ :customer_payment_profile_id => @customer_payment_profile_id,
113
+ :type => :capture_only,
114
+ :amount => @amount,
115
+ :approval_code => approval_code
116
+ }
117
+ )
118
+
119
+ assert response.test?
120
+ assert_success response
121
+ assert_nil response.authorization
122
+ assert_equal "This transaction has been approved.", response.params['direct_response']['message']
123
+ assert_equal approval_code, response.params['direct_response']['approval_code']
124
+ assert_equal "capture_only", response.params['direct_response']['transaction_type']
125
+ assert_equal "100.00", response.params['direct_response']['amount']
126
+ end
127
+
128
+ def test_successful_create_customer_profile_transaction_auth_capture_request
129
+ assert response = @gateway.create_customer_profile(@options)
130
+ @customer_profile_id = response.authorization
131
+
132
+ assert response = @gateway.get_customer_profile(:customer_profile_id => @customer_profile_id)
133
+ @customer_payment_profile_id = response.params['profile']['payment_profiles']['customer_payment_profile_id']
134
+
135
+ assert response = @gateway.create_customer_profile_transaction(
136
+ :transaction => {
137
+ :customer_profile_id => @customer_profile_id,
138
+ :customer_payment_profile_id => @customer_payment_profile_id,
139
+ :type => :auth_capture,
140
+ :order => {
141
+ :invoice_number => '1234',
142
+ :description => 'Test Order Description',
143
+ :purchase_order_number => '4321'
144
+ },
145
+ :amount => @amount
146
+ }
147
+ )
148
+
149
+ assert response.test?
150
+ assert_success response
151
+ assert_nil response.authorization
152
+ assert_equal "This transaction has been approved.", response.params['direct_response']['message']
153
+ assert response.params['direct_response']['approval_code'] =~ /\w{6}/
154
+ assert_equal "auth_capture", response.params['direct_response']['transaction_type']
155
+ assert_equal "100.00", response.params['direct_response']['amount']
156
+ assert_equal response.params['direct_response']['invoice_number'], '1234'
157
+ assert_equal response.params['direct_response']['order_description'], 'Test Order Description'
158
+ assert_equal response.params['direct_response']['purchase_order_number'], '4321'
159
+ end
160
+
161
+ def test_successful_create_customer_payment_profile_request
162
+ payment_profile = @options[:profile].delete(:payment_profiles)
163
+ assert response = @gateway.create_customer_profile(@options)
164
+ @customer_profile_id = response.authorization
165
+
166
+ assert response = @gateway.get_customer_profile(:customer_profile_id => @customer_profile_id)
167
+ assert_nil response.params['profile']['payment_profiles']
168
+
169
+ assert response = @gateway.create_customer_payment_profile(
170
+ :customer_profile_id => @customer_profile_id,
171
+ :payment_profile => payment_profile
172
+ )
173
+
174
+ assert response.test?
175
+ assert_success response
176
+ assert_nil response.authorization
177
+ assert customer_payment_profile_id = response.params['customer_payment_profile_id']
178
+ assert customer_payment_profile_id =~ /\d+/, "The customerPaymentProfileId should be numeric. It was #{customer_payment_profile_id}"
179
+ end
180
+
181
+ def test_successful_create_customer_payment_profile_request_with_bank_account
182
+ payment_profile = @options[:profile].delete(:payment_profiles)
183
+ assert response = @gateway.create_customer_profile(@options)
184
+ @customer_profile_id = response.authorization
185
+
186
+ assert response = @gateway.get_customer_profile(:customer_profile_id => @customer_profile_id)
187
+ assert_nil response.params['profile']['payment_profiles']
188
+
189
+ assert response = @gateway.create_customer_payment_profile(
190
+ :customer_profile_id => @customer_profile_id,
191
+ :payment_profile => {
192
+ :customer_type => 'individual', # Optional
193
+ :bill_to => @address,
194
+ :payment => {
195
+ :bank_account => {
196
+ :account_type => :checking,
197
+ :name_on_account => 'John Doe',
198
+ :echeck_type => :ccd,
199
+ :bank_name => 'Bank of America',
200
+ :routing_number => '123456789',
201
+ :account_number => '12345'
202
+ }
203
+ },
204
+ :drivers_license => {
205
+ :state => 'MD',
206
+ :number => '12345',
207
+ :date_of_birth => '1981-3-31'
208
+ },
209
+ :tax_id => '123456789'
210
+ }
211
+ )
212
+
213
+ assert response.test?
214
+ assert_success response
215
+ assert_nil response.authorization
216
+ assert customer_payment_profile_id = response.params['customer_payment_profile_id']
217
+ assert customer_payment_profile_id =~ /\d+/, "The customerPaymentProfileId should be numeric. It was #{customer_payment_profile_id}"
218
+ end
219
+
220
+ def test_successful_create_customer_shipping_address_request
221
+ shipping_address = @options[:profile].delete(:ship_to_list)
222
+ assert response = @gateway.create_customer_profile(@options)
223
+ @customer_profile_id = response.authorization
224
+
225
+ assert response = @gateway.get_customer_profile(:customer_profile_id => @customer_profile_id)
226
+ assert_nil response.params['profile']['ship_to_list']
227
+
228
+ assert response = @gateway.create_customer_shipping_address(
229
+ :customer_profile_id => @customer_profile_id,
230
+ :address => shipping_address
231
+ )
232
+
233
+ assert response.test?
234
+ assert_success response
235
+ assert_nil response.authorization
236
+ assert customer_address_id = response.params['customer_address_id']
237
+ assert customer_address_id =~ /\d+/, "The customerAddressId should be numeric. It was #{customer_address_id}"
238
+ end
239
+
240
+ def test_successful_get_customer_profile_with_multiple_payment_profiles
241
+ second_payment_profile = {
242
+ :customer_type => 'individual',
243
+ :bill_to => @address,
244
+ :payment => {
245
+ :credit_card => credit_card('1234123412341234')
246
+ }
247
+ }
248
+ assert response = @gateway.create_customer_profile(@options)
249
+ @customer_profile_id = response.authorization
250
+
251
+ assert response = @gateway.get_customer_profile(:customer_profile_id => @customer_profile_id)
252
+
253
+ assert response = @gateway.create_customer_payment_profile(
254
+ :customer_profile_id => @customer_profile_id,
255
+ :payment_profile => second_payment_profile
256
+ )
257
+
258
+ assert response.test?
259
+ assert_success response
260
+ assert_nil response.authorization
261
+ assert customer_payment_profile_id = response.params['customer_payment_profile_id']
262
+ assert customer_payment_profile_id =~ /\d+/, "The customerPaymentProfileId should be numeric. It was #{customer_payment_profile_id}"
263
+
264
+ assert response = @gateway.get_customer_profile(:customer_profile_id => @customer_profile_id)
265
+ assert_equal 2, response.params['profile']['payment_profiles'].size
266
+ assert_equal 'XXXX4242', response.params['profile']['payment_profiles'][0]['payment']['credit_card']['card_number']
267
+ assert_equal 'XXXX1234', response.params['profile']['payment_profiles'][1]['payment']['credit_card']['card_number']
268
+ end
269
+
270
+ def test_successful_delete_customer_payment_profile_request
271
+ assert response = @gateway.create_customer_profile(@options)
272
+ @customer_profile_id = response.authorization
273
+
274
+ assert response = @gateway.get_customer_profile(:customer_profile_id => @customer_profile_id)
275
+ assert customer_payment_profile_id = response.params['profile']['payment_profiles']['customer_payment_profile_id']
276
+
277
+ assert response = @gateway.delete_customer_payment_profile(
278
+ :customer_profile_id => @customer_profile_id,
279
+ :customer_payment_profile_id => customer_payment_profile_id
280
+ )
281
+
282
+ assert response.test?
283
+ assert_success response
284
+ assert_nil response.authorization
285
+
286
+ assert response = @gateway.get_customer_profile(:customer_profile_id => @customer_profile_id)
287
+ assert_nil response.params['profile']['payment_profiles']
288
+ end
289
+
290
+ def test_successful_delete_customer_shipping_address_request
291
+ assert response = @gateway.create_customer_profile(@options)
292
+ @customer_profile_id = response.authorization
293
+
294
+ assert response = @gateway.get_customer_profile(:customer_profile_id => @customer_profile_id)
295
+ assert customer_address_id = response.params['profile']['ship_to_list']['customer_address_id']
296
+
297
+ assert response = @gateway.delete_customer_shipping_address(
298
+ :customer_profile_id => @customer_profile_id,
299
+ :customer_address_id => customer_address_id
300
+ )
301
+
302
+ assert response.test?
303
+ assert_success response
304
+ assert_nil response.authorization
305
+
306
+ assert response = @gateway.get_customer_profile(:customer_profile_id => @customer_profile_id)
307
+ assert_nil response.params['profile']['ship_to_list']
308
+ end
309
+
310
+ def test_successful_get_customer_payment_profile_request
311
+ assert response = @gateway.create_customer_profile(@options)
312
+ @customer_profile_id = response.authorization
313
+
314
+ assert response = @gateway.get_customer_profile(:customer_profile_id => @customer_profile_id)
315
+ assert customer_payment_profile_id = response.params['profile']['payment_profiles']['customer_payment_profile_id']
316
+
317
+ assert response = @gateway.get_customer_payment_profile(
318
+ :customer_profile_id => @customer_profile_id,
319
+ :customer_payment_profile_id => customer_payment_profile_id
320
+ )
321
+
322
+ assert response.test?
323
+ assert_success response
324
+ assert_nil response.authorization
325
+ assert response.params['payment_profile']['customer_payment_profile_id'] =~ /\d+/, 'The customer_payment_profile_id should be a number'
326
+ assert_equal "XXXX#{@credit_card.last_digits}", response.params['payment_profile']['payment']['credit_card']['card_number'], "The card number should contain the last 4 digits of the card we passed in #{@credit_card.last_digits}"
327
+ assert_equal @profile[:payment_profiles][:customer_type], response.params['payment_profile']['customer_type']
328
+ end
329
+
330
+ def test_successful_get_customer_shipping_address_request
331
+ assert response = @gateway.create_customer_profile(@options)
332
+ @customer_profile_id = response.authorization
333
+
334
+ assert response = @gateway.get_customer_profile(:customer_profile_id => @customer_profile_id)
335
+ assert customer_address_id = response.params['profile']['ship_to_list']['customer_address_id']
336
+
337
+ assert response = @gateway.get_customer_shipping_address(
338
+ :customer_profile_id => @customer_profile_id,
339
+ :customer_address_id => customer_address_id
340
+ )
341
+
342
+ assert response.test?
343
+ assert_success response
344
+ assert_nil response.authorization
345
+ assert response.params['address']['customer_address_id'] =~ /\d+/, 'The customer_address_id should be a number'
346
+ assert_equal @profile[:ship_to_list][:city], response.params['address']['city']
347
+ end
348
+
349
+ def test_successful_update_customer_payment_profile_request
350
+ # Create a new Customer Profile with Payment Profile
351
+ assert response = @gateway.create_customer_profile(@options)
352
+ @customer_profile_id = response.authorization
353
+
354
+ # Get the customerPaymentProfileId
355
+ assert response = @gateway.get_customer_profile(:customer_profile_id => @customer_profile_id)
356
+ assert customer_payment_profile_id = response.params['profile']['payment_profiles']['customer_payment_profile_id']
357
+
358
+ # Get the customerPaymentProfile
359
+ assert response = @gateway.get_customer_payment_profile(
360
+ :customer_profile_id => @customer_profile_id,
361
+ :customer_payment_profile_id => customer_payment_profile_id
362
+ )
363
+
364
+ # The value before updating
365
+ assert_equal "XXXX4242", response.params['payment_profile']['payment']['credit_card']['card_number'], "The card number should contain the last 4 digits of the card we passed in 4242"
366
+
367
+ #Update the payment profile
368
+ assert response = @gateway.update_customer_payment_profile(
369
+ :customer_profile_id => @customer_profile_id,
370
+ :payment_profile => {
371
+ :customer_payment_profile_id => customer_payment_profile_id,
372
+ :payment => {
373
+ :credit_card => credit_card('1234123412341234')
374
+ }
375
+ }
376
+ )
377
+ assert response.test?
378
+ assert_success response
379
+ assert_nil response.authorization
380
+
381
+ # Get the updated payment profile
382
+ assert response = @gateway.get_customer_payment_profile(
383
+ :customer_profile_id => @customer_profile_id,
384
+ :customer_payment_profile_id => customer_payment_profile_id
385
+ )
386
+
387
+ # Show that the payment profile was updated
388
+ assert_equal "XXXX1234", response.params['payment_profile']['payment']['credit_card']['card_number'], "The card number should contain the last 4 digits of the card we passed in: 1234"
389
+ # Show that fields that were left out of the update were cleared
390
+ assert_nil response.params['payment_profile']['customer_type']
391
+ end
392
+
393
+ def test_successful_update_customer_shipping_address_request
394
+ # Create a new Customer Profile with Shipping Address
395
+ assert response = @gateway.create_customer_profile(@options)
396
+ @customer_profile_id = response.authorization
397
+
398
+ # Get the customerAddressId
399
+ assert response = @gateway.get_customer_profile(:customer_profile_id => @customer_profile_id)
400
+ assert customer_address_id = response.params['profile']['ship_to_list']['customer_address_id']
401
+
402
+ # Get the customerShippingAddress
403
+ assert response = @gateway.get_customer_shipping_address(
404
+ :customer_profile_id => @customer_profile_id,
405
+ :customer_address_id => customer_address_id
406
+ )
407
+
408
+ assert address = response.params['address']
409
+ # The value before updating
410
+ assert_equal "1234 Fake Street", address['address']
411
+
412
+ # Update the address and remove the phone_number
413
+ new_address = address.symbolize_keys.merge!(
414
+ :address => '5678 Fake Street'
415
+ )
416
+ new_address.delete(:phone_number)
417
+
418
+ #Update the shipping address
419
+ assert response = @gateway.update_customer_shipping_address(
420
+ :customer_profile_id => @customer_profile_id,
421
+ :address => new_address
422
+ )
423
+ assert response.test?
424
+ assert_success response
425
+ assert_nil response.authorization
426
+
427
+ # Get the updated shipping address
428
+ assert response = @gateway.get_customer_shipping_address(
429
+ :customer_profile_id => @customer_profile_id,
430
+ :customer_address_id => customer_address_id
431
+ )
432
+
433
+ # Show that the shipping address was updated
434
+ assert_equal "5678 Fake Street", response.params['address']['address']
435
+ # Show that fields that were left out of the update were cleared
436
+ assert_nil response.params['address']['phone_number']
437
+ end
438
+
439
+ def test_successful_validate_customer_payment_profile_request
440
+ assert response = @gateway.create_customer_profile(@options)
441
+ @customer_profile_id = response.authorization
442
+
443
+ assert response = @gateway.get_customer_profile(:customer_profile_id => @customer_profile_id)
444
+ assert @customer_payment_profile_id = response.params['profile']['payment_profiles']['customer_payment_profile_id']
445
+ assert @customer_address_id = response.params['profile']['ship_to_list']['customer_address_id']
446
+
447
+ assert response = @gateway.validate_customer_payment_profile(
448
+ :customer_profile_id => @customer_profile_id,
449
+ :customer_payment_profile_id => @customer_payment_profile_id,
450
+ :customer_address_id => @customer_address_id,
451
+ :validation_mode => :live
452
+ )
453
+
454
+ assert response.test?
455
+ assert_success response
456
+ assert_nil response.authorization
457
+ assert_equal "This transaction has been approved.", response.params['direct_response']['message']
458
+ end
459
+ end