workarea-kount 3.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (163) hide show
  1. checksums.yaml +7 -0
  2. data/.editorconfig +20 -0
  3. data/.eslintrc +24 -0
  4. data/.github/ISSUE_TEMPLATE/bug_report.md +37 -0
  5. data/.github/ISSUE_TEMPLATE/documentation-request.md +17 -0
  6. data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  7. data/.github/workflows/ci.yml +58 -0
  8. data/.gitignore +14 -0
  9. data/.rubocop.yml +2 -0
  10. data/CHANGELOG.md +212 -0
  11. data/CODE_OF_CONDUCT.md +3 -0
  12. data/CONTRIBUTING.md +3 -0
  13. data/Gemfile +17 -0
  14. data/LICENSE.md +3 -0
  15. data/README.md +98 -0
  16. data/Rakefile +53 -0
  17. data/app/controllers/workarea/admin/orders_controller.decorator +5 -0
  18. data/app/controllers/workarea/storefront/checkout/place_order_controller.decorator +11 -0
  19. data/app/controllers/workarea/storefront/kount_controller.rb +19 -0
  20. data/app/controllers/workarea/storefront/kount_orders_controller.rb +40 -0
  21. data/app/lib/active_shipping/rate_estimate.decorator +10 -0
  22. data/app/mailers/workarea/storefront/order_mailer.decorator +14 -0
  23. data/app/models/workarea/checkout.decorator +37 -0
  24. data/app/models/workarea/checkout/fraud/kount_analyzer.rb +71 -0
  25. data/app/models/workarea/kount/ens_event.rb +13 -0
  26. data/app/models/workarea/kount/order.rb +14 -0
  27. data/app/models/workarea/order.decorator +62 -0
  28. data/app/models/workarea/order/fraud_decision.decorator +9 -0
  29. data/app/models/workarea/order/item.decorator +8 -0
  30. data/app/models/workarea/order/status/review.rb +13 -0
  31. data/app/models/workarea/payment/credit_card.decorator +13 -0
  32. data/app/models/workarea/payment/payment.decorator +11 -0
  33. data/app/models/workarea/payment/status/kount_declined.rb +13 -0
  34. data/app/models/workarea/payment/status/kount_review.rb +13 -0
  35. data/app/models/workarea/payment/tender/credit_card.decorator +10 -0
  36. data/app/models/workarea/search/admin.decorator +12 -0
  37. data/app/models/workarea/search/admin/order.decorator +7 -0
  38. data/app/models/workarea/shipping/rate_lookup.decorator +26 -0
  39. data/app/models/workarea/shipping/service.decorator +9 -0
  40. data/app/models/workarea/shipping/service_selection.decorator +7 -0
  41. data/app/models/workarea/shipping_option.decorator +27 -0
  42. data/app/services/workarea/kount/cancel_order_under_review.rb +28 -0
  43. data/app/services/workarea/kount/event.rb +43 -0
  44. data/app/services/workarea/kount/event/dmc_event.rb +9 -0
  45. data/app/services/workarea/kount/event/risk_change_event.rb +21 -0
  46. data/app/services/workarea/kount/event/special_alert_event.rb +21 -0
  47. data/app/services/workarea/kount/event/workflow_event.rb +25 -0
  48. data/app/services/workarea/kount/event_batch.rb +37 -0
  49. data/app/services/workarea/kount/order_fraud_update_service.rb +42 -0
  50. data/app/services/workarea/kount/ris_inquiry.rb +120 -0
  51. data/app/services/workarea/kount/ris_inquiry/product.rb +53 -0
  52. data/app/services/workarea/kount/ris_request.rb +84 -0
  53. data/app/services/workarea/kount/ris_update.rb +39 -0
  54. data/app/view_models/workarea/admin/order_view_model.decorator +35 -0
  55. data/app/view_models/workarea/storefront/order_view_model.decorator +11 -0
  56. data/app/views/workarea/admin/orders/_kount.html.haml +28 -0
  57. data/app/views/workarea/admin/orders/kount.html.haml +46 -0
  58. data/app/views/workarea/storefront/checkouts/_kount_data_collector.html.haml +4 -0
  59. data/app/views/workarea/storefront/order_mailer/hold_denial.html.haml +14 -0
  60. data/app/workers/workarea/kount/process_review_order.rb +75 -0
  61. data/app/workers/workarea/kount/update_ris_inquiry.rb +31 -0
  62. data/bin/rails +18 -0
  63. data/config/initializers/appends.rb +11 -0
  64. data/config/initializers/workarea.rb +26 -0
  65. data/config/locales/en.yml +26 -0
  66. data/config/routes.rb +14 -0
  67. data/doc/Kount Technical Specification Guide 5.5.5.pdf +0 -0
  68. data/lib/workarea/kount.rb +87 -0
  69. data/lib/workarea/kount/address.rb +39 -0
  70. data/lib/workarea/kount/bogus_gateway.rb +415 -0
  71. data/lib/workarea/kount/engine.rb +8 -0
  72. data/lib/workarea/kount/errors.rb +2 -0
  73. data/lib/workarea/kount/gateway.rb +50 -0
  74. data/lib/workarea/kount/mappings.rb +195 -0
  75. data/lib/workarea/kount/payment_types.rb +50 -0
  76. data/lib/workarea/kount/response.rb +141 -0
  77. data/lib/workarea/kount/security_mash.rb +79 -0
  78. data/lib/workarea/kount/user_defined_fields.rb +16 -0
  79. data/lib/workarea/kount/version.rb +5 -0
  80. data/lib/workarea/mailer_previews/storefront/order_mailer_preview.rb +10 -0
  81. data/test/dummy/Rakefile +6 -0
  82. data/test/dummy/app/assets/config/manifest.js +4 -0
  83. data/test/dummy/app/assets/images/.keep +0 -0
  84. data/test/dummy/app/assets/javascripts/application.js +13 -0
  85. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  86. data/test/dummy/app/controllers/application_controller.rb +3 -0
  87. data/test/dummy/app/controllers/concerns/.keep +0 -0
  88. data/test/dummy/app/helpers/application_helper.rb +2 -0
  89. data/test/dummy/app/jobs/application_job.rb +2 -0
  90. data/test/dummy/app/mailers/application_mailer.rb +4 -0
  91. data/test/dummy/app/models/concerns/.keep +0 -0
  92. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  93. data/test/dummy/app/views/layouts/mailer.html.erb +13 -0
  94. data/test/dummy/app/views/layouts/mailer.text.erb +1 -0
  95. data/test/dummy/bin/bundle +3 -0
  96. data/test/dummy/bin/rails +4 -0
  97. data/test/dummy/bin/rake +4 -0
  98. data/test/dummy/bin/setup +34 -0
  99. data/test/dummy/bin/update +29 -0
  100. data/test/dummy/config.ru +5 -0
  101. data/test/dummy/config/application.rb +23 -0
  102. data/test/dummy/config/boot.rb +5 -0
  103. data/test/dummy/config/cable.yml +9 -0
  104. data/test/dummy/config/environment.rb +5 -0
  105. data/test/dummy/config/environments/development.rb +56 -0
  106. data/test/dummy/config/environments/production.rb +86 -0
  107. data/test/dummy/config/environments/test.rb +44 -0
  108. data/test/dummy/config/initializers/application_controller_renderer.rb +6 -0
  109. data/test/dummy/config/initializers/assets.rb +11 -0
  110. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  111. data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
  112. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  113. data/test/dummy/config/initializers/inflections.rb +16 -0
  114. data/test/dummy/config/initializers/mime_types.rb +4 -0
  115. data/test/dummy/config/initializers/new_framework_defaults.rb +21 -0
  116. data/test/dummy/config/initializers/session_store.rb +3 -0
  117. data/test/dummy/config/initializers/workarea.rb +5 -0
  118. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  119. data/test/dummy/config/locales/en.yml +23 -0
  120. data/test/dummy/config/puma.rb +47 -0
  121. data/test/dummy/config/routes.rb +6 -0
  122. data/test/dummy/config/secrets.yml +22 -0
  123. data/test/dummy/config/spring.rb +6 -0
  124. data/test/dummy/db/seeds.rb +2 -0
  125. data/test/dummy/lib/assets/.keep +0 -0
  126. data/test/dummy/log/.keep +0 -0
  127. data/test/dummy/public/404.html +67 -0
  128. data/test/dummy/public/422.html +67 -0
  129. data/test/dummy/public/500.html +66 -0
  130. data/test/dummy/public/apple-touch-icon-precomposed.png +0 -0
  131. data/test/dummy/public/apple-touch-icon.png +0 -0
  132. data/test/dummy/public/favicon.ico +0 -0
  133. data/test/factories/kount.rb +164 -0
  134. data/test/integration/workarea/api/admin/payment_transactions_integration_test.decorator +29 -0
  135. data/test/integration/workarea/kount_moneris_integration_test.rb +37 -0
  136. data/test/integration/workarea/storefront/kount_integration_test.rb +37 -0
  137. data/test/integration/workarea/storefront/kount_orders_integration_test.rb +89 -0
  138. data/test/lib/workarea/kount/response_test.rb +95 -0
  139. data/test/lib/workarea/kount/security_mash_test.rb +62 -0
  140. data/test/models/workarea/checkout/fraud/kount_analyzer_test.rb +44 -0
  141. data/test/models/workarea/checkout_test.decorator +22 -0
  142. data/test/models/workarea/order/queries_test.decorator +28 -0
  143. data/test/models/workarea/order_test.decorator +25 -0
  144. data/test/models/workarea/payment/payment_test.rb +106 -0
  145. data/test/models/workarea/payment/saved_credit_card_test.rb +24 -0
  146. data/test/models/workarea/payment_test.decorator +54 -0
  147. data/test/models/workarea/shipping_option_test.rb +29 -0
  148. data/test/services/workarea/kount/event_batch_test.rb +95 -0
  149. data/test/services/workarea/kount/event_test.rb +51 -0
  150. data/test/services/workarea/kount/order_fraud_update_service_test.rb +48 -0
  151. data/test/support/workarea/kount_api_config.rb +27 -0
  152. data/test/system/workarea/kount_system_test.rb +72 -0
  153. data/test/system/workarea/storefront/kount_guest_checkout_system_test.rb +32 -0
  154. data/test/system/workarea/storefront/kount_logged_in_checkout_system_test.rb +102 -0
  155. data/test/test_helper.rb +16 -0
  156. data/test/vcr_cassettes/kount/basic_fraud_test.yml +43 -0
  157. data/test/vcr_cassettes/kount/integration/moneris_new_credit_card.yml +84 -0
  158. data/test/vcr_cassettes/kount/integration/moneris_saved_credit_card.yml +84 -0
  159. data/test/vcr_cassettes/kount/order_fraud_update.yml +82 -0
  160. data/test/workers/workarea/kount/clean_orders_test.rb +40 -0
  161. data/test/workers/workarea/kount/process_review_order_test.rb +100 -0
  162. data/workarea-kount.gemspec +17 -0
  163. metadata +238 -0
File without changes
File without changes
@@ -0,0 +1,164 @@
1
+ module Workarea
2
+ module Factories
3
+ module Kount
4
+ Factories.add self
5
+
6
+ def create_purchasable_checkout(options = {})
7
+ product = create_product(variants: [{ sku: 'SKU', regular: 5.to_m }])
8
+
9
+ order_attributes = {
10
+ email: 'bcrouse-new@workarea.com'
11
+ }.merge(options[:order] || {})
12
+
13
+ order = Workarea::Order.new(order_attributes).tap do |o|
14
+ o.add_item(product_id: product.id, sku: 'SKU', quantity: 2)
15
+ end
16
+
17
+ order.items.each do |item|
18
+ item.update_attributes!(OrderItemDetails.find!(item.sku).to_h)
19
+ end
20
+ checkout = Checkout.new(order)
21
+
22
+ shipping_address = {
23
+ first_name: 'Ben',
24
+ last_name: 'Crouse',
25
+ street: '22 S. 3rd St.',
26
+ street_2: 'Second Floor',
27
+ city: 'Philadelphia',
28
+ region: 'PA',
29
+ postal_code: '19106',
30
+ country: 'US'
31
+ }.merge(options[:shipping_address] || {})
32
+
33
+ billing_address = {
34
+ first_name: 'Ben',
35
+ last_name: 'Crouse',
36
+ street: '22 S. 3rd St.',
37
+ street_2: 'Second Floor',
38
+ city: 'Philadelphia',
39
+ region: 'PA',
40
+ postal_code: '19106',
41
+ country: 'US'
42
+ }.merge(options[:billing_address] || {})
43
+
44
+ payment = options.fetch(:payment, "new_card")
45
+
46
+ credit_card = {
47
+ number: '4111_1111_1111_1111',
48
+ month: '01',
49
+ year: Time.current.year + 1,
50
+ cvv: '999'
51
+ }.merge(options[:credit_card] || {})
52
+
53
+ if payment != "new_card"
54
+ order.save!
55
+ card = checkout.payment_profile.credit_cards.create credit_card.merge(
56
+ first_name: 'Eric',
57
+ last_name: 'Pigeon'
58
+ )
59
+ raise 'Failed to store credit card' unless card.persisted?
60
+ credit_card = {}
61
+ payment = card.id.to_s
62
+ end
63
+
64
+ shipping_service = options[:shipping_service].presence ||
65
+ create_shipping_service.name
66
+
67
+
68
+ checkout.update(
69
+ shipping_address: shipping_address,
70
+ billing_address: billing_address,
71
+ shipping_service: shipping_service,
72
+ payment: payment,
73
+ credit_card: credit_card
74
+ )
75
+
76
+ checkout
77
+ end
78
+
79
+ def create_kount_order(options = {})
80
+ attributes = {
81
+ id: SecureRandom.hex(5).upcase,
82
+ response: {
83
+ "VERS" => "0630",
84
+ "MODE" => "Q",
85
+ "TRAN" => "7SSM08H1H0JG",
86
+ "MERC" => "200755",
87
+ "SESS" => "5F16B01A1A1543855163R26055",
88
+ "ORDR" => "5F16B01A1A",
89
+ "AUTO" => "A",
90
+ "SCOR" => "34",
91
+ "GEOX" => "US",
92
+ "BRND" => "VISA",
93
+ "REGN" => "US_PA",
94
+ "NETW" => "N",
95
+ "KAPT" => "N",
96
+ "CARDS" => "1",
97
+ "DEVICES" => "1",
98
+ "EMAILS" => "1",
99
+ "VELO" => "0",
100
+ "VMAX" => "0",
101
+ "SITE" => "DEFAULT",
102
+ "DEVICE_LAYERS" => "....",
103
+ "FINGERPRINT" => nil,
104
+ "TIMEZONE" => nil,
105
+ "LOCALTIME" => " ",
106
+ "REGION" => nil,
107
+ "COUNTRY" => nil,
108
+ "PROXY" => nil,
109
+ "JAVASCRIPT" => nil,
110
+ "FLASH" => nil,
111
+ "COOKIES" => nil,
112
+ "HTTP_COUNTRY" => nil,
113
+ "LANGUAGE" => nil,
114
+ "MOBILE_DEVICE" => nil,
115
+ "MOBILE_TYPE" => nil,
116
+ "MOBILE_FORWARDER" => nil,
117
+ "VOICE_DEVICE" => nil,
118
+ "PC_REMOTE" => nil,
119
+ "RULES_TRIGGERED" => 1,
120
+ "RULE_ID_0" => "1326652",
121
+ "RULE_DESCRIPTION_0" => "WEBLINC AUTO APPROVE",
122
+ "COUNTERS_TRIGGERED" => 0,
123
+ "REASON_CODE" => nil,
124
+ "MASTERCARD" => "",
125
+ "DDFS" => nil,
126
+ "DSR" => nil,
127
+ "UAS" => nil,
128
+ "BROWSER" => nil,
129
+ "OS" => nil,
130
+ "PIP_IPAD" => nil,
131
+ "PIP_LAT" => nil,
132
+ "PIP_LON" => nil,
133
+ "PIP_COUNTRY" => nil,
134
+ "PIP_REGION" => nil,
135
+ "PIP_CITY" => nil,
136
+ "PIP_ORG" => nil,
137
+ "IP_IPAD" => nil,
138
+ "IP_LAT" => nil,
139
+ "IP_LON" => nil,
140
+ "IP_COUNTRY" => nil,
141
+ "IP_REGION" => nil,
142
+ "IP_CITY" => nil,
143
+ "IP_ORG" => nil,
144
+ "WARNING_COUNT" => 0
145
+ },
146
+ update_response: {
147
+ "VERS" => "0630",
148
+ "MODE" => "U",
149
+ "TRAN" => "7SSM08H1H0JG",
150
+ "MERC" => "200755",
151
+ "SESS" => "5F16B01A1A1543855163R26055",
152
+ "RULES_TRIGGERED" => 0,
153
+ "COUNTERS_TRIGGERED" => 0,
154
+ "REASON_CODE" => nil,
155
+ "MASTERCARD" => "",
156
+ "WARNING_COUNT" => 0
157
+ }
158
+ }.merge options
159
+
160
+ Workarea::Kount::Order.create! attributes
161
+ end
162
+ end
163
+ end
164
+ end
@@ -0,0 +1,29 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ if Plugin.installed?(:api)
5
+ module Api
6
+ module Admin
7
+ decorate PaymentTransactionsIntegrationTest, with: :kount do
8
+ def create_transaction
9
+ order = create_order
10
+ payment = create_payment(id: order.id)
11
+ payment.set_credit_card(
12
+ number: '1',
13
+ month: 1,
14
+ year: Time.now.year + 1,
15
+ cvv: '999'
16
+ )
17
+
18
+ Payment::Transaction.create!(
19
+ payment: payment,
20
+ tender_id: payment.credit_card.id,
21
+ amount: 45,
22
+ action: 'authorize'
23
+ )
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,37 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ if Plugin.installed?(:moneris)
5
+ class KountMonerisIntegrationTest < Workarea::TestCase
6
+ include KountApiConfig
7
+ include MonerisGatewayVCRConfig
8
+
9
+ def test_new_credit_card
10
+ VCR.use_cassette 'kount/integration/moneris_new_credit_card' do
11
+ checkout = create_purchasable_checkout(order: {
12
+ kount_session_id: '12345666',
13
+ ip_address: '170.115.187.68'
14
+ })
15
+
16
+ assert(checkout.place_order)
17
+ refute(checkout.order.fraud_suspected_at?)
18
+ end
19
+ end
20
+
21
+ def test_saved_credit_card
22
+ VCR.use_cassette 'kount/integration/moneris_saved_credit_card' do
23
+ checkout = create_purchasable_checkout(
24
+ order: {
25
+ kount_session_id: '12345666',
26
+ ip_address: '170.115.187.68'
27
+ },
28
+ payment: "saved_card"
29
+ )
30
+
31
+ assert(checkout.place_order)
32
+ refute(checkout.order.fraud_suspected_at?)
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,37 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ module Storefront
5
+ class KountIntegrationTest < Workarea::IntegrationTest
6
+ setup :mock_kount_order
7
+
8
+ def test_redirects_to_kount_data_collector_htm_path
9
+ get '/logo.htm'
10
+
11
+ assert_redirected_to("#{Workarea::Kount.data_collector_url}logo.htm?#{{ merchant_id: Workarea::Kount.merchant_id, s: kount_session_id }.to_query }")
12
+ end
13
+
14
+ def test_redirects_to_kount_data_collector_gif_path
15
+ get '/logo.gif'
16
+
17
+ assert_redirected_to("#{Workarea::Kount.data_collector_url}logo.htm?#{{ merchant_id: Workarea::Kount.merchant_id, s: kount_session_id }.to_query }")
18
+ end
19
+
20
+ private
21
+
22
+ def mock_kount_order
23
+ order = create_order
24
+
25
+ Workarea::Storefront::KountController
26
+ .any_instance.stubs(:current_order).returns(order)
27
+
28
+ Workarea::Storefront::KountController
29
+ .any_instance.stubs(:kount_session_id).returns(kount_session_id)
30
+ end
31
+
32
+ def kount_session_id
33
+ @kount_session_id ||= '1234-092340423-52341'
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,89 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ module Storefront
5
+ class KountOrdersIntegationTest < Workarea::IntegrationTest
6
+ setup :setup_kount_basic_auth_credentials
7
+ teardown :restore_credentials
8
+
9
+ def test_bulk_events_with_valid_xml
10
+ xml = <<~XML
11
+ <?xml version="1.0" encoding="UTF-8" standalone="no"?>
12
+ <events merchant="200755" total="2">
13
+ <event>
14
+ <name>WORKFLOW_STATUS_EDIT</name>
15
+ <key order_number="D58470FCF0" site="DEFAULT">7JG1075ML345</key>
16
+ <old_value>R</old_value>
17
+ <new_value>A</new_value>
18
+ <agent>SYSTEM@KOUNT.NET</agent>
19
+ <occurred>2018-05-18 06:47:47.413756</occurred>
20
+ </event>
21
+ <event>
22
+ <name>WORKFLOW_STATUS_EDIT</name>
23
+ <key order_number="D58470FCF1" site="DEFAULT">7JG601D6MG7S</key>
24
+ <old_value>R</old_value>
25
+ <new_value>D</new_value>
26
+ <agent>SYSTEM@KOUNT.NET</agent>
27
+ <occurred>2018-05-18 06:47:59.252024</occurred>
28
+ </event>
29
+ </events>
30
+ XML
31
+
32
+ Kount::ProcessReviewOrder.expects(:perform_async)
33
+ Kount::ProcessReviewOrder.expects(:perform_async)
34
+
35
+ post storefront.kount_orders_path, params: xml, headers: auth_headers
36
+ assert(response.ok?)
37
+ assert_equal({ "status" => 200 }, JSON.parse(response.body))
38
+ assert_equal(200, response.status)
39
+ end
40
+
41
+ def test_bulk_events_with_invalid_xml
42
+ xml = <<~XML
43
+ <?xml version="1.0" encoding="UTF-8" standalone="no"?
44
+ <events merchant="200755" total="2">
45
+ <event>
46
+ <name>WORKFLOW_STATUS_EDIT</name>
47
+ <key order_number="D58470FCF0" site="DEFAULT">7JG1075ML345</key>
48
+ <old_value>R</old_value>
49
+ <new_value>A</new_value>
50
+ <agent>SYSTEM@KOUNT.NET</agent>
51
+ <occurred>2018-05-18 06:47:47.413756</occurred>
52
+ </event>
53
+ <event>
54
+ <name>WORKFLOW_STATUS_EDIT</name>
55
+ <key order_number="D58470FCF0" site="DEFAULT">7JG601D6MG7S</key>
56
+ <old_value>R</old_value>
57
+ <new_value>D</new_value>
58
+ <agent>SYSTEM@KOUNT.NET</agent>
59
+ <occurred>2018-05-18 06:47:59.252024</occurred>
60
+ </event>
61
+ </events>
62
+ XML
63
+
64
+ post storefront.kount_orders_path, params: xml, headers: auth_headers
65
+ refute(response.ok?)
66
+ assert_equal(400, response.status)
67
+ end
68
+
69
+ private
70
+
71
+ def setup_kount_basic_auth_credentials
72
+ @_old_credentials = Workarea::Kount.credentials
73
+
74
+ Rails.application.secrets.kount = {
75
+ ens_username: "kount",
76
+ ens_password: "password"
77
+ }
78
+ end
79
+
80
+ def restore_credentials
81
+ Rails.application.secrets.kount = @_old_credentials
82
+ end
83
+
84
+ def auth_headers
85
+ { "Authorization" => "Basic #{Base64.encode64('kount:password')}" }
86
+ end
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,95 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ module Kount
5
+ class ResponseTest < Workarea::TestCase
6
+ def test_json_response
7
+ response = Response.new(kount_response)
8
+ assert response.success?
9
+ end
10
+
11
+ def test_from_error
12
+ response = Response.from_error(kount_error_response)
13
+ expected_body = {
14
+ "MODE" => "E",
15
+ "ERRO" => "701",
16
+ "ERROR_0" => "701 NO_HDR",
17
+ "ERROR_COUNT" => "1",
18
+ "WARNING_COUNT" => "0"
19
+ }
20
+ assert_equal(expected_body, response.body)
21
+ end
22
+
23
+ private
24
+
25
+ def kount_response
26
+ {
27
+ "VERS" => "0630",
28
+ "MODE" => "Q",
29
+ "TRAN" => "7JMZ092R3BMX",
30
+ "MERC" => "200755",
31
+ "SESS" => "12345666",
32
+ "ORDR" => "1234",
33
+ "AUTO" => "A",
34
+ "SCOR" => "34",
35
+ "GEOX" => "US",
36
+ "BRND" => "VISA",
37
+ "REGN" => "US_PA",
38
+ "NETW" => "N",
39
+ "KAPT" => "N",
40
+ "CARDS" => "1",
41
+ "DEVICES" => "1",
42
+ "EMAILS" => "1",
43
+ "VELO" => "0",
44
+ "VMAX" => "0",
45
+ "SITE" => "DEFAULT",
46
+ "DEVICE_LAYERS" => "....",
47
+ "FINGERPRINT" => nil,
48
+ "TIMEZONE" => nil,
49
+ "LOCALTIME" => " ",
50
+ "REGION" => nil,
51
+ "COUNTRY" => nil,
52
+ "PROXY" => nil,
53
+ "JAVASCRIPT" => nil,
54
+ "FLASH" => nil,
55
+ "COOKIES" => nil,
56
+ "HTTP_COUNTRY" => nil,
57
+ "LANGUAGE" => nil,
58
+ "MOBILE_DEVICE" => nil,
59
+ "MOBILE_TYPE" => nil,
60
+ "MOBILE_FORWARDER" => nil,
61
+ "VOICE_DEVICE" => nil,
62
+ "PC_REMOTE" => nil,
63
+ "RULES_TRIGGERED" => 0,
64
+ "COUNTERS_TRIGGERED" => 0,
65
+ "REASON_CODE" => nil,
66
+ "MASTERCARD" => "",
67
+ "DDFS" => nil,
68
+ "DSR" => nil,
69
+ "UAS" => nil,
70
+ "BROWSER" => nil,
71
+ "OS" => nil,
72
+ "PIP_IPAD" => nil,
73
+ "PIP_LAT" => nil,
74
+ "PIP_LON" => nil,
75
+ "PIP_COUNTRY" => nil,
76
+ "PIP_REGION" => nil,
77
+ "PIP_CITY" => nil,
78
+ "PIP_ORG" => nil,
79
+ "IP_IPAD" => nil,
80
+ "IP_LAT" => nil,
81
+ "IP_LON" => nil,
82
+ "IP_COUNTRY" => nil,
83
+ "IP_REGION" => nil,
84
+ "IP_CITY" => nil,
85
+ "IP_ORG" => nil,
86
+ "WARNING_COUNT" => 0,
87
+ }
88
+ end
89
+
90
+ def kount_error_response
91
+ "MODE=E\nERRO=701\nERROR_0=701 NO_HDR\nERROR_COUNT=1\nWARNING_COUNT=0"
92
+ end
93
+ end
94
+ end
95
+ end