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
@@ -0,0 +1,62 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ module Kount
5
+ class SecurityMashTest < Workarea::TestCase
6
+ def test_hash_token
7
+ fixture_cards = [
8
+ ["7103387671500967", "710338010UCJ25C9JLKG"],
9
+ ["5199185454061655", "5199182QMVHKQ9X56M9X"],
10
+ ["4259344583883", "425934CG9C5L4J9JU6W3"],
11
+ ["6495347478600780", "649534VVS6JHO5CDQFIW"],
12
+ ["4990160432687370", "499016QLDL0OP3SMX0MT"],
13
+ ["2630847576846156", "263084CARRC9W3XDLS8R"]
14
+ ]
15
+
16
+ fixture_cards.each do |(card, hashed)|
17
+ assert_equal(
18
+ hashed,
19
+ Kount::SecurityMash.hash_token(card, 'CARD', ksalt)
20
+ )
21
+ end
22
+ end
23
+
24
+ def test_hash_token_when_already_hashed
25
+ fixture_cards = [
26
+ ["499016QLDL0OP3SMX0MT", "499016QLDL0OP3SMX0MT"],
27
+ ["425934CG9C5L4J9JU6W3", "425934CG9C5L4J9JU6W3"],
28
+ ["710338010UCJ25C9JLKG", "710338010UCJ25C9JLKG"]
29
+ ]
30
+
31
+ fixture_cards.each do |(card, hashed)|
32
+ assert_equal(
33
+ hashed,
34
+ Kount::SecurityMash.hash_token(card, 'CARD', ksalt)
35
+ )
36
+ end
37
+ end
38
+
39
+ def test_hash_gift_card
40
+ merchant_id = '555555'
41
+ fixture_cards = [
42
+ ["7388460E9D", "555555UF1IG4DV7HRWN3"],
43
+ ["50906199", "5555559JUX7H9KGJYHH8"],
44
+ ["41658068FC266C309", "555555ZFV2XK4ELP9OMJ"]
45
+ ]
46
+
47
+ fixture_cards.each do |(card, hashed)|
48
+ assert_equal(
49
+ hashed,
50
+ Kount::SecurityMash.hash_token(card, 'GIFT', ksalt, merchant_id)
51
+ )
52
+ end
53
+ end
54
+
55
+ private
56
+
57
+ def ksalt
58
+ 'public-test-salt'
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,44 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ class Checkout
5
+ module Fraud
6
+ class KountAnalyzerTest < Workarea::TestCase
7
+ setup :setup_sandbox_credentials
8
+ teardown :restore_credentials
9
+
10
+ def test_basic_fraud_test
11
+ checkout = create_purchasable_checkout(order: {
12
+ kount_session_id: '12345666',
13
+ ip_address: '170.115.187.68'
14
+ })
15
+
16
+ VCR.use_cassette("kount/basic_fraud_test") do
17
+ analyzer = KountAnalyzer.new(checkout)
18
+ response = analyzer.decide!
19
+
20
+ assert_equal(:approved, response.decision)
21
+ end
22
+ end
23
+
24
+ private
25
+
26
+ def setup_sandbox_credentials
27
+ @_old_credentials = Workarea::Kount.credentials
28
+
29
+ Rails.application.secrets.kount = {
30
+ merchant_id: '200755',
31
+ version: '0630',
32
+ key: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiIyMDA3NTUiLCJhdWQiOiJLb3VudC4xIiwiaWF0IjoxNTAwNDA3NTE1LCJzY3AiOnsia2EiOm51bGwsImtjIjpudWxsLCJhcGkiOnRydWUsInJpcyI6dHJ1ZX19.1YwTR1G8qBQ_TDK8MBYxDB2EhpUD0IlwWdvqHVOnm0o',
33
+ ksalt: '4077th hawkeye trapper radar section-8',
34
+ is_test: true
35
+ }
36
+ end
37
+
38
+ def restore_credentials
39
+ Rails.application.secrets.kount = @_old_credentials
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,22 @@
1
+ module Workarea
2
+ decorate CheckoutTest, with: :kount do
3
+ def test_handle_kount_review_fails_if_inventory_fails
4
+ checkout = Checkout.new(@order)
5
+
6
+ @order.update!(kount_decision: :review)
7
+ checkout.expects(:complete?).returns(true)
8
+ checkout.expects(:shippable?).returns(true)
9
+ checkout.expects(:payable?).returns(true)
10
+ checkout.inventory.expects(:captured?).returns(false)
11
+
12
+ refute(checkout.handle_kount_review)
13
+ end
14
+
15
+ def test_handle_kount_review_tokenizes_the_card
16
+ checkout = create_purchasable_checkout(order: { kount_decision: :review })
17
+
18
+ assert(checkout.handle_kount_review)
19
+ assert(checkout.payment.credit_card.present?)
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,28 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ decorate Order::QueriesTest, with: :kount do
5
+ def test_kount_orders_do_not_need_reminding
6
+ kount_review = Order.create!(email: email, checkout_started_at: 2.hours.ago, items: [{ product_id: '1', sku: 2 }], kount_decision: :review)
7
+ kount_decline = Order.create!(email: email, checkout_started_at: 2.hours.ago, items: [{ product_id: '1', sku: 2 }], kount_decision: :decline)
8
+ results = Order.need_reminding.to_a
9
+
10
+ refute_includes(results, kount_review)
11
+ refute_includes(results, kount_decline)
12
+ end
13
+
14
+ def test_find_current_by_id_excludes_orders_under_review
15
+ order = create_order(kount_decision: :review)
16
+
17
+ result = Order.find_current(id: order.id)
18
+ refute result.persisted?
19
+ end
20
+
21
+ def test_find_current_by_user_id_excludes_orders_under_review
22
+ _order = create_order(user_id: 'foo', kount_decision: :review)
23
+
24
+ result = Order.find_current(user_id: 'foo')
25
+ refute result.persisted?
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,25 @@
1
+ module Workarea
2
+ decorate OrderTest, with: :kount do
3
+ def test_review_status
4
+ order = Order.new(
5
+ email: 'test@workarea.com',
6
+ created_at: Time.current,
7
+ kount_decision: :review
8
+ )
9
+ order.items.build(product_id: 'PROD', sku: 'SKU1')
10
+
11
+ assert_equal(:review, order.status)
12
+ end
13
+
14
+ def test_kount_review_orders_are_not_abandoned
15
+ order = Order.new(
16
+ email: 'test@workarea.com',
17
+ created_at: Time.current - 1.day,
18
+ kount_decision: :review
19
+ )
20
+ order.items.build(product_id: 'PROD', sku: 'SKU1')
21
+
22
+ refute(order.abandoned?)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,106 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ class PaymentIntegrationTest < Workarea::TestCase
5
+ def test_set_credit_card_sets_the_credit_card_on_the_order
6
+ payment.set_credit_card(number: '1',
7
+ month: 1,
8
+ year: 2012,
9
+ cvv: 999)
10
+
11
+ refute_nil(payment.credit_card)
12
+
13
+ assert_equal('1', payment.credit_card.number)
14
+ assert_equal(1, payment.credit_card.month)
15
+ assert_equal(2012, payment.credit_card.year)
16
+ assert_equal(999, payment.credit_card.cvv)
17
+ end
18
+
19
+ def test_set_credit_card_resets_saved_card_id_on_the_credit_card_when_resetting
20
+ card = create_saved_credit_card(profile: profile)
21
+ card_id = card.id
22
+
23
+ payment.set_credit_card(saved_card_id: card_id, cvv: '999')
24
+ assert_equal(card_id.to_s, payment.credit_card.saved_card_id.to_s)
25
+ assert_equal('999', payment.credit_card.cvv)
26
+
27
+ payment.set_credit_card(
28
+ number: '1',
29
+ month: 1,
30
+ year: 2012,
31
+ cvv: 999
32
+ )
33
+
34
+ assert_equal('1', payment.credit_card.number)
35
+ assert_equal(1, payment.credit_card.month)
36
+ assert_equal(2012, payment.credit_card.year)
37
+ assert(payment.credit_card.saved_card_id.blank?)
38
+ assert_equal(999, payment.credit_card.cvv)
39
+ end
40
+
41
+ def test_set_credit_card_stores_kount_number
42
+ travel_to Time.zone.local(2017, 8, 15, 9, 00, 00)
43
+ profile = create_payment_profile
44
+ payment = create_payment(profile: profile, address: address)
45
+
46
+ payment.set_credit_card(
47
+ number: '4111111111111111',
48
+ month: 1,
49
+ year: Time.now.year + 1,
50
+ cvv: '123',
51
+ amount: 1.to_m,
52
+ saved_card_id: nil
53
+ )
54
+ payment.save
55
+ payment.tenders.first.save
56
+
57
+ payment.reload
58
+ assert_equal('41111193FBKM1EIVIXVP', payment.credit_card.kount_number)
59
+ travel_back
60
+ end
61
+
62
+ def test_set_credit_card_stores_kount_number_from_saved_credit_card
63
+ travel_to Time.zone.local(2017, 8, 15, 9, 00, 00)
64
+ profile = create_payment_profile(email: 'user@workarea.com')
65
+ payment = create_payment(profile: profile, address: address)
66
+
67
+ saved_card = create_saved_credit_card(
68
+ number: '4111111111111111',
69
+ profile: profile
70
+ )
71
+
72
+ payment.set_credit_card(
73
+ saved_card_id: saved_card.id,
74
+ amount: 1.to_m
75
+ )
76
+
77
+ payment.save!
78
+ payment.tenders.first.save
79
+
80
+ payment.reload
81
+ assert_equal('41111193FBKM1EIVIXVP', payment.credit_card.kount_number)
82
+ travel_back
83
+ end
84
+
85
+ def address
86
+ @address ||= Workarea::Address.new(
87
+ first_name: 'Mickey',
88
+ last_name: 'Daltono',
89
+ street: '22 S. 3rd St.',
90
+ city: 'Philadelphia',
91
+ region: 'PA',
92
+ postal_code: '19106',
93
+ country: 'US',
94
+ phone_number: '267-247-2541'
95
+ )
96
+ end
97
+
98
+ def profile
99
+ @profile ||= create_payment_profile
100
+ end
101
+
102
+ def payment
103
+ @payment ||= create_payment(profile: profile)
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,24 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ module Storefront
5
+ class SavedCreditCardTest < Workarea::TestCase
6
+ def test_saving_credit_card_stores_kount_number_for_saved_credit_card
7
+ travel_to Time.zone.local(2017, 8, 15, 9, 00, 00)
8
+
9
+ saved_card = Workarea::Payment::SavedCreditCard.create(
10
+ profile: create_payment_profile(email: 'user@workarea.com'),
11
+ first_name: 'Ben',
12
+ last_name: 'Crouse',
13
+ number: '4111111111111111',
14
+ month: 1,
15
+ year: Time.now.year + 1,
16
+ cvv: '999'
17
+ )
18
+
19
+ assert_equal('41111193FBKM1EIVIXVP', saved_card.kount_number)
20
+ travel_back
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,54 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ decorate PaymentTest, with: :kount do
5
+ def test_status
6
+ order = create_order
7
+ payment = Payment.new(
8
+ id: order.id,
9
+ address: {
10
+ first_name: 'Ben',
11
+ last_name: 'Crouse',
12
+ street: '22 S. 3rd St.',
13
+ street_2: 'Second Floor',
14
+ city: 'Philadelphia',
15
+ region: 'PA',
16
+ postal_code: '19106',
17
+ country: 'US',
18
+ phone_number: '2159251800'
19
+ }
20
+ )
21
+
22
+ assert_equal(:not_applicable, payment.status)
23
+
24
+ payment.build_credit_card(
25
+ number: '4111111111111111',
26
+ month: 1,
27
+ year: Time.current.year + 1,
28
+ cvv: 999,
29
+ amount: 10.to_m
30
+ )
31
+
32
+ tender = payment.credit_card
33
+ payment.save!
34
+
35
+ assert_equal(:pending, payment.status)
36
+
37
+ tender.build_transaction(amount: 10.to_m, success: true, action: 'authorize').save!
38
+
39
+ assert_equal(:authorized, payment.reload.status)
40
+
41
+ tender.build_transaction(amount: 5.to_m, success: true, action: 'capture').save!
42
+ assert_equal(:partially_captured, payment.reload.status)
43
+
44
+ tender.build_transaction(amount: 5.to_m, success: true, action: 'purchase').save!
45
+ assert_equal(:captured, payment.status)
46
+
47
+ tender.build_transaction(amount: 5.to_m, success: true, action: 'refund').save!
48
+ assert_equal(:partially_refunded, payment.reload.status)
49
+
50
+ tender.build_transaction(amount: 5.to_m, success: true, action: 'refund').save!
51
+ assert_equal(:refunded, payment.reload.status)
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,29 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ class ShippingOptionTest < TestCase
5
+ def order
6
+ @order ||= Order.create!(email: 'user@workarea.com')
7
+ end
8
+
9
+ def shipping_service
10
+ @shipping_service ||= create_shipping_service(
11
+ id: '123',
12
+ name: 'Standard Shipping',
13
+ tax_code: '001',
14
+ rates: [{ price: 7.to_m }],
15
+ kount_code: 'ST'
16
+ )
17
+ end
18
+
19
+ def shipment
20
+ @shipment ||= Workarea::Shipping.create!(order_id: order.id).tap { |shipment|
21
+ shipment.shipping_service = shipping_service
22
+ }
23
+ end
24
+
25
+ def test_valid_returns_true_if_a_shipments_shipping_service_contains_a_kount_code
26
+ assert_equal(shipment.shipping_service.kount_code, 'ST')
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,95 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ module Kount
5
+ class EventBatchTest < Workarea::TestCase
6
+ setup :setup_sidekiq
7
+ teardown :teardown_sidekiq
8
+
9
+ def test_valid_with_valid_xml
10
+ event_batch = EventBatch.new(valid_xml)
11
+ assert(event_batch.valid?)
12
+ end
13
+
14
+ def test_valid_with_invalid_xml
15
+ event_batch = EventBatch.new(invalid_xml)
16
+ refute(event_batch.valid?)
17
+ end
18
+
19
+ def test_process_with_valid_xml
20
+ event_batch = EventBatch.new(valid_xml)
21
+ assert_difference 'Workarea::Kount::ProcessReviewOrder.jobs.count', 2 do
22
+ event_batch.process!
23
+ end
24
+ end
25
+
26
+ def test_process_with_invalid_xml
27
+ event_batch = EventBatch.new(invalid_xml)
28
+ assert_difference 'Workarea::Kount::ProcessReviewOrder.jobs.count', 0 do
29
+ event_batch.process!
30
+ end
31
+ end
32
+
33
+ private
34
+
35
+ def valid_xml
36
+ <<~XML
37
+ <?xml version="1.0" encoding="UTF-8" standalone="no"?>
38
+ <events merchant="200755" total="2">
39
+ <event>
40
+ <name>WORKFLOW_STATUS_EDIT</name>
41
+ <key order_number="D58470FCF0" site="DEFAULT">7JG1075ML345</key>
42
+ <old_value>R</old_value>
43
+ <new_value>A</new_value>
44
+ <agent>SYSTEM@KOUNT.NET</agent>
45
+ <occurred>2018-05-18 06:47:47.413756</occurred>
46
+ </event>
47
+ <event>
48
+ <name>WORKFLOW_STATUS_EDIT</name>
49
+ <key order_number="D58470FCF0" site="DEFAULT">7JG601D6MG7S</key>
50
+ <old_value>R</old_value>
51
+ <new_value>D</new_value>
52
+ <agent>SYSTEM@KOUNT.NET</agent>
53
+ <occurred>2018-05-18 06:47:59.252024</occurred>
54
+ </event>
55
+ </events>
56
+ XML
57
+ end
58
+
59
+ def invalid_xml
60
+ <<~XML
61
+ <?xml version="1.0" encoding="UTF-8" standalone="no"?
62
+ <events merchant="200755" total="2">
63
+ <event>
64
+ <name>WORKFLOW_STATUS_EDIT</name>
65
+ <key order_number="D58470FCF0" site="DEFAULT">7JG1075ML345</key>
66
+ <old_value>R</old_value>
67
+ <new_value>A</new_value>
68
+ <agent>SYSTEM@KOUNT.NET</agent>
69
+ <occurred>2018-05-18 06:47:47.413756</occurred>
70
+ </event>
71
+ <event>
72
+ <name>WORKFLOW_STATUS_EDIT</name>
73
+ <key order_number="D58470FCF0" site="DEFAULT">7JG601D6MG7S</key>
74
+ <old_value>R</old_value>
75
+ <new_value>D</new_value>
76
+ <agent>SYSTEM@KOUNT.NET</agent>
77
+ <occurred>2018-05-18 06:47:59.252024</occurred>
78
+ </event>
79
+ </events>
80
+ XML
81
+ end
82
+
83
+ def setup_sidekiq
84
+ Sidekiq::Testing.fake!
85
+
86
+ Workarea::Kount::ProcessReviewOrder.clear
87
+ end
88
+
89
+ def teardown_sidekiq
90
+ Workarea::Kount::ProcessReviewOrder.clear
91
+ Sidekiq::Testing.inline!
92
+ end
93
+ end
94
+ end
95
+ end