workarea-flow_io 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (272) hide show
  1. checksums.yaml +7 -0
  2. data/.eslintignore +2 -0
  3. data/.eslintrc.json +37 -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 +90 -0
  8. data/.gitignore +21 -0
  9. data/.rubocop.yml +2 -0
  10. data/.ruby-version +1 -0
  11. data/.stylelintrc.json +12 -0
  12. data/CHANGELOG.md +200 -0
  13. data/Gemfile +19 -0
  14. data/LICENSE +52 -0
  15. data/README.md +200 -0
  16. data/Rakefile +59 -0
  17. data/app/assets/javascripts/workarea/storefront/flow_io/adapters/flow_io_adapter.js +61 -0
  18. data/app/assets/javascripts/workarea/storefront/flow_io/configuration.js.erb +10 -0
  19. data/app/assets/javascripts/workarea/storefront/flow_io/flow.js +91 -0
  20. data/app/assets/stylesheets/flow_io/storefront/country_picker.scss +189 -0
  21. data/app/controllers/workarea/admin/application_controller.decorator +5 -0
  22. data/app/controllers/workarea/admin/catalog_categories_controller.decorator +9 -0
  23. data/app/controllers/workarea/admin/flow_imports_controller.rb +9 -0
  24. data/app/controllers/workarea/admin/orders_controller.decorator +6 -0
  25. data/app/controllers/workarea/admin/pricing_skus_controller.decorator +7 -0
  26. data/app/controllers/workarea/admin/search_settings_controller.decorator +27 -0
  27. data/app/controllers/workarea/storefront/application_controller.decorator +80 -0
  28. data/app/controllers/workarea/storefront/checkouts_controller.decorator +38 -0
  29. data/app/controllers/workarea/storefront/flow_io_webhook_controller.rb +49 -0
  30. data/app/controllers/workarea/storefront/recent_views_controller.decorator +15 -0
  31. data/app/controllers/workarea/storefront/searches_controller.decorator +11 -0
  32. data/app/helpers/workarea/admin/flow_helper.rb +13 -0
  33. data/app/helpers/workarea/storefront/flow_analytics_helper.rb +23 -0
  34. data/app/helpers/workarea/storefront/flow_content_helper.rb +21 -0
  35. data/app/middleware/workarea/flow_io/session_middleware.rb +68 -0
  36. data/app/models/workarea/address.decorator +12 -0
  37. data/app/models/workarea/catalog/category.decorator +8 -0
  38. data/app/models/workarea/checkout.decorator +26 -0
  39. data/app/models/workarea/flow_io/experience_geo.rb +18 -0
  40. data/app/models/workarea/flow_io/experience_summary.rb +15 -0
  41. data/app/models/workarea/flow_io/import.rb +31 -0
  42. data/app/models/workarea/flow_io/imported_item.rb +124 -0
  43. data/app/models/workarea/flow_io/local_item.rb +28 -0
  44. data/app/models/workarea/flow_io/localized_price.rb +30 -0
  45. data/app/models/workarea/flow_io/price.rb +12 -0
  46. data/app/models/workarea/flow_io/price_with_base.rb +7 -0
  47. data/app/models/workarea/flow_io/webhook/shared_secret.rb +12 -0
  48. data/app/models/workarea/flow_price_adjustment_set.rb +80 -0
  49. data/app/models/workarea/fulfillment.decorator +63 -0
  50. data/app/models/workarea/order.decorator +39 -0
  51. data/app/models/workarea/order/item.decorator +43 -0
  52. data/app/models/workarea/payment.decorator +11 -0
  53. data/app/models/workarea/payment/authorize/flow_payment.rb +48 -0
  54. data/app/models/workarea/payment/capture/flow_payment.rb +35 -0
  55. data/app/models/workarea/payment/flow_payment_data.rb +25 -0
  56. data/app/models/workarea/payment/flow_payment_operation.rb +20 -0
  57. data/app/models/workarea/payment/purchase/flow_payment.rb +44 -0
  58. data/app/models/workarea/payment/refund/flow_payment.rb +42 -0
  59. data/app/models/workarea/payment/store_flow_credit_card.rb +34 -0
  60. data/app/models/workarea/payment/tender.decorator +8 -0
  61. data/app/models/workarea/payment/tender/flow_payment.rb +15 -0
  62. data/app/models/workarea/payment/transaction.decorator +12 -0
  63. data/app/models/workarea/pricing/calculators/flow_localization_calculator.rb +30 -0
  64. data/app/models/workarea/pricing/calculators/item_calculator.decorator +39 -0
  65. data/app/models/workarea/pricing/collection.decorator +113 -0
  66. data/app/models/workarea/pricing/order_totals.decorator +53 -0
  67. data/app/models/workarea/pricing/price.decorator +17 -0
  68. data/app/models/workarea/pricing/price_distributor.decorator +51 -0
  69. data/app/models/workarea/pricing/request.decorator +17 -0
  70. data/app/models/workarea/pricing/shipping_totals.decorator +24 -0
  71. data/app/models/workarea/pricing/sku.decorator +46 -0
  72. data/app/models/workarea/search/settings.decorator +8 -0
  73. data/app/models/workarea/search/storefront/product.decorator +25 -0
  74. data/app/models/workarea/shipping.decorator +28 -0
  75. data/app/queries/workarea/order_metrics.decorator +23 -0
  76. data/app/queries/workarea/search/product_search.decorator +14 -0
  77. data/app/queries/workarea/search/storefront_search/response.decorator +40 -0
  78. data/app/services/workarea/flow_io/checkout.rb +242 -0
  79. data/app/services/workarea/flow_io/checkout_token_form.rb +36 -0
  80. data/app/services/workarea/flow_io/countries.rb +14 -0
  81. data/app/services/workarea/flow_io/detailed_shipping_notification_form.rb +84 -0
  82. data/app/services/workarea/flow_io/experiences.rb +24 -0
  83. data/app/services/workarea/flow_io/fulfillment_cancellation_form.rb +40 -0
  84. data/app/services/workarea/flow_io/item.rb +122 -0
  85. data/app/services/workarea/flow_io/item_importer.rb +108 -0
  86. data/app/services/workarea/flow_io/line_item_form.rb +72 -0
  87. data/app/services/workarea/flow_io/order_put_form.rb +62 -0
  88. data/app/services/workarea/flow_io/price_applier.rb +81 -0
  89. data/app/services/workarea/flow_io/price_applier/item_applier.rb +157 -0
  90. data/app/services/workarea/flow_io/routing_contraints.rb +10 -0
  91. data/app/services/workarea/flow_io/session.rb +90 -0
  92. data/app/services/workarea/flow_io/webhook.rb +28 -0
  93. data/app/services/workarea/flow_io/webhook/experience_deleted_v2.rb +9 -0
  94. data/app/services/workarea/flow_io/webhook/experience_upserted_v2.rb +9 -0
  95. data/app/services/workarea/flow_io/webhook/order_upserted_v2.rb +36 -0
  96. data/app/services/workarea/flow_io/webhook_request_signature.rb +19 -0
  97. data/app/view_models/workarea/admin/flow_imports_view_model.rb +36 -0
  98. data/app/view_models/workarea/storefront/cart_view_model.decorator +27 -0
  99. data/app/view_models/workarea/storefront/content_blocks/category_summary_view_model.decorator +11 -0
  100. data/app/view_models/workarea/storefront/content_blocks/product_insights_view_model.decorator +11 -0
  101. data/app/view_models/workarea/storefront/content_blocks/product_list_view_model.decorator +13 -0
  102. data/app/view_models/workarea/storefront/order_item_view_model.decorator +35 -0
  103. data/app/view_models/workarea/storefront/order_view_model.decorator +51 -0
  104. data/app/view_models/workarea/storefront/product_templates/option_set_view_model.decorator +20 -0
  105. data/app/view_models/workarea/storefront/product_templates/package_view_model.decorator +14 -0
  106. data/app/view_models/workarea/storefront/product_view_model.decorator +15 -0
  107. data/app/view_models/workarea/storefront/product_view_model/cache_key.decorator +7 -0
  108. data/app/view_models/workarea/storefront/recommendations_view_model.decorator +20 -0
  109. data/app/view_models/workarea/storefront/user_activity_view_model.decorator +18 -0
  110. data/app/views/workarea/admin/catalog_categories/edit.html.haml +85 -0
  111. data/app/views/workarea/admin/facets/_price_inputs.html.haml +50 -0
  112. data/app/views/workarea/admin/flow_imports/index.html.haml +44 -0
  113. data/app/views/workarea/admin/orders/_flow.html.haml +22 -0
  114. data/app/views/workarea/admin/orders/_flow_aux_navigation.html.haml +2 -0
  115. data/app/views/workarea/admin/orders/flow.html.haml +109 -0
  116. data/app/views/workarea/admin/orders/tenders/_flow_payment.html.haml +3 -0
  117. data/app/views/workarea/admin/pricing_skus/_cards.html.haml +83 -0
  118. data/app/views/workarea/admin/pricing_skus/flow.html.haml +60 -0
  119. data/app/views/workarea/admin/search_settings/show.html.haml +55 -0
  120. data/app/views/workarea/admin/shared/_flow_imports_link.html.haml +1 -0
  121. data/app/views/workarea/storefront/_flow_io_country_picker.html.haml +2 -0
  122. data/app/views/workarea/storefront/_flow_io_country_picker_javascript.html.haml +1 -0
  123. data/app/views/workarea/storefront/order_mailer/tenders/_flow_payment.html.haml +2 -0
  124. data/app/views/workarea/storefront/order_mailer/tenders/_flow_payment.text.erb +1 -0
  125. data/app/views/workarea/storefront/orders/tenders/_flow_payment.html.haml +3 -0
  126. data/app/views/workarea/storefront/products/_pricing.html.haml +41 -0
  127. data/app/workers/workarea/flow_io/delete_items.rb +30 -0
  128. data/app/workers/workarea/flow_io/fetch_import.rb +34 -0
  129. data/app/workers/workarea/flow_io/fulfillment_cancellation.rb +14 -0
  130. data/app/workers/workarea/flow_io/item_exporter.rb +47 -0
  131. data/app/workers/workarea/flow_io/process_import.rb +28 -0
  132. data/app/workers/workarea/flow_io/shipping_notifications.rb +13 -0
  133. data/bin/rails +25 -0
  134. data/config/initializers/appends.rb +39 -0
  135. data/config/initializers/freedom_patches.rb +23 -0
  136. data/config/initializers/middleware.rb +11 -0
  137. data/config/initializers/payment_proxy.rb +5 -0
  138. data/config/initializers/rack_attack.rb +15 -0
  139. data/config/initializers/scheduled_jobs.rb +9 -0
  140. data/config/initializers/workarea.rb +101 -0
  141. data/config/initializers/workarea_i18n.rb +11 -0
  142. data/config/locales/en.yml +72 -0
  143. data/config/routes.rb +21 -0
  144. data/lib/active_merchant/billing/bogus_flow_gateway.rb +16 -0
  145. data/lib/active_merchant/billing/flow_gateway.rb +48 -0
  146. data/lib/tasks/flow_io.rake +117 -0
  147. data/lib/workarea/flow_io.rb +73 -0
  148. data/lib/workarea/flow_io/bogus_client.rb +57 -0
  149. data/lib/workarea/flow_io/bogus_client/checkout_tokens.rb +25 -0
  150. data/lib/workarea/flow_io/bogus_client/experiences.rb +152 -0
  151. data/lib/workarea/flow_io/bogus_client/fulfillments.rb +9 -0
  152. data/lib/workarea/flow_io/bogus_client/items.rb +11 -0
  153. data/lib/workarea/flow_io/bogus_client/orders.rb +499 -0
  154. data/lib/workarea/flow_io/bogus_client/organizations.rb +42 -0
  155. data/lib/workarea/flow_io/bogus_client/proxy_client.rb +29 -0
  156. data/lib/workarea/flow_io/bogus_client/sessions.rb +115 -0
  157. data/lib/workarea/flow_io/bogus_client/shipping_notifications.rb +10 -0
  158. data/lib/workarea/flow_io/bogus_client/webhook_settings.rb +11 -0
  159. data/lib/workarea/flow_io/bogus_client/webhooks.rb +11 -0
  160. data/lib/workarea/flow_io/controller_log_subscriber.rb +21 -0
  161. data/lib/workarea/flow_io/engine.rb +8 -0
  162. data/lib/workarea/flow_io/http_handler.rb +27 -0
  163. data/lib/workarea/flow_io/version.rb +5 -0
  164. data/lib/workarea/freedom_patches/flow_io.rb +53 -0
  165. data/package.json +9 -0
  166. data/script/admin_ci +9 -0
  167. data/script/ci +11 -0
  168. data/script/core_ci +9 -0
  169. data/script/plugins_ci +9 -0
  170. data/script/storefront_ci +9 -0
  171. data/test/dummy/.ruby-version +1 -0
  172. data/test/dummy/Rakefile +6 -0
  173. data/test/dummy/bin/bundle +3 -0
  174. data/test/dummy/bin/rails +4 -0
  175. data/test/dummy/bin/rake +4 -0
  176. data/test/dummy/bin/setup +28 -0
  177. data/test/dummy/bin/update +28 -0
  178. data/test/dummy/bin/yarn +11 -0
  179. data/test/dummy/config.ru +5 -0
  180. data/test/dummy/config/application.rb +32 -0
  181. data/test/dummy/config/boot.rb +5 -0
  182. data/test/dummy/config/cable.yml +10 -0
  183. data/test/dummy/config/environment.rb +5 -0
  184. data/test/dummy/config/environments/development.rb +52 -0
  185. data/test/dummy/config/environments/production.rb +88 -0
  186. data/test/dummy/config/environments/test.rb +45 -0
  187. data/test/dummy/config/initializers/application_controller_renderer.rb +8 -0
  188. data/test/dummy/config/initializers/assets.rb +14 -0
  189. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  190. data/test/dummy/config/initializers/content_security_policy.rb +25 -0
  191. data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
  192. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  193. data/test/dummy/config/initializers/inflections.rb +16 -0
  194. data/test/dummy/config/initializers/mime_types.rb +4 -0
  195. data/test/dummy/config/initializers/workarea.rb +5 -0
  196. data/test/dummy/config/initializers/wrap_parameters.rb +9 -0
  197. data/test/dummy/config/locales/en.yml +33 -0
  198. data/test/dummy/config/puma.rb +34 -0
  199. data/test/dummy/config/routes.rb +5 -0
  200. data/test/dummy/config/secrets.yml +22 -0
  201. data/test/dummy/config/spring.rb +6 -0
  202. data/test/dummy/db/seeds.rb +2 -0
  203. data/test/dummy/log/.keep +0 -0
  204. data/test/dummy/package.json +5 -0
  205. data/test/factories/workarea/flow_io.rb +136 -0
  206. data/test/factories/workarea/flow_io/euro_order_upserted_payload.rb +581 -0
  207. data/test/fixtures/files/example.csv +14 -0
  208. data/test/integration/workarea/admin/flow_imports_integration_test.rb +20 -0
  209. data/test/integration/workarea/admin/flow_order_integration_test.rb +37 -0
  210. data/test/integration/workarea/admin/search_settings_integration_test.decorator +44 -0
  211. data/test/integration/workarea/flow_locale_integration_test.rb +34 -0
  212. data/test/integration/workarea/storefront/copying_guest_order_integration_test.decorator +113 -0
  213. data/test/integration/workarea/storefront/flow_io_order_redirect_test.rb +55 -0
  214. data/test/integration/workarea/storefront/flow_io_session_integration_test.rb +122 -0
  215. data/test/integration/workarea/storefront/flow_io_webhooks/order_integration_test.rb +750 -0
  216. data/test/integration/workarea/storefront/flow_webhook_rack_attack_integration_test.rb +54 -0
  217. data/test/integration/workarea/storefront/search_integration_test.decorator +51 -0
  218. data/test/javascripts/flow_spec.js +39 -0
  219. data/test/javascripts/spec_helper.js +3 -0
  220. data/test/models/workarea/address_test.decorator +20 -0
  221. data/test/models/workarea/checkout_test.decorator +20 -0
  222. data/test/models/workarea/flow_io/imported_item_test.rb +50 -0
  223. data/test/models/workarea/fulfillment_test.decorator +12 -0
  224. data/test/models/workarea/oms_fulfillment_test.decorator +14 -0
  225. data/test/models/workarea/order/item_test.decorator +46 -0
  226. data/test/models/workarea/order_test.decorator +16 -0
  227. data/test/models/workarea/payment/flow_payment_integration_test.rb +163 -0
  228. data/test/models/workarea/price_adjustment_set_flow_test.rb +8 -0
  229. data/test/models/workarea/pricing/calculators/flow_localization_calculator_test.rb +152 -0
  230. data/test/models/workarea/pricing/calculators/item_calculator_test.decorator +59 -0
  231. data/test/models/workarea/pricing/collection_test.decorator +140 -0
  232. data/test/models/workarea/pricing/order_totals_test.rb +247 -0
  233. data/test/models/workarea/pricing/price_distributor_test.decorator +21 -0
  234. data/test/models/workarea/pricing/sku_test.decorator +113 -0
  235. data/test/models/workarea/shipping_test.decorator +70 -0
  236. data/test/queries/workarea/flow_order_metrics_test.rb +104 -0
  237. data/test/services/workarea/commit_shipments_test.decorator +14 -0
  238. data/test/services/workarea/flow_io/checkout_test.rb +43 -0
  239. data/test/services/workarea/flow_io/detailed_shipping_notification_form_test.rb +145 -0
  240. data/test/services/workarea/flow_io/experiences_test.rb +14 -0
  241. data/test/services/workarea/flow_io/fulfillment_cancellation_form_test.rb +46 -0
  242. data/test/services/workarea/flow_io/item_importer_test.rb +357 -0
  243. data/test/services/workarea/flow_io/item_test.rb +72 -0
  244. data/test/services/workarea/flow_io/line_item_form_test.rb +34 -0
  245. data/test/services/workarea/flow_io/order_put_form_test.rb +48 -0
  246. data/test/services/workarea/flow_io/price_applier_test.rb +916 -0
  247. data/test/support/flow_fixtures.rb +1362 -0
  248. data/test/support/webhook_integration_test.rb +43 -0
  249. data/test/support/workarea/flow_bogus_client_support.rb +18 -0
  250. data/test/support/workarea/flow_io_vcr_config.rb +22 -0
  251. data/test/system/workarea/admin/search_fulfillment_system_test.decorator +25 -0
  252. data/test/system/workarea/storefront/analytics_system_test.decorator +28 -0
  253. data/test/system/workarea/storefront/flow_cart_recommendations_system_test.rb +70 -0
  254. data/test/system/workarea/storefront/users_flow_orders_system_test.rb +25 -0
  255. data/test/teaspoon_env.rb +6 -0
  256. data/test/test_helper.rb +27 -0
  257. data/test/vcr_cassettes/payment/flow/auth_capture.yml +188 -0
  258. data/test/vcr_cassettes/payment/flow/auth_capture_refund.yml +249 -0
  259. data/test/vcr_cassettes/payment/flow/auth_void.yml +188 -0
  260. data/test/vcr_cassettes/payment/flow/purchase_refund.yml +249 -0
  261. data/test/vcr_cassettes/payment/flow/store_auth.yml +127 -0
  262. data/test/vcr_cassettes/payment/flow/store_purchase.yml +188 -0
  263. data/test/view_models/workarea/storefront/cart_view_model_test.decorator +19 -0
  264. data/test/view_models/workarea/storefront/order_item_view_model_test.decorator +24 -0
  265. data/test/view_models/workarea/storefront/order_view_model_test.decorator +41 -0
  266. data/test/view_models/workarea/storefront/package_view_model_test.decorator +11 -0
  267. data/test/workers/workarea/flow_io/delete_items_test.rb +37 -0
  268. data/test/workers/workarea/flow_io/fetch_import_test.rb +41 -0
  269. data/test/workers/workarea/flow_io/item_exporter_test.rb +47 -0
  270. data/test/workers/workarea/flow_io/process_import_test.rb +25 -0
  271. data/workarea-flow_io.gemspec +20 -0
  272. metadata +375 -0
data/Gemfile ADDED
@@ -0,0 +1,19 @@
1
+ source 'https://rubygems.org'
2
+
3
+ git_source :github do |repo|
4
+ if ENV['GITHUB_TOKEN']
5
+ "https://x-access-token:#{ENV['GITHUB_TOKEN']}@github.com/#{repo}.git"
6
+ else
7
+ "https://github.com/#{repo}.git"
8
+ end
9
+ end
10
+
11
+ gemspec
12
+
13
+ gem 'byebug'
14
+ gem 'simplecov', require: false
15
+ gem 'sprockets', '~> 3'
16
+
17
+ source 'https://gems.weblinc.com' do
18
+ gem 'workarea-oms', '~> 5.1.1'
19
+ 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.
@@ -0,0 +1,200 @@
1
+ # Workarea Flow Io
2
+
3
+ [Flow](https://flow.io) is an international checkout solution. Clients set up
4
+ an "experience" in Flow that targets specific currencies or regions. A
5
+ customer is geolocated using a javascript call, or they can opt to change
6
+ their shipping country via a javascript widget. Customers checking out
7
+ in foreign currencies get redirected to Flow's hosted checkout solution.
8
+
9
+ ## Installation
10
+
11
+ To install Flow, add it to your Gemfile:
12
+
13
+ ```ruby
14
+ gem 'workarea-flow_io'
15
+ ```
16
+
17
+ ...and run `bundle install`!
18
+
19
+ Next, configure your credentials in **config/secrets.yml**, as shown here:
20
+
21
+ ```yaml
22
+ flow_io:
23
+ # get your API token from https://console.flow.io
24
+ # under 'Organization Settings > Integrations"
25
+ api_token:
26
+ organization_id:
27
+ # the following credentials are provided by flow.io representatives..
28
+ ftp_username:
29
+ ftp_password:
30
+ ```
31
+
32
+ Finally, run the generator to set up Flow for use with your application:
33
+
34
+ rails workarea:flow_io:install
35
+
36
+ This task creates localization attributes, webhooks, and exports products
37
+ to Flow for later use, which are broken out into the following Rake
38
+ tasks (run in the same order):
39
+
40
+ workarea:flow_io:create_localization_attributes
41
+ workarea:flow_io:create_webhooks
42
+ workarea:flow_io:export_products
43
+
44
+ Now you're ready to Let It Flow!
45
+
46
+ ## Configuration
47
+
48
+ Flow is configured using your `Workarea.config`, much like most of our
49
+ other plugins. Many of these settings have defaults provided out of the
50
+ box. The above steps in "Installation" should be the bare minimum you
51
+ need to get the plugin working.
52
+
53
+ ### JavaScript Integration
54
+
55
+ `Workarea::FlowIo` can optionally use [FlowJS](https://docs-beta.flow.io/docs/flowjs)
56
+ as an additional layer of real-time pricing updates, or as the primary
57
+ means by which "global" experience customers with no pre-defined
58
+ experience can view localized prices. It is off by default, but can be
59
+ enabled by setting the following in an initializer:
60
+
61
+ ```ruby
62
+ Workarea.configure do |config|
63
+ config.flow_io.enable_javascript = true
64
+ end
65
+ ```
66
+
67
+ ### Localization Attributes
68
+
69
+ The plugin provides localization attributes for: `original_price`,
70
+ `sale_price`, `msrp`, `product_id` and `digital` These correspond to
71
+ values of the `attributes` when exporting an item to flow, and they come back
72
+ in the `local_item_pricing` `attributes` field. Other fields include
73
+ `gtin`, `brand`, and `hazardous`. For more information, visit
74
+ https://docs.flow.io/module/localization/resource/attributes and
75
+ https://docs.flow.io/type/attribute-form
76
+
77
+ ### Checkout
78
+
79
+ All international orders will be routed to a Flow.io hosted checkout
80
+ page. By default the order confirmation page will be hosted with Flow.io as
81
+ well.
82
+
83
+ Customers will be redirected to the default Flow.io checkout url.
84
+ However, most clients will choose to redirect to a subdomain. The
85
+ redirect domain is controlled via the following config:
86
+
87
+
88
+ ```ruby
89
+ Workarea.configure do |config|
90
+ config.flow_io.checkout_uri = 'https://checkout.flow.io'
91
+ end
92
+ ```
93
+
94
+ ## Under The Hood
95
+
96
+ This section explains a bit about how Flow integrates their pricing
97
+ model into your Workarea store.
98
+
99
+ ### Item Exporting / Importing
100
+
101
+ A callbacks worker gets enqueued when `Catalog::Product`, `Shipping::Sku`,
102
+ `Pricing::Sku`, or `Pricing::Price` are saved. Depending on the number of
103
+ skus changed, the worker will export the affected items to Flow. Flow
104
+ will then create Local Items to represent those skus in each experience,
105
+ and push those prices back to Workarea in a flat file sent over SFTP.
106
+ The plugin embeds those local items on the `Pricing::Sku` for display.
107
+ The base price of a localized price will not necessarily be the same.
108
+ After the initial price is converted into the localized currency,
109
+ rounding and margin rules are applied and then it is converted back into
110
+ the default currency as the base price.
111
+
112
+ ### Order Pricing
113
+
114
+ When a customer is transacting in a currency other than the default
115
+ currency, two sets of `PriceAdjustment`s are in effect. The standard
116
+ `#price_adjustments` on `Order::Item` and `Shipping` are used to track
117
+ pricing in the sites default currency while `#flow_price_adjustments`
118
+ will store pricing the customer transacted in.
119
+
120
+ ### Checkout Flow
121
+
122
+ A new pricing calculator is added, `FlowLocalizationCalculator` and
123
+ appended to the END of the pricing calculators array; it is important
124
+ that if a build adds custom calculators that the
125
+ `FlowLocalizationCalculator` is last. This calculator sends the order
126
+ to flow and updates the `Order::Item` and `Shipping` `#price_adjutments`
127
+ with localized prices and updated base prices. Because of the way
128
+ discounting is passed to flow, discounts are displaying as a generic
129
+ Discount adjustment, instead of an adjustment for each discount.
130
+ Display will still happen at the order or item level depending on how
131
+ the initial discount price adjutments were created.
132
+
133
+ A `before_action` in `Storefront::CheckoutsController` will send
134
+ customers to Flow's hosted checkout if they are checking out in a Flow
135
+ `Experience`. After the customer completes the order in hosted
136
+ checkout. Flow will send an `OrderUpsertedV2` webhook with a
137
+ `#submitted_at` value. The `Workarea::Order` will be updated and marked
138
+ as placed.
139
+
140
+ When `Fulfillment::Item`s are shipped or canceled in Workarea, workers
141
+ will update Flow with `ShippingNotifications` or
142
+ `FulfillmentCancellations`.
143
+
144
+ ### Session
145
+
146
+ A piece of middleware sits in front of `Rack::Cache` that will upsert a
147
+ `Session` in Flow if the `_f60_session` cookie is blank, passing the
148
+ `request.remote_ip` and `HTTP_GEOIP_CITY_COUNTRY_CODE3` from Nginx. If
149
+ the `_f60_session` cookie is present and the `flow_experience` cookie
150
+ isn't a request will be made to get the session from the Flow API. If
151
+ the API request 404s, a new session will be created and the
152
+ `_f60_session` cookie will be updated. It updates HTTP's `Vary` header
153
+ to include `X-Flow-Experience` and stores the current `Experience` in
154
+ the `flow_experience` cookie as JSON. If a user updates their country
155
+ via the `country_picker.js`, the `flow_experience` cookie is updated in
156
+ the `onSessionUpdate` in javascript.
157
+
158
+ ### Caching
159
+
160
+ Cache keys are decorated to include the current `Experience` key. The
161
+ Http Vary header is adjusted to include `X-Flow-Experience` The current
162
+ country ISO-3166-3 code is added to the `locale` as an added measure
163
+ agaisnt browser caching and the etag is updated to include the
164
+ `Experience` key.
165
+
166
+ ## Client Considerations
167
+
168
+ It's assumed that Flow will be the payment processor for foreign orders,
169
+ and that Flow will `purchase` those funds. 3PL(Third Party Logistics)
170
+ will need to be discussed between the client and Flow for foreign orders.
171
+
172
+ ## Incompatibilities and Gotchas
173
+
174
+ When using this plugin with Gift Cards, make sure `flow_io` appears
175
+ after `gift_cards` in your Gemfile, like so:
176
+
177
+ ```ruby
178
+ gem 'workarea-gift_cards'
179
+ gem 'workarea-flow_io'
180
+ ```
181
+
182
+ ## Contributing
183
+
184
+ Do you have a feature request, documentation update, bug report, or any
185
+ kind of feedback about this plugin? [Create a new issue](https://github.com/workarea-commerce/workarea-flow-io/issues/new/choose)
186
+ and tell us all about it!
187
+
188
+ If you have some code you'd like to contribute to `Workarea::FlowIo`,
189
+ make sure tests pass locally by running:
190
+
191
+ ```bash
192
+ rails test # runs tests local to the plugin
193
+ rails app:workarea:test:decorated # runs decorated tests
194
+ ```
195
+
196
+ Then, fork this repo and submit a pull request!
197
+
198
+ ## License
199
+
200
+ `Workarea::FlowIo` is released under the [Business Software License](LICENSE)
@@ -0,0 +1,59 @@
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 = 'Flow Io'
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/flow_io/version'
32
+
33
+ desc "Release version #{Workarea::FlowIo::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
+
41
+ system "git tag -a v#{Workarea::FlowIo::VERSION} -m 'Tagging #{Workarea::FlowIo::VERSION}'"
42
+ system 'git push origin HEAD --follow-tags'
43
+
44
+ system "gem build workarea-flow_io.gemspec"
45
+ system "gem push workarea-flow_io-#{Workarea::FlowIo::VERSION}.gem #{host}"
46
+ system "gem push workarea-flow_io-#{Workarea::FlowIo::VERSION}.gem --host #{host}"
47
+ system "rm workarea-flow_io-#{Workarea::FlowIo::VERSION}.gem"
48
+ end
49
+
50
+ desc 'Run the JavaScript tests'
51
+ ENV['TEASPOON_RAILS_ENV'] = File.expand_path('../test/dummy/config/environment', __FILE__)
52
+ task teaspoon: 'app:teaspoon'
53
+
54
+ desc 'Start a server at http://localhost:3000/teaspoon for JavaScript tests'
55
+ task :teaspoon_server do
56
+ Dir.chdir("test/dummy")
57
+ teaspoon_env = File.expand_path('../test/teaspoon_env.rb', __FILE__)
58
+ system "RAILS_ENV=test TEASPOON_ENV=#{teaspoon_env} rails s"
59
+ end
@@ -0,0 +1,61 @@
1
+ /**
2
+ * @namespace WORKAREA.flowIoAdapter
3
+ */
4
+
5
+ WORKAREA.analytics.registerAdapter('flowIoAdapter', function () {
6
+ 'use strict';
7
+
8
+ return {
9
+ 'addToCartConfirmation': function (payload) {
10
+ var cartAddEvent = {
11
+ item_number: payload.sku,
12
+ quantity: payload.quantity,
13
+ price: {
14
+ amount: payload.price,
15
+ currency: payload.currency_code,
16
+ },
17
+ };
18
+
19
+ flow.beacon('event', 'cart_add', cartAddEvent);
20
+ },
21
+
22
+ 'removeFromCart': function (payload) {
23
+ var cartRemoveEvent = {
24
+ item_number: payload.sku
25
+ };
26
+
27
+ flow.beacon('event', 'cart_remove', cartRemoveEvent);
28
+ },
29
+
30
+ 'checkoutOrderPlaced': function (payload) {
31
+ var transactionEvent = {
32
+ number: payload.id,
33
+ revenue: {
34
+ amount: payload.total_price,
35
+ currency: payload.total_price_currence_code,
36
+ },
37
+ shipping: {
38
+ amount: payload.shipping_total,
39
+ currency: payload.shipping_total_currency_code
40
+ },
41
+ tax: {
42
+ amount: payload.tax_total,
43
+ currency: payload.tax_total_currency_code,
44
+ },
45
+ items: _.map(payload.items, function (impression) {
46
+ return {
47
+ number: impression.sku,
48
+ price: {
49
+ amount: impression.price,
50
+ currency: impression.currency_code
51
+ },
52
+ quantity: impression.quantity,
53
+ name: impression.product_name
54
+ };
55
+ })
56
+ };
57
+
58
+ flow.beacon('event', 'transaction', transactionEvent);
59
+ }
60
+ };
61
+ });
@@ -0,0 +1,10 @@
1
+
2
+ (function () {
3
+ 'use strict';
4
+
5
+ <% if Workarea.config.flow_io.enable_javascript %>
6
+ WORKAREA.config.flow = {
7
+ organizationID: "<%= Workarea::FlowIo.organization_id %>"
8
+ };
9
+ <% end %>
10
+ })();
@@ -0,0 +1,91 @@
1
+ /**
2
+ * Integrate flow.io's JS into your Workarea application.
3
+ *
4
+ * @namespace WORKAREA.flow
5
+ */
6
+ WORKAREA.registerModule('flow', (function () {
7
+ 'use strict';
8
+
9
+ var getScript = _.once(function () {
10
+ !function (f, l, o, w, i, n, g) {
11
+ f[i] = f[i] || {};f[i].cmd = f[i].cmd || function () {
12
+ (f[i].q = f[i].q || []).push(arguments);};n = l.createElement(o);
13
+ n.src = w;g = l.getElementsByTagName(o)[0];g.parentNode.insertBefore(n, g);
14
+ }(window,document,'script','https://cdn.flow.io/flowjs/latest/flow.min.js','flow');
15
+
16
+ flow.cmd('set', 'organization', WORKAREA.config.flow.organizationID);
17
+ flow.cmd('init');
18
+ }),
19
+
20
+ urlLocale = function (url) {
21
+ var parsedUrl = WORKAREA.url.parse(url),
22
+ parts = _.filter(parsedUrl.path.split("/"), function(part) { return part !== ""; } ),
23
+ matches = (parts[0] || "").match(/^(\w{3})$/);
24
+
25
+ if (matches === null) {
26
+ return;
27
+ }
28
+ else {
29
+ return matches[1];
30
+ }
31
+ },
32
+
33
+ redirectUrl = function(url, locale) {
34
+ var oldLocale = urlLocale(url),
35
+ parsedUrl;
36
+
37
+ if (_.isUndefined(oldLocale)) {
38
+ parsedUrl = WORKAREA.url.parse(url);
39
+ return url.replace(new RegExp(parsedUrl.path + "$"), "/" + locale + parsedUrl.path);
40
+ } else {
41
+ return url.replace(oldLocale, locale);
42
+ }
43
+ },
44
+
45
+ updateSession = function(status, session) {
46
+ var country = session.geo.country.iso_3166_3.toLowerCase(),
47
+ url = WORKAREA.url.current();
48
+
49
+ WORKAREA.cookie.create('flow_country', country, 365);
50
+ WORKAREA.cookie.create('flow_experience', encodeURIComponent(JSON.stringify(session.experience)), 365);
51
+ WORKAREA.url.redirectTo(redirectUrl(url, country));
52
+ },
53
+
54
+ initCountryPicker = _.once(function() {
55
+ flow.cmd('on', 'ready', function () {
56
+ flow.countryPicker.createCountryPicker({
57
+ type: "modal",
58
+ containerId: "country-picker",
59
+ onSessionUpdate: updateSession
60
+ });
61
+ });
62
+ }),
63
+
64
+ localizePrices = function() {
65
+ flow.cmd('localize');
66
+ },
67
+
68
+ /**
69
+ * @method
70
+ * @name init
71
+ * @memberof WORKAREA.flow
72
+ */
73
+ init = function () {
74
+ if (_.isUndefined(WORKAREA.config.flow)) { return; }
75
+
76
+ getScript();
77
+ localizePrices();
78
+
79
+ if (!_.isEmpty($("#country-picker"))) {
80
+ initCountryPicker();
81
+ }
82
+ };
83
+
84
+ // urlLocale and redirectUrl are only exposed for testing and
85
+ // shouldn't be used as part of public API
86
+ return {
87
+ init: init,
88
+ urlLocale: urlLocale,
89
+ redirectUrl: redirectUrl
90
+ };
91
+ }()));