workarea-affirm 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. checksums.yaml +7 -0
  2. data/.github/ISSUE_TEMPLATE/bug_report.md +37 -0
  3. data/.github/ISSUE_TEMPLATE/documentation-request.md +17 -0
  4. data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  5. data/.github/workflows/ci.yml +54 -0
  6. data/.gitignore +25 -0
  7. data/.rubocop.yml +3 -0
  8. data/CHANGELOG.md +54 -0
  9. data/Gemfile +16 -0
  10. data/LICENSE +52 -0
  11. data/README.md +40 -0
  12. data/Rakefile +53 -0
  13. data/app/assets/images/workarea/admin/affirm/.keep +0 -0
  14. data/app/assets/images/workarea/storefront/affirm/.keep +0 -0
  15. data/app/assets/javascripts/workarea/admin/affirm/.keep +0 -0
  16. data/app/assets/javascripts/workarea/storefront/affirm/.keep +0 -0
  17. data/app/assets/javascripts/workarea/storefront/affirm/modules/affirm_analytics.js +120 -0
  18. data/app/assets/javascripts/workarea/storefront/affirm/modules/affirm_errors.js +19 -0
  19. data/app/assets/javascripts/workarea/storefront/affirm/modules/affirm_payment_triggers.js +29 -0
  20. data/app/assets/javascripts/workarea/storefront/affirm/modules/affirm_refresh.js +13 -0
  21. data/app/assets/stylesheets/workarea/admin/affirm/.keep +0 -0
  22. data/app/assets/stylesheets/workarea/storefront/affirm/components/_affirm_as_low_as.scss +12 -0
  23. data/app/assets/stylesheets/workarea/storefront/affirm/components/_payment_icon.scss +18 -0
  24. data/app/controllers/.keep +0 -0
  25. data/app/controllers/workarea/affirm_controller.rb +54 -0
  26. data/app/helpers/.keep +0 -0
  27. data/app/mailers/.keep +0 -0
  28. data/app/models/.keep +0 -0
  29. data/app/models/workarea/catalog/product.decorator +7 -0
  30. data/app/models/workarea/order.decorator +7 -0
  31. data/app/models/workarea/order/item.decorator +7 -0
  32. data/app/models/workarea/payment.decorator +31 -0
  33. data/app/models/workarea/payment/authorize/affirm.rb +49 -0
  34. data/app/models/workarea/payment/capture/affirm.rb +45 -0
  35. data/app/models/workarea/payment/purchase/affirm.rb +56 -0
  36. data/app/models/workarea/payment/refund/affirm.rb +46 -0
  37. data/app/models/workarea/payment/tender/affirm.rb +18 -0
  38. data/app/services/workarea/affirm/order.rb +106 -0
  39. data/app/services/workarea/affirm/update.rb +29 -0
  40. data/app/view_models/workarea/storefront/checkout/payment_view_model.decorator +11 -0
  41. data/app/views/.keep +0 -0
  42. data/app/views/workarea/admin/catalog_products/_affirm.html.haml +3 -0
  43. data/app/views/workarea/admin/orders/tenders/_affirm.html.haml +2 -0
  44. data/app/views/workarea/storefront/affirm/_affirm_javascript_sdk.html.haml +8 -0
  45. data/app/views/workarea/storefront/carts/_affirm_cart_promo_messaging.html.haml +6 -0
  46. data/app/views/workarea/storefront/checkouts/_affirm_cart.html.haml +3 -0
  47. data/app/views/workarea/storefront/checkouts/_affirm_payment.html.haml +29 -0
  48. data/app/views/workarea/storefront/order_mailer/tenders/_affirm.html.haml +4 -0
  49. data/app/views/workarea/storefront/order_mailer/tenders/_affirm.text.erb +1 -0
  50. data/app/views/workarea/storefront/orders/tenders/_affirm.html.haml +5 -0
  51. data/app/views/workarea/storefront/products/_affirm_product_promo_messaging.html.haml +6 -0
  52. data/bin/rails +25 -0
  53. data/config/initializers/appends.rb +37 -0
  54. data/config/initializers/configuration.rb +37 -0
  55. data/config/initializers/workarea.rb +7 -0
  56. data/config/locales/en.yml +44 -0
  57. data/config/routes.rb +3 -0
  58. data/lib/workarea/affirm.rb +51 -0
  59. data/lib/workarea/affirm/bogus_gateway.rb +302 -0
  60. data/lib/workarea/affirm/engine.rb +10 -0
  61. data/lib/workarea/affirm/gateway.rb +105 -0
  62. data/lib/workarea/affirm/response.rb +22 -0
  63. data/lib/workarea/affirm/version.rb +5 -0
  64. data/test/dummy/Rakefile +6 -0
  65. data/test/dummy/app/assets/config/manifest.js +3 -0
  66. data/test/dummy/app/assets/images/.keep +0 -0
  67. data/test/dummy/app/assets/javascripts/application.js +14 -0
  68. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  69. data/test/dummy/app/controllers/application_controller.rb +2 -0
  70. data/test/dummy/app/controllers/concerns/.keep +0 -0
  71. data/test/dummy/app/helpers/application_helper.rb +2 -0
  72. data/test/dummy/app/jobs/application_job.rb +2 -0
  73. data/test/dummy/app/mailers/application_mailer.rb +4 -0
  74. data/test/dummy/app/models/concerns/.keep +0 -0
  75. data/test/dummy/app/views/layouts/application.html.erb +15 -0
  76. data/test/dummy/app/views/layouts/mailer.html.erb +13 -0
  77. data/test/dummy/app/views/layouts/mailer.text.erb +1 -0
  78. data/test/dummy/bin/bundle +3 -0
  79. data/test/dummy/bin/rails +4 -0
  80. data/test/dummy/bin/rake +4 -0
  81. data/test/dummy/bin/setup +28 -0
  82. data/test/dummy/bin/update +28 -0
  83. data/test/dummy/bin/yarn +11 -0
  84. data/test/dummy/config.ru +5 -0
  85. data/test/dummy/config/application.rb +32 -0
  86. data/test/dummy/config/boot.rb +5 -0
  87. data/test/dummy/config/environment.rb +5 -0
  88. data/test/dummy/config/environments/development.rb +52 -0
  89. data/test/dummy/config/environments/production.rb +83 -0
  90. data/test/dummy/config/environments/test.rb +45 -0
  91. data/test/dummy/config/initializers/application_controller_renderer.rb +8 -0
  92. data/test/dummy/config/initializers/assets.rb +14 -0
  93. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  94. data/test/dummy/config/initializers/content_security_policy.rb +25 -0
  95. data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
  96. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  97. data/test/dummy/config/initializers/inflections.rb +16 -0
  98. data/test/dummy/config/initializers/mime_types.rb +4 -0
  99. data/test/dummy/config/initializers/workarea.rb +5 -0
  100. data/test/dummy/config/initializers/wrap_parameters.rb +9 -0
  101. data/test/dummy/config/locales/en.yml +33 -0
  102. data/test/dummy/config/puma.rb +37 -0
  103. data/test/dummy/config/routes.rb +5 -0
  104. data/test/dummy/config/spring.rb +6 -0
  105. data/test/dummy/db/seeds.rb +2 -0
  106. data/test/dummy/lib/assets/.keep +0 -0
  107. data/test/dummy/log/.keep +0 -0
  108. data/test/dummy/package.json +5 -0
  109. data/test/integration/workarea/storefront/affirm_integration_test.rb +119 -0
  110. data/test/models/workarea/affirm_order_test.rb +27 -0
  111. data/test/models/workarea/payment/affirm_payment_integration_test.rb +81 -0
  112. data/test/services/workarea/affirm/order_test.rb +45 -0
  113. data/test/system/workarea/storefront/affirm_cart_system_test.rb +72 -0
  114. data/test/system/workarea/storefront/affirm_logged_in_checkout_system_test.rb +24 -0
  115. data/test/teaspoon_env.rb +6 -0
  116. data/test/test_helper.rb +10 -0
  117. data/workarea-affirm.gemspec +21 -0
  118. metadata +188 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: cc4e636fe2c8107db2687aa08efcaeddbe2ff5c8aebcfb2fba19c46a4f844ddd
4
+ data.tar.gz: 6ea51e46e80aae2f14d8f50ffa05ba53d4732f0ceb57342fb13cdddf4f2ac395
5
+ SHA512:
6
+ metadata.gz: b7156d82595b0a4e76936fc1eb44e2eda2943ec4294a4131948009a8b45c09352afc87b42d724a4d2255dc3553235c483f2ee3c0a331b312b0be98a2352bdbdb
7
+ data.tar.gz: 6cc3188f14f21fd6b8fd1b0783894d0e3a45b96aa63544b3b4f3a54ed009de2021c74b8a46a8bf1698d92b73348b1789e3f3f741ce70688187d49bc0d837f3ce
@@ -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.
@@ -0,0 +1,54 @@
1
+ name: CI
2
+ on: [push]
3
+
4
+ jobs:
5
+ static_analysis:
6
+ runs-on: ubuntu-latest
7
+ steps:
8
+ - uses: actions/checkout@v1
9
+ - uses: workarea-commerce/ci/bundler-audit@v1
10
+ - uses: workarea-commerce/ci/rubocop@v1
11
+
12
+ admin_tests:
13
+ runs-on: ubuntu-latest
14
+ steps:
15
+ - uses: actions/checkout@v1
16
+ - uses: actions/setup-ruby@v1
17
+ with:
18
+ ruby-version: 2.6.x
19
+ - uses: workarea-commerce/ci/test@v1
20
+ with:
21
+ command: bin/rails app:workarea:test:admin
22
+
23
+ core_tests:
24
+ runs-on: ubuntu-latest
25
+ steps:
26
+ - uses: actions/checkout@v1
27
+ - uses: actions/setup-ruby@v1
28
+ with:
29
+ ruby-version: 2.6.x
30
+ - uses: workarea-commerce/ci/test@v1
31
+ with:
32
+ command: bin/rails app:workarea:test:core
33
+
34
+ storefront_tests:
35
+ runs-on: ubuntu-latest
36
+ steps:
37
+ - uses: actions/checkout@v1
38
+ - uses: actions/setup-ruby@v1
39
+ with:
40
+ ruby-version: 2.6.x
41
+ - uses: workarea-commerce/ci/test@v1
42
+ with:
43
+ command: bin/rails app:workarea:test:storefront
44
+
45
+ plugins_tests:
46
+ runs-on: ubuntu-latest
47
+ steps:
48
+ - uses: actions/checkout@v1
49
+ - uses: actions/setup-ruby@v1
50
+ with:
51
+ ruby-version: 2.6.x
52
+ - uses: workarea-commerce/ci/test@v1
53
+ with:
54
+ command: bin/rails app:workarea:test:plugins
@@ -0,0 +1,25 @@
1
+ .bundle/
2
+ log/*.log
3
+ pkg/
4
+ test/dummy/log/*.log
5
+ test/dummy/node_modules/
6
+ test/dummy/yarn-error.log
7
+ test/dummy/tmp/
8
+ .DS_Store
9
+ .byebug_history
10
+ .bundle/
11
+ .sass-cache/
12
+ Gemfile.lock
13
+ pkg/
14
+ test/dummy/tmp/
15
+ test/dummy/public/
16
+ log/*.log
17
+ test/dummy/log/*.log
18
+ test/dummy/db/*.sqlite3
19
+ test/dummy/db/*.sqlite3-journal
20
+ node_modules
21
+ yarn.lock
22
+ yarn-error.log
23
+ package-lock.json
24
+ .rubocop-https-*
25
+ .ruby-version
@@ -0,0 +1,3 @@
1
+ inherit_from:
2
+ - https://raw.githubusercontent.com/workarea-commerce/workarea/master/.rubocop.yml
3
+
@@ -0,0 +1,54 @@
1
+ Workarea Affirm 1.0.0 (2020-07-02)
2
+ --------------------------------------------------------------------------------
3
+
4
+ * Fix buttons remaining disabled after Afterpay error
5
+
6
+
7
+ Ben Crouse
8
+
9
+ * Add field to disable product Affirm availability
10
+
11
+
12
+ Ben Crouse
13
+
14
+ * Don't check for analytics JS to be defined, sometimes there's a race condition
15
+
16
+
17
+ Ben Crouse
18
+
19
+ * Fix checking for affirm defined in JS
20
+
21
+
22
+ Ben Crouse
23
+
24
+ * Add checkout messaging when below Affirm minimum
25
+
26
+
27
+ Ben Crouse
28
+
29
+ * Integrate Affirm analytics
30
+
31
+
32
+ Ben Crouse
33
+
34
+ * Add toggle to disable Affirm without removing credentials
35
+
36
+
37
+ Ben Crouse
38
+
39
+ * Ensure affirm info on page gets refreshed when DOM changes
40
+
41
+
42
+ Ben Crouse
43
+
44
+ * Affirm payment plug
45
+
46
+ Add affirm as a primary payment tender. Enables promo messaging
47
+ using JS sdk.
48
+
49
+ AFFIRM-1
50
+
51
+ Jeff Yucis
52
+
53
+
54
+
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ source 'https://rubygems.org'
2
+ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
3
+
4
+ # Declare your gem's dependencies in affirm.gemspec.
5
+ # Bundler will treat runtime dependencies like base dependencies, and
6
+ # development dependencies will be added by default to the :development group.
7
+ gemspec
8
+
9
+ # Declare any dependencies that are still in development here instead of in
10
+ # your gemspec. These might include edge Rails or gems from your path or
11
+ # Git. Remember to move these dependencies to your gemspec before releasing
12
+ # your gem to rubygems.org.
13
+
14
+ # To use a debugger
15
+ # gem 'byebug', group: %i[development test]
16
+ gem 'workarea', github: 'workarea-commerce/workarea', branch: 'v3.5-stable'
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.
@@ -0,0 +1,40 @@
1
+ Workarea Affirm
2
+ ================================================================================
3
+
4
+ Affirm plugin for the Workarea platform.
5
+
6
+ Overview
7
+ --------------------------------------------------------------------------------
8
+
9
+ 1. TODO
10
+
11
+ Getting Started
12
+ --------------------------------------------------------------------------------
13
+
14
+ This gem contains a Rails engine that must be mounted onto a host Rails application.
15
+
16
+ Then add the gem to your application's Gemfile specifying the source:
17
+
18
+ # ...
19
+ gem 'workarea-affirm'
20
+ # ...
21
+
22
+ Update your application's bundle.
23
+
24
+ cd path/to/application
25
+ bundle
26
+
27
+ Features
28
+ --------------------------------------------------------------------------------
29
+
30
+ ### TODO
31
+
32
+ Workarea Platform Documentation
33
+ --------------------------------------------------------------------------------
34
+
35
+ See [https://developer.workarea.com](https://developer.workarea.com) for Workarea platform documentation.
36
+
37
+ License
38
+ --------------------------------------------------------------------------------
39
+
40
+ Workarea Affirm is released under the [Business Software License](LICENSE)
@@ -0,0 +1,53 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+
8
+ require 'rdoc/task'
9
+
10
+ RDoc::Task.new(:rdoc) do |rdoc|
11
+ rdoc.rdoc_dir = 'rdoc'
12
+ rdoc.title = 'Workarea3 Plugin'
13
+ rdoc.options << '--line-numbers'
14
+ rdoc.rdoc_files.include('README.md')
15
+ rdoc.rdoc_files.include('lib/**/*.rb')
16
+ end
17
+
18
+ APP_RAKEFILE = File.expand_path('../test/dummy/Rakefile', __FILE__)
19
+ load 'rails/tasks/engine.rake'
20
+ load 'rails/tasks/statistics.rake'
21
+ load 'workarea/changelog.rake'
22
+
23
+ require 'rake/testtask'
24
+
25
+ Rake::TestTask.new(:test) do |t|
26
+ t.libs << 'lib'
27
+ t.libs << 'test'
28
+ t.pattern = 'test/**/*_test.rb'
29
+ t.verbose = false
30
+ end
31
+
32
+
33
+ task default: :test
34
+
35
+ $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
36
+ require 'workarea/affirm/version'
37
+
38
+ desc "Release version #{Workarea::Affirm::VERSION} of the gem"
39
+ task :release do
40
+ host = "https://#{ENV['BUNDLE_GEMS__WEBLINC__COM']}@gems.weblinc.com"
41
+
42
+ #Rake::Task['workarea:changelog'].execute
43
+ #system 'git add CHANGELOG.md'
44
+ #system 'git commit -m "Update CHANGELOG"'
45
+
46
+ #system "git tag -a v#{Workarea::Affirm::VERSION} -m 'Tagging #{Workarea::Affirm::VERSION}'"
47
+ #system 'git push origin HEAD --follow-tags'
48
+
49
+ system 'gem build workarea-affirm.gemspec'
50
+ system "gem push workarea-affirm-#{Workarea::Affirm::VERSION}.gem"
51
+ system "gem push workarea-affirm-#{Workarea::Affirm::VERSION}.gem --host #{host}"
52
+ system "rm workarea-affirm-#{Workarea::Affirm::VERSION}.gem"
53
+ end
@@ -0,0 +1,120 @@
1
+ WORKAREA.analytics.registerAdapter('affirm', function () {
2
+ var productListImpressions = [],
3
+
4
+ whenAffirmReady = function (fn) {
5
+ if (window.affirm && affirm.ui) {
6
+ return function (payload) {
7
+ affirm.ui.ready(function () { fn(payload); });
8
+ };
9
+ } else {
10
+ return $.noop;
11
+ }
12
+ },
13
+
14
+ buildProduct = function (payload) {
15
+ return {
16
+ 'category': payload.category,
17
+ 'name': payload.name,
18
+ 'price': payload.price,
19
+ 'productID': payload.id,
20
+ 'variant': payload.sku
21
+ }
22
+ };
23
+
24
+ buildOrder = function (payload) {
25
+ return {
26
+ 'storeName': payload.site_name,
27
+ 'coupon': payload.promo_codes.join(','),
28
+ 'revenue': payload.total_price,
29
+ 'shipping': payload.shipping_total,
30
+ 'shippingMethod': payload.shipping_service,
31
+ 'tax': payload.tax_total,
32
+ 'orderID': payload.id,
33
+ 'total': payload.total_price
34
+ };
35
+ },
36
+
37
+ buildItem = function (payload) {
38
+ return {
39
+ 'category': payload.category,
40
+ 'name': payload.name,
41
+ 'price': payload.price,
42
+ 'productID': payload.product_id,
43
+ 'quantity': payload.quantity,
44
+ 'variant': payload.sku
45
+ };
46
+ };
47
+
48
+ return {
49
+ 'productList': function (payload) {
50
+ productListImpressions = productListImpressions.concat(payload.impressions);
51
+ },
52
+
53
+ 'categoryView': whenAffirmReady(function (payload) {
54
+ affirm.analytics.trackProductListViewed(
55
+ { 'listId': payload.id, 'name': payload.name },
56
+ _.map(productListImpressions, buildProduct)
57
+ );
58
+ }),
59
+
60
+ 'searchResultsView': whenAffirmReady(function (payload) {
61
+ affirm.analytics.trackProductsSearched(payload.terms);
62
+ affirm.analytics.trackProductListViewed(
63
+ { 'listId': payload.terms },
64
+ _.map(productListImpressions, buildProduct)
65
+ );
66
+ }),
67
+
68
+ 'productClick': whenAffirmReady(function (payload) {
69
+ affirm.analytics.trackProductClicked(buildProduct(payload));
70
+ }),
71
+
72
+ 'productView': whenAffirmReady(function (payload) {
73
+ affirm.analytics.trackProductViewed(buildProduct(payload));
74
+ }),
75
+
76
+ 'addToCart': whenAffirmReady(function (payload) {
77
+ affirm.analytics.trackProductAdded(buildItem(payload));
78
+ }),
79
+
80
+ 'removeFromCart': whenAffirmReady(function (payload) {
81
+ affirm.analytics.trackProductRemoved(buildItem(payload));
82
+ }),
83
+
84
+ 'cartView': whenAffirmReady(function (payload) {
85
+ affirm.analytics.trackCartViewed(_.map(payload.items, buildItem));
86
+ }),
87
+
88
+ 'checkoutAddressesView': whenAffirmReady(function (payload) {
89
+ var order = buildOrder(payload);
90
+
91
+ affirm.analytics.trackCheckoutStarted(
92
+ order,
93
+ _.map(payload.items, buildItem)
94
+ );
95
+
96
+ affirm.analytics.trackCheckoutStepViewed(1, order);
97
+ }),
98
+
99
+ 'checkoutShippingView': whenAffirmReady(function (payload) {
100
+ var order = buildOrder(payload);
101
+ affirm.analytics.trackCheckoutStepCompleted(1, order);
102
+ affirm.analytics.trackCheckoutStepViewed(2, order);
103
+ }),
104
+
105
+ 'checkoutPaymentView': whenAffirmReady(function (payload) {
106
+ var order = buildOrder(payload);
107
+ affirm.analytics.trackCheckoutStepCompleted(2, order);
108
+ affirm.analytics.trackCheckoutStepViewed(3, order);
109
+ }),
110
+
111
+ 'checkoutOrderPlaced': whenAffirmReady(function (payload) {
112
+ var order = buildOrder(payload);
113
+ affirm.analytics.trackCheckoutStepCompleted(3, order);
114
+ affirm.analytics.trackOrderConfirmed(
115
+ order,
116
+ _.map(payload.items, buildItem)
117
+ );
118
+ })
119
+ };
120
+ });