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
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8677c1ba833efc27b03b9268a5b3fec4c1ec08e489e7129b1a4cd06e4b2a80b1
4
+ data.tar.gz: 10b6c5bb01c38a7b24c2d255f03100dc5685169a2f7caaecda03d8935bb606d8
5
+ SHA512:
6
+ metadata.gz: 0bc6361719646f98994bdee5bdbe868becb86bd45d3cc28a2997a02dbfffeb609e77c2bc810c61c836b39eda7acbf03cf96c72497dd01f7b6e5ed635b5dfb469
7
+ data.tar.gz: e3a963a6e9155da34bfeee2bfcca89ca2603e8e8895dad5978b86033f23a3f109e2414a22c348ca58f9e238d6d75a42ce2367ea0d98712e4be1fd346fa29010d
data/.editorconfig ADDED
@@ -0,0 +1,20 @@
1
+ # editorconfig.org
2
+ root = true
3
+
4
+ [*]
5
+ charset = utf-8
6
+ indent_style = space
7
+ end_of_line = lf
8
+ trim_trailing_whitespace = true
9
+ insert_final_newline = true
10
+
11
+ [{*.rb,*.haml,*.decorator,*.yml,*.yaml,*.jbuilder}]
12
+ indent_size = 2
13
+ indent_style = space
14
+
15
+ [{*.js,*.jst,*.ejs,*.scss}]
16
+ indent_size = 4
17
+
18
+ [*.md]
19
+ indent_size = 4
20
+ trim_trailing_whitespace = false
@@ -0,0 +1,37 @@
1
+ ---
2
+ name: Bug report
3
+ about: Create a report to help us improve Workarea
4
+ title: ''
5
+ labels: bug
6
+ assignees: ''
7
+
8
+ ---
9
+
10
+ ⚠️**Before you create**⚠️
11
+ Please verify the issue you're experiencing is not part of your Workarea project customizations. The best way to do this is with a [vanilla Workarea installation](https://developer.workarea.com/articles/create-a-new-host-application.html). This will help us spend time on fixes/improvements for the whole community. Thank you!
12
+
13
+ **Describe the bug**
14
+ A clear and concise description of what the bug is.
15
+
16
+ **To Reproduce**
17
+ Steps to reproduce the behavior:
18
+ 1. Go to '...'
19
+ 2. Click on '....'
20
+ 3. Scroll down to '....'
21
+ 4. See error
22
+
23
+ **Expected behavior**
24
+ A clear and concise description of what you expected to happen.
25
+
26
+ **Workarea Setup (please complete the following information):**
27
+ - Workarea Version: [e.g. v3.4.6]
28
+ - Plugins [e.g. workarea-blog, workarea-sitemaps]
29
+
30
+ **Attachments**
31
+ If applicable, add any attachments to help explain your problem, things like:
32
+ - screenshots
33
+ - Gemfile.lock
34
+ - test cases
35
+
36
+ **Additional context**
37
+ Add any other context about the problem here.
@@ -0,0 +1,17 @@
1
+ ---
2
+ name: Documentation request
3
+ about: Suggest documentation
4
+ title: ''
5
+ labels: documentation
6
+ assignees: ''
7
+
8
+ ---
9
+
10
+ **Is your documentation related to a problem? Please describe.**
11
+ A clear and concise description of what the problem is. Ex. I'm confused by [...]
12
+
13
+ **Describe the article you'd like**
14
+ A clear and concise description of what would be in the documentation article.
15
+
16
+ **Additional context**
17
+ Add any other context or screenshots about the feature request here.
@@ -0,0 +1,20 @@
1
+ ---
2
+ name: Feature request
3
+ about: Suggest an idea for Workarea
4
+ title: ''
5
+ labels: enhancement
6
+ assignees: ''
7
+
8
+ ---
9
+
10
+ **Is your feature request related to a problem? Please describe.**
11
+ A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12
+
13
+ **Describe the solution you'd like**
14
+ A clear and concise description of what you want to happen.
15
+
16
+ **Describe alternatives you've considered**
17
+ A clear and concise description of any alternative solutions or features you've considered.
18
+
19
+ **Additional context**
20
+ Add any other context or screenshots about the feature request here.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ .bundle/
2
+ log/*.log
3
+ pkg/
4
+ test/dummy/db/*.sqlite3
5
+ test/dummy/db/*.sqlite3-journal
6
+ test/dummy/log/*.log
7
+ test/dummy/tmp/
8
+ .DS_Store
9
+ .byebug_history
10
+ .bundle/
11
+ .sass-cache/
12
+ Gemfile.lock
13
+ test/dummy/public/
14
+ node_modules
15
+ coverage/
16
+ package.json
17
+ yarn.lock
data/CHANGELOG.md ADDED
@@ -0,0 +1,63 @@
1
+ Workarea Forter 1.2.2 (2019-08-21)
2
+ --------------------------------------------------------------------------------
3
+
4
+ * Open Source!
5
+
6
+
7
+
8
+ Workarea Forter 1.2.1 (2019-08-06)
9
+ --------------------------------------------------------------------------------
10
+
11
+ * Add API version to configuration.
12
+
13
+ FORTER-15
14
+ Jeff Yucis
15
+
16
+ * Set the BIN for saved cards added from my account section
17
+
18
+ FORTER-17
19
+ Jeff Yucis
20
+
21
+
22
+
23
+ Workarea Forter 1.2.0 (2019-04-30)
24
+ --------------------------------------------------------------------------------
25
+
26
+ * Add support for checkout.com payment processor
27
+
28
+ Extracts the payment processor response code used by forter when
29
+ evaluating for fraud.
30
+
31
+ FORTER-13
32
+ Jeff Yucis
33
+
34
+
35
+
36
+ Workarea Forter 1.1.0 (2019-03-19)
37
+ --------------------------------------------------------------------------------
38
+
39
+ * * Remove checkout controller decorator, user agent functionality is part of Workarea now
40
+
41
+ FORTER-12
42
+ Jake Beresford
43
+
44
+ * Update for v3.4
45
+
46
+ * Update CI scripts
47
+ * Remove user_agent decoration from order.rb, this is part of Workarea::Order as of v3.4
48
+ * Update gemspec dependency for workarea to >= 3.4
49
+
50
+ FORTER-12
51
+ Jake Beresford
52
+
53
+
54
+
55
+ Workarea Forter 1.0.0 (2019-03-05)
56
+ --------------------------------------------------------------------------------
57
+
58
+ * Forter fraud protection integration. Automatic decision at checkout with no intervention required from admins.
59
+
60
+ Jeff Yucis
61
+
62
+
63
+
@@ -0,0 +1,3 @@
1
+ View this plugin's code of conduct here:
2
+
3
+ <https://github.com/workarea-commerce/workarea/blob/master/CODE_OF_CONDUCT.md>
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,3 @@
1
+ View this plugin's contribution guidelines here:
2
+
3
+ <https://github.com/workarea-commerce/workarea/blob/master/CONTRIBUTING.md>
data/Gemfile ADDED
@@ -0,0 +1,25 @@
1
+ source 'https://rubygems.org'
2
+ git_source(:github) { |repo| "git@github.com:#{repo}.git" }
3
+
4
+ gemspec
5
+
6
+ gem 'workarea'
7
+ gem 'byebug'
8
+ group :test do
9
+ gem 'simplecov', require: false
10
+
11
+ case ENV['CC_PROCESSOR']
12
+ when 'braintree'
13
+ gem 'workarea-braintree'
14
+ when 'moneris'
15
+ gem 'workarea-moneris'
16
+ when 'authorize_cim'
17
+ gem 'workarea-authorize_cim'
18
+ when 'payflow_pro'
19
+ gem 'workarea-payflow_pro'
20
+ when 'cyber_source'
21
+ gem 'workarea-cyber_source'
22
+ when 'checkoutdotcom'
23
+ gem 'workarea-checkoutdotcom'
24
+ end
25
+ end
data/LICENSE ADDED
@@ -0,0 +1,52 @@
1
+ WebLinc
2
+ Business Source License
3
+
4
+ Licensor: WebLinc Corporation, 22 S. 3rd Street, 2nd Floor, Philadelphia PA 19106
5
+
6
+ Licensed Work: Workarea Commerce Platform
7
+ The Licensed Work is (c) 2019 WebLinc Corporation
8
+
9
+ Additional Use Grant:
10
+ You may make production use of the Licensed Work without an additional license agreement with WebLinc so long as you do not use the Licensed Work for a Commerce Service.
11
+
12
+ A "Commerce Service" is a commercial offering that allows third parties (other than your employees and contractors) to access the functionality of the Licensed Work by creating or managing commerce functionality, the products, taxonomy, assets and/or content of which are controlled by such third parties.
13
+
14
+ For information about obtaining an additional license agreement with WebLinc, contact licensing@workarea.com.
15
+
16
+ Change Date: 2019-08-20
17
+
18
+ Change License: Version 2.0 or later of the GNU General Public License as published by the Free Software Foundation
19
+
20
+ Terms
21
+
22
+ The Licensor hereby grants you the right to copy, modify, create derivative works, redistribute, and make non-production use of the Licensed Work. The Licensor may make an Additional Use Grant, above, permitting limited production use.
23
+
24
+ Effective on the Change Date, or the fourth anniversary of the first publicly available distribution of a specific version of the Licensed Work under this License, whichever comes first, the Licensor hereby grants you rights under the terms of the Change License, and the rights granted in the paragraph above terminate.
25
+
26
+ If your use of the Licensed Work does not comply with the requirements currently in effect as described in this License, you must purchase a commercial license from the Licensor, its affiliated entities, or authorized resellers, or you must refrain from using the Licensed Work.
27
+
28
+ All copies of the original and modified Licensed Work, and derivative works of the Licensed Work, are subject to this License. This License applies separately for each version of the Licensed Work and the Change Date may vary for each version of the Licensed Work released by Licensor.
29
+
30
+ You must conspicuously display this License on each original or modified copy of the Licensed Work. If you receive the Licensed Work in original or modified form from a third party, the terms and conditions set forth in this License apply to your use of that work.
31
+
32
+ Any use of the Licensed Work in violation of this License will automatically terminate your rights under this License for the current and all other versions of the Licensed Work.
33
+
34
+ This License does not grant you any right in any trademark or logo of Licensor or its affiliates (provided that you may use a trademark or logo of Licensor as expressly required by this License). TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON AN "AS IS" BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND TITLE. MariaDB hereby grants you permission to use this License’s text to license your works and to refer to it using the trademark "Business Source License" as long as you comply with the Covenants of Licensor below.
35
+
36
+ Covenants of Licensor
37
+ In consideration of the right to use this License’s text and the "Business Source License" name and trademark, Licensor covenants to MariaDB, and to all other recipients of the licensed work to be provided by Licensor:
38
+
39
+ To specify as the Change License the GPL Version 2.0 or any later version, or a license that is compatible with GPL Version 2.0 or a later version, where "compatible" means that software provided under the Change License can be included in a program with software provided under GPL Version 2.0 or a later version. Licensor may specify additional Change Licenses without limitation.
40
+
41
+ To either: (a) specify an additional grant of rights to use that does not impose any additional restriction on the right granted in this License, as the Additional Use Grant; or (b) insert the text "None."
42
+
43
+ To specify a Change Date.
44
+
45
+ Not to modify this License in any other way.
46
+
47
+ Notice
48
+ The Business Source License (this document, or the "License") is not an Open Source license. However, the Licensed Work will eventually be made available under an Open Source License, as stated in this License.
49
+
50
+ For more information on the use of the Business Source License generally, please visit the Adopting and Developing Business Source License FAQ.
51
+
52
+ License text copyright (c) 2017 MariaDB Corporation Ab, All Rights Reserved. "Business Source License" is a trademark of MariaDB Corporation Ab.
data/LICENSE.md ADDED
@@ -0,0 +1,3 @@
1
+ View this plugin's license here:
2
+
3
+ <https://github.com/workarea-commerce/workarea/blob/master/LICENSE.md>
data/README.md ADDED
@@ -0,0 +1,113 @@
1
+ Workarea Forter
2
+ ================================================================================
3
+
4
+ Forter fraud protection for the Workarea platform that offers guarantees against charge-backs for eligible transactions.
5
+
6
+ This solution currently works for a pre-authorization model of payment, meaning that funds are authorized at checkout then captured at a later date, usually when the product ships.
7
+
8
+ Payments use the following flow:
9
+ 1. A user enters their payment in checkout.
10
+ 2. The payment is authorized.
11
+ 3. An API call is made to Forter.
12
+ + On approval or no-decision the order is placed as usual.
13
+ + On decline the authorized payments are voided and a message is displayed to the user.
14
+
15
+ This plugin is compatible with following Workarea supported payment types:
16
+ + Credit Cards
17
+ + Paypal
18
+ + Gift cards
19
+ + Store credit
20
+
21
+ Payment types not in this list will still function but are not eligible for fraud protection.
22
+
23
+ Configuration
24
+ --------------------------------------------------------------------------------
25
+ Add the secret key to your secrets file:
26
+
27
+ ```
28
+ forter:
29
+ secret_key: XXXXXXXX
30
+ ```
31
+
32
+ Add the site ID to an initializer file in your host app:
33
+
34
+ ```ruby
35
+ Workarea.config.forter.site_id = nil
36
+ ```
37
+
38
+ You can specify which version of the API via configuration:
39
+
40
+ ```ruby
41
+ Workarea.config.forter.api_version = "2.4"
42
+ ```
43
+
44
+ If no API version is configured the default of **2.2** will be used.
45
+
46
+ Implementation Notes
47
+ --------------------------------------------------------------------------------
48
+ **Verifcation Data**
49
+
50
+ Forter relies on verification data returned from the credit processor when validating credit card transactions. This data can vary by credit card processor.
51
+
52
+ Be sure to test that the following data is sent in the **verificationResults** hash sent with each credit card:
53
+ ```
54
+ {
55
+ "avsFullResult": "",
56
+ "cvvResult": "",
57
+ "avsNameResult": "",
58
+ "authorizationCode": "",
59
+ "processorResponseCode": "",
60
+ "processorResponseText": ""
61
+ }
62
+ ```
63
+ **Rolling Back Fraud Transactions**
64
+
65
+ Credit card authorizations are voided when a transaction is deemed to be fraudulent. The void action relies on the #cancel! method implemented on each tenders authorization class. It is very important to implement and test this method when creating a new payment type.
66
+
67
+
68
+ Getting Started
69
+ --------------------------------------------------------------------------------
70
+
71
+ This gem contains a rails engine that must be mounted onto a host Rails application.
72
+
73
+ To access Workarea gems and source code, you must be an employee of WebLinc or a licensed retailer or partner.
74
+
75
+ Workarea gems are hosted privately at https://gems.weblinc.com/.
76
+ You must have individual or team credentials to install gems from this server. Add your gems server credentials to Bundler:
77
+
78
+ bundle config gems.weblinc.com my_username:my_password
79
+
80
+ Or set the appropriate environment variable in a shell startup file:
81
+
82
+ export BUNDLE_GEMS__WEBLINC__COM='my_username:my_password'
83
+
84
+ Then add the gem to your application's Gemfile specifying the source:
85
+
86
+ # ...
87
+ gem 'workarea-forter', source: 'https://gems.weblinc.com'
88
+ # ...
89
+
90
+ Or use a source block:
91
+
92
+ # ...
93
+ source 'https://gems.weblinc.com' do
94
+ gem 'workarea-forter'
95
+ end
96
+ # ...
97
+
98
+ Update your application's bundle.
99
+
100
+ cd path/to/application
101
+ bundle
102
+
103
+ Workarea Platform Documentation
104
+ --------------------------------------------------------------------------------
105
+
106
+ See [http://developer.weblinc.com](http://developer.weblinc.com) for Workarea platform documentation.
107
+
108
+ Copyright & Licensing
109
+ --------------------------------------------------------------------------------
110
+
111
+ Copyright WebLinc 2018. All rights reserved.
112
+
113
+ For licensing, contact sales@workarea.com.
data/Rakefile ADDED
@@ -0,0 +1,60 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+ RDoc::Task.new(:rdoc) do |rdoc|
9
+ rdoc.rdoc_dir = 'rdoc'
10
+ rdoc.title = 'Forter'
11
+ rdoc.options << '--line-numbers'
12
+ rdoc.rdoc_files.include('README.md')
13
+ rdoc.rdoc_files.include('lib/**/*.rb')
14
+ end
15
+
16
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
17
+ load 'rails/tasks/engine.rake'
18
+ load 'rails/tasks/statistics.rake'
19
+ load 'workarea/changelog.rake'
20
+
21
+ require 'rake/testtask'
22
+ Rake::TestTask.new(:test) do |t|
23
+ t.libs << 'lib'
24
+ t.libs << 'test'
25
+ t.pattern = 'test/**/*_test.rb'
26
+ t.verbose = false
27
+ end
28
+ task default: :test
29
+
30
+ $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
31
+ require 'workarea/forter/version'
32
+
33
+ desc "Release version #{Workarea::Forter::VERSION} of the gem"
34
+ task :release do
35
+ host = "https://#{ENV['BUNDLE_GEMS__WEBLINC__COM']}@gems.weblinc.com"
36
+
37
+ #Rake::Task['workarea:changelog'].execute
38
+ #system 'git add CHANGELOG.md'
39
+ #system 'git commit -m "Update CHANGELOG"'
40
+ #system 'git push origin HEAD'
41
+
42
+ system "git tag -a v#{Workarea::Forter::VERSION} -m 'Tagging #{Workarea::Forter::VERSION}'"
43
+ system 'git push --tags'
44
+
45
+ system "gem build workarea-forter.gemspec"
46
+ system "gem push workarea-forter-#{Workarea::Forter::VERSION}.gem"
47
+ system "gem push workarea-forter-#{Workarea::Forter::VERSION}.gem --host #{host}"
48
+ system "rm workarea-forter-#{Workarea::Forter::VERSION}.gem"
49
+ end
50
+
51
+ desc 'Run the JavaScript tests'
52
+ ENV['TEASPOON_RAILS_ENV'] = File.expand_path('../test/dummy/config/environment', __FILE__)
53
+ task teaspoon: 'app:teaspoon'
54
+
55
+ desc 'Start a server at http://localhost:3000/teaspoon for JavaScript tests'
56
+ task :teaspoon_server do
57
+ Dir.chdir("test/dummy")
58
+ teaspoon_env = File.expand_path('../test/teaspoon_env.rb', __FILE__)
59
+ system "RAILS_ENV=test TEASPOON_ENV=#{teaspoon_env} rails s"
60
+ end
@@ -0,0 +1,6 @@
1
+ module Workarea
2
+ decorate Admin::OrdersController, with: :forter do
3
+ def fraud
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,10 @@
1
+ module Workarea
2
+ decorate Storefront::ApplicationController, with: :forter do
3
+
4
+ def current_order
5
+ super.tap do |order|
6
+ order.forter_tracking_code = cookies[:forterToken]
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,7 @@
1
+ module Workarea
2
+ decorate Search::Admin::Order, with: :forter do
3
+ def should_be_indexed?
4
+ model.placed? || model.flagged_for_fraud?
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,75 @@
1
+ module Workarea
2
+ decorate Checkout::CollectPayment, with: :forter do
3
+ def purchase
4
+ collect_result = super
5
+
6
+ begin
7
+ decision = Forter::Decision.find_or_create_by(id: @order.id)
8
+ order_hash = Forter::Order.new(@order).to_h
9
+
10
+ response = get_decision(@order_id, order_hash, decision)
11
+
12
+ # Rollback all transactions if the original collection
13
+ # was successful but the forter decision was a decline.
14
+ if collect_result && response.suspected_fraud?
15
+ payment.rollback!
16
+ payment.flagged_for_fraud = true
17
+
18
+ payment.save!
19
+ false
20
+ else
21
+ # need to re-add errors indicating the payment operation failed
22
+ error_messages = payment.errors.messages.clone
23
+ payment.update_attribute(:flagged_for_fraud, false)
24
+ error_messages.each do |attribute, message|
25
+ payment.errors.add(attribute, message)
26
+ end
27
+ collect_result
28
+ end
29
+
30
+ rescue => e
31
+ Forter.log_error(e)
32
+ return collect_result
33
+ ensure
34
+ decision.save!
35
+ end
36
+ end
37
+
38
+ private
39
+
40
+ ERROR_STATUSES = 500..599
41
+ MAX_RETRIES = 2
42
+
43
+ # Gets forter decision and builds decision responses on the Forter Decision
44
+ # model
45
+ #
46
+ # @raises Error
47
+ #
48
+ # @return [Workarea::Forter::DecisionResponse] response
49
+ #
50
+ def get_decision(order_id, order_hash, decision)
51
+ count = 1
52
+ begin
53
+ fraud_response = Forter.gateway.create_decision(@order.id, order_hash)
54
+ body = JSON.parse(fraud_response.body)
55
+ response = Forter::DecisionResponse.new(body)
56
+
57
+ decision.responses.build(decision_response: response)
58
+ raise if ERROR_STATUSES.include? fraud_response.status
59
+
60
+ response
61
+ rescue => error
62
+ decision.responses.build(
63
+ timed_out: error.is_a?(Faraday::Error::TimeoutError),
64
+ error: error.message
65
+ )
66
+ if count < MAX_RETRIES
67
+ count += 1
68
+ retry
69
+ else
70
+ raise error
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,18 @@
1
+ module Workarea
2
+ module Forter
3
+ class Decision
4
+ include ApplicationDocument
5
+
6
+ embeds_many :responses, class_name: 'Workarea::Forter::Response'
7
+ field :external_order_status, type: String, default: "PROCESSING"
8
+
9
+ index(created_at: -1)
10
+
11
+ # the last response returned from the forter service.
12
+ def response
13
+ return if responses.empty?
14
+ responses.sort_by { |r| r.created_at.to_i }.last.decision_response
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,15 @@
1
+ module Workarea
2
+ module Forter
3
+ class Response
4
+ include Workarea::ApplicationDocument
5
+
6
+ field :decision_response, type: Workarea::Forter::DecisionResponse
7
+ field :timed_out, type: Boolean, default: false
8
+ field :error, type: String
9
+
10
+ def fraud_decision_action
11
+ decision_response&.action.presence || I18n.t('workarea.admin.orders.forter.decision_error')
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,77 @@
1
+ module Workarea
2
+ decorate Fulfillment, with: :forter do
3
+ def ship_items(tracking_number, shipped_items)
4
+ shipped_items.each do |shipped_item|
5
+ mark_item_shipped(
6
+ shipped_item.merge(tracking_number: tracking_number.downcase)
7
+ )
8
+ end
9
+
10
+ save.tap do |result|
11
+ if result && Workarea.config.send_transactional_emails
12
+ Storefront::FulfillmentMailer
13
+ .shipped(id, tracking_number)
14
+ .deliver_later
15
+ end
16
+
17
+
18
+ if result
19
+ status_hash = {
20
+ orderId: id,
21
+ eventTime: Time.new.to_i * 1000,
22
+ updatedStatus: "SENT",
23
+ updatedMerchantStatus: status.to_s
24
+
25
+ }
26
+ Workarea::Forter::UpdateStatus.perform_async(id, status_hash)
27
+ end
28
+ end
29
+ end
30
+
31
+ def cancel_items(canceled_items)
32
+ return unless canceled_items.present?
33
+
34
+ occured_at = Time.current
35
+
36
+ canceled_items = canceled_items.map do |canceled_item|
37
+ canceled_item = canceled_item.with_indifferent_access
38
+ next unless canceled_item['quantity'].to_i > 0
39
+
40
+ item = items.detect { |i| i.order_item_id == canceled_item['id'].to_s }
41
+ next unless item.present?
42
+
43
+ item.events.build(
44
+ status: 'canceled',
45
+ quantity: canceled_item['quantity'],
46
+ created_at: occured_at,
47
+ updated_at: occured_at,
48
+ data: canceled_item.except('id', 'quantity')
49
+ )
50
+ [canceled_item['id'].to_s, canceled_item['quantity']]
51
+ end.compact
52
+
53
+ return unless canceled_items.present?
54
+
55
+ result = save
56
+
57
+ if result && Workarea.config.send_transactional_emails
58
+ Storefront::FulfillmentMailer
59
+ .canceled(id, Hash[canceled_items])
60
+ .deliver_later
61
+ end
62
+
63
+ if result
64
+ status_hash = {
65
+ orderId: id,
66
+ eventTime: Time.new.to_i * 1000,
67
+ updatedStatus: "CANCELED_BY_MERCHANT",
68
+ updatedMerchantStatus: status.to_s
69
+
70
+ }
71
+ Workarea::Forter::UpdateStatus.perform_async(id, status_hash)
72
+ end
73
+
74
+ result
75
+ end
76
+ end
77
+ end