workarea-forter 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (120) hide show
  1. checksums.yaml +7 -0
  2. data/.editorconfig +20 -0
  3. data/.github/ISSUE_TEMPLATE/bug_report.md +37 -0
  4. data/.github/ISSUE_TEMPLATE/documentation-request.md +17 -0
  5. data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  6. data/.gitignore +17 -0
  7. data/CHANGELOG.md +63 -0
  8. data/CODE_OF_CONDUCT.md +3 -0
  9. data/CONTRIBUTING.md +3 -0
  10. data/Gemfile +25 -0
  11. data/LICENSE +52 -0
  12. data/LICENSE.md +3 -0
  13. data/README.md +113 -0
  14. data/Rakefile +60 -0
  15. data/app/controllers/workarea/admin/orders_controller.decorator +6 -0
  16. data/app/controllers/workarea/storefront/application_controller.decorator +10 -0
  17. data/app/models/search/admin/order.decorator +7 -0
  18. data/app/models/workarea/checkout/collect_payment.decorator +75 -0
  19. data/app/models/workarea/forter/decision.rb +18 -0
  20. data/app/models/workarea/forter/response.rb +15 -0
  21. data/app/models/workarea/fulfillment.decorator +77 -0
  22. data/app/models/workarea/order/status/suspected_fraud.rb +13 -0
  23. data/app/models/workarea/order.decorator +14 -0
  24. data/app/models/workarea/payment/saved_credit_card.decorator +14 -0
  25. data/app/models/workarea/payment/status/suspected_fraud.rb +13 -0
  26. data/app/models/workarea/payment/tender/credit_card.decorator +25 -0
  27. data/app/models/workarea/payment.decorator +13 -0
  28. data/app/services/workarea/forter/account.rb +42 -0
  29. data/app/services/workarea/forter/order.rb +145 -0
  30. data/app/services/workarea/forter/payment.rb +80 -0
  31. data/app/services/workarea/forter/tender/credit_card.rb +73 -0
  32. data/app/services/workarea/forter/tender/general.rb +29 -0
  33. data/app/services/workarea/forter/tender/gift_card.rb +23 -0
  34. data/app/services/workarea/forter/tender/paypal.rb +38 -0
  35. data/app/services/workarea/forter/tender/store_credit.rb +23 -0
  36. data/app/view_models/workarea/admin/order_view_model.decorator +7 -0
  37. data/app/views/workarea/admin/orders/_forter.html.haml +18 -0
  38. data/app/views/workarea/admin/orders/forter.html.haml +57 -0
  39. data/app/views/workarea/storefront/_forter_tracking.html.haml +4 -0
  40. data/app/workers/forter/update_status.rb +21 -0
  41. data/app/workers/workarea/save_user_order_details.decorator +34 -0
  42. data/bin/rails +20 -0
  43. data/config/initializers/appends.rb +9 -0
  44. data/config/initializers/workarea.rb +22 -0
  45. data/config/locales/en.yml +26 -0
  46. data/config/routes.rb +7 -0
  47. data/lib/workarea/forter/bogus_gateway.rb +62 -0
  48. data/lib/workarea/forter/decision_response.rb +60 -0
  49. data/lib/workarea/forter/engine.rb +8 -0
  50. data/lib/workarea/forter/gateway.rb +66 -0
  51. data/lib/workarea/forter/version.rb +5 -0
  52. data/lib/workarea/forter.rb +50 -0
  53. data/test/dummy/Rakefile +6 -0
  54. data/test/dummy/bin/bundle +3 -0
  55. data/test/dummy/bin/rails +4 -0
  56. data/test/dummy/bin/rake +4 -0
  57. data/test/dummy/bin/setup +30 -0
  58. data/test/dummy/bin/update +26 -0
  59. data/test/dummy/bin/yarn +11 -0
  60. data/test/dummy/config/application.rb +30 -0
  61. data/test/dummy/config/boot.rb +5 -0
  62. data/test/dummy/config/cable.yml +10 -0
  63. data/test/dummy/config/environment.rb +5 -0
  64. data/test/dummy/config/environments/development.rb +51 -0
  65. data/test/dummy/config/environments/production.rb +88 -0
  66. data/test/dummy/config/environments/test.rb +44 -0
  67. data/test/dummy/config/initializers/application_controller_renderer.rb +8 -0
  68. data/test/dummy/config/initializers/assets.rb +14 -0
  69. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  70. data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
  71. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  72. data/test/dummy/config/initializers/inflections.rb +16 -0
  73. data/test/dummy/config/initializers/mime_types.rb +4 -0
  74. data/test/dummy/config/initializers/workarea.rb +5 -0
  75. data/test/dummy/config/initializers/wrap_parameters.rb +9 -0
  76. data/test/dummy/config/locales/en.yml +33 -0
  77. data/test/dummy/config/puma.rb +56 -0
  78. data/test/dummy/config/routes.rb +5 -0
  79. data/test/dummy/config/secrets.yml +32 -0
  80. data/test/dummy/config/spring.rb +6 -0
  81. data/test/dummy/config.ru +5 -0
  82. data/test/dummy/db/seeds.rb +2 -0
  83. data/test/dummy/log/.keep +0 -0
  84. data/test/factories/forter.rb +132 -0
  85. data/test/integration/workarea/admin/forter_order_integration_test.rb +36 -0
  86. data/test/integration/workarea/forter_authorize_cim_response_code_integration_test.rb +69 -0
  87. data/test/integration/workarea/forter_braintree_response_code_integration_test.rb +69 -0
  88. data/test/integration/workarea/forter_checkoutdotcom_integration_test.rb +71 -0
  89. data/test/integration/workarea/forter_cybersource_response_code_integration_test.rb +69 -0
  90. data/test/integration/workarea/forter_moneris_response_code_integration_test.rb +69 -0
  91. data/test/integration/workarea/forter_payflow_pro_response_code_test.rb +69 -0
  92. data/test/integration/workarea/storefront/forter_integration_test.rb +138 -0
  93. data/test/lib/workarea/forter/gateway_test.rb +47 -0
  94. data/test/models/workarea/checkout/forter_collect_payment_test.rb +60 -0
  95. data/test/models/workarea/forter_payment_test.rb +58 -0
  96. data/test/models/workarea/payment/forter_credit_card_test.rb +19 -0
  97. data/test/models/workarea/payment/forter_saved_credit_card_test.rb +32 -0
  98. data/test/services/workarea/forter/order_test.rb +82 -0
  99. data/test/support/workarea/forter_api_config.rb +27 -0
  100. data/test/system/workarea/admin/forter_system_test.rb +31 -0
  101. data/test/system/workarea/storefront/forter_braintree_checkout_system_test.rb +79 -0
  102. data/test/system/workarea/storefront/forter_tracking_system_test.rb +20 -0
  103. data/test/system/workarea/storefront/guest_checkout_system_test.decorator +43 -0
  104. data/test/teaspoon_env.rb +6 -0
  105. data/test/test_helper.rb +11 -0
  106. data/test/vcr_cassettes/forter/get_decision.yml +66 -0
  107. data/test/vcr_cassettes/forter/integration/authorize_net_response_code.yml +410 -0
  108. data/test/vcr_cassettes/forter/integration/braintree_response_code.yml +231 -0
  109. data/test/vcr_cassettes/forter/integration/checkoutdotcom_response_code.yml +129 -0
  110. data/test/vcr_cassettes/forter/integration/cyber_response_code.yml +199 -0
  111. data/test/vcr_cassettes/forter/integration/moneris_response_code.yml +84 -0
  112. data/test/vcr_cassettes/forter/integration/payflow_pro_response_code.yml +60 -0
  113. data/test/vcr_cassettes/forter/system/braintree_approved.yml +293 -0
  114. data/test/vcr_cassettes/forter/system/braintree_declined.yml +485 -0
  115. data/test/vcr_cassettes/forter/system/braintree_not_reviewed.yml +293 -0
  116. data/test/vcr_cassettes/forter/update_status.yml +182 -0
  117. data/test/view_models/workarea/storefront/order_view_model_test.decorator +10 -0
  118. data/test/workers/forter/update_status_test.rb +22 -0
  119. data/workarea-forter.gemspec +18 -0
  120. metadata +195 -0
@@ -0,0 +1,69 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ class ForterCybersourceResponseCodeIntegrationTest < Workarea::IntegrationTest
5
+ if Workarea::Plugin.installed?(:CyberSource)
6
+ include ForterApiConfig
7
+ include CyberSourceGatewayVCRConfig
8
+
9
+ def test_response_code
10
+ VCR.use_cassette 'forter/integration/cyber_response_code' do
11
+
12
+ tender.amount = 5.to_m
13
+ transaction = tender.build_transaction(action: 'authorize')
14
+ operation = Payment::Authorize::CreditCard.new(tender, transaction)
15
+ operation.complete!
16
+ transaction.save!
17
+
18
+ response_code = Workarea.config.forter.response_code[gateway_class].call(transaction)
19
+ assert_equal('100', response_code)
20
+ end
21
+ end
22
+
23
+ private
24
+
25
+ def gateway_class
26
+ gateway.class.to_s
27
+ end
28
+
29
+ def gateway
30
+ Workarea.config.gateways.credit_card
31
+ end
32
+
33
+ def payment
34
+ @payment ||=
35
+ begin
36
+ profile = create_payment_profile
37
+ create_payment(
38
+ profile_id: profile.id,
39
+ address: {
40
+ first_name: 'Ben',
41
+ last_name: 'Crouse',
42
+ street: '22 s. 3rd st.',
43
+ city: 'Philadelphia',
44
+ region: 'PA',
45
+ postal_code: '19106',
46
+ country: Country['US']
47
+ }
48
+ )
49
+ end
50
+ end
51
+
52
+ def tender
53
+ @tender ||=
54
+ begin
55
+ payment.set_address(first_name: 'Ben', last_name: 'Crouse')
56
+
57
+ payment.build_credit_card(
58
+ number: 4111111111111111,
59
+ month: 1,
60
+ year: Time.current.year + 1,
61
+ cvv: 999
62
+ )
63
+
64
+ payment.credit_card
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,69 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ class ForterMonerisResponseCodeIntegrationTest < Workarea::IntegrationTest
5
+ if Workarea::Plugin.installed?(:moneris)
6
+ include ForterApiConfig
7
+ include MonerisGatewayVCRConfig
8
+
9
+ def test_response_code
10
+ VCR.use_cassette 'forter/integration/moneris_response_code' do
11
+
12
+ tender.amount = 10.10.to_m
13
+ transaction = tender.build_transaction(action: 'authorize')
14
+ operation = Payment::Authorize::CreditCard.new(tender, transaction)
15
+ operation.complete!
16
+ transaction.save!
17
+
18
+ response_code = Workarea.config.forter.response_code[gateway_class].call(transaction)
19
+ assert_equal('027', response_code)
20
+ end
21
+ end
22
+
23
+ private
24
+
25
+ def gateway_class
26
+ gateway.class.to_s
27
+ end
28
+
29
+ def gateway
30
+ Workarea.config.gateways.credit_card
31
+ end
32
+
33
+ def payment
34
+ @payment ||=
35
+ begin
36
+ profile = create_payment_profile
37
+ create_payment(
38
+ profile_id: profile.id,
39
+ address: {
40
+ first_name: 'Ben',
41
+ last_name: 'Crouse',
42
+ street: '22 s. 3rd st.',
43
+ city: 'Philadelphia',
44
+ region: 'PA',
45
+ postal_code: '19106',
46
+ country: Country['US']
47
+ }
48
+ )
49
+ end
50
+ end
51
+
52
+ def tender
53
+ @tender ||=
54
+ begin
55
+ payment.set_address(first_name: 'Ben', last_name: 'Crouse')
56
+
57
+ payment.build_credit_card(
58
+ number: 4111111111111111,
59
+ month: 1,
60
+ year: Time.current.year + 1,
61
+ cvv: 999
62
+ )
63
+
64
+ payment.credit_card
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,69 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ class ForterPayFlowProResponseCodeIntegrationTest < Workarea::IntegrationTest
5
+ if Workarea::Plugin.installed?(:PayflowPro)
6
+ include ForterApiConfig
7
+ include PayflowProGatewayVCRConfig
8
+
9
+ def test_response_code
10
+ VCR.use_cassette 'forter/integration/payflow_pro_response_code' do
11
+
12
+ tender.amount = 5.to_m
13
+ transaction = tender.build_transaction(action: 'authorize')
14
+ operation = Payment::Authorize::CreditCard.new(tender, transaction)
15
+ operation.complete!
16
+ transaction.save!
17
+
18
+ response_code = Workarea.config.forter.response_code[gateway_class].call(transaction)
19
+ assert_equal('0', response_code)
20
+ end
21
+ end
22
+
23
+ private
24
+
25
+ def gateway_class
26
+ gateway.class.to_s
27
+ end
28
+
29
+ def gateway
30
+ Workarea.config.gateways.credit_card
31
+ end
32
+
33
+ def payment
34
+ @payment ||=
35
+ begin
36
+ profile = create_payment_profile
37
+ create_payment(
38
+ profile_id: profile.id,
39
+ address: {
40
+ first_name: 'Ben',
41
+ last_name: 'Crouse',
42
+ street: '22 s. 3rd st.',
43
+ city: 'Philadelphia',
44
+ region: 'PA',
45
+ postal_code: '19106',
46
+ country: Country['US']
47
+ }
48
+ )
49
+ end
50
+ end
51
+
52
+ def tender
53
+ @tender ||=
54
+ begin
55
+ payment.set_address(first_name: 'Ben', last_name: 'Crouse')
56
+
57
+ payment.build_credit_card(
58
+ number: 4111111111111111,
59
+ month: 1,
60
+ year: Time.current.year + 1,
61
+ cvv: 999
62
+ )
63
+
64
+ payment.credit_card
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,138 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ module Storefront
5
+ class ForterIntegrationTest < Workarea::IntegrationTest
6
+
7
+ def test_decision_approved
8
+ complete_checkout("approved@workarea.com", 'W3blinc1')
9
+
10
+ order = Workarea::Order.last
11
+ payment = Workarea::Payment.last
12
+
13
+ decision = Workarea::Forter::Decision.find(order.id)
14
+
15
+ refute(decision.response.suspected_fraud?)
16
+
17
+ order.reload
18
+ refute(order.flagged_for_fraud?)
19
+ refute(payment.flagged_for_fraud?)
20
+ end
21
+
22
+ def test_decision_not_reviewed
23
+ user = create_user(email: "notreviewed@workarea.com", password: 'W3blinc1')
24
+ complete_checkout("notreviewed@workarea.com", 'W3blinc1')
25
+
26
+ order = Workarea::Order.last
27
+ payment = Workarea::Payment.last
28
+ decision = Workarea::Forter::Decision.find(order.id)
29
+
30
+ refute(payment.flagged_for_fraud?)
31
+ refute(decision.response.suspected_fraud?)
32
+ end
33
+
34
+ def test_decision_declined
35
+ user = create_user(email: "decline@workarea.com", password: 'W3blinc1')
36
+ complete_checkout("decline@workarea.com", 'W3blinc1')
37
+
38
+ order = Workarea::Order.last
39
+ decision = Workarea::Forter::Decision.find(order.id)
40
+ assert(decision.response.suspected_fraud?)
41
+
42
+ payment = Workarea::Payment.last
43
+ transaction = payment.tenders.first.transactions.first
44
+
45
+ assert(transaction.cancellation.present?)
46
+
47
+ order.reload
48
+ payment.reload
49
+
50
+ assert(order.flagged_for_fraud?)
51
+ assert_equal(:suspected_fraud, order.status)
52
+
53
+ assert(payment.flagged_for_fraud?)
54
+ assert_equal(:suspected_fraud, payment.status)
55
+ end
56
+
57
+ def test_gateway_error
58
+ user = create_user(email: "error@workarea.com", password: 'W3blinc1')
59
+ complete_checkout("error@workarea.com", 'W3blinc1')
60
+
61
+ order = Workarea::Order.last
62
+ payment = Workarea::Payment.last
63
+ decision = Workarea::Forter::Decision.find(order.id)
64
+
65
+ refute(payment.flagged_for_fraud?)
66
+ refute(decision.response.suspected_fraud?)
67
+ assert(decision.response.errors.present?)
68
+ end
69
+
70
+ def product
71
+ @product ||= create_product(
72
+ name: 'Integration Product',
73
+ variants: [
74
+ { sku: 'SKU1', tax_code: '001', regular: 5.to_m }
75
+ ]
76
+ )
77
+ end
78
+
79
+ def complete_checkout(email = nil, password = nil)
80
+ if Shipping::Service.blank?
81
+ create_shipping_service(
82
+ name: 'Ground',
83
+ tax_code: '001',
84
+ rates: [{ price: 7.to_m }]
85
+ )
86
+ end
87
+
88
+ post storefront.cart_items_path,
89
+ params: {
90
+ product_id: product.id,
91
+ sku: product.skus.first,
92
+ quantity: 2
93
+ }
94
+
95
+ if email.present? && password.present?
96
+ post storefront.login_path,
97
+ params: { email: email, password: password }
98
+ end
99
+
100
+ patch storefront.checkout_addresses_path,
101
+ params: {
102
+ email: email,
103
+ billing_address: {
104
+ first_name: 'Ben',
105
+ last_name: 'Crouse',
106
+ street: '12 N. 3rd St.',
107
+ city: 'Philadelphia',
108
+ region: 'PA',
109
+ postal_code: '19106',
110
+ country: 'US',
111
+ phone_number: '2159251800'
112
+ },
113
+ shipping_address: {
114
+ first_name: 'Ben',
115
+ last_name: 'Crouse',
116
+ street: '22 S. 3rd St.',
117
+ city: 'Philadelphia',
118
+ region: 'PA',
119
+ postal_code: '19106',
120
+ country: 'US',
121
+ phone_number: '2159251800'
122
+ }
123
+ }
124
+
125
+ patch storefront.checkout_place_order_path,
126
+ params: {
127
+ payment: 'new_card',
128
+ credit_card: {
129
+ number: '1',
130
+ month: 1,
131
+ year: 2020,
132
+ cvv: '999'
133
+ }
134
+ }
135
+ end
136
+ end
137
+ end
138
+ end
@@ -0,0 +1,47 @@
1
+ require "test_helper"
2
+
3
+ module Workarea
4
+ module Forter
5
+ class GatewayTest < Workarea::TestCase
6
+ include ForterApiConfig
7
+
8
+ def gateway
9
+ Workarea::Forter::Gateway.new(
10
+ secret_key: Rails.application.secrets.forter[:secret_key],
11
+ site_id: site_id
12
+ )
13
+ end
14
+
15
+ def test_get_decision
16
+ VCR.use_cassette("forter/get_decision", match_requests_on: [:method, :uri]) do
17
+ order = create_placed_forter_order(id: "fortertest1234", email: "approve@forter.com")
18
+
19
+ forter_decision = Forter::Decision.find order.id
20
+ response = forter_decision.responses.first
21
+ assert response.decision_response.success?
22
+ end
23
+ end
24
+
25
+ def test_update_order_status
26
+ VCR.use_cassette("forter/update_status", match_requests_on: [:method, :uri]) do
27
+ order = create_placed_forter_order(id: "statusfortertest12345", email: "approve@forter.com")
28
+
29
+ hsh = Forter::Order.new(order).to_h
30
+
31
+ response = gateway.create_decision(order.id, hsh)
32
+ assert(response.success?)
33
+
34
+
35
+ hsh = {
36
+ orderId: order.id,
37
+ eventTime: Time.new.to_i * 1000,
38
+ updatedStatus: "CANCELED_BY_MERCHANT"
39
+ }
40
+
41
+ update_status_response = gateway.update_order_status(order.id, hsh)
42
+ assert(update_status_response.success?)
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,60 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ class Checkout
5
+ class ForterCollectPaymentTest < TestCase
6
+ setup :create_models
7
+
8
+ def test_rescuing_timeout_errors
9
+ Workarea::Forter::BogusGateway
10
+ .any_instance
11
+ .stubs(:create_decision)
12
+ .raises(Faraday::Error::TimeoutError)
13
+ refute(@collect_payment.purchase)
14
+
15
+ forter_decision = Forter::Decision.find(@order.id)
16
+ assert_equal(2, forter_decision.responses.size)
17
+ forter_decision.responses.each do |response|
18
+ assert response.timed_out
19
+ end
20
+ end
21
+
22
+ def test_with_one_timeout
23
+ normal_response = Forter.gateway.create_decision(@order.id, Forter::Order.new(@order).to_h)
24
+ Workarea::Forter::BogusGateway
25
+ .any_instance
26
+ .stubs(:create_decision)
27
+ .raises(Faraday::Error::TimeoutError)
28
+ .then
29
+ .returns(normal_response)
30
+
31
+ refute(@collect_payment.purchase)
32
+ forter_decision = Forter::Decision.find(@order.id)
33
+ assert_equal(2, forter_decision.responses.size)
34
+
35
+ assert(forter_decision.responses.first.timed_out)
36
+ refute(forter_decision.responses.second.timed_out)
37
+ end
38
+
39
+ private
40
+
41
+ def create_models
42
+ @order = Order.create!(email: 'test@workarea.com', total_price: 5.to_m)
43
+ @checkout = Checkout.new(@order)
44
+ @payment = Payment.create!(
45
+ id: @order.id,
46
+ address: {
47
+ first_name: "Ben",
48
+ last_name: "Crouse",
49
+ street: "22 S 3rd St",
50
+ city: "Philadelphia",
51
+ region: "PA",
52
+ country: Country['US'],
53
+ postal_code: 19106
54
+ }
55
+ )
56
+ @collect_payment = CollectPayment.new(@checkout)
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,58 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ class ForterPaymentTest < TestCase
5
+
6
+ def response
7
+ ActiveMerchant::Billing::Response.new(
8
+ true,
9
+ 'Message',
10
+ {},
11
+ { authorization: 'ABCDEFG' }
12
+ )
13
+ end
14
+
15
+ def test_rollback
16
+ payment = Payment.new(
17
+ address: {
18
+ first_name: 'Ben',
19
+ last_name: 'Crouse',
20
+ street: '22 S. 3rd St.',
21
+ street_2: 'Second Floor',
22
+ city: 'Philadelphia',
23
+ region: 'PA',
24
+ postal_code: '19106',
25
+ country: 'US',
26
+ phone_number: '2159251800'
27
+ }
28
+ )
29
+ payment.profile = create_payment_profile(
30
+ email: 'test@workarea.com',
31
+ store_credit: 1.to_m
32
+ )
33
+ payment.build_store_credit
34
+
35
+ payment.build_credit_card(
36
+ number: '4111111111111111',
37
+ month: 1,
38
+ year: Time.current.year + 1,
39
+ cvv: 999,
40
+ amount: 9.to_m
41
+ )
42
+
43
+ payment.save!
44
+
45
+ tender = payment.credit_card
46
+ tender.build_transaction(amount: 10.to_m, success: true, action: 'authorize', response: response).save!
47
+
48
+ store_credit_tender = payment.store_credit
49
+ store_credit_tender.build_transaction(amount: 1.to_m, success: true, action: 'authorize', response: response).save!
50
+
51
+ payment.rollback!
52
+
53
+ transactions = payment.tenders.flat_map(&:transactions)
54
+
55
+ assert(transactions.all? { |t| t.canceled_at.present? })
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,19 @@
1
+ require 'test_helper'
2
+ module Workarea
3
+ class Payment
4
+ class ForterCreditCardTest < TestCase
5
+
6
+ def credit_card
7
+ @credit_card ||= Workarea::Payment::Tender::CreditCard.new
8
+ end
9
+
10
+ def test_valid?
11
+ credit_card.number = 4111111111111111
12
+ credit_card.valid?
13
+ assert(credit_card.display_number.present?)
14
+ assert(credit_card.issuer.present?)
15
+ assert(credit_card.bin.present?)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,32 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ class Payment::ForterSavedCreditCardTest < TestCase
5
+ def test_save
6
+ card = Workarea::Payment::SavedCreditCard.new(
7
+ profile: create_payment_profile(reference: '234'),
8
+ number: '4111111111111111',
9
+ cvv: '123',
10
+ month: 12,
11
+ year: Time.current.year + 1,
12
+ first_name: 'Robert',
13
+ last_name: 'Clams'
14
+ )
15
+
16
+ card.save
17
+ assert(card.tokenized?)
18
+ assert(card.bin.present?)
19
+ assert_equal('411111', card.bin)
20
+
21
+ profile = create_payment_profile
22
+ current_default = create_saved_credit_card(profile: profile, default: true)
23
+ new_default = create_saved_credit_card(profile: profile, default: true)
24
+
25
+ current_default.reload
26
+ new_default.reload
27
+
28
+ refute(current_default.default?)
29
+ assert(new_default.default?)
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,82 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ module Foter
5
+ class OrderTest < Workarea::TestCase
6
+ def test_to_h
7
+ user = create_user(id: 'u-1234', first_name: 'jeffy', last_name: 'tester')
8
+ order = create_placed_forter_order(overrides = { id: '1234', user_id: user.id })
9
+ hsh = Forter::Order.new(order).to_h
10
+
11
+ payment = Workarea::Payment.find('1234')
12
+ shipping = Workarea::Shipping.find_by_order('1234')
13
+
14
+ assert_equal(order.id, hsh[:orderId])
15
+ assert_equal("WEB", hsh[:orderType])
16
+
17
+ assert_equal(payment.address.first_name, hsh[:primaryRecipient][:personalDetails][:firstName])
18
+ assert_equal(payment.address.last_name, hsh[:primaryRecipient][:personalDetails][:lastName])
19
+
20
+ assert_equal(shipping.address.street, hsh[:primaryRecipient][:address][:address1])
21
+ assert_equal(shipping.address.city, hsh[:primaryRecipient][:address][:city])
22
+ assert_equal(shipping.address.country.alpha2, hsh[:primaryRecipient][:address][:country])
23
+
24
+ assert_equal(order.total_price.to_s, hsh[:totalAmount][:amountUSD])
25
+
26
+ assert_equal(1, hsh[:cartItems].size)
27
+
28
+ assert_equal(1, hsh[:payment].size)
29
+ assert_equal(order.total_price.to_s, hsh[:payment].first[:amount][:amountUSD])
30
+
31
+ assert_equal(user.first_name, hsh[:accountOwner][:firstName])
32
+ assert_equal(user.last_name, hsh[:accountOwner][:lastName])
33
+ assert_equal(user.email, hsh[:accountOwner][:email])
34
+ assert_equal(user.id, hsh[:accountOwner][:accountId])
35
+
36
+ assert_equal("123ABC", hsh[:connectionInformation][:forterTokenCookie])
37
+ end
38
+
39
+ def test_to_h_with_no_shipping_address
40
+ order = create_placed_forter_order(overrides = { id: '1234' })
41
+ payment = Workarea::Payment.find('1234')
42
+
43
+ #remove the shipping so it falls back to payment address
44
+ shipping = Workarea::Shipping.find_by_order('1234')
45
+ shipping.delete
46
+
47
+ hsh = Forter::Order.new(order).to_h
48
+ assert_equal(payment.address.street, hsh[:primaryRecipient][:address][:address1])
49
+ assert_equal(payment.address.city, hsh[:primaryRecipient][:address][:city])
50
+ assert_equal(payment.address.country.alpha2, hsh[:primaryRecipient][:address][:country])
51
+ end
52
+
53
+ def test_to_h_multiple_tenders
54
+ user = create_user(id: 'u-12345', first_name: 'jeffy', last_name: 'tester')
55
+ order = create_placed_forter_order(overrides = { id: '1234', user_id: user.id }, options = { store_credit_amount: 5.00 })
56
+ hsh = Forter::Order.new(order).to_h
57
+
58
+ assert_equal(2, hsh[:payment].size)
59
+ assert(hsh[:payment].all? { |p| p[:billingDetails].present? })
60
+ end
61
+
62
+ def test_to_h_guest_order
63
+ order = create_placed_order(id: '1234')
64
+ payment = Workarea::Payment.find('1234')
65
+
66
+ hsh = Forter::Order.new(order).to_h
67
+
68
+ assert_equal(payment.address.first_name, hsh[:accountOwner][:firstName])
69
+ assert_equal(payment.address.last_name, hsh[:accountOwner][:lastName])
70
+ assert_equal(order.email, hsh[:accountOwner][:email])
71
+ end
72
+
73
+ def test_to_h_promo_code
74
+ order = create_placed_order(id: '1234')
75
+ order.promo_codes = ['1234']
76
+
77
+ hsh = Forter::Order.new(order).to_h
78
+ assert_equal('1234', hsh[:totalDiscount][:couponCodeUsed])
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,27 @@
1
+ module Workarea
2
+ module ForterApiConfig
3
+ def self.included(test)
4
+ super
5
+ test.setup :set_key
6
+ test.teardown :reset_key
7
+ end
8
+
9
+ def site_id
10
+ "4d12ac5d794c"
11
+ end
12
+
13
+ def set_key
14
+ @_old_secrets = Rails.application.secrets.forter
15
+ @old_site_id = Workarea.config.forter.site_id
16
+ Workarea.config.forter.site_id = site_id
17
+ Rails.application.secrets.forter = {
18
+ secret_key: 'a'
19
+ }
20
+ end
21
+
22
+ def reset_key
23
+ Rails.application.secrets.forter = @_old_secrets
24
+ Workarea.config.forter.site_id = @old_site_id
25
+ end
26
+ end
27
+ end