solidus_easypost 2.0.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +6 -0
  3. data/.github/stale.yml +4 -4
  4. data/.github_changelog_generator +2 -0
  5. data/.gitignore +1 -0
  6. data/.rubocop.yml +3 -0
  7. data/.rubocop_todo.yml +12 -47
  8. data/CHANGELOG.md +113 -0
  9. data/LICENSE +1 -1
  10. data/README.md +111 -21
  11. data/app/controllers/spree/admin/postage_labels_controller.rb +20 -0
  12. data/app/decorators/models/solidus_easypost/spree/carton_decorator.rb +38 -0
  13. data/app/decorators/models/solidus_easypost/spree/shipment_decorator.rb +18 -23
  14. data/app/models/solidus_easypost/parcel_dimension.rb +34 -0
  15. data/app/models/solidus_easypost/return_authorization.rb +2 -13
  16. data/app/overrides/spree/admin/orders/_shipment/add_postage_label.html.erb.deface +10 -0
  17. data/bin/rails +0 -1
  18. data/bin/rails-engine +0 -2
  19. data/bin/rails-sandbox +1 -2
  20. data/bin/sandbox +2 -0
  21. data/config/initializers/webhooks.rb +7 -0
  22. data/config/locales/en.yml +7 -4
  23. data/config/routes.rb +5 -1
  24. data/db/migrate/20201025110912_add_tracker_id_to_cartons.rb +6 -0
  25. data/lib/generators/solidus_easypost/install/install_generator.rb +7 -1
  26. data/lib/generators/solidus_easypost/install/templates/initializer.rb +26 -0
  27. data/lib/solidus_easypost/address_builder.rb +45 -0
  28. data/lib/solidus_easypost/calculator/base_dimension_calculator.rb +28 -0
  29. data/lib/solidus_easypost/calculator/weight_dimension_calculator.rb +22 -0
  30. data/lib/solidus_easypost/configuration.rb +25 -2
  31. data/lib/solidus_easypost/errors/unknown_partial_resource_error.rb +11 -0
  32. data/lib/solidus_easypost/estimator.rb +37 -0
  33. data/lib/solidus_easypost/parcel_builder.rb +27 -0
  34. data/lib/solidus_easypost/shipment_builder.rb +32 -0
  35. data/lib/solidus_easypost/shipping_method_selector.rb +17 -0
  36. data/lib/solidus_easypost/shipping_rate_calculator.rb +9 -0
  37. data/lib/solidus_easypost/testing_support/factories/address_factory.rb +10 -0
  38. data/lib/solidus_easypost/testing_support/factories/product_factory.rb +7 -0
  39. data/lib/solidus_easypost/testing_support/factories/shipment_factory.rb +30 -0
  40. data/lib/solidus_easypost/testing_support/factories/shipping_method_factory.rb +8 -0
  41. data/lib/solidus_easypost/testing_support/factories/stock_location_factory.rb +10 -0
  42. data/lib/solidus_easypost/testing_support/factories/variant_factory.rb +7 -0
  43. data/lib/solidus_easypost/testing_support/factories.rb +3 -0
  44. data/lib/solidus_easypost/tracker_webhook_handler.rb +14 -0
  45. data/lib/solidus_easypost/version.rb +1 -1
  46. data/lib/solidus_easypost.rb +11 -0
  47. data/solidus_easypost.gemspec +8 -5
  48. data/spec/cassettes/{Spree_Address/_easypost_address/is_an_EasyPost_Address_object.yml → address_builder/from_address.yml} +19 -23
  49. data/spec/cassettes/{Spree_StockLocation/_easypost_address/is_an_EasyPost_Address_object.yml → address_builder/from_stock_location.yml} +19 -23
  50. data/spec/cassettes/{Spree_Stock_Estimator/_shipping_rates/when_rates_are_found/when_shipping_methods_exist/when_shipping_methods_are_front_end_visible/has_the_correct_costs.yml → estimator.yml} +0 -0
  51. data/spec/cassettes/integration/checkout.yml +377 -0
  52. data/spec/cassettes/integration/order_shipping/with_purchase_labels.yml +373 -0
  53. data/spec/cassettes/integration/order_shipping/without_purchase_labels.yml +251 -0
  54. data/spec/cassettes/{Spree_Stock_Package/_easypost_parcel/is_an_EasyPost_Parcel_object.yml → parcel_builder/from_package.yml} +17 -22
  55. data/spec/cassettes/{Spree_Stock_Package/_easypost_parcel/has_the_correct_attributes.yml → parcel_builder/from_return_authorization.yml} +17 -22
  56. data/spec/cassettes/postage_labels/show.yml +72 -0
  57. data/spec/cassettes/return_authorization.yml +310 -0
  58. data/spec/cassettes/{Spree_Stock_Package/_easypost_shipment/is_an_EasyPost_Shipment_object.yml → shipment_builder/from_package.yml} +74 -92
  59. data/spec/cassettes/{Spree_Stock_Estimator/_shipping_rates/when_rates_are_found/when_shipping_methods_exist/create_no_new_shipping_methods.yml → shipment_builder/from_return_authorization.yml} +77 -95
  60. data/spec/cassettes/shipment_builder/from_shipment.yml +250 -0
  61. data/spec/controllers/spree/admin/postage_labels_controller_spec.rb +18 -0
  62. data/spec/features/admin/postage_labels_spec.rb +18 -0
  63. data/spec/integration/checkout_spec.rb +45 -0
  64. data/spec/integration/order_shipping_spec.rb +33 -0
  65. data/spec/models/solidus_easypost/parcel_dimension_spec.rb +80 -0
  66. data/spec/models/solidus_easypost/return_authorization_spec.rb +7 -40
  67. data/spec/models/spree/carton_spec.rb +57 -0
  68. data/spec/models/spree/shipment_spec.rb +48 -59
  69. data/spec/models/spree/shipping_rate_spec.rb +14 -7
  70. data/spec/solidus_easypost/address_builder_spec.rb +17 -0
  71. data/spec/solidus_easypost/calculator/weight_dimension_calculator_spec.rb +39 -0
  72. data/spec/solidus_easypost/estimator_spec.rb +52 -0
  73. data/spec/solidus_easypost/parcel_builder_spec.rb +113 -0
  74. data/spec/solidus_easypost/shipment_builder_spec.rb +28 -0
  75. data/spec/solidus_easypost/shipping_method_selector_spec.rb +33 -0
  76. data/spec/solidus_easypost/shipping_rate_calculator_spec.rb +12 -0
  77. data/spec/solidus_easypost/tracker_webhook_handler_spec.rb +58 -0
  78. data/spec/spec_helper.rb +11 -7
  79. data/spec/support/easypost.rb +3 -1
  80. data/spec/support/helpers/api_stubs.rb +40 -0
  81. data/spec/support/helpers/configuration.rb +28 -0
  82. data/spec/support/helpers/shipping_methods.rb +26 -0
  83. data/spec/support/solidus.rb +1 -0
  84. data/spec/support/vcr.rb +1 -0
  85. metadata +118 -85
  86. data/app/decorators/models/solidus_easypost/spree/address_decorator.rb +0 -30
  87. data/app/decorators/models/solidus_easypost/spree/stock/estimator_decorator.rb +0 -15
  88. data/app/decorators/models/solidus_easypost/spree/stock/package_decorator.rb +0 -27
  89. data/app/decorators/models/solidus_easypost/spree/stock_location_decorator.rb +0 -26
  90. data/app/models/solidus_easypost/estimator.rb +0 -51
  91. data/lib/solidus_easypost/factories.rb +0 -24
  92. data/spec/cassettes/SolidusEasypost_ReturnAuthorization/_easypost_shipment/is_an_EasyPost_Shipment_object.yml +0 -271
  93. data/spec/cassettes/SolidusEasypost_ReturnAuthorization/_return_label/has_the_correct_fields.yml +0 -336
  94. data/spec/cassettes/SolidusEasypost_ReturnAuthorization/_return_label/is_an_EasyPost_PackageLabel_object.yml +0 -336
  95. data/spec/cassettes/Spree_Address/_easypost_address/has_the_correct_attributes.yml +0 -69
  96. data/spec/cassettes/Spree_Order/_refresh_shipment_rates/can_get_rates_from_easy_post.yml +0 -271
  97. data/spec/cassettes/Spree_Order/_refresh_shipment_rates/create_shipping_methods_for_the_rates.yml +0 -269
  98. data/spec/cassettes/Spree_Shipment/_buys_a_shipping_rate_after_transitioning_to_ship.yml +0 -403
  99. data/spec/cassettes/Spree_Shipment/_easypost_shipment/when_it_is_a_new_shipment/behaves_like_an_easypost_shipment/is_an_EasyPost_Shipment_object.yml +0 -271
  100. data/spec/cassettes/Spree_Shipment/_easypost_shipment/when_it_is_a_new_shipment/calls_the_api.yml +0 -200
  101. data/spec/cassettes/Spree_Shipment/_easypost_shipment/when_it_is_an_existing_shipment/behaves_like_an_easypost_shipment/is_an_EasyPost_Shipment_object.yml +0 -334
  102. data/spec/cassettes/Spree_Shipment/_easypost_shipment/when_it_is_an_existing_shipment/loads_the_existing_shipment.yml +0 -271
  103. data/spec/cassettes/Spree_StockLocation/_easypost_address/has_the_correct_attributes.yml +0 -69
  104. data/spec/cassettes/Spree_Stock_Estimator/_shipping_rates/when_rates_are_found/when_shipping_methods_dont_exist/creates_new_shipping_methods.yml +0 -269
  105. data/spec/cassettes/Spree_Stock_Estimator/_shipping_rates/when_rates_are_found/when_shipping_methods_dont_exist/is_empty.yml +0 -269
  106. data/spec/cassettes/Spree_Stock_Estimator/_shipping_rates/when_rates_are_found/when_shipping_methods_exist/when_shipping_methods_are_front_end_visible/has_the_correct_names.yml +0 -269
  107. data/spec/cassettes/Spree_Stock_Estimator/_shipping_rates/when_rates_are_found/when_shipping_methods_exist/when_shipping_methods_are_not_front_end_visible/is_empty.yml +0 -269
  108. data/spec/cassettes/Spree_Stock_Package/_easypost_shipment/calls_the_api.yml +0 -200
  109. data/spec/factories/spree_modification.rb +0 -25
  110. data/spec/models/spree/address_spec.rb +0 -31
  111. data/spec/models/spree/order_spec.rb +0 -31
  112. data/spec/models/spree/stock/estimator_spec.rb +0 -80
  113. data/spec/models/spree/stock/package_spec.rb +0 -35
  114. data/spec/models/spree/stock_location_spec.rb +0 -31
  115. data/spec/support/shipping_method_helpers.rb +0 -43
@@ -0,0 +1,33 @@
1
+ RSpec.describe SolidusEasypost::ShippingMethodSelector do
2
+ describe '#shipping_method_for' do
3
+ context 'when a shipping method for the given carrier and service exists' do
4
+ it 'returns the existing shipping method' do
5
+ shipping_method = create(:shipping_method, carrier: 'USPS', service_level: 'Express')
6
+ easypost_rate = EasyPost::Rate.construct_from('carrier' => 'USPS', 'service' => 'Express')
7
+
8
+ selector = described_class.new
9
+ selected_shipping_method = selector.shipping_method_for(easypost_rate)
10
+
11
+ expect(selected_shipping_method).to eq(shipping_method)
12
+ end
13
+ end
14
+
15
+ context 'when a shipping method for the given carrier and service does not exist' do
16
+ it 'creates a new shipping method' do
17
+ shipping_category = create(:shipping_category)
18
+ easypost_rate = EasyPost::Rate.construct_from('carrier' => 'USPS', 'service' => 'Express')
19
+
20
+ selector = described_class.new
21
+ selected_shipping_method = selector.shipping_method_for(easypost_rate)
22
+
23
+ expect(selected_shipping_method).to have_attributes(
24
+ name: 'USPS Express',
25
+ carrier: 'USPS',
26
+ service_level: 'Express',
27
+ shipping_categories: [shipping_category],
28
+ available_to_users: false,
29
+ )
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,12 @@
1
+ RSpec.describe SolidusEasypost::ShippingRateCalculator do
2
+ describe '#compute' do
3
+ it 'returns the amount on the EasyPost rate' do
4
+ easypost_rate = EasyPost::Rate.construct_from('rate' => 25.0)
5
+
6
+ calculator = described_class.new
7
+ computed_rate = calculator.compute(easypost_rate)
8
+
9
+ expect(computed_rate).to eq(25.0)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,58 @@
1
+ RSpec.describe SolidusEasypost::TrackerWebhookHandler do
2
+ describe '.call' do
3
+ context 'when the event is not tracker.updated' do
4
+ it 'does not process the event' do
5
+ stub_const('Spree::Event', class_spy(Spree::Event))
6
+ create(:carton, easy_post_tracker_id: 'trk_test')
7
+
8
+ payload = {
9
+ 'description' => 'tracker.created',
10
+ 'result' => {
11
+ 'id' => 'trk_test',
12
+ },
13
+ }
14
+ described_class.call(payload)
15
+
16
+ expect(Spree::Event).not_to have_received(:fire)
17
+ end
18
+ end
19
+
20
+ context 'when the tracker was not registered in Solidus' do
21
+ it 'does not process the event' do
22
+ stub_const('Spree::Event', class_spy(Spree::Event))
23
+ create(:carton, easy_post_tracker_id: 'trk_test')
24
+
25
+ payload = {
26
+ 'description' => 'tracker.updated',
27
+ 'result' => {
28
+ 'id' => 'trk_test1',
29
+ },
30
+ }
31
+ described_class.call(payload)
32
+
33
+ expect(Spree::Event).not_to have_received(:fire)
34
+ end
35
+ end
36
+
37
+ context 'when the event is a tracker update for a registered tracker' do
38
+ it 'forwards the event via the event bus' do
39
+ stub_const('Spree::Event', class_spy(Spree::Event))
40
+ carton = create(:carton, easy_post_tracker_id: 'trk_test')
41
+
42
+ payload = {
43
+ 'description' => 'tracker.updated',
44
+ 'result' => {
45
+ 'id' => 'trk_test',
46
+ },
47
+ }
48
+ described_class.call(payload)
49
+
50
+ expect(Spree::Event).to have_received(:fire).with(
51
+ 'solidus_easypost.tracker.updated',
52
+ carton: carton,
53
+ payload: payload,
54
+ )
55
+ end
56
+ end
57
+ end
58
+ end
data/spec/spec_helper.rb CHANGED
@@ -6,22 +6,26 @@ ENV['RAILS_ENV'] = 'test'
6
6
  # Run Coverage report
7
7
  require 'solidus_dev_support/rspec/coverage'
8
8
 
9
- require(File.expand_path('dummy/config/environment.rb', __dir__).tap { |file|
10
- # Create the dummy app if it's still missing.
11
- system 'bin/rake extension:test_app' unless File.exist? file
12
- })
9
+ # Create the dummy app if it's still missing.
10
+ dummy_env = "#{__dir__}/dummy/config/environment.rb"
11
+ system 'bin/rake extension:test_app' unless File.exist? dummy_env
12
+ require dummy_env
13
13
 
14
14
  # Requires factories and other useful helpers defined in spree_core.
15
15
  require 'solidus_dev_support/rspec/feature_helper'
16
16
 
17
17
  # Requires supporting ruby files with custom matchers and macros, etc,
18
18
  # in spec/support/ and its subdirectories.
19
- Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].each { |f| require f }
19
+ Dir["#{__dir__}/support/**/*.rb"].sort.each { |f| require f }
20
20
 
21
- # Requires factories defined in lib/solidus_easypost/factories.rb
22
- require 'solidus_easypost/factories'
21
+ # Requires factories defined in lib/solidus_easypost/testing_support/factories.rb
22
+ require 'solidus_easypost/testing_support/factories'
23
23
 
24
24
  RSpec.configure do |config|
25
25
  config.infer_spec_type_from_file_location!
26
26
  config.use_transactional_fixtures = false
27
+
28
+ if Spree.solidus_gem_version < Gem::Version.new('2.11')
29
+ config.extend Spree::TestingSupport::AuthorizationHelpers::Request, type: :system
30
+ end
27
31
  end
@@ -1,3 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- EasyPost.api_key = 'CvzYtuda6KRI9JjG7SAHbA'
3
+ RSpec.configure do |config|
4
+ config.before { EasyPost.api_key = 'CvzYtuda6KRI9JjG7SAHbA' }
5
+ end
@@ -0,0 +1,40 @@
1
+ module SolidusEasypost
2
+ module TestHelpers
3
+ module ApiStubs
4
+ def stub_easypost_shipment
5
+ EasyPost::Shipment.class_eval do
6
+ def rates; end
7
+
8
+ def tracking_code; end
9
+ end
10
+
11
+ easypost_shipment = instance_spy(
12
+ EasyPost::Shipment,
13
+ id: SecureRandom.hex,
14
+ tracking_code: SecureRandom.hex,
15
+ rates: Array.new(3) { stub_easypost_rate },
16
+ )
17
+
18
+ allow(EasyPost::Shipment).to receive(:retrieve)
19
+ .with(easypost_shipment.id)
20
+ .and_return(easypost_shipment)
21
+
22
+ easypost_shipment
23
+ end
24
+
25
+ def stub_easypost_rate
26
+ easypost_rate = instance_spy(EasyPost::Rate, id: SecureRandom.hex)
27
+
28
+ allow(EasyPost::Shipment).to receive(:retrieve)
29
+ .with(easypost_rate.id)
30
+ .and_return(easypost_rate)
31
+
32
+ easypost_rate
33
+ end
34
+ end
35
+ end
36
+ end
37
+
38
+ RSpec.configure do |config|
39
+ config.include SolidusEasypost::TestHelpers::ApiStubs
40
+ end
@@ -0,0 +1,28 @@
1
+ module SolidusEasypost
2
+ module TestHelpers
3
+ module Configuration
4
+ def stub_easypost_config(values)
5
+ allow(SolidusEasypost.configuration).to receive_messages(values)
6
+ end
7
+
8
+ def use_easypost_estimator
9
+ stock_configuration = ::Spree::Core::StockConfiguration.new.tap do |stock_config|
10
+ stock_config.estimator_class = 'SolidusEasypost::Estimator'
11
+ end
12
+
13
+ if ::Spree.solidus_gem_version >= Gem::Version.new('2.9.0')
14
+ stub_spree_preferences(stock: stock_configuration)
15
+ else
16
+ # rubocop:disable RSpec/AnyInstance
17
+ allow_any_instance_of(::Spree::AppConfiguration).to receive(:stock)
18
+ .and_return(stock_configuration)
19
+ # rubocop:enable RSpec/AnyInstance
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+
26
+ RSpec.configure do |config|
27
+ config.include SolidusEasypost::TestHelpers::Configuration
28
+ end
@@ -0,0 +1,26 @@
1
+ module SolidusEasypost
2
+ module TestHelpers
3
+ module ShippingMethods
4
+ def create_easypost_shipping_methods
5
+ [
6
+ %w[USPS Express],
7
+ %w[USPS First],
8
+ %w[USPS ParcelSelect],
9
+ %w[USPS Priority],
10
+ ].each do |(carrier, service_level)|
11
+ create(
12
+ :shipping_method,
13
+ name: "#{carrier} #{service_level}",
14
+ carrier: carrier,
15
+ service_level: service_level,
16
+ available_to_users: true,
17
+ )
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+
24
+ RSpec.configure do |config|
25
+ config.include SolidusEasypost::TestHelpers::ShippingMethods
26
+ end
@@ -0,0 +1 @@
1
+ require 'spree/testing_support/order_walkthrough'
data/spec/support/vcr.rb CHANGED
@@ -8,4 +8,5 @@ VCR.configure do |config|
8
8
  config.hook_into :webmock
9
9
  config.configure_rspec_metadata!
10
10
  config.default_cassette_options = { record: :none }
11
+ config.ignore_localhost = true
11
12
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solidus_easypost
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brendan Deere
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-07-24 00:00:00.000000000 Z
11
+ date: 2022-01-05 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: deface
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: easypost
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -33,7 +47,7 @@ dependencies:
33
47
  version: 2.0.0
34
48
  - - "<"
35
49
  - !ruby/object:Gem::Version
36
- version: '3'
50
+ version: '4'
37
51
  type: :runtime
38
52
  prerelease: false
39
53
  version_requirements: !ruby/object:Gem::Requirement
@@ -43,7 +57,7 @@ dependencies:
43
57
  version: 2.0.0
44
58
  - - "<"
45
59
  - !ruby/object:Gem::Version
46
- version: '3'
60
+ version: '4'
47
61
  - !ruby/object:Gem::Dependency
48
62
  name: solidus_support
49
63
  requirement: !ruby/object:Gem::Requirement
@@ -62,16 +76,16 @@ dependencies:
62
76
  name: solidus_dev_support
63
77
  requirement: !ruby/object:Gem::Requirement
64
78
  requirements:
65
- - - ">="
79
+ - - "~>"
66
80
  - !ruby/object:Gem::Version
67
- version: '0'
81
+ version: '2.1'
68
82
  type: :development
69
83
  prerelease: false
70
84
  version_requirements: !ruby/object:Gem::Requirement
71
85
  requirements:
72
- - - ">="
86
+ - - "~>"
73
87
  - !ruby/object:Gem::Version
74
- version: '0'
88
+ version: '2.1'
75
89
  - !ruby/object:Gem::Dependency
76
90
  name: vcr
77
91
  requirement: !ruby/object:Gem::Requirement
@@ -100,7 +114,7 @@ dependencies:
100
114
  - - ">="
101
115
  - !ruby/object:Gem::Version
102
116
  version: '0'
103
- description: Easy post integration for Solidus
117
+ description:
104
118
  email: brendan@stembolt.com
105
119
  executables: []
106
120
  extensions: []
@@ -109,22 +123,23 @@ files:
109
123
  - ".circleci/config.yml"
110
124
  - ".gem_release.yml"
111
125
  - ".github/stale.yml"
126
+ - ".github_changelog_generator"
112
127
  - ".gitignore"
113
128
  - ".rspec"
114
129
  - ".rubocop.yml"
115
130
  - ".rubocop_todo.yml"
131
+ - CHANGELOG.md
116
132
  - Gemfile
117
133
  - LICENSE
118
134
  - README.md
119
135
  - Rakefile
120
- - app/decorators/models/solidus_easypost/spree/address_decorator.rb
136
+ - app/controllers/spree/admin/postage_labels_controller.rb
137
+ - app/decorators/models/solidus_easypost/spree/carton_decorator.rb
121
138
  - app/decorators/models/solidus_easypost/spree/shipment_decorator.rb
122
139
  - app/decorators/models/solidus_easypost/spree/shipping_rate_decorator.rb
123
- - app/decorators/models/solidus_easypost/spree/stock/estimator_decorator.rb
124
- - app/decorators/models/solidus_easypost/spree/stock/package_decorator.rb
125
- - app/decorators/models/solidus_easypost/spree/stock_location_decorator.rb
126
- - app/models/solidus_easypost/estimator.rb
140
+ - app/models/solidus_easypost/parcel_dimension.rb
127
141
  - app/models/solidus_easypost/return_authorization.rb
142
+ - app/overrides/spree/admin/orders/_shipment/add_postage_label.html.erb.deface
128
143
  - bin/console
129
144
  - bin/rails
130
145
  - bin/rails-engine
@@ -132,68 +147,86 @@ files:
132
147
  - bin/rake
133
148
  - bin/sandbox
134
149
  - bin/setup
150
+ - config/initializers/webhooks.rb
135
151
  - config/locales/en.yml
136
152
  - config/routes.rb
137
153
  - db/migrate/20140515024440_add_easy_post_fields_to_shipping_rate.rb
154
+ - db/migrate/20201025110912_add_tracker_id_to_cartons.rb
138
155
  - lib/generators/solidus_easypost/install/install_generator.rb
156
+ - lib/generators/solidus_easypost/install/templates/initializer.rb
139
157
  - lib/solidus_easypost.rb
158
+ - lib/solidus_easypost/address_builder.rb
159
+ - lib/solidus_easypost/calculator/base_dimension_calculator.rb
160
+ - lib/solidus_easypost/calculator/weight_dimension_calculator.rb
140
161
  - lib/solidus_easypost/configuration.rb
141
162
  - lib/solidus_easypost/engine.rb
142
- - lib/solidus_easypost/factories.rb
163
+ - lib/solidus_easypost/errors/unknown_partial_resource_error.rb
164
+ - lib/solidus_easypost/estimator.rb
165
+ - lib/solidus_easypost/parcel_builder.rb
166
+ - lib/solidus_easypost/shipment_builder.rb
167
+ - lib/solidus_easypost/shipping_method_selector.rb
168
+ - lib/solidus_easypost/shipping_rate_calculator.rb
169
+ - lib/solidus_easypost/testing_support/factories.rb
170
+ - lib/solidus_easypost/testing_support/factories/address_factory.rb
171
+ - lib/solidus_easypost/testing_support/factories/product_factory.rb
172
+ - lib/solidus_easypost/testing_support/factories/shipment_factory.rb
173
+ - lib/solidus_easypost/testing_support/factories/shipping_method_factory.rb
174
+ - lib/solidus_easypost/testing_support/factories/stock_location_factory.rb
175
+ - lib/solidus_easypost/testing_support/factories/variant_factory.rb
176
+ - lib/solidus_easypost/tracker_webhook_handler.rb
143
177
  - lib/solidus_easypost/version.rb
144
178
  - solidus_easypost.gemspec
145
- - spec/cassettes/SolidusEasypost_ReturnAuthorization/_easypost_shipment/is_an_EasyPost_Shipment_object.yml
146
- - spec/cassettes/SolidusEasypost_ReturnAuthorization/_return_label/has_the_correct_fields.yml
147
- - spec/cassettes/SolidusEasypost_ReturnAuthorization/_return_label/is_an_EasyPost_PackageLabel_object.yml
148
- - spec/cassettes/Spree_Address/_easypost_address/has_the_correct_attributes.yml
149
- - spec/cassettes/Spree_Address/_easypost_address/is_an_EasyPost_Address_object.yml
150
- - spec/cassettes/Spree_Order/_refresh_shipment_rates/can_get_rates_from_easy_post.yml
151
- - spec/cassettes/Spree_Order/_refresh_shipment_rates/create_shipping_methods_for_the_rates.yml
152
- - spec/cassettes/Spree_Shipment/_buys_a_shipping_rate_after_transitioning_to_ship.yml
153
- - spec/cassettes/Spree_Shipment/_easypost_shipment/when_it_is_a_new_shipment/behaves_like_an_easypost_shipment/is_an_EasyPost_Shipment_object.yml
154
- - spec/cassettes/Spree_Shipment/_easypost_shipment/when_it_is_a_new_shipment/calls_the_api.yml
155
- - spec/cassettes/Spree_Shipment/_easypost_shipment/when_it_is_an_existing_shipment/behaves_like_an_easypost_shipment/is_an_EasyPost_Shipment_object.yml
156
- - spec/cassettes/Spree_Shipment/_easypost_shipment/when_it_is_an_existing_shipment/loads_the_existing_shipment.yml
157
- - spec/cassettes/Spree_StockLocation/_easypost_address/has_the_correct_attributes.yml
158
- - spec/cassettes/Spree_StockLocation/_easypost_address/is_an_EasyPost_Address_object.yml
159
- - spec/cassettes/Spree_Stock_Estimator/_shipping_rates/when_rates_are_found/when_shipping_methods_dont_exist/creates_new_shipping_methods.yml
160
- - spec/cassettes/Spree_Stock_Estimator/_shipping_rates/when_rates_are_found/when_shipping_methods_dont_exist/is_empty.yml
161
- - spec/cassettes/Spree_Stock_Estimator/_shipping_rates/when_rates_are_found/when_shipping_methods_exist/create_no_new_shipping_methods.yml
162
- - spec/cassettes/Spree_Stock_Estimator/_shipping_rates/when_rates_are_found/when_shipping_methods_exist/when_shipping_methods_are_front_end_visible/has_the_correct_costs.yml
163
- - spec/cassettes/Spree_Stock_Estimator/_shipping_rates/when_rates_are_found/when_shipping_methods_exist/when_shipping_methods_are_front_end_visible/has_the_correct_names.yml
164
- - spec/cassettes/Spree_Stock_Estimator/_shipping_rates/when_rates_are_found/when_shipping_methods_exist/when_shipping_methods_are_not_front_end_visible/is_empty.yml
165
- - spec/cassettes/Spree_Stock_Package/_easypost_parcel/has_the_correct_attributes.yml
166
- - spec/cassettes/Spree_Stock_Package/_easypost_parcel/is_an_EasyPost_Parcel_object.yml
167
- - spec/cassettes/Spree_Stock_Package/_easypost_shipment/calls_the_api.yml
168
- - spec/cassettes/Spree_Stock_Package/_easypost_shipment/is_an_EasyPost_Shipment_object.yml
169
- - spec/factories/spree_modification.rb
179
+ - spec/cassettes/address_builder/from_address.yml
180
+ - spec/cassettes/address_builder/from_stock_location.yml
181
+ - spec/cassettes/estimator.yml
182
+ - spec/cassettes/integration/checkout.yml
183
+ - spec/cassettes/integration/order_shipping/with_purchase_labels.yml
184
+ - spec/cassettes/integration/order_shipping/without_purchase_labels.yml
185
+ - spec/cassettes/parcel_builder/from_package.yml
186
+ - spec/cassettes/parcel_builder/from_return_authorization.yml
187
+ - spec/cassettes/postage_labels/show.yml
188
+ - spec/cassettes/return_authorization.yml
189
+ - spec/cassettes/shipment_builder/from_package.yml
190
+ - spec/cassettes/shipment_builder/from_return_authorization.yml
191
+ - spec/cassettes/shipment_builder/from_shipment.yml
192
+ - spec/controllers/spree/admin/postage_labels_controller_spec.rb
193
+ - spec/features/admin/postage_labels_spec.rb
194
+ - spec/integration/checkout_spec.rb
195
+ - spec/integration/order_shipping_spec.rb
196
+ - spec/models/solidus_easypost/parcel_dimension_spec.rb
170
197
  - spec/models/solidus_easypost/return_authorization_spec.rb
171
- - spec/models/spree/address_spec.rb
172
- - spec/models/spree/order_spec.rb
198
+ - spec/models/spree/carton_spec.rb
173
199
  - spec/models/spree/shipment_spec.rb
174
200
  - spec/models/spree/shipping_rate_spec.rb
175
- - spec/models/spree/stock/estimator_spec.rb
176
- - spec/models/spree/stock/package_spec.rb
177
- - spec/models/spree/stock_location_spec.rb
201
+ - spec/solidus_easypost/address_builder_spec.rb
202
+ - spec/solidus_easypost/calculator/weight_dimension_calculator_spec.rb
203
+ - spec/solidus_easypost/estimator_spec.rb
204
+ - spec/solidus_easypost/parcel_builder_spec.rb
205
+ - spec/solidus_easypost/shipment_builder_spec.rb
206
+ - spec/solidus_easypost/shipping_method_selector_spec.rb
207
+ - spec/solidus_easypost/shipping_rate_calculator_spec.rb
208
+ - spec/solidus_easypost/tracker_webhook_handler_spec.rb
178
209
  - spec/solidus_easypost_spec.rb
179
210
  - spec/spec_helper.rb
180
211
  - spec/support/easypost.rb
181
212
  - spec/support/factory_bot.rb
182
- - spec/support/shipping_method_helpers.rb
213
+ - spec/support/helpers/api_stubs.rb
214
+ - spec/support/helpers/configuration.rb
215
+ - spec/support/helpers/shipping_methods.rb
216
+ - spec/support/solidus.rb
183
217
  - spec/support/vcr.rb
184
218
  homepage: https://github.com/solidusio-contrib/solidus_easypost
185
219
  licenses:
186
220
  - BSD-3-Clause
187
221
  metadata:
188
- homepage_uri: https://github.com/solidusio-contrib/solidus_easypost
189
- source_code_uri: https://github.com/solidusio-contrib/solidus_easypost
190
- post_install_message:
222
+ rubygems_mfa_required: 'true'
223
+ post_install_message:
191
224
  rdoc_options: []
192
225
  require_paths:
193
226
  - lib
194
227
  required_ruby_version: !ruby/object:Gem::Requirement
195
228
  requirements:
196
- - - "~>"
229
+ - - ">="
197
230
  - !ruby/object:Gem::Version
198
231
  version: '2.5'
199
232
  required_rubygems_version: !ruby/object:Gem::Requirement
@@ -202,47 +235,47 @@ required_rubygems_version: !ruby/object:Gem::Requirement
202
235
  - !ruby/object:Gem::Version
203
236
  version: '0'
204
237
  requirements: []
205
- rubygems_version: 3.0.8
206
- signing_key:
238
+ rubygems_version: 3.1.2
239
+ signing_key:
207
240
  specification_version: 4
208
- summary: Easy post integration for Solidus
241
+ summary: EasyPost integration for Solidus stores.
209
242
  test_files:
210
- - spec/cassettes/SolidusEasypost_ReturnAuthorization/_easypost_shipment/is_an_EasyPost_Shipment_object.yml
211
- - spec/cassettes/SolidusEasypost_ReturnAuthorization/_return_label/has_the_correct_fields.yml
212
- - spec/cassettes/SolidusEasypost_ReturnAuthorization/_return_label/is_an_EasyPost_PackageLabel_object.yml
213
- - spec/cassettes/Spree_Address/_easypost_address/has_the_correct_attributes.yml
214
- - spec/cassettes/Spree_Address/_easypost_address/is_an_EasyPost_Address_object.yml
215
- - spec/cassettes/Spree_Order/_refresh_shipment_rates/can_get_rates_from_easy_post.yml
216
- - spec/cassettes/Spree_Order/_refresh_shipment_rates/create_shipping_methods_for_the_rates.yml
217
- - spec/cassettes/Spree_Shipment/_buys_a_shipping_rate_after_transitioning_to_ship.yml
218
- - spec/cassettes/Spree_Shipment/_easypost_shipment/when_it_is_a_new_shipment/behaves_like_an_easypost_shipment/is_an_EasyPost_Shipment_object.yml
219
- - spec/cassettes/Spree_Shipment/_easypost_shipment/when_it_is_a_new_shipment/calls_the_api.yml
220
- - spec/cassettes/Spree_Shipment/_easypost_shipment/when_it_is_an_existing_shipment/behaves_like_an_easypost_shipment/is_an_EasyPost_Shipment_object.yml
221
- - spec/cassettes/Spree_Shipment/_easypost_shipment/when_it_is_an_existing_shipment/loads_the_existing_shipment.yml
222
- - spec/cassettes/Spree_StockLocation/_easypost_address/has_the_correct_attributes.yml
223
- - spec/cassettes/Spree_StockLocation/_easypost_address/is_an_EasyPost_Address_object.yml
224
- - spec/cassettes/Spree_Stock_Estimator/_shipping_rates/when_rates_are_found/when_shipping_methods_dont_exist/creates_new_shipping_methods.yml
225
- - spec/cassettes/Spree_Stock_Estimator/_shipping_rates/when_rates_are_found/when_shipping_methods_dont_exist/is_empty.yml
226
- - spec/cassettes/Spree_Stock_Estimator/_shipping_rates/when_rates_are_found/when_shipping_methods_exist/create_no_new_shipping_methods.yml
227
- - spec/cassettes/Spree_Stock_Estimator/_shipping_rates/when_rates_are_found/when_shipping_methods_exist/when_shipping_methods_are_front_end_visible/has_the_correct_costs.yml
228
- - spec/cassettes/Spree_Stock_Estimator/_shipping_rates/when_rates_are_found/when_shipping_methods_exist/when_shipping_methods_are_front_end_visible/has_the_correct_names.yml
229
- - spec/cassettes/Spree_Stock_Estimator/_shipping_rates/when_rates_are_found/when_shipping_methods_exist/when_shipping_methods_are_not_front_end_visible/is_empty.yml
230
- - spec/cassettes/Spree_Stock_Package/_easypost_parcel/has_the_correct_attributes.yml
231
- - spec/cassettes/Spree_Stock_Package/_easypost_parcel/is_an_EasyPost_Parcel_object.yml
232
- - spec/cassettes/Spree_Stock_Package/_easypost_shipment/calls_the_api.yml
233
- - spec/cassettes/Spree_Stock_Package/_easypost_shipment/is_an_EasyPost_Shipment_object.yml
234
- - spec/factories/spree_modification.rb
243
+ - spec/cassettes/address_builder/from_address.yml
244
+ - spec/cassettes/address_builder/from_stock_location.yml
245
+ - spec/cassettes/estimator.yml
246
+ - spec/cassettes/integration/checkout.yml
247
+ - spec/cassettes/integration/order_shipping/with_purchase_labels.yml
248
+ - spec/cassettes/integration/order_shipping/without_purchase_labels.yml
249
+ - spec/cassettes/parcel_builder/from_package.yml
250
+ - spec/cassettes/parcel_builder/from_return_authorization.yml
251
+ - spec/cassettes/postage_labels/show.yml
252
+ - spec/cassettes/return_authorization.yml
253
+ - spec/cassettes/shipment_builder/from_package.yml
254
+ - spec/cassettes/shipment_builder/from_return_authorization.yml
255
+ - spec/cassettes/shipment_builder/from_shipment.yml
256
+ - spec/controllers/spree/admin/postage_labels_controller_spec.rb
257
+ - spec/features/admin/postage_labels_spec.rb
258
+ - spec/integration/checkout_spec.rb
259
+ - spec/integration/order_shipping_spec.rb
260
+ - spec/models/solidus_easypost/parcel_dimension_spec.rb
235
261
  - spec/models/solidus_easypost/return_authorization_spec.rb
236
- - spec/models/spree/address_spec.rb
237
- - spec/models/spree/order_spec.rb
262
+ - spec/models/spree/carton_spec.rb
238
263
  - spec/models/spree/shipment_spec.rb
239
264
  - spec/models/spree/shipping_rate_spec.rb
240
- - spec/models/spree/stock/estimator_spec.rb
241
- - spec/models/spree/stock/package_spec.rb
242
- - spec/models/spree/stock_location_spec.rb
265
+ - spec/solidus_easypost/address_builder_spec.rb
266
+ - spec/solidus_easypost/calculator/weight_dimension_calculator_spec.rb
267
+ - spec/solidus_easypost/estimator_spec.rb
268
+ - spec/solidus_easypost/parcel_builder_spec.rb
269
+ - spec/solidus_easypost/shipment_builder_spec.rb
270
+ - spec/solidus_easypost/shipping_method_selector_spec.rb
271
+ - spec/solidus_easypost/shipping_rate_calculator_spec.rb
272
+ - spec/solidus_easypost/tracker_webhook_handler_spec.rb
243
273
  - spec/solidus_easypost_spec.rb
244
274
  - spec/spec_helper.rb
245
275
  - spec/support/easypost.rb
246
276
  - spec/support/factory_bot.rb
247
- - spec/support/shipping_method_helpers.rb
277
+ - spec/support/helpers/api_stubs.rb
278
+ - spec/support/helpers/configuration.rb
279
+ - spec/support/helpers/shipping_methods.rb
280
+ - spec/support/solidus.rb
248
281
  - spec/support/vcr.rb
@@ -1,30 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module SolidusEasypost
4
- module Spree
5
- module AddressDecorator
6
- def easypost_address
7
- attributes = {
8
- street1: address1,
9
- street2: address2,
10
- city: city,
11
- zip: zipcode,
12
- phone: phone
13
- }
14
-
15
- attributes[:company] = company if respond_to?(:company)
16
- attributes[:name] = if respond_to?(:name)
17
- name
18
- elsif respond_to?(:full_name)
19
- full_name
20
- end
21
- attributes[:state] = state ? state.abbr : state_name
22
- attributes[:country] = country&.iso
23
-
24
- ::EasyPost::Address.create attributes
25
- end
26
-
27
- ::Spree::Address.prepend self
28
- end
29
- end
30
- end
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module SolidusEasypost
4
- module Spree
5
- module Stock
6
- module EstimatorDecorator
7
- def shipping_rates(package, frontend_only = true)
8
- SolidusEasypost::Estimator.new.shipping_rates(package, frontend_only)
9
- end
10
-
11
- ::Spree::Stock::Estimator.prepend self
12
- end
13
- end
14
- end
15
- end
@@ -1,27 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module SolidusEasypost
4
- module Spree
5
- module Stock
6
- module PackageDecorator
7
- def easypost_parcel
8
- total_weight = contents.sum do |item|
9
- item.quantity * item.variant.weight
10
- end
11
-
12
- ::EasyPost::Parcel.create weight: total_weight
13
- end
14
-
15
- def easypost_shipment
16
- ::EasyPost::Shipment.create(
17
- to_address: order.ship_address.easypost_address,
18
- from_address: stock_location.easypost_address,
19
- parcel: easypost_parcel
20
- )
21
- end
22
-
23
- ::Spree::Stock::Package.prepend self
24
- end
25
- end
26
- end
27
- end