workarea-global_e 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (232) hide show
  1. checksums.yaml +7 -0
  2. data/.eslintrc.json +37 -0
  3. data/.github/ISSUE_TEMPLATE/bug_report.md +37 -0
  4. data/.github/ISSUE_TEMPLATE/documentation-request.md +17 -0
  5. data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  6. data/.github/workflows/ci.yml +77 -0
  7. data/.gitignore +20 -0
  8. data/.rubocop.yml +2 -0
  9. data/.ruby-version +1 -0
  10. data/CHANGELOG.md +261 -0
  11. data/Gemfile +16 -0
  12. data/README.md +39 -0
  13. data/Rakefile +59 -0
  14. data/app/assets/javascripts/workarea/storefront/global_e/modules/checkout_info_validator.js +122 -0
  15. data/app/assets/javascripts/workarea/storefront/global_e/modules/suppress_price_ranges.js +19 -0
  16. data/app/controllers/workarea/admin/country_exceptions_controller.rb +67 -0
  17. data/app/controllers/workarea/admin/fixed_prices_controller.rb +89 -0
  18. data/app/controllers/workarea/admin/orders_controller.decorator +6 -0
  19. data/app/controllers/workarea/storefront/application_controller.decorator +30 -0
  20. data/app/controllers/workarea/storefront/checkouts_controller.decorator +22 -0
  21. data/app/controllers/workarea/storefront/ge_checkouts_controller.rb +10 -0
  22. data/app/controllers/workarea/storefront/global_e_controller.rb +42 -0
  23. data/app/controllers/workarea/storefront/globale/api_controller.rb +108 -0
  24. data/app/controllers/workarea/storefront/globale/refund_controller.rb +65 -0
  25. data/app/controllers/workarea/storefront/users/logins_controller.decorator +13 -0
  26. data/app/helpers/workarea/admin/global_e_helpers.rb +28 -0
  27. data/app/models/workarea/address.decorator +11 -0
  28. data/app/models/workarea/catalog/product.decorator +14 -0
  29. data/app/models/workarea/fulfillment/status/partially_refunded.rb +13 -0
  30. data/app/models/workarea/fulfillment/status/refunded.rb +15 -0
  31. data/app/models/workarea/fulfillment.decorator +55 -0
  32. data/app/models/workarea/global_e/country_exception.rb +37 -0
  33. data/app/models/workarea/global_e/fixed_price.rb +93 -0
  34. data/app/models/workarea/global_e/order_api_events.rb +29 -0
  35. data/app/models/workarea/order/item.decorator +46 -0
  36. data/app/models/workarea/order/status/pending_global_e_fraud_check.rb +12 -0
  37. data/app/models/workarea/order.decorator +64 -0
  38. data/app/models/workarea/payment/status/global_e_appoved.rb +9 -0
  39. data/app/models/workarea/payment/status/pending_global_e_fraud_check.rb +9 -0
  40. data/app/models/workarea/payment/tender/global_e_payment.rb +16 -0
  41. data/app/models/workarea/payment.decorator +10 -0
  42. data/app/models/workarea/price_adjustment.decorator +13 -0
  43. data/app/models/workarea/price_adjustment_set.decorator +25 -0
  44. data/app/models/workarea/pricing/calculators/item_calculator.decorator +48 -0
  45. data/app/models/workarea/pricing/collection.decorator +90 -0
  46. data/app/models/workarea/pricing/discount/appliation_group.decorator +16 -0
  47. data/app/models/workarea/pricing/discount/international_item_proxy.rb +27 -0
  48. data/app/models/workarea/pricing/discount/international_order.rb +29 -0
  49. data/app/models/workarea/pricing/discount.decorator +65 -0
  50. data/app/models/workarea/pricing/price_distributor.decorator +37 -0
  51. data/app/models/workarea/pricing/request.decorator +17 -0
  52. data/app/models/workarea/pricing/sku.decorator +17 -0
  53. data/app/models/workarea/search/admin/order.decorator +11 -0
  54. data/app/models/workarea/shipping/sku.decorator +23 -0
  55. data/app/models/workarea/shipping.decorator +11 -0
  56. data/app/models/workarea/user.decorator +10 -0
  57. data/app/seeds/workarea/global_e_seeds.rb +66 -0
  58. data/app/services/workarea/create_fulfillment.decorator +12 -0
  59. data/app/services/workarea/global_e/address_details.rb +218 -0
  60. data/app/services/workarea/global_e/api/notify_order_refunded.rb +45 -0
  61. data/app/services/workarea/global_e/api/perform_order_payment.rb +46 -0
  62. data/app/services/workarea/global_e/api/remove_restricted_products.rb +28 -0
  63. data/app/services/workarea/global_e/api/send_order_to_merchant/item_pricer.rb +147 -0
  64. data/app/services/workarea/global_e/api/send_order_to_merchant/save_user.rb +59 -0
  65. data/app/services/workarea/global_e/api/send_order_to_merchant.rb +359 -0
  66. data/app/services/workarea/global_e/api/update_order_shipping_info.rb +38 -0
  67. data/app/services/workarea/global_e/api/update_order_status/canceled.rb +42 -0
  68. data/app/services/workarea/global_e/api/update_order_status.rb +28 -0
  69. data/app/services/workarea/global_e/attribute.rb +44 -0
  70. data/app/services/workarea/global_e/brand.rb +19 -0
  71. data/app/services/workarea/global_e/cart_user_details.rb +34 -0
  72. data/app/services/workarea/global_e/category.rb +19 -0
  73. data/app/services/workarea/global_e/checkout_cart_info.rb +358 -0
  74. data/app/services/workarea/global_e/custom_product_attribute.rb +19 -0
  75. data/app/services/workarea/global_e/discount.rb +215 -0
  76. data/app/services/workarea/global_e/merchant/brand.rb +21 -0
  77. data/app/services/workarea/global_e/merchant/category.rb +21 -0
  78. data/app/services/workarea/global_e/merchant/customer.rb +36 -0
  79. data/app/services/workarea/global_e/merchant/customer_details.rb +201 -0
  80. data/app/services/workarea/global_e/merchant/discount.rb +127 -0
  81. data/app/services/workarea/global_e/merchant/international_details.rb +296 -0
  82. data/app/services/workarea/global_e/merchant/order.rb +425 -0
  83. data/app/services/workarea/global_e/merchant/order_refund.rb +103 -0
  84. data/app/services/workarea/global_e/merchant/original_order.rb +28 -0
  85. data/app/services/workarea/global_e/merchant/parcel_tracking.rb +31 -0
  86. data/app/services/workarea/global_e/merchant/payment_details.rb +161 -0
  87. data/app/services/workarea/global_e/merchant/product.rb +222 -0
  88. data/app/services/workarea/global_e/merchant/refund_product.rb +69 -0
  89. data/app/services/workarea/global_e/merchant/response_info.rb +115 -0
  90. data/app/services/workarea/global_e/merchant_cart_product_attribute.rb +21 -0
  91. data/app/services/workarea/global_e/order_status.rb +20 -0
  92. data/app/services/workarea/global_e/order_status_details.rb +79 -0
  93. data/app/services/workarea/global_e/order_status_reason.rb +20 -0
  94. data/app/services/workarea/global_e/parcel.rb +53 -0
  95. data/app/services/workarea/global_e/product.rb +612 -0
  96. data/app/services/workarea/global_e/product_meta_data.rb +13 -0
  97. data/app/services/workarea/global_e/tracking_details.rb +23 -0
  98. data/app/services/workarea/global_e/update_order_dispatch_exception.rb +46 -0
  99. data/app/services/workarea/global_e/update_order_dispatch_request.rb +108 -0
  100. data/app/services/workarea/global_e/user_id_number_type.rb +21 -0
  101. data/app/services/workarea/global_e/users_details.rb +151 -0
  102. data/app/services/workarea/global_e/vat_category.rb +20 -0
  103. data/app/services/workarea/global_e/vat_rate_type.rb +27 -0
  104. data/app/services/workarea/save_order_analytics.decorator +18 -0
  105. data/app/view_models/workarea/admin/order_view_model.decorator +13 -0
  106. data/app/view_models/workarea/storefront/cart_view_model.decorator +7 -0
  107. data/app/view_models/workarea/storefront/order_item_view_model.decorator +16 -0
  108. data/app/view_models/workarea/storefront/order_view_model.decorator +45 -0
  109. data/app/view_models/workarea/storefront/product_view_model.decorator +35 -0
  110. data/app/views/workarea/admin/catalog_products/_country_exceptions_card.html.haml +31 -0
  111. data/app/views/workarea/admin/catalog_products/_global_e_attributes.html.haml +3 -0
  112. data/app/views/workarea/admin/catalog_products/_global_e_fields.html.haml +4 -0
  113. data/app/views/workarea/admin/country_exceptions/edit.html.haml +48 -0
  114. data/app/views/workarea/admin/country_exceptions/index.html.haml +47 -0
  115. data/app/views/workarea/admin/country_exceptions/new.html.haml +44 -0
  116. data/app/views/workarea/admin/fixed_prices/edit.html.haml +73 -0
  117. data/app/views/workarea/admin/fixed_prices/index.html.haml +55 -0
  118. data/app/views/workarea/admin/fixed_prices/new.html.haml +70 -0
  119. data/app/views/workarea/admin/orders/_global_e.html.haml +27 -0
  120. data/app/views/workarea/admin/orders/attributes.html.haml +131 -0
  121. data/app/views/workarea/admin/orders/global_e.html.haml +110 -0
  122. data/app/views/workarea/admin/orders/show.html.haml +27 -0
  123. data/app/views/workarea/admin/orders/tenders/_global_e_payment.html.haml +3 -0
  124. data/app/views/workarea/admin/pricing_skus/_cards.html.haml +98 -0
  125. data/app/views/workarea/storefront/cart_items/create.html.haml +71 -0
  126. data/app/views/workarea/storefront/carts/_pricing.html.haml +14 -0
  127. data/app/views/workarea/storefront/carts/show.html.haml +187 -0
  128. data/app/views/workarea/storefront/ge_checkouts/show.html.haml +1 -0
  129. data/app/views/workarea/storefront/global_e/_country_picker.html.haml +1 -0
  130. data/app/views/workarea/storefront/global_e/_head.html.haml +10 -0
  131. data/app/views/workarea/storefront/orders/_summary.html.haml +275 -0
  132. data/app/views/workarea/storefront/orders/tenders/_global_e_payment.html.haml +3 -0
  133. data/app/views/workarea/storefront/products/_pricing.html.haml +49 -0
  134. data/app/views/workarea/storefront/products/_restricted_item_text.html.haml +1 -0
  135. data/app/views/workarea/storefront/users/orders/_summary.html.haml +22 -0
  136. data/app/workers/workarea/global_e/update_order_dispatch.rb +28 -0
  137. data/app/workers/workarea/save_user_order_details.decorator +9 -0
  138. data/bin/rails +25 -0
  139. data/config/initializers/appends.rb +46 -0
  140. data/config/initializers/seeds.rb +1 -0
  141. data/config/initializers/workarea.rb +64 -0
  142. data/config/locales/en.yml +105 -0
  143. data/config/routes.rb +31 -0
  144. data/lib/workarea/global_e/engine.rb +10 -0
  145. data/lib/workarea/global_e/error.rb +8 -0
  146. data/lib/workarea/global_e/version.rb +5 -0
  147. data/lib/workarea/global_e.rb +58 -0
  148. data/script/admin_ci +5 -0
  149. data/script/ci +8 -0
  150. data/script/core_ci +5 -0
  151. data/script/plugins_ci +5 -0
  152. data/script/storefront_ci +5 -0
  153. data/test/dummy/.ruby-version +1 -0
  154. data/test/dummy/Rakefile +6 -0
  155. data/test/dummy/app/assets/config/manifest.js +3 -0
  156. data/test/dummy/app/assets/images/.keep +0 -0
  157. data/test/dummy/app/assets/javascripts/application.js +14 -0
  158. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  159. data/test/dummy/app/controllers/application_controller.rb +2 -0
  160. data/test/dummy/app/controllers/concerns/.keep +0 -0
  161. data/test/dummy/app/helpers/application_helper.rb +2 -0
  162. data/test/dummy/app/jobs/application_job.rb +2 -0
  163. data/test/dummy/app/mailers/application_mailer.rb +4 -0
  164. data/test/dummy/app/models/concerns/.keep +0 -0
  165. data/test/dummy/app/views/layouts/application.html.erb +15 -0
  166. data/test/dummy/app/views/layouts/mailer.html.erb +13 -0
  167. data/test/dummy/app/views/layouts/mailer.text.erb +1 -0
  168. data/test/dummy/bin/bundle +3 -0
  169. data/test/dummy/bin/rails +4 -0
  170. data/test/dummy/bin/rake +4 -0
  171. data/test/dummy/bin/setup +28 -0
  172. data/test/dummy/bin/update +28 -0
  173. data/test/dummy/bin/yarn +11 -0
  174. data/test/dummy/config/application.rb +23 -0
  175. data/test/dummy/config/boot.rb +5 -0
  176. data/test/dummy/config/environment.rb +5 -0
  177. data/test/dummy/config/environments/development.rb +52 -0
  178. data/test/dummy/config/environments/production.rb +83 -0
  179. data/test/dummy/config/environments/test.rb +45 -0
  180. data/test/dummy/config/initializers/application_controller_renderer.rb +8 -0
  181. data/test/dummy/config/initializers/assets.rb +14 -0
  182. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  183. data/test/dummy/config/initializers/content_security_policy.rb +25 -0
  184. data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
  185. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  186. data/test/dummy/config/initializers/inflections.rb +16 -0
  187. data/test/dummy/config/initializers/mime_types.rb +4 -0
  188. data/test/dummy/config/initializers/workarea.rb +5 -0
  189. data/test/dummy/config/initializers/wrap_parameters.rb +9 -0
  190. data/test/dummy/config/locales/en.yml +33 -0
  191. data/test/dummy/config/puma.rb +34 -0
  192. data/test/dummy/config/routes.rb +5 -0
  193. data/test/dummy/config/secrets.yml +18 -0
  194. data/test/dummy/config/spring.rb +6 -0
  195. data/test/dummy/config.ru +5 -0
  196. data/test/dummy/db/seeds.rb +2 -0
  197. data/test/dummy/lib/assets/.keep +0 -0
  198. data/test/dummy/log/.keep +0 -0
  199. data/test/factories/workarea/global_e_factories.rb +836 -0
  200. data/test/integration/workarea/admin/catalog_product_country_exceptions_integration_test.rb +81 -0
  201. data/test/integration/workarea/admin/global_e_jump_to_integration_test.rb +20 -0
  202. data/test/integration/workarea/admin/pricing_sku_fixed_prices_integration_test.rb +83 -0
  203. data/test/integration/workarea/storefront/global_e_api/receive_order_integration_test.rb +278 -0
  204. data/test/integration/workarea/storefront/global_e_api/receive_order_refund_integration_test.rb +25 -0
  205. data/test/integration/workarea/storefront/global_e_api/receive_payment_integration_test.rb +34 -0
  206. data/test/integration/workarea/storefront/global_e_api/receive_shipping_info_integration_test.rb +29 -0
  207. data/test/integration/workarea/storefront/global_e_api/remove_restricted_products_integration_test.rb +27 -0
  208. data/test/integration/workarea/storefront/global_e_api/update_order_status_integration_test.rb +29 -0
  209. data/test/integration/workarea/storefront/global_e_checkout_cart_info/fixed_pricing_test.rb +438 -0
  210. data/test/integration/workarea/storefront/global_e_checkout_cart_info/gift_card_test.rb +63 -0
  211. data/test/integration/workarea/storefront/global_e_checkout_cart_info_integration_test.rb +660 -0
  212. data/test/integration/workarea/storefront/global_e_checkouts_integration_test.rb +71 -0
  213. data/test/integration/workarea/storefront/users/global_e_logins_integration_test.rb +20 -0
  214. data/test/models/workarea/catalog/product_global_e_test.rb +13 -0
  215. data/test/models/workarea/fixed_pricing_test.rb +117 -0
  216. data/test/models/workarea/global_e/country_exception_test.rb +36 -0
  217. data/test/models/workarea/payment_test.decorator +31 -0
  218. data/test/models/workarea/pricing/calculators/item_calculator_fixed_prices_test.rb +83 -0
  219. data/test/models/workarea/pricing/collection_fixed_prices_test.rb +83 -0
  220. data/test/models/workarea/pricing/price_distributor_test.decorator +21 -0
  221. data/test/models/workarea/pricing/sku_fixed_price_test.rb +133 -0
  222. data/test/support/workarea/global_e_support.rb +18 -0
  223. data/test/system/workarea/admin/global_e_system_test.rb +21 -0
  224. data/test/system/workarea/storefront/global_e_cart_system_test.rb +48 -0
  225. data/test/system/workarea/storefront/global_e_order_history_system_test.rb +43 -0
  226. data/test/teaspoon_env.rb +6 -0
  227. data/test/test_helper.rb +9 -0
  228. data/test/view_models/workarea/admin/global_e_order_view_model_test.rb +22 -0
  229. data/test/workers/workarea/global_e/update_order_dispatch_test.rb +64 -0
  230. data/test/workers/workarea/global_e_save_user_order_details_test.rb +41 -0
  231. data/workarea-global_e.gemspec +16 -0
  232. metadata +293 -0
@@ -0,0 +1,836 @@
1
+ module Workarea
2
+ module GlobalEFactories
3
+ Factories.add self
4
+
5
+ def create_cart(order: nil, items: nil, user: nil)
6
+ order ||= create_order(
7
+ email: user&.email,
8
+ checkout_started_at: Time.current,
9
+ user_id: user&.id&.to_s
10
+ )
11
+ items = items ||
12
+ begin
13
+ product = create_product
14
+ [
15
+ {
16
+ product: product,
17
+ sku: product.skus.first,
18
+ quantity: 2
19
+ }
20
+ ]
21
+ end
22
+
23
+ items.each do |item|
24
+ item_details = OrderItemDetails
25
+ .find!(item[:sku])
26
+ .to_h
27
+ .merge(product_id: item[:product].id, sku: item[:sku], quantity: item[:quantity])
28
+
29
+ order.add_item(item_details)
30
+ end
31
+
32
+ Workarea::Pricing.perform(order)
33
+
34
+ order.tap(&:save!)
35
+ end
36
+
37
+ def create_global_e_completed_checkout(order: nil, items: nil)
38
+ order ||= create_order(global_e_id: create_global_e_order_id)
39
+ items = items ||
40
+ begin
41
+ product = create_product
42
+ [
43
+ {
44
+ product: product,
45
+ sku: product.skus.first,
46
+ quantity: 1
47
+ }
48
+ ]
49
+ end
50
+
51
+ items.each do |item|
52
+ item_details = OrderItemDetails
53
+ .find!(item[:sku])
54
+ .to_h
55
+ .merge(product_id: item[:product].id, sku: item[:sku], quantity: item[:quantity])
56
+
57
+ order.add_item(item_details)
58
+ end
59
+
60
+ Workarea::Pricing.perform(order)
61
+
62
+ order.tap(&:save!).reload
63
+
64
+ merchant_order = GlobalE::Merchant::Order.new(JSON.parse(global_e_send_order_to_mechant_body(order: order)))
65
+ response = GlobalE::Api::SendOrderToMerchant.new(order, merchant_order).response
66
+
67
+ GlobalE::OrderApiEvents.upsert_one(
68
+ order.id,
69
+ set: {
70
+ "receive_order" => merchant_order.to_h,
71
+ "receive_order_response" => response.to_h
72
+ }
73
+ )
74
+
75
+ order.reload
76
+ end
77
+
78
+ def create_global_e_placed_order(order: nil, items: nil)
79
+ order = create_global_e_completed_checkout(order: order, items: items)
80
+
81
+ merchant_order = GlobalE::Merchant::Order.new(
82
+ JSON.parse(global_e_peform_order_payment_body(order: order))
83
+ )
84
+ GlobalE::Api::PerformOrderPayment.new(order, merchant_order).response
85
+
86
+ order.reload
87
+ end
88
+
89
+ def create_global_e_shipped_order(order: nil)
90
+ order = create_global_e_placed_order
91
+
92
+ merchant_order = GlobalE::Merchant::Order.new(
93
+ JSON.parse(global_e_update_order_shipping_info_body(order: order))
94
+ )
95
+
96
+ GlobalE::Api::UpdateOrderShippingInfo.new(order, merchant_order).response
97
+
98
+ order
99
+ end
100
+
101
+ def create_complete_product(overrides = {})
102
+ attributes = {
103
+ name: 'Test Product',
104
+ description: "Description",
105
+ details: { 'Material' => 'Cotton', 'Style' => '12345' },
106
+ filters: { 'Material' => 'Cotton', 'Style' => '12345' },
107
+ variants: [{ sku: 'SKU', details: { material: 'Cotton' }, regular: 5.00 }]
108
+ }.merge(overrides)
109
+
110
+ Workarea::Catalog::Product.new(attributes.except(:variants)).tap do |product|
111
+ product.id = attributes[:id] if attributes[:id].present?
112
+
113
+ if attributes[:variants].present?
114
+ attributes[:variants].each do |attrs|
115
+ pricing_attrs = [
116
+ :regular, :sale, :msrp, :on_sale,
117
+ :tax_code, :discountable, :fixed_prices
118
+ ]
119
+ inventory_attrs = [:available, :policy]
120
+
121
+ sku = Workarea::Pricing::Sku.find_or_create_by(id: attrs[:sku])
122
+ sku.attributes = attrs.slice(
123
+ :on_sale,
124
+ :tax_code,
125
+ :discountable,
126
+ :fixed_prices
127
+ )
128
+ sku.prices.build(attrs.slice(:regular, :sale, :msrp))
129
+ sku.save!
130
+
131
+ shipping_sku = Workarea::Shipping::Sku.find_or_create_by(id: attrs[:sku])
132
+ shipping_sku.update_attributes(
133
+ weight: 5.0,
134
+ dimensions: [5, 5, 5]
135
+ )
136
+
137
+ inventory_sku = Workarea::Inventory::Sku.find_or_create_by(id: attrs[:sku])
138
+ inventory_sku.update_attributes(attrs.slice(:policy, :available).reverse_merge(available: 5))
139
+
140
+ variant_attrs = attrs.except(*(pricing_attrs + inventory_attrs))
141
+ product.variants.build(variant_attrs)
142
+ if variant_attrs[:details]&.any?
143
+ product.images.build(
144
+ image: product_image_file,
145
+ option: variant_attrs[:details].values.first
146
+ )
147
+ else
148
+ product.images.build(image: product_image_file)
149
+ end
150
+ end
151
+ end
152
+
153
+ product.save!
154
+ end
155
+ end
156
+
157
+ def global_e_send_order_to_mechant_body(email: "John.Smith@global-e.com", order: nil, user: nil)
158
+ order ||= create_cart(user: user)
159
+
160
+ shipping_address = {
161
+ "FirstName" => "John",
162
+ "LastName" => "S mith",
163
+ "MiddleName" => nil,
164
+ "Salutation" => nil,
165
+ "Company" => nil,
166
+ "Address1" => "Amishav 24",
167
+ "Address2" => nil,
168
+ "City" => "Paris",
169
+ "StateCode" => nil,
170
+ "StateOrProvince" => nil,
171
+ "Zip" => "66666",
172
+ "Email" => email,
173
+ "Phone1" => "98756344782",
174
+ "Phone2" => nil,
175
+ "Fax" => nil,
176
+ "CountryCode" => "FR",
177
+ "CountryName" => "France"
178
+ }
179
+
180
+ billing_address = {
181
+ "FirstName" => "John",
182
+ "LastName" => "S mith",
183
+ "MiddleName" => nil,
184
+ "Salutation" => nil,
185
+ "Company" => "GlobalE",
186
+ "Address1" => "Amishav 24",
187
+ "Address2" => nil,
188
+ "City" => "Paris",
189
+ "StateCode" => nil,
190
+ "StateOrProvince" => nil,
191
+ "Zip" => "66666",
192
+ "Email" => email,
193
+ "Phone1" => "972500000",
194
+ "Phone2" => nil,
195
+ "Fax" => nil,
196
+ "CountryCode" => "FR",
197
+ "CountryName" => "France"
198
+ }
199
+ if user.present?
200
+ billing_address.merge!(
201
+ "AddressBookId" => user.default_shipping_address.id.to_s
202
+ )
203
+ shipping_address.merge!(
204
+ "AddressBookId" => user.default_billing_address.id.to_s
205
+ )
206
+ end
207
+
208
+ discounts = Pricing::Discount.all.to_a
209
+
210
+ order_discounts = order.price_adjustments.discounts.reject { |pa| pa.price == "order" } +
211
+ order.price_adjustments.discounts.select { |pa| pa.price == "order" }.group_discounts_by_id
212
+
213
+ {
214
+ "AllowMailsFromMerchant" => false,
215
+ "ReservationRequestId" => nil,
216
+ "ClearCart" => true,
217
+ "CurrencyCode" => "USD",
218
+ "Customer" => {
219
+ "EmailAddress" => "info@global-e.com",
220
+ "IsEndCustomerPrimary" => false,
221
+ "SendConfirmation" => false
222
+ },
223
+ "CustomerComments" => nil,
224
+ "Discounts" => order_discounts.map do |price_adjustment|
225
+ discount = discounts.detect { |d| price_adjustment.data["discount_id"] == d.id.to_s }
226
+ {
227
+ "Name" => discount.name,
228
+ "Description" => "#{discount.class.name.demodulize.underscore.titleize} - #{discount.name}",
229
+ "Price" => (price_adjustment.amount * 1.1).abs.to_f,
230
+ "DiscountType" => 1,
231
+ "VATRate" => 0.0,
232
+ "LocalVATRate" => 0.0,
233
+ "CouponCode" => nil,
234
+ "InternationalPrice" => (price_adjustment.amount * 1.4).abs.to_f,
235
+ "DiscountCode" => price_adjustment.global_e_discount_code,
236
+ "ProductCartItemId" => price_adjustment.price == "item" ? price_adjustment._parent.id.to_s : nil,
237
+ "LoyaltyVoucherCode" => nil
238
+ }
239
+ end,
240
+ "DoNotChargeVAT" => false,
241
+ "FreeShippingCouponCode" => nil,
242
+ "IsFreeShipping" => false,
243
+ "IsSplitOrder" => false,
244
+ "LoyaltyCode" => nil,
245
+ "LoyaltyPointsEarned" => 0.0,
246
+ "LoyaltyPointsSpent" => 0.0,
247
+ "Markups" => [],
248
+ "OriginalMerchantTotalProductsDiscountedPrice" => 249.32,
249
+ "OTVoucherAmount" => nil,
250
+ "OTVoucherCode" => nil,
251
+ "OTVoucherCurrencyCode" => nil,
252
+ "InitialCheckoutCultureCode" => "en-GB",
253
+ "CultureCode" => "en-GB",
254
+ "HubId" => 40,
255
+ "UserId" => nil,
256
+ "Products" => order.items.map do |order_item|
257
+ {
258
+ "Attributes" => [
259
+ {
260
+ "AttributeKey" => "color",
261
+ "AttributeValue" => "GREY"
262
+ }
263
+ ],
264
+ "Sku" => "7290012491726",
265
+ "Price" => 21.5500,
266
+ "DiscountedPrice" => 20.50,
267
+ "Quantity" => 8,
268
+ "VATRate" => 18.000000,
269
+ "InternationalPrice" => 4.8400,
270
+ "InternationalDiscountedPrice" => 4.8400,
271
+ "CartItemId" => order_item.id.to_s,
272
+ "Brand" => nil,
273
+ "Categories" => [],
274
+ "ListPrice" => 5.11,
275
+ "InternationalListPrice" => 5.00,
276
+ "DiscountedPriceExcDutiesAndTaxes" => 0.0
277
+ }
278
+ end,
279
+ "RoundingRate" => 0.723416,
280
+ "SameDayDispatch" => false,
281
+ "SameDayDispatchCost" => 0.0,
282
+ "PrimaryShipping" => {
283
+ "FirstName" => "GlobalE ",
284
+ "LastName" => "GlobalE",
285
+ "MiddleName" => nil,
286
+ "Salutation" => nil,
287
+ "Company" => "GlobalE",
288
+ "Address1" => "21/D, Yegi'a Kapayim st. Yellow building - Floor 1",
289
+ "Address2" => "Test Address2\r\nGlobal-e OrderId => GE927127",
290
+ "City" => "Petach Tikva",
291
+ "StateCode" => "NN",
292
+ "StateOrProvince" => nil,
293
+ "Zip" => "4913020",
294
+ "Email" => "info@global-e.com",
295
+ "Phone1" => " 972 73 204 1384",
296
+ "Phone2" => "Test Phone2",
297
+ "Fax" => "Test Fax",
298
+ "CountryCode" => "IL",
299
+ "CountryName" => "Israel"
300
+ },
301
+ "SecondaryShipping" => shipping_address,
302
+ "ShippingMethodCode" => "globaleintegration_standard",
303
+ "InternationalDetails" => {
304
+ "CurrencyCode" => "EUR",
305
+ "TotalPrice" => 64.8800,
306
+ "TransactionCurrencyCode" => " EUR",
307
+ "TransactionTotalPrice" => 64.8800,
308
+ "TotalShippingPrice" => 32.7400,
309
+ "DiscountedShippingPrice" => 19.97,
310
+ "TotalDutiesPrice" => 0.0000,
311
+ "ShippingMethodCode" => "2",
312
+ "PaymentMethodCode" => "1",
313
+ "PaymentMethodName" => "Visa",
314
+ "ShippingMethodName" => "DHL Express Worldwide",
315
+ "ShippingMethodTypeCode" => "Express",
316
+ "ShippingMethodTypeName" => "Express Courier (Air)",
317
+ "DutiesGuaranteed" => false,
318
+ "OrderTrackingNumber" => nil,
319
+ "OrderTrackingUrl" => "http://www.israelpost.co.il/itemtrace.nsf/mainsearch?openform",
320
+ "OrderWaybillNumber" => nil,
321
+ "OrderWaybillUrl" => nil,
322
+ "ShippingMethodStatusCode" => "0",
323
+ "ShippingMethodStatusName" => "undefined",
324
+ "CardNumberLastFourDigits" => "7854",
325
+ "ExpirationDate" => "2023-06-30",
326
+ "TotalVATAmount" => 11.1400
327
+ },
328
+ "PaymentDetails" => nil,
329
+ "PrimaryBilling" => {
330
+ "FirstName" => "GlobalE",
331
+ "LastName" => "GlobalE",
332
+ "MiddleName" => nil,
333
+ "Salutation" => nil,
334
+ "Company" => "GlobalE",
335
+ "Address1" => "21/D, Yegi'a Kapayim st. Yellow building - Floor 1",
336
+ "Address2" => nil,
337
+ "City" => "Petach Tikva",
338
+ "StateCode" => nil,
339
+ "StateOrProvince" => nil,
340
+ "Zip" => "4913020",
341
+ "Email" => "info@global-e.com",
342
+ "Phone1" => " 972 73 204 1384",
343
+ "Phone2" => nil,
344
+ "Fax" => " 972 73 204 1386",
345
+ "CountryCode" => "IL",
346
+ "CountryName" => "Israel"
347
+ },
348
+ "SecondaryBilling" => billing_address,
349
+ "OrderId" => "GE927127",
350
+ "DiscountedShippingPrice" => 19.97,
351
+ "StatusCode" => "N/A",
352
+ "MerchantGUID" => "abcdabcd-abcd-abcd-abcd-abcdabcdabcd",
353
+ "CartId" => order.global_e_token,
354
+ "MerchantOrderId" => nil,
355
+ "PriceCoefficientRate" => 1.000000,
356
+ "GenericHSCode" => nil,
357
+ "TotalDutiesAndTaxesPrice" => 0.0,
358
+ "CCFPrice" => 0.0
359
+ }.to_json
360
+ end
361
+
362
+ def global_e_send_order_to_merchant_with_shipping_discounts_body(email: "John.Smith@global-e.com", order: nil)
363
+ order ||= create_cart
364
+
365
+ discounts = Pricing::Discount.all.to_a
366
+
367
+ order_discounts = order.price_adjustments.discounts.reject { |pa| pa.price == "order" } +
368
+ order.price_adjustments.discounts.select { |pa| pa.price == "order" }.group_discounts_by_id
369
+
370
+ {
371
+ "AllowMailsFromMerchant" => false,
372
+ "ReservationRequestId" => nil,
373
+ "ClearCart" => true,
374
+ "CurrencyCode" => "USD",
375
+ "Customer" => {
376
+ "EmailAddress" => "info@global-e.com",
377
+ "IsEndCustomerPrimary" => false,
378
+ "SendConfirmation" => false
379
+ },
380
+ "CustomerComments" => nil,
381
+ "Discounts" => order_discounts.map do |price_adjustment|
382
+ discount = discounts.detect { |d| price_adjustment.data["discount_id"] == d.id.to_s }
383
+ {
384
+ "Name" => discount.name,
385
+ "Description" => "#{discount.class.name.demodulize.underscore.titleize} - #{discount.name}",
386
+ "Price" => (price_adjustment.amount * 1.1).abs.to_f,
387
+ "DiscountType" => 1,
388
+ "VATRate" => 0.0,
389
+ "LocalVATRate" => 0.0,
390
+ "CouponCode" => nil,
391
+ "InternationalPrice" => (price_adjustment.amount * 1.4).abs.to_f,
392
+ "DiscountCode" => price_adjustment.global_e_discount_code,
393
+ "ProductCartItemId" => price_adjustment.price == "item" ? price_adjustment._parent.id.to_s : nil,
394
+ "LoyaltyVoucherCode" => nil
395
+ }
396
+ end + [
397
+ {
398
+ "CouponCode" => nil,
399
+ "Description" => "Shipping discount provided from fixed price range 205739",
400
+ "DiscountCode" => nil,
401
+ "DiscountType" => 2,
402
+ "InternationalPrice" => 14.13,
403
+ "LocalVATRate" => 0,
404
+ "LoyaltyVoucherCode" => nil,
405
+ "Name" => "Shipping discount for fixed price",
406
+ "Price" => 15.35,
407
+ "ProductCartItemId" => nil,
408
+ "VATRate" => 0
409
+ },
410
+ {
411
+ "CouponCode" => nil,
412
+ "Description" => "Discount generated to discount the DDP",
413
+ "DiscountCode" => nil,
414
+ "DiscountType" => 4,
415
+ "InternationalPrice" => 47.43,
416
+ "LocalVATRate" => 0,
417
+ "LoyaltyVoucherCode" => nil,
418
+ "Name" => "Hidden DDP",
419
+ "Price" => 53.03,
420
+ "ProductCartItemId" => nil,
421
+ "VATRate" => 0
422
+ }
423
+ ],
424
+ "DoNotChargeVAT" => false,
425
+ "FreeShippingCouponCode" => nil,
426
+ "IsFreeShipping" => false,
427
+ "IsSplitOrder" => false,
428
+ "LoyaltyCode" => nil,
429
+ "LoyaltyPointsEarned" => 0.0,
430
+ "LoyaltyPointsSpent" => 0.0,
431
+ "Markups" => [],
432
+ "OriginalMerchantTotalProductsDiscountedPrice" => 249.32,
433
+ "OTVoucherAmount" => nil,
434
+ "OTVoucherCode" => nil,
435
+ "OTVoucherCurrencyCode" => nil,
436
+ "InitialCheckoutCultureCode" => "en-GB",
437
+ "CultureCode" => "en-GB",
438
+ "HubId" => 40,
439
+ "UserId" => nil,
440
+ "Products" => order.items.map do |order_item|
441
+ {
442
+ "Attributes" => [
443
+ {
444
+ "AttributeKey" => "color",
445
+ "AttributeValue" => "GREY"
446
+ }
447
+ ],
448
+ "Sku" => "7290012491726",
449
+ "Price" => 21.5500,
450
+ "DiscountedPrice" => 20.50,
451
+ "Quantity" => 8,
452
+ "VATRate" => 18.000000,
453
+ "InternationalPrice" => 4.8400,
454
+ "InternationalDiscountedPrice" => 4.8400,
455
+ "CartItemId" => order_item.id.to_s,
456
+ "Brand" => nil,
457
+ "Categories" => [],
458
+ "ListPrice" => 5.11,
459
+ "InternationalListPrice" => 5.00,
460
+ "DiscountedPriceExcDutiesAndTaxes" => 0.0
461
+ }
462
+ end,
463
+ "RoundingRate" => 0.723416,
464
+ "SameDayDispatch" => false,
465
+ "SameDayDispatchCost" => 0.0,
466
+ "PrimaryShipping" => {
467
+ "FirstName" => "GlobalE ",
468
+ "LastName" => "GlobalE",
469
+ "MiddleName" => nil,
470
+ "Salutation" => nil,
471
+ "Company" => "GlobalE",
472
+ "Address1" => "21/D, Yegi'a Kapayim st. Yellow building - Floor 1",
473
+ "Address2" => "Test Address2\r\nGlobal-e OrderId => GE927127",
474
+ "City" => "Petach Tikva",
475
+ "StateCode" => "NN",
476
+ "StateOrProvince" => nil,
477
+ "Zip" => "4913020",
478
+ "Email" => "info@global-e.com",
479
+ "Phone1" => " 972 73 204 1384",
480
+ "Phone2" => "Test Phone2",
481
+ "Fax" => "Test Fax",
482
+ "CountryCode" => "IL",
483
+ "CountryName" => "Israel"
484
+ },
485
+ "SecondaryShipping" => {
486
+ "FirstName" => "John",
487
+ "LastName" => "S mith",
488
+ "MiddleName" => nil,
489
+ "Salutation" => nil,
490
+ "Company" => nil,
491
+ "Address1" => "Amishav 24",
492
+ "Address2" => nil,
493
+ "City" => "Paris",
494
+ "StateCode" => nil,
495
+ "StateOrProvince" => nil,
496
+ "Zip" => "66666",
497
+ "Email" => email,
498
+ "Phone1" => "98756344782",
499
+ "Phone2" => nil,
500
+ "Fax" => nil,
501
+ "CountryCode" => "FR",
502
+ "CountryName" => "France"
503
+ },
504
+ "ShippingMethodCode" => "globaleintegration_standard",
505
+ "InternationalDetails" => {
506
+ "CurrencyCode" => "EUR",
507
+ "TotalPrice" => 64.8800,
508
+ "TransactionCurrencyCode" => " EUR",
509
+ "TransactionTotalPrice" => 64.8800,
510
+ "TotalShippingPrice" => 32.7400,
511
+ "DiscountedShippingPrice" => 19.97,
512
+ "TotalDutiesPrice" => 0.0000,
513
+ "ShippingMethodCode" => "2",
514
+ "PaymentMethodCode" => "1",
515
+ "PaymentMethodName" => "Visa",
516
+ "ShippingMethodName" => "DHL Express Worldwide",
517
+ "ShippingMethodTypeCode" => "Express",
518
+ "ShippingMethodTypeName" => "Express Courier (Air)",
519
+ "DutiesGuaranteed" => false,
520
+ "OrderTrackingNumber" => nil,
521
+ "OrderTrackingUrl" => "http://www.israelpost.co.il/itemtrace.nsf/mainsearch?openform",
522
+ "OrderWaybillNumber" => nil,
523
+ "OrderWaybillUrl" => nil,
524
+ "ShippingMethodStatusCode" => "0",
525
+ "ShippingMethodStatusName" => "undefined",
526
+ "CardNumberLastFourDigits" => "7854",
527
+ "ExpirationDate" => "2023-06-30",
528
+ "TotalVATAmount" => 11.1400
529
+ },
530
+ "PaymentDetails" => nil,
531
+ "PrimaryBilling" => {
532
+ "FirstName" => "GlobalE",
533
+ "LastName" => "GlobalE",
534
+ "MiddleName" => nil,
535
+ "Salutation" => nil,
536
+ "Company" => "GlobalE",
537
+ "Address1" => "21/D, Yegi'a Kapayim st. Yellow building - Floor 1",
538
+ "Address2" => nil,
539
+ "City" => "Petach Tikva",
540
+ "StateCode" => nil,
541
+ "StateOrProvince" => nil,
542
+ "Zip" => "4913020",
543
+ "Email" => "info@global-e.com",
544
+ "Phone1" => " 972 73 204 1384",
545
+ "Phone2" => nil,
546
+ "Fax" => " 972 73 204 1386",
547
+ "CountryCode" => "IL",
548
+ "CountryName" => "Israel"
549
+ },
550
+ "SecondaryBilling" => {
551
+ "FirstName" => "John",
552
+ "LastName" => "S mith",
553
+ "MiddleName" => nil,
554
+ "Salutation" => nil,
555
+ "Company" => "GlobalE",
556
+ "Address1" => "Amishav 24",
557
+ "Address2" => nil,
558
+ "City" => "Paris",
559
+ "StateCode" => nil,
560
+ "StateOrProvince" => nil,
561
+ "Zip" => "66666",
562
+ "Email" => email,
563
+ "Phone1" => "972500000",
564
+ "Phone2" => nil,
565
+ "Fax" => nil,
566
+ "CountryCode" => "FR",
567
+ "CountryName" => "France"
568
+ },
569
+ "OrderId" => "GE927127",
570
+ "DiscountedShippingPrice" => 19.97,
571
+ "StatusCode" => "N/A",
572
+ "MerchantGUID" => "abcdabcd-abcd-abcd-abcd-abcdabcdabcd",
573
+ "CartId" => order.global_e_token,
574
+ "MerchantOrderId" => nil,
575
+ "PriceCoefficientRate" => 1.000000,
576
+ "GenericHSCode" => nil,
577
+ "TotalDutiesAndTaxesPrice" => 0.0,
578
+ "CCFPrice" => 0.0
579
+ }.to_json
580
+ end
581
+
582
+ def global_e_peform_order_payment_body(order: nil)
583
+ order ||= create_global_e_completed_checkout
584
+
585
+ {
586
+ "AllowMailsFromMerchant" => false,
587
+ "ReservationRequestId" => nil,
588
+ "ClearCart" => false,
589
+ "CurrencyCode" => nil,
590
+ "Customer" => {
591
+ "EmailAddress" => nil,
592
+ "IsEndCustomerPrimary" => false,
593
+ "SendConfirmation" => false
594
+ },
595
+ "CustomerComments" => nil,
596
+ "Discounts" => [
597
+ ],
598
+ "DoNotChargeVAT" => false,
599
+ "FreeShippingCouponCode" => nil,
600
+ "IsFreeShipping" => false,
601
+ "IsSplitOrder" => false,
602
+ "LoyaltyCode" => nil,
603
+ "LoyaltyPointsEarned" => nil,
604
+ "LoyaltyPointsSpent" => nil,
605
+ "Markups" => [
606
+ ],
607
+ "OriginalMerchantTotalProductsDiscountedPrice" => 0.0,
608
+ "OTVoucherAmount" => nil,
609
+ "OTVoucherCode" => nil,
610
+ "OTVoucherCurrencyCode" => nil,
611
+ "InitialCheckoutCultureCode" => nil,
612
+ "CultureCode" => nil,
613
+ "HubId" => nil,
614
+ "PrimaryShipping" => {
615
+ "Address1" => nil,
616
+ "Address2" => nil,
617
+ "City" => nil,
618
+ "Company" => nil,
619
+ "CountryCode" => nil,
620
+ "CountryCode3" => nil,
621
+ "CountryName" => nil,
622
+ "Email" => nil,
623
+ "Fax" => nil,
624
+ "FirstName" => nil,
625
+ "LastName" => nil,
626
+ "MiddleName" => nil,
627
+ "Phone1" => nil,
628
+ "Phone2" => nil,
629
+ "Salutation" => nil,
630
+ "StateCode" => nil,
631
+ "StateOrProvince" => nil,
632
+ "Zip" => nil
633
+ },
634
+ "Products" => [
635
+ ],
636
+ "RoundingRate" => 0.0,
637
+ "SameDayDispatch" => false,
638
+ "SameDayDispatchCost" => 0.0,
639
+ "SecondaryShipping" => {
640
+ "Address1" => nil,
641
+ "Address2" => nil,
642
+ "City" => nil,
643
+ "Company" => nil,
644
+ "CountryCode" => nil,
645
+ "CountryCode3" => nil,
646
+ "CountryName" => nil,
647
+ "Email" => nil,
648
+ "Fax" => nil,
649
+ "FirstName" => nil,
650
+ "LastName" => nil,
651
+ "MiddleName" => nil,
652
+ "Phone1" => nil,
653
+ "Phone2" => nil,
654
+ "Salutation" => nil,
655
+ "StateCode" => nil,
656
+ "StateOrProvince" => nil,
657
+ "Zip" => nil
658
+ },
659
+ "ShippingMethodCode" => nil,
660
+ "ShipToStoreCode" => nil,
661
+ "UrlParameters" => nil,
662
+ "IsReplacementOrder" => false,
663
+ "OriginalOrder" => nil,
664
+ "UserId" => nil,
665
+ "PaymentDetails" => {
666
+ "Address1" => "79 Madison Ave",
667
+ "Address2" => nil,
668
+ "CardNumber" => nil,
669
+ "City" => "New York",
670
+ "CountryCode" => "US",
671
+ "CountryCode3" => "USA",
672
+ "CountryName" => "United States",
673
+ "CVVNumber" => nil,
674
+ "Email" => "service@global-e.com",
675
+ "ExpirationDate" => "2999-12-31",
676
+ "Fax" => nil,
677
+ "OwnerFirstName" => "GlobalE",
678
+ "OwnerLastName" => "GlobalE",
679
+ "OwnerName" => "GlobalE US",
680
+ "PaymentMethodCode" => "OT",
681
+ "PaymentMethodName" => "Undefined",
682
+ "PaymentMethodTypeCode" => "globaleintegration",
683
+ "Phone1" => "+1 (212) 634-3952",
684
+ "Phone2" => nil,
685
+ "StateCode" => "NY",
686
+ "StateOrProvince" => "NY",
687
+ "Zip" => "10016"
688
+ },
689
+ "PrimaryBilling" => {
690
+ "Address1" => "Hertzel+12",
691
+ "Address2" => nil,
692
+ "City" => "Petah+Tiqwa",
693
+ "Company" => nil,
694
+ "CountryCode" => "IL",
695
+ "CountryCode3" => "ISR",
696
+ "CountryName" => "Israel",
697
+ "Email" => "alextest%40test.com",
698
+ "Fax" => nil,
699
+ "FirstName" => "alex+test",
700
+ "LastName" => "alex+test",
701
+ "MiddleName" => nil,
702
+ "Phone1" => "234242342342",
703
+ "Phone2" => nil,
704
+ "Salutation" => nil,
705
+ "StateCode" => nil,
706
+ "StateOrProvince" => nil,
707
+ "Zip" => "34324234"
708
+ },
709
+ "SecondaryBilling" => {
710
+ "Address1" => "79 Madison Ave",
711
+ "Address2" => nil,
712
+ "City" => "New York",
713
+ "Company" => "GlobalE",
714
+ "CountryCode" => "US",
715
+ "CountryCode3" => "USA",
716
+ "CountryName" => "United States",
717
+ "Email" => "service@global-e.com",
718
+ "Fax" => nil,
719
+ "FirstName" => "GlobalE",
720
+ "LastName" => "GlobalE",
721
+ "MiddleName" => nil,
722
+ "Phone1" => "+1 (212) 634-3952",
723
+ "Phone2" => nil,
724
+ "Salutation" => nil,
725
+ "StateCode" => "NY",
726
+ "StateOrProvince" => "NY",
727
+ "Zip" => "10016"
728
+ },
729
+ "CartHash" => "98307541B9081C6CFE7E62C34FF4EDF3",
730
+ "CartId" => order.global_e_token,
731
+ "DiscountedShippingPrice" => 19.97,
732
+ "InternationalDetails" => {
733
+ "ConsignmentFee" => 0.0000,
734
+ "CurrencyCode" => "ILS",
735
+ "DeliveryDaysFrom" => 2,
736
+ "DeliveryDaysTo" => 2,
737
+ "DiscountedShippingPrice" => 74.9500,
738
+ "DutiesGuaranteed" => true,
739
+ "OrderTrackingNumber" => "0010173682",
740
+ "OrderTrackingUrl" => "https%3a%2f%2fqa.bglobale.com%2fOrder%2fTrack%2fmZ7c%3fOrderId%3dGE2130509US%26ShippingEmail%3dalextest%40test.com",
741
+ "OrderWaybillNumber" => nil,
742
+ "PaymentMethodCode" => "1",
743
+ "PaymentMethodName" => "Visa",
744
+ "RemoteAreaSurcharge" => 0.0000,
745
+ "SameDayDispatchCost" => 0.0000,
746
+ "ShippingMethodCode" => "40001858",
747
+ "ShippingMethodName" => "DHL Express Worldwide",
748
+ "ShippingMethodTypeCode" => "Express",
749
+ "ShippingMethodTypeName" => "Express Courier (Air)",
750
+ "SizeOverchargeValue" => 0.0000,
751
+ "TotalCCFPrice" => 0.0000,
752
+ "TotalDutiesPrice" => 0.0000,
753
+ "TotalPrice" => 709.95,
754
+ "TotalShippingPrice" => 74.9500,
755
+ "TransactionCurrencyCode" => "ILS",
756
+ "TransactionTotalPrice" => 709.9500,
757
+ "ParcelsTracking" => nil,
758
+ "CardNumberLastFourDigits" => "1111",
759
+ "ExpirationDate" => "2020-10-31",
760
+ "CashOnDeliveryFee" => 0.0,
761
+ "ShipmentLocation" => nil,
762
+ "ShipmentStatusUpdateTime" => nil,
763
+ "ShippingMethodStatusCode" => "Undefined",
764
+ "ShippingMethodStatusName" => "undefined"
765
+ },
766
+ "MerchantGUID" => "abcdabcd-abcd-abcd-abcd-abcdabcdabcd",
767
+ "MerchantOrderId" => order.id,
768
+ "OrderId" => "GE2130509US",
769
+ "PriceCoefficientRate" => 1.000000,
770
+ "StatusCode" => "N/A",
771
+ "WebStoreCode" => nil,
772
+ "WebStoreInstanceCode" => "GlobalEDefaultStoreInstance"
773
+ }.to_json
774
+ end
775
+
776
+ def global_e_update_order_status_body(global_e_order_id:)
777
+ {
778
+ "OrderId" => global_e_order_id,
779
+ "StatusCode" => "canceled",
780
+ "MerchantGUID" => "abcdabcd-abcd-abcd-abcd-abcdabcdabcd"
781
+ }.to_json
782
+ end
783
+
784
+ def global_e_update_order_shipping_info_body(order: nil)
785
+ order ||= create_global_e_placed_order
786
+
787
+ {
788
+ "OrderId" => order.global_e_id,
789
+ "InternationalDetails" => {
790
+ "OrderTrackingNumber" => "1265443",
791
+ "OrderTrackingUrl" => "http://www.somecarrier.com/?1265443"
792
+ },
793
+ "MerchantGUID" => "abcdabcd-abcd-abcd-abcd-abcdabcdabcd"
794
+ }.to_json
795
+ end
796
+
797
+ def global_e_notify_order_refunded_body(order: nil)
798
+ order ||= create_global_e_completed_checkout
799
+
800
+ {
801
+ "MerchantGUID" => "abcdabcd-abcd-abcd-abcd-abcdabcdabcd",
802
+ "MerchantOrderId" => order.id.to_s,
803
+ "Products" => order.items.map do |order_item|
804
+ {
805
+ "CartItemId" => order_item.id.to_s,
806
+ "RefundQuantity" => order_item.quantity,
807
+ "OriginalRefundAmount" => "114.5300",
808
+ "RefundAmount" => "170.1000",
809
+ "RefundReason" => {
810
+ "OrderRefundReasonCode" => "DAMAGED-ITEM-CODE",
811
+ "Name" => "Damaged Item"
812
+ },
813
+ "RefundComments" => "Fully refunded order"
814
+ }
815
+ end,
816
+ "OrderId" => order.global_e_id,
817
+ "TotalRefundAmount" => "170.10",
818
+ "RefundReason" => {
819
+ "OrderRefundReasonCode" => "DAMAGED-ITEM-CODE",
820
+ "Name" => "Damaged Item"
821
+ },
822
+ "RefundComments" => "Fully refunded order",
823
+ "OriginalTotalRefundAmount" => "114.53",
824
+ "ServiceGestureAmount" => "0.00",
825
+ "WebStoreCode" => nil
826
+ }.to_json
827
+ end
828
+
829
+ private
830
+
831
+ def create_global_e_order_id
832
+ number = "%07i" % SecureRandom.random_number(10_000_000)
833
+ "GE#{number}US"
834
+ end
835
+ end
836
+ end