workarea-flow_io 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.eslintignore +2 -0
- data/.eslintrc.json +37 -0
- data/.github/ISSUE_TEMPLATE/bug_report.md +37 -0
- data/.github/ISSUE_TEMPLATE/documentation-request.md +17 -0
- data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
- data/.github/workflows/ci.yml +90 -0
- data/.gitignore +21 -0
- data/.rubocop.yml +2 -0
- data/.ruby-version +1 -0
- data/.stylelintrc.json +12 -0
- data/CHANGELOG.md +200 -0
- data/Gemfile +19 -0
- data/LICENSE +52 -0
- data/README.md +200 -0
- data/Rakefile +59 -0
- data/app/assets/javascripts/workarea/storefront/flow_io/adapters/flow_io_adapter.js +61 -0
- data/app/assets/javascripts/workarea/storefront/flow_io/configuration.js.erb +10 -0
- data/app/assets/javascripts/workarea/storefront/flow_io/flow.js +91 -0
- data/app/assets/stylesheets/flow_io/storefront/country_picker.scss +189 -0
- data/app/controllers/workarea/admin/application_controller.decorator +5 -0
- data/app/controllers/workarea/admin/catalog_categories_controller.decorator +9 -0
- data/app/controllers/workarea/admin/flow_imports_controller.rb +9 -0
- data/app/controllers/workarea/admin/orders_controller.decorator +6 -0
- data/app/controllers/workarea/admin/pricing_skus_controller.decorator +7 -0
- data/app/controllers/workarea/admin/search_settings_controller.decorator +27 -0
- data/app/controllers/workarea/storefront/application_controller.decorator +80 -0
- data/app/controllers/workarea/storefront/checkouts_controller.decorator +38 -0
- data/app/controllers/workarea/storefront/flow_io_webhook_controller.rb +49 -0
- data/app/controllers/workarea/storefront/recent_views_controller.decorator +15 -0
- data/app/controllers/workarea/storefront/searches_controller.decorator +11 -0
- data/app/helpers/workarea/admin/flow_helper.rb +13 -0
- data/app/helpers/workarea/storefront/flow_analytics_helper.rb +23 -0
- data/app/helpers/workarea/storefront/flow_content_helper.rb +21 -0
- data/app/middleware/workarea/flow_io/session_middleware.rb +68 -0
- data/app/models/workarea/address.decorator +12 -0
- data/app/models/workarea/catalog/category.decorator +8 -0
- data/app/models/workarea/checkout.decorator +26 -0
- data/app/models/workarea/flow_io/experience_geo.rb +18 -0
- data/app/models/workarea/flow_io/experience_summary.rb +15 -0
- data/app/models/workarea/flow_io/import.rb +31 -0
- data/app/models/workarea/flow_io/imported_item.rb +124 -0
- data/app/models/workarea/flow_io/local_item.rb +28 -0
- data/app/models/workarea/flow_io/localized_price.rb +30 -0
- data/app/models/workarea/flow_io/price.rb +12 -0
- data/app/models/workarea/flow_io/price_with_base.rb +7 -0
- data/app/models/workarea/flow_io/webhook/shared_secret.rb +12 -0
- data/app/models/workarea/flow_price_adjustment_set.rb +80 -0
- data/app/models/workarea/fulfillment.decorator +63 -0
- data/app/models/workarea/order.decorator +39 -0
- data/app/models/workarea/order/item.decorator +43 -0
- data/app/models/workarea/payment.decorator +11 -0
- data/app/models/workarea/payment/authorize/flow_payment.rb +48 -0
- data/app/models/workarea/payment/capture/flow_payment.rb +35 -0
- data/app/models/workarea/payment/flow_payment_data.rb +25 -0
- data/app/models/workarea/payment/flow_payment_operation.rb +20 -0
- data/app/models/workarea/payment/purchase/flow_payment.rb +44 -0
- data/app/models/workarea/payment/refund/flow_payment.rb +42 -0
- data/app/models/workarea/payment/store_flow_credit_card.rb +34 -0
- data/app/models/workarea/payment/tender.decorator +8 -0
- data/app/models/workarea/payment/tender/flow_payment.rb +15 -0
- data/app/models/workarea/payment/transaction.decorator +12 -0
- data/app/models/workarea/pricing/calculators/flow_localization_calculator.rb +30 -0
- data/app/models/workarea/pricing/calculators/item_calculator.decorator +39 -0
- data/app/models/workarea/pricing/collection.decorator +113 -0
- data/app/models/workarea/pricing/order_totals.decorator +53 -0
- data/app/models/workarea/pricing/price.decorator +17 -0
- data/app/models/workarea/pricing/price_distributor.decorator +51 -0
- data/app/models/workarea/pricing/request.decorator +17 -0
- data/app/models/workarea/pricing/shipping_totals.decorator +24 -0
- data/app/models/workarea/pricing/sku.decorator +46 -0
- data/app/models/workarea/search/settings.decorator +8 -0
- data/app/models/workarea/search/storefront/product.decorator +25 -0
- data/app/models/workarea/shipping.decorator +28 -0
- data/app/queries/workarea/order_metrics.decorator +23 -0
- data/app/queries/workarea/search/product_search.decorator +14 -0
- data/app/queries/workarea/search/storefront_search/response.decorator +40 -0
- data/app/services/workarea/flow_io/checkout.rb +242 -0
- data/app/services/workarea/flow_io/checkout_token_form.rb +36 -0
- data/app/services/workarea/flow_io/countries.rb +14 -0
- data/app/services/workarea/flow_io/detailed_shipping_notification_form.rb +84 -0
- data/app/services/workarea/flow_io/experiences.rb +24 -0
- data/app/services/workarea/flow_io/fulfillment_cancellation_form.rb +40 -0
- data/app/services/workarea/flow_io/item.rb +122 -0
- data/app/services/workarea/flow_io/item_importer.rb +108 -0
- data/app/services/workarea/flow_io/line_item_form.rb +72 -0
- data/app/services/workarea/flow_io/order_put_form.rb +62 -0
- data/app/services/workarea/flow_io/price_applier.rb +81 -0
- data/app/services/workarea/flow_io/price_applier/item_applier.rb +157 -0
- data/app/services/workarea/flow_io/routing_contraints.rb +10 -0
- data/app/services/workarea/flow_io/session.rb +90 -0
- data/app/services/workarea/flow_io/webhook.rb +28 -0
- data/app/services/workarea/flow_io/webhook/experience_deleted_v2.rb +9 -0
- data/app/services/workarea/flow_io/webhook/experience_upserted_v2.rb +9 -0
- data/app/services/workarea/flow_io/webhook/order_upserted_v2.rb +36 -0
- data/app/services/workarea/flow_io/webhook_request_signature.rb +19 -0
- data/app/view_models/workarea/admin/flow_imports_view_model.rb +36 -0
- data/app/view_models/workarea/storefront/cart_view_model.decorator +27 -0
- data/app/view_models/workarea/storefront/content_blocks/category_summary_view_model.decorator +11 -0
- data/app/view_models/workarea/storefront/content_blocks/product_insights_view_model.decorator +11 -0
- data/app/view_models/workarea/storefront/content_blocks/product_list_view_model.decorator +13 -0
- data/app/view_models/workarea/storefront/order_item_view_model.decorator +35 -0
- data/app/view_models/workarea/storefront/order_view_model.decorator +51 -0
- data/app/view_models/workarea/storefront/product_templates/option_set_view_model.decorator +20 -0
- data/app/view_models/workarea/storefront/product_templates/package_view_model.decorator +14 -0
- data/app/view_models/workarea/storefront/product_view_model.decorator +15 -0
- data/app/view_models/workarea/storefront/product_view_model/cache_key.decorator +7 -0
- data/app/view_models/workarea/storefront/recommendations_view_model.decorator +20 -0
- data/app/view_models/workarea/storefront/user_activity_view_model.decorator +18 -0
- data/app/views/workarea/admin/catalog_categories/edit.html.haml +85 -0
- data/app/views/workarea/admin/facets/_price_inputs.html.haml +50 -0
- data/app/views/workarea/admin/flow_imports/index.html.haml +44 -0
- data/app/views/workarea/admin/orders/_flow.html.haml +22 -0
- data/app/views/workarea/admin/orders/_flow_aux_navigation.html.haml +2 -0
- data/app/views/workarea/admin/orders/flow.html.haml +109 -0
- data/app/views/workarea/admin/orders/tenders/_flow_payment.html.haml +3 -0
- data/app/views/workarea/admin/pricing_skus/_cards.html.haml +83 -0
- data/app/views/workarea/admin/pricing_skus/flow.html.haml +60 -0
- data/app/views/workarea/admin/search_settings/show.html.haml +55 -0
- data/app/views/workarea/admin/shared/_flow_imports_link.html.haml +1 -0
- data/app/views/workarea/storefront/_flow_io_country_picker.html.haml +2 -0
- data/app/views/workarea/storefront/_flow_io_country_picker_javascript.html.haml +1 -0
- data/app/views/workarea/storefront/order_mailer/tenders/_flow_payment.html.haml +2 -0
- data/app/views/workarea/storefront/order_mailer/tenders/_flow_payment.text.erb +1 -0
- data/app/views/workarea/storefront/orders/tenders/_flow_payment.html.haml +3 -0
- data/app/views/workarea/storefront/products/_pricing.html.haml +41 -0
- data/app/workers/workarea/flow_io/delete_items.rb +30 -0
- data/app/workers/workarea/flow_io/fetch_import.rb +34 -0
- data/app/workers/workarea/flow_io/fulfillment_cancellation.rb +14 -0
- data/app/workers/workarea/flow_io/item_exporter.rb +47 -0
- data/app/workers/workarea/flow_io/process_import.rb +28 -0
- data/app/workers/workarea/flow_io/shipping_notifications.rb +13 -0
- data/bin/rails +25 -0
- data/config/initializers/appends.rb +39 -0
- data/config/initializers/freedom_patches.rb +23 -0
- data/config/initializers/middleware.rb +11 -0
- data/config/initializers/payment_proxy.rb +5 -0
- data/config/initializers/rack_attack.rb +15 -0
- data/config/initializers/scheduled_jobs.rb +9 -0
- data/config/initializers/workarea.rb +101 -0
- data/config/initializers/workarea_i18n.rb +11 -0
- data/config/locales/en.yml +72 -0
- data/config/routes.rb +21 -0
- data/lib/active_merchant/billing/bogus_flow_gateway.rb +16 -0
- data/lib/active_merchant/billing/flow_gateway.rb +48 -0
- data/lib/tasks/flow_io.rake +117 -0
- data/lib/workarea/flow_io.rb +73 -0
- data/lib/workarea/flow_io/bogus_client.rb +57 -0
- data/lib/workarea/flow_io/bogus_client/checkout_tokens.rb +25 -0
- data/lib/workarea/flow_io/bogus_client/experiences.rb +152 -0
- data/lib/workarea/flow_io/bogus_client/fulfillments.rb +9 -0
- data/lib/workarea/flow_io/bogus_client/items.rb +11 -0
- data/lib/workarea/flow_io/bogus_client/orders.rb +499 -0
- data/lib/workarea/flow_io/bogus_client/organizations.rb +42 -0
- data/lib/workarea/flow_io/bogus_client/proxy_client.rb +29 -0
- data/lib/workarea/flow_io/bogus_client/sessions.rb +115 -0
- data/lib/workarea/flow_io/bogus_client/shipping_notifications.rb +10 -0
- data/lib/workarea/flow_io/bogus_client/webhook_settings.rb +11 -0
- data/lib/workarea/flow_io/bogus_client/webhooks.rb +11 -0
- data/lib/workarea/flow_io/controller_log_subscriber.rb +21 -0
- data/lib/workarea/flow_io/engine.rb +8 -0
- data/lib/workarea/flow_io/http_handler.rb +27 -0
- data/lib/workarea/flow_io/version.rb +5 -0
- data/lib/workarea/freedom_patches/flow_io.rb +53 -0
- data/package.json +9 -0
- data/script/admin_ci +9 -0
- data/script/ci +11 -0
- data/script/core_ci +9 -0
- data/script/plugins_ci +9 -0
- data/script/storefront_ci +9 -0
- data/test/dummy/.ruby-version +1 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/bin/setup +28 -0
- data/test/dummy/bin/update +28 -0
- data/test/dummy/bin/yarn +11 -0
- data/test/dummy/config.ru +5 -0
- data/test/dummy/config/application.rb +32 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/cable.yml +10 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +52 -0
- data/test/dummy/config/environments/production.rb +88 -0
- data/test/dummy/config/environments/test.rb +45 -0
- data/test/dummy/config/initializers/application_controller_renderer.rb +8 -0
- data/test/dummy/config/initializers/assets.rb +14 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/content_security_policy.rb +25 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/dummy/config/initializers/workarea.rb +5 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +9 -0
- data/test/dummy/config/locales/en.yml +33 -0
- data/test/dummy/config/puma.rb +34 -0
- data/test/dummy/config/routes.rb +5 -0
- data/test/dummy/config/secrets.yml +22 -0
- data/test/dummy/config/spring.rb +6 -0
- data/test/dummy/db/seeds.rb +2 -0
- data/test/dummy/log/.keep +0 -0
- data/test/dummy/package.json +5 -0
- data/test/factories/workarea/flow_io.rb +136 -0
- data/test/factories/workarea/flow_io/euro_order_upserted_payload.rb +581 -0
- data/test/fixtures/files/example.csv +14 -0
- data/test/integration/workarea/admin/flow_imports_integration_test.rb +20 -0
- data/test/integration/workarea/admin/flow_order_integration_test.rb +37 -0
- data/test/integration/workarea/admin/search_settings_integration_test.decorator +44 -0
- data/test/integration/workarea/flow_locale_integration_test.rb +34 -0
- data/test/integration/workarea/storefront/copying_guest_order_integration_test.decorator +113 -0
- data/test/integration/workarea/storefront/flow_io_order_redirect_test.rb +55 -0
- data/test/integration/workarea/storefront/flow_io_session_integration_test.rb +122 -0
- data/test/integration/workarea/storefront/flow_io_webhooks/order_integration_test.rb +750 -0
- data/test/integration/workarea/storefront/flow_webhook_rack_attack_integration_test.rb +54 -0
- data/test/integration/workarea/storefront/search_integration_test.decorator +51 -0
- data/test/javascripts/flow_spec.js +39 -0
- data/test/javascripts/spec_helper.js +3 -0
- data/test/models/workarea/address_test.decorator +20 -0
- data/test/models/workarea/checkout_test.decorator +20 -0
- data/test/models/workarea/flow_io/imported_item_test.rb +50 -0
- data/test/models/workarea/fulfillment_test.decorator +12 -0
- data/test/models/workarea/oms_fulfillment_test.decorator +14 -0
- data/test/models/workarea/order/item_test.decorator +46 -0
- data/test/models/workarea/order_test.decorator +16 -0
- data/test/models/workarea/payment/flow_payment_integration_test.rb +163 -0
- data/test/models/workarea/price_adjustment_set_flow_test.rb +8 -0
- data/test/models/workarea/pricing/calculators/flow_localization_calculator_test.rb +152 -0
- data/test/models/workarea/pricing/calculators/item_calculator_test.decorator +59 -0
- data/test/models/workarea/pricing/collection_test.decorator +140 -0
- data/test/models/workarea/pricing/order_totals_test.rb +247 -0
- data/test/models/workarea/pricing/price_distributor_test.decorator +21 -0
- data/test/models/workarea/pricing/sku_test.decorator +113 -0
- data/test/models/workarea/shipping_test.decorator +70 -0
- data/test/queries/workarea/flow_order_metrics_test.rb +104 -0
- data/test/services/workarea/commit_shipments_test.decorator +14 -0
- data/test/services/workarea/flow_io/checkout_test.rb +43 -0
- data/test/services/workarea/flow_io/detailed_shipping_notification_form_test.rb +145 -0
- data/test/services/workarea/flow_io/experiences_test.rb +14 -0
- data/test/services/workarea/flow_io/fulfillment_cancellation_form_test.rb +46 -0
- data/test/services/workarea/flow_io/item_importer_test.rb +357 -0
- data/test/services/workarea/flow_io/item_test.rb +72 -0
- data/test/services/workarea/flow_io/line_item_form_test.rb +34 -0
- data/test/services/workarea/flow_io/order_put_form_test.rb +48 -0
- data/test/services/workarea/flow_io/price_applier_test.rb +916 -0
- data/test/support/flow_fixtures.rb +1362 -0
- data/test/support/webhook_integration_test.rb +43 -0
- data/test/support/workarea/flow_bogus_client_support.rb +18 -0
- data/test/support/workarea/flow_io_vcr_config.rb +22 -0
- data/test/system/workarea/admin/search_fulfillment_system_test.decorator +25 -0
- data/test/system/workarea/storefront/analytics_system_test.decorator +28 -0
- data/test/system/workarea/storefront/flow_cart_recommendations_system_test.rb +70 -0
- data/test/system/workarea/storefront/users_flow_orders_system_test.rb +25 -0
- data/test/teaspoon_env.rb +6 -0
- data/test/test_helper.rb +27 -0
- data/test/vcr_cassettes/payment/flow/auth_capture.yml +188 -0
- data/test/vcr_cassettes/payment/flow/auth_capture_refund.yml +249 -0
- data/test/vcr_cassettes/payment/flow/auth_void.yml +188 -0
- data/test/vcr_cassettes/payment/flow/purchase_refund.yml +249 -0
- data/test/vcr_cassettes/payment/flow/store_auth.yml +127 -0
- data/test/vcr_cassettes/payment/flow/store_purchase.yml +188 -0
- data/test/view_models/workarea/storefront/cart_view_model_test.decorator +19 -0
- data/test/view_models/workarea/storefront/order_item_view_model_test.decorator +24 -0
- data/test/view_models/workarea/storefront/order_view_model_test.decorator +41 -0
- data/test/view_models/workarea/storefront/package_view_model_test.decorator +11 -0
- data/test/workers/workarea/flow_io/delete_items_test.rb +37 -0
- data/test/workers/workarea/flow_io/fetch_import_test.rb +41 -0
- data/test/workers/workarea/flow_io/item_exporter_test.rb +47 -0
- data/test/workers/workarea/flow_io/process_import_test.rb +25 -0
- data/workarea-flow_io.gemspec +20 -0
- metadata +375 -0
@@ -0,0 +1,499 @@
|
|
1
|
+
module Workarea
|
2
|
+
module FlowIo
|
3
|
+
class BogusClient
|
4
|
+
class Orders
|
5
|
+
def put_by_number(_organization_id, number, order_put_form, options = {})
|
6
|
+
if order_put_form.items.empty?
|
7
|
+
raise ::Io::Flow::V0::HttpClient::ServerError.new(
|
8
|
+
422,
|
9
|
+
"Unprocessable Entity",
|
10
|
+
body: "{\"code\":\"generic_error\",\"messages\":[\"Must have at least 1 item to create an order\"]}"
|
11
|
+
)
|
12
|
+
else
|
13
|
+
OrderResponse.new(number, order_put_form, options).flow_model
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
class OrderResponse
|
20
|
+
attr_reader :number, :order_put_form, :options
|
21
|
+
|
22
|
+
def initialize(number, order_put_form, options)
|
23
|
+
@number = number
|
24
|
+
@order_put_form = order_put_form
|
25
|
+
@options = options
|
26
|
+
end
|
27
|
+
|
28
|
+
def flow_model
|
29
|
+
unless ["canada", "europe"].include? experience_key
|
30
|
+
raise "No bogus response for #{experience_key}"
|
31
|
+
end
|
32
|
+
|
33
|
+
order
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def convert_price(money, rate: 1.2)
|
39
|
+
return unless money.present?
|
40
|
+
|
41
|
+
fractional = (money.dup * rate).fractional
|
42
|
+
remainder = fractional % 500
|
43
|
+
|
44
|
+
Money.from_amount((fractional + 500 - remainder) / 100, currency_code)
|
45
|
+
end
|
46
|
+
|
47
|
+
def experience_key
|
48
|
+
options[:experience]
|
49
|
+
end
|
50
|
+
|
51
|
+
def experience_id
|
52
|
+
@experience_id ||= "exp-#{SecureRandom.hex(16)}"
|
53
|
+
end
|
54
|
+
|
55
|
+
def experience
|
56
|
+
@experience ||=
|
57
|
+
case experience_key
|
58
|
+
when "canada"
|
59
|
+
when "europe"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def experience_summary
|
64
|
+
@experience_summary ||= {
|
65
|
+
id: experience_id,
|
66
|
+
key: experience_key.downcase,
|
67
|
+
name: experience_key,
|
68
|
+
country: nil,
|
69
|
+
currency: nil,
|
70
|
+
language: nil
|
71
|
+
}
|
72
|
+
end
|
73
|
+
|
74
|
+
def currency_code
|
75
|
+
@experience ||=
|
76
|
+
case experience_key
|
77
|
+
when "canada" then "CAD"
|
78
|
+
when "europe" then "EUR"
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def currency_symbol
|
83
|
+
@experience ||=
|
84
|
+
case experience_key
|
85
|
+
when "canada" then "CA$"
|
86
|
+
when "europe" then "€"
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def total
|
91
|
+
126.72.to_m
|
92
|
+
end
|
93
|
+
|
94
|
+
def converted_total
|
95
|
+
convert_price total
|
96
|
+
end
|
97
|
+
|
98
|
+
def order
|
99
|
+
::Io::Flow::V0::Models::Order.new(
|
100
|
+
id: "order-#{SecureRandom.hex(20).downcase}",
|
101
|
+
number: number,
|
102
|
+
merchant_of_record: "flow",
|
103
|
+
experience: { key: experience_key, discriminator: "experience_reference" },
|
104
|
+
customer: customer,
|
105
|
+
delivered_duty: "paid",
|
106
|
+
destination: destination,
|
107
|
+
expires_at: Time.now.iso8601,
|
108
|
+
items: items,
|
109
|
+
deliveries: deliveries,
|
110
|
+
selections: ["opt-c6cd61df76c64786b336e3d40098e797"],
|
111
|
+
prices: prices,
|
112
|
+
total: {
|
113
|
+
currency: currency_code,
|
114
|
+
amount: converted_total.to_f,
|
115
|
+
label: "#{currency_symbol}#{converted_total.to_f}",
|
116
|
+
base: { amount: total.to_f, currency: "USD", label: "US$#{total.to_f}" },
|
117
|
+
key: "localized_total"
|
118
|
+
},
|
119
|
+
attributes: { "number" => number },
|
120
|
+
submitted_at: nil,
|
121
|
+
lines: lines,
|
122
|
+
identifiers: nil,
|
123
|
+
promotions: nil,
|
124
|
+
payments: [],
|
125
|
+
balance: {
|
126
|
+
currency: currency_code,
|
127
|
+
amount: converted_total.to_f,
|
128
|
+
label: "#{currency_symbol}#{converted_total.to_f}",
|
129
|
+
base: { amount: total.to_f, currency: "USD", label: "US$#{total.to_f}" },
|
130
|
+
key: "localized_total"
|
131
|
+
},
|
132
|
+
rules: nil,
|
133
|
+
tax_registration: nil,
|
134
|
+
discriminator: "order"
|
135
|
+
)
|
136
|
+
end
|
137
|
+
|
138
|
+
# TODO fix to correct currency
|
139
|
+
#
|
140
|
+
def prices
|
141
|
+
[
|
142
|
+
{
|
143
|
+
key: "subtotal",
|
144
|
+
currency: "CAD",
|
145
|
+
amount: 0.11964e3,
|
146
|
+
label: "CA$119.64",
|
147
|
+
base: { amount: 88.41, currency: "USD", label: "US$88.41" },
|
148
|
+
components: [
|
149
|
+
{
|
150
|
+
key: "item_price",
|
151
|
+
currency: "CAD",
|
152
|
+
amount: 0.11712e3,
|
153
|
+
label: "CA$117.12",
|
154
|
+
base: { amount: 86.53, currency: "USD", label: "US$86.53" },
|
155
|
+
name: "Item price"
|
156
|
+
},
|
157
|
+
{
|
158
|
+
key: "item_discount",
|
159
|
+
currency: "CAD",
|
160
|
+
amount: -0.36e0,
|
161
|
+
label: "-CA$0.36",
|
162
|
+
base: { amount: -0.25, currency: "USD", label: "-US$0.25" },
|
163
|
+
name: "Item discount"
|
164
|
+
},
|
165
|
+
{
|
166
|
+
key: "rounding",
|
167
|
+
currency: "CAD",
|
168
|
+
amount: 0.288e1,
|
169
|
+
label: "CA$2.88",
|
170
|
+
base: { amount: 2.13, currency: "USD", label: "US$2.13" },
|
171
|
+
name: "Rounding"
|
172
|
+
}
|
173
|
+
],
|
174
|
+
name: "Item subtotal",
|
175
|
+
rate: nil
|
176
|
+
},
|
177
|
+
{
|
178
|
+
key: "vat",
|
179
|
+
currency: "CAD",
|
180
|
+
amount: 0.2124e2,
|
181
|
+
label: "CA$21.24",
|
182
|
+
base: { amount: 15.69, currency: "USD", label: "US$15.69" },
|
183
|
+
components: [
|
184
|
+
{
|
185
|
+
key: "vat_item_price",
|
186
|
+
currency: "CAD",
|
187
|
+
amount: 0.18e2,
|
188
|
+
label: "CA$18.00",
|
189
|
+
base: { amount: 13.3, currency: "USD", label: "US$13.30" },
|
190
|
+
name: "HST on item price"
|
191
|
+
},
|
192
|
+
{
|
193
|
+
key: "vat_duties_item_price",
|
194
|
+
currency: "CAD",
|
195
|
+
amount: 0.324e1,
|
196
|
+
label: "CA$3.24",
|
197
|
+
base: { amount: 2.39, currency: "USD", label: "US$2.39" },
|
198
|
+
name: "HST on duties on item price"
|
199
|
+
}
|
200
|
+
],
|
201
|
+
name: "HST",
|
202
|
+
rate: nil
|
203
|
+
},
|
204
|
+
{
|
205
|
+
key: "duty",
|
206
|
+
currency: "CAD",
|
207
|
+
amount: 0.216e2,
|
208
|
+
label: "CA$21.60",
|
209
|
+
base: { amount: 15.96, currency: "USD", label: "US$15.96" },
|
210
|
+
components: [
|
211
|
+
{
|
212
|
+
key: "duties_item_price",
|
213
|
+
currency: "CAD",
|
214
|
+
amount: 0.216e2,
|
215
|
+
label: "CA$21.60",
|
216
|
+
base: { amount: 15.96, currency: "USD", label: "US$15.96" },
|
217
|
+
name: "Duties on item price"
|
218
|
+
}
|
219
|
+
],
|
220
|
+
name: "Duties",
|
221
|
+
rate: nil
|
222
|
+
},
|
223
|
+
{
|
224
|
+
key: "shipping",
|
225
|
+
currency: "CAD",
|
226
|
+
amount: 0.929e1,
|
227
|
+
label: "CA$9.29",
|
228
|
+
base: { amount: 6.86, currency: "USD", label: "US$6.86" },
|
229
|
+
components: [
|
230
|
+
{
|
231
|
+
key: "shipping",
|
232
|
+
currency: "CAD",
|
233
|
+
amount: 0.929e1,
|
234
|
+
label: "CA$9.29",
|
235
|
+
base: { amount: 6.86, currency: "USD", label: "US$6.86" },
|
236
|
+
name: "Shipping"
|
237
|
+
}
|
238
|
+
],
|
239
|
+
name: "Shipping",
|
240
|
+
rate: nil
|
241
|
+
},
|
242
|
+
{
|
243
|
+
key: "discount",
|
244
|
+
currency: "CAD",
|
245
|
+
amount: -0.28e0,
|
246
|
+
label: "-CA$0.28",
|
247
|
+
base: { amount: -0.2, currency: "USD", label: "-US$0.20" },
|
248
|
+
components: [
|
249
|
+
{
|
250
|
+
key: "order_discount",
|
251
|
+
currency: "CAD",
|
252
|
+
amount: -0.28e0,
|
253
|
+
label: "-CA$0.28",
|
254
|
+
base: { amount: -0.2, currency: "USD", label: "-US$0.20" },
|
255
|
+
name: "Order discount"
|
256
|
+
}
|
257
|
+
],
|
258
|
+
name: "Discount",
|
259
|
+
rate: nil
|
260
|
+
}
|
261
|
+
]
|
262
|
+
end
|
263
|
+
|
264
|
+
def customer
|
265
|
+
{
|
266
|
+
name: { first: nil, last: nil },
|
267
|
+
number: nil,
|
268
|
+
phone: nil,
|
269
|
+
email: nil
|
270
|
+
}
|
271
|
+
end
|
272
|
+
|
273
|
+
def country_code
|
274
|
+
@country_code ||=
|
275
|
+
case experience_key
|
276
|
+
when "CAD"
|
277
|
+
when "GBR"
|
278
|
+
end
|
279
|
+
end
|
280
|
+
|
281
|
+
def destination
|
282
|
+
{
|
283
|
+
text: nil,
|
284
|
+
streets: nil,
|
285
|
+
city: nil,
|
286
|
+
province: nil,
|
287
|
+
postal: nil,
|
288
|
+
country: country_code,
|
289
|
+
latitude: nil,
|
290
|
+
longitude: nil,
|
291
|
+
contact: {
|
292
|
+
name: { first: nil, last: nil },
|
293
|
+
company: nil,
|
294
|
+
email: nil,
|
295
|
+
phone: nil
|
296
|
+
}
|
297
|
+
}
|
298
|
+
end
|
299
|
+
|
300
|
+
# TODO fix to correct currency
|
301
|
+
#
|
302
|
+
def delivery_option(delivered_duty:)
|
303
|
+
{
|
304
|
+
id: "opt-9ea4f6c3b2894d7ebf334447469627e5",
|
305
|
+
cost: {
|
306
|
+
currency: "CAD",
|
307
|
+
amount: 9.29,
|
308
|
+
label: "CA$9.29",
|
309
|
+
base: { amount: 6.86, currency: "USD", label: "US$6.86" }
|
310
|
+
},
|
311
|
+
cost_details: [
|
312
|
+
{
|
313
|
+
source: "ratecard",
|
314
|
+
currency: "CAD",
|
315
|
+
amount: 0.929e1,
|
316
|
+
label: "CA$9.29",
|
317
|
+
base: { amount: 6.86, currency: "USD", label: "US$6.86" },
|
318
|
+
components: [
|
319
|
+
{
|
320
|
+
key: "ratecard_base_cost",
|
321
|
+
currency: "CAD",
|
322
|
+
amount: 0.929e1,
|
323
|
+
label: "CA$9.29",
|
324
|
+
base: { amount: 6.86, currency: "USD", label: "US$6.86" }
|
325
|
+
}
|
326
|
+
]
|
327
|
+
}
|
328
|
+
],
|
329
|
+
delivered_duty: delivered_duty,
|
330
|
+
price: {
|
331
|
+
currency: "CAD",
|
332
|
+
amount: 9.29,
|
333
|
+
label: "CA$9.29",
|
334
|
+
base: { amount: 6.86, currency: "USD", label: "US$6.86" }
|
335
|
+
},
|
336
|
+
service: {
|
337
|
+
id: "landmark-global",
|
338
|
+
carrier: { id: "landmark" },
|
339
|
+
name: "Global",
|
340
|
+
center_code: nil
|
341
|
+
},
|
342
|
+
tier: {
|
343
|
+
id: "tie-fc0ec702c4384dc8805ae645ef6156e8",
|
344
|
+
experience: { id: "canada", currency: "CAD" },
|
345
|
+
integration: "information",
|
346
|
+
name: "Standard Shipping",
|
347
|
+
services: ["landmark-global", "dhl-express-worldwide"],
|
348
|
+
strategy: "lowest_cost",
|
349
|
+
visibility: "public",
|
350
|
+
currency: "CAD",
|
351
|
+
display: { estimate: { type: "calculated", label: "2-5 Business Days" } }
|
352
|
+
},
|
353
|
+
window: {
|
354
|
+
from: "Fri, 03 Aug 2018 00:00:00 +0000",
|
355
|
+
to: "Wed, 08 Aug 2018 00:00:00 +0000",
|
356
|
+
timezone: "America/Toronto",
|
357
|
+
label: "2-5 Business Days"
|
358
|
+
},
|
359
|
+
rule_outcome: { ignore: nil, discriminator: "at_cost" },
|
360
|
+
weight: {
|
361
|
+
gravitational: { value: "1.25", units: "pound" },
|
362
|
+
dimensional: { value: "2.12", units: "inch" }
|
363
|
+
},
|
364
|
+
send_to: nil
|
365
|
+
}
|
366
|
+
end
|
367
|
+
|
368
|
+
def deliveries
|
369
|
+
[
|
370
|
+
{
|
371
|
+
id: "del-4070e782d85245f4bc29a8f56d55f33d",
|
372
|
+
center: { id: "cen-394b1db3c61a495c964dd1fe60969160", key: "center-workarea" },
|
373
|
+
items: delivery_items,
|
374
|
+
options: [
|
375
|
+
delivery_option(delivered_duty: "unpaid"),
|
376
|
+
delivery_option(delivered_duty: "paid"),
|
377
|
+
],
|
378
|
+
discriminator: "physical_delivery"
|
379
|
+
}
|
380
|
+
]
|
381
|
+
end
|
382
|
+
|
383
|
+
def items
|
384
|
+
order_put_form.items.map do |line_item_form|
|
385
|
+
price =
|
386
|
+
if line_item_form.price.is_a? Io::Flow::V0::Models::Price
|
387
|
+
line_item_form.price.to_m
|
388
|
+
elsif line_item_form.price.is_a? Hash
|
389
|
+
Io::Flow::V0::Models::Price.new(line_item_form.price).to_m
|
390
|
+
else
|
391
|
+
# ((rand(0..100.0) * 100).floor / 100.0).to_m
|
392
|
+
88.66.to_m
|
393
|
+
end
|
394
|
+
|
395
|
+
converted_price = convert_price(price)
|
396
|
+
|
397
|
+
{
|
398
|
+
number: line_item_form.number,
|
399
|
+
name: "Incredible Cotton Bag",
|
400
|
+
quantity: line_item_form.quantity,
|
401
|
+
center: nil,
|
402
|
+
price: nil,
|
403
|
+
attributes: nil,
|
404
|
+
local: {
|
405
|
+
experience: experience_summary,
|
406
|
+
prices: [
|
407
|
+
{
|
408
|
+
currency: converted_price.currency.iso_code,
|
409
|
+
amount: converted_price.to_f,
|
410
|
+
label: converted_price.format(disambiguate: true),
|
411
|
+
base: { amount: price.to_f, currency: price.currency.iso_code, label: price.format(disambiguate: true) },
|
412
|
+
includes: { key: "vat", label: "Includes VAT" },
|
413
|
+
key: "localized_item_price"
|
414
|
+
}
|
415
|
+
],
|
416
|
+
rates: [],
|
417
|
+
spot_rates: [],
|
418
|
+
status: "included",
|
419
|
+
attributes: {
|
420
|
+
"Size" => "Extra Large",
|
421
|
+
"product_id" => "890726C80A",
|
422
|
+
"fulfillment_method" => "physical"
|
423
|
+
},
|
424
|
+
price_attributes: {}
|
425
|
+
},
|
426
|
+
shipment_estimate: nil,
|
427
|
+
discounts: line_item_form.discounts.discounts.map do |discount_form|
|
428
|
+
{
|
429
|
+
amount: -0.36,
|
430
|
+
requested: {
|
431
|
+
amount: -0.0358,
|
432
|
+
currency: currency_code,
|
433
|
+
},
|
434
|
+
currency: currency_code,
|
435
|
+
label: "-#{currency_symbol}0.36",
|
436
|
+
discount_label: discount_form.label,
|
437
|
+
base: {
|
438
|
+
amount: -0.25,
|
439
|
+
currency: 'USD',
|
440
|
+
label: "-US$0.25"
|
441
|
+
}
|
442
|
+
}
|
443
|
+
end
|
444
|
+
}
|
445
|
+
end
|
446
|
+
end
|
447
|
+
|
448
|
+
# TODO fix to correct currency
|
449
|
+
#
|
450
|
+
def lines
|
451
|
+
order_put_form.items.map do |line_item_form|
|
452
|
+
{
|
453
|
+
item_number: line_item_form.number,
|
454
|
+
quantity: line_item_form.quantity,
|
455
|
+
price: {
|
456
|
+
currency: "CAD",
|
457
|
+
amount: 119.64,
|
458
|
+
label: "CA$119.64",
|
459
|
+
base: { amount: 88.41, currency: "USD", label: "US$88.41" }
|
460
|
+
},
|
461
|
+
total: {
|
462
|
+
currency: "CAD",
|
463
|
+
amount: 119.64,
|
464
|
+
label: "CA$119.64",
|
465
|
+
base: { amount: 88.41, currency: "USD", label: "US$88.41" }
|
466
|
+
},
|
467
|
+
attributes: nil
|
468
|
+
}
|
469
|
+
end
|
470
|
+
end
|
471
|
+
|
472
|
+
def delivery_items
|
473
|
+
order_put_form.items.map do |line_item_form|
|
474
|
+
price =
|
475
|
+
if line_item_form.price.is_a? Io::Flow::V0::Models::Price
|
476
|
+
line_item_form.price.to_m
|
477
|
+
elsif line_item_form.price.is_a? Hash
|
478
|
+
Io::Flow::V0::Models::Price.new(line_item_form.price).to_m
|
479
|
+
else
|
480
|
+
((rand(0..100.0) * 100).floor / 100.0).to_m
|
481
|
+
end
|
482
|
+
|
483
|
+
converted_price = convert_price(price)
|
484
|
+
{
|
485
|
+
number: line_item_form.number,
|
486
|
+
quantity: line_item_form.quantity,
|
487
|
+
shipment_estimate: nil,
|
488
|
+
price: { amount: converted_price.to_f, currency: currency_code },
|
489
|
+
attributes: { "base_amount" => "88.66", "base_currency" => "USD" },
|
490
|
+
center: nil,
|
491
|
+
discount: line_item_form.discount&.to_hash,
|
492
|
+
}
|
493
|
+
end
|
494
|
+
end
|
495
|
+
end
|
496
|
+
end
|
497
|
+
end
|
498
|
+
end
|
499
|
+
end
|