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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d31b734374e49e27bb7f182577cd2f1693b716299d8419e0d9b9d456bdfe9d50
4
- data.tar.gz: 603ca168bb0c4a460af1fa498c7b5448316e4986cb285b5fe9eb442f9a3fa11d
3
+ metadata.gz: 0d54d7ac2a6876f5b69df700919019c7ef094bb58e146139ff8ec93a9da754a0
4
+ data.tar.gz: 4e75d5636a2fb85d1277dd4fe6ffc2e2a61c616ed0688ba247dc72c218dabf8a
5
5
  SHA512:
6
- metadata.gz: 3b0c53d359fd325783c1e4646cfd8a8f97c392ae5ddfcba384c79b05efcf755fa7ed8f06c62fac7bfea0dc41471243327f6e62c916ba463efe1dccccc625c36b
7
- data.tar.gz: 21cd54816073d19859d1077002237ebf4b2c302f29e7fc3cc0e1d567ddc96a78ce69dcea6d461e207b46e67697d37a9f2f8d4f25b49f431fbc668e45a156efea
6
+ metadata.gz: 62e2e3f86ccbab5feab3550b7e32c3e168169b11790663a629dc56a34ede6b2bd6cbe63c4e5459b3af62c084f9686f58c02e05faac10c418836bfe2e00433dc8
7
+ data.tar.gz: adf8d14742ea4da96c3b4950b9db43b46b61fd279528a8f5610a2061ff7a03aa6a8ca610775862004784cef06af1e0a49c2e667d0c47b188a487ed76c5b3f912
data/.circleci/config.yml CHANGED
@@ -16,12 +16,18 @@ jobs:
16
16
  executor: solidusio_extensions/mysql
17
17
  steps:
18
18
  - solidusio_extensions/run-tests
19
+ lint-code:
20
+ executor: solidusio_extensions/sqlite-memory
21
+ steps:
22
+ - solidusio_extensions/lint-code
19
23
 
20
24
  workflows:
21
25
  "Run specs on supported Solidus versions":
22
26
  jobs:
23
27
  - run-specs-with-postgres
24
28
  - run-specs-with-mysql
29
+ - lint-code
30
+
25
31
  "Weekly run specs against master":
26
32
  triggers:
27
33
  - schedule:
data/.github/stale.yml CHANGED
@@ -1,17 +1,17 @@
1
1
  # Number of days of inactivity before an issue becomes stale
2
2
  daysUntilStale: 60
3
3
  # Number of days of inactivity before a stale issue is closed
4
- daysUntilClose: 7
4
+ daysUntilClose: false
5
5
  # Issues with these labels will never be considered stale
6
6
  exemptLabels:
7
7
  - pinned
8
8
  - security
9
9
  # Label to use when marking an issue as stale
10
- staleLabel: wontfix
10
+ staleLabel: stale
11
11
  # Comment to post when marking an issue as stale. Set to `false` to disable
12
12
  markComment: >
13
13
  This issue has been automatically marked as stale because it has not had
14
- recent activity. It will be closed if no further activity occurs. Thank you
14
+ recent activity. It might be closed if no further activity occurs. Thank you
15
15
  for your contributions.
16
16
  # Comment to post when closing a stale issue. Set to `false` to disable
17
- closeComment: false
17
+ closeComment: false
@@ -0,0 +1,2 @@
1
+ issues=false
2
+ exclude-labels=infrastructure
data/.gitignore CHANGED
@@ -18,3 +18,4 @@ spec/examples.txt
18
18
  .rvmrc
19
19
  .ruby-version
20
20
  .ruby-gemset
21
+ .bundle
data/.rubocop.yml CHANGED
@@ -2,3 +2,6 @@ inherit_from: .rubocop_todo.yml
2
2
 
3
3
  require:
4
4
  - solidus_dev_support/rubocop
5
+
6
+ AllCops:
7
+ NewCops: enable
data/.rubocop_todo.yml CHANGED
@@ -1,71 +1,36 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2020-07-24 11:17:48 +0200 using RuboCop version 0.76.0.
3
+ # on 2020-09-23 14:11:08 UTC using RuboCop version 0.91.1.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
7
7
  # versions of RuboCop, may require this file to be generated again.
8
8
 
9
9
  # Offense count: 1
10
- # Cop supports --auto-correct.
11
- # Configuration parameters: EnforcedStyleAlignWith, AutoCorrect, Severity.
12
- # SupportedStylesAlignWith: keyword, variable, start_of_line
13
- Layout/EndAlignment:
14
- Exclude:
15
- - 'app/decorators/models/solidus_easypost/spree/address_decorator.rb'
16
-
17
- # Offense count: 1
18
- # Cop supports --auto-correct.
19
- Lint/RedundantCopDisableDirective:
20
- Exclude:
21
- - 'lib/generators/solidus_easypost/install/install_generator.rb'
22
-
23
- # Offense count: 1
24
- # Cop supports --auto-correct.
25
- RSpec/EmptyLineAfterFinalLet:
10
+ RSpec/DescribeClass:
26
11
  Exclude:
27
- - 'spec/models/solidus_easypost/return_authorization_spec.rb'
12
+ - 'spec/features/**/*'
13
+ - 'spec/integration/order_shipping_spec.rb'
28
14
 
29
15
  # Offense count: 3
30
- # Configuration parameters: .
31
- # SupportedStyles: have_received, receive
32
- RSpec/MessageSpies:
33
- EnforcedStyle: receive
34
-
35
- # Offense count: 1
36
16
  RSpec/MultipleExpectations:
37
17
  Max: 3
38
18
 
39
- # Offense count: 22
40
- # Configuration parameters: IgnoreSharedExamples.
41
- RSpec/NamedSubject:
42
- Exclude:
43
- - 'spec/models/solidus_easypost/return_authorization_spec.rb'
44
- - 'spec/models/spree/address_spec.rb'
45
- - 'spec/models/spree/shipment_spec.rb'
46
- - 'spec/models/spree/shipping_rate_spec.rb'
47
- - 'spec/models/spree/stock/estimator_spec.rb'
48
- - 'spec/models/spree/stock/package_spec.rb'
49
- - 'spec/models/spree/stock_location_spec.rb'
50
-
51
19
  # Offense count: 4
52
- RSpec/NestedGroups:
53
- Max: 5
54
-
55
- # Offense count: 2
56
- RSpec/ScatteredSetup:
20
+ # Configuration parameters: EnforcedStyle.
21
+ # SupportedStyles: scientific, engineering, integral
22
+ Style/ExponentialNotation:
57
23
  Exclude:
58
- - 'spec/models/solidus_easypost/return_authorization_spec.rb'
24
+ - 'spec/integration/checkout_spec.rb'
59
25
 
60
26
  # Offense count: 1
61
- # Configuration parameters: IgnoreNameless, IgnoreSymbolicNames.
62
- RSpec/VerifiedDoubles:
27
+ Style/OptionalBooleanParameter:
63
28
  Exclude:
64
- - 'spec/models/spree/stock/estimator_spec.rb'
29
+ - 'lib/solidus_easypost/estimator.rb'
65
30
 
66
- # Offense count: 1
31
+ # Offense count: 3
67
32
  # Cop supports --auto-correct.
68
33
  # Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
69
34
  # URISchemes: http, https
70
- Metrics/LineLength:
35
+ Layout/LineLength:
71
36
  Max: 137
data/CHANGELOG.md ADDED
@@ -0,0 +1,113 @@
1
+ # Changelog
2
+
3
+ ## [v3.0.0](https://github.com/solidusio-contrib/solidus_easypost/tree/v3.0.0) (2022-01-05)
4
+
5
+ [Full Changelog](https://github.com/solidusio-contrib/solidus_easypost/compare/v2.0.0...v3.0.0)
6
+
7
+ **Closed issues:**
8
+
9
+ - Dependabot can't resolve your Ruby dependency files [\#92](https://github.com/solidusio-contrib/solidus_easypost/issues/92)
10
+ - Prepare Solidus Easypost for Solidus 3.0 [\#88](https://github.com/solidusio-contrib/solidus_easypost/issues/88)
11
+ - Dependabot can't resolve your Ruby dependency files [\#77](https://github.com/solidusio-contrib/solidus_easypost/issues/77)
12
+ - Dependabot can't resolve your Ruby dependency files [\#76](https://github.com/solidusio-contrib/solidus_easypost/issues/76)
13
+ - README is incompatible with latest rubygems release [\#73](https://github.com/solidusio-contrib/solidus_easypost/issues/73)
14
+ - Unable to Handle Refunds Out of the Box [\#58](https://github.com/solidusio-contrib/solidus_easypost/issues/58)
15
+
16
+ **Merged pull requests:**
17
+
18
+ - fix new cops [\#102](https://github.com/solidusio-contrib/solidus_easypost/pull/102) ([ccarruitero](https://github.com/ccarruitero))
19
+ - fix webhooks handler setup and allow customize [\#100](https://github.com/solidusio-contrib/solidus_easypost/pull/100) ([ccarruitero](https://github.com/ccarruitero))
20
+ - relax ruby version to support ruby 3.0 [\#99](https://github.com/solidusio-contrib/solidus_easypost/pull/99) ([ccarruitero](https://github.com/ccarruitero))
21
+ - Add custom parcel dimension calculator class [\#98](https://github.com/solidusio-contrib/solidus_easypost/pull/98) ([vassalloandrea](https://github.com/vassalloandrea))
22
+ - Update gemspec to allow Solidus 3 [\#94](https://github.com/solidusio-contrib/solidus_easypost/pull/94) ([vassalloandrea](https://github.com/vassalloandrea))
23
+ - Prepare extension for solidus 3.0 [\#89](https://github.com/solidusio-contrib/solidus_easypost/pull/89) ([ccarruitero](https://github.com/ccarruitero))
24
+ - Allow tracking packages via EasyPost [\#87](https://github.com/solidusio-contrib/solidus_easypost/pull/87) ([aldesantis](https://github.com/aldesantis))
25
+ - Upgrade extension to latest defaults [\#86](https://github.com/solidusio-contrib/solidus_easypost/pull/86) ([aldesantis](https://github.com/aldesantis))
26
+ - Allow admins to download postage labels [\#84](https://github.com/solidusio-contrib/solidus_easypost/pull/84) ([aldesantis](https://github.com/aldesantis))
27
+ - Update extension with latest solidus\_dev\_support defaults [\#82](https://github.com/solidusio-contrib/solidus_easypost/pull/82) ([aldesantis](https://github.com/aldesantis))
28
+ - Streamline and reorganize tests for better reliability [\#81](https://github.com/solidusio-contrib/solidus_easypost/pull/81) ([aldesantis](https://github.com/aldesantis))
29
+ - Extract EasyPost object builders into separate classes [\#80](https://github.com/solidusio-contrib/solidus_easypost/pull/80) ([aldesantis](https://github.com/aldesantis))
30
+ - Improve extension extendability [\#79](https://github.com/solidusio-contrib/solidus_easypost/pull/79) ([aldesantis](https://github.com/aldesantis))
31
+ - Update extension to latest defaults from solidus\_dev\_support [\#78](https://github.com/solidusio-contrib/solidus_easypost/pull/78) ([aldesantis](https://github.com/aldesantis))
32
+
33
+ ## [v2.0.0](https://github.com/solidusio-contrib/solidus_easypost/tree/v2.0.0) (2020-07-24)
34
+
35
+ [Full Changelog](https://github.com/solidusio-contrib/solidus_easypost/compare/v1.0.4...v2.0.0)
36
+
37
+ **Breaking changes:**
38
+
39
+ - keep same namespace in all files [\#68](https://github.com/solidusio-contrib/solidus_easypost/pull/68) ([ccarruitero](https://github.com/ccarruitero))
40
+
41
+ **Closed issues:**
42
+
43
+ - Dependabot can't resolve your Ruby dependency files [\#59](https://github.com/solidusio-contrib/solidus_easypost/issues/59)
44
+ - Dependabot can't resolve your Ruby dependency files [\#57](https://github.com/solidusio-contrib/solidus_easypost/issues/57)
45
+ - Dependabot can't resolve your Ruby dependency files [\#56](https://github.com/solidusio-contrib/solidus_easypost/issues/56)
46
+ - Dependabot can't resolve your Ruby dependency files [\#54](https://github.com/solidusio-contrib/solidus_easypost/issues/54)
47
+ - Dependabot can't resolve your Ruby dependency files [\#53](https://github.com/solidusio-contrib/solidus_easypost/issues/53)
48
+ - Dependabot can't resolve your Ruby dependency files [\#52](https://github.com/solidusio-contrib/solidus_easypost/issues/52)
49
+ - Config is now frozen. [\#49](https://github.com/solidusio-contrib/solidus_easypost/issues/49)
50
+ - Easypost rate is bought twice [\#42](https://github.com/solidusio-contrib/solidus_easypost/issues/42)
51
+ - UPS carrier doesn't allow empty company name in `from_address` [\#41](https://github.com/solidusio-contrib/solidus_easypost/issues/41)
52
+ - Exception thrown by Estimator [\#35](https://github.com/solidusio-contrib/solidus_easypost/issues/35)
53
+ - rake railties:install:migrations [\#30](https://github.com/solidusio-contrib/solidus_easypost/issues/30)
54
+ - Easypost Migrations aren't working [\#22](https://github.com/solidusio-contrib/solidus_easypost/issues/22)
55
+ - Missing for 2.1 solidus? [\#18](https://github.com/solidusio-contrib/solidus_easypost/issues/18)
56
+ - Charge customer different amount? [\#17](https://github.com/solidusio-contrib/solidus_easypost/issues/17)
57
+ - 1.3.0 seems to be empty [\#15](https://github.com/solidusio-contrib/solidus_easypost/issues/15)
58
+ - Uninitialized constant EasyPost Error [\#14](https://github.com/solidusio-contrib/solidus_easypost/issues/14)
59
+
60
+ **Merged pull requests:**
61
+
62
+ - Extension cleanup [\#74](https://github.com/solidusio-contrib/solidus_easypost/pull/74) ([aldesantis](https://github.com/aldesantis))
63
+ - Standardize whitespace in README [\#72](https://github.com/solidusio-contrib/solidus_easypost/pull/72) ([brchristian](https://github.com/brchristian))
64
+ - Fix deprecation warning in engine.rb [\#71](https://github.com/solidusio-contrib/solidus_easypost/pull/71) ([brchristian](https://github.com/brchristian))
65
+ - Update README.md [\#70](https://github.com/solidusio-contrib/solidus_easypost/pull/70) ([brchristian](https://github.com/brchristian))
66
+ - Relax solidus\_support dependency [\#65](https://github.com/solidusio-contrib/solidus_easypost/pull/65) ([kennyadsl](https://github.com/kennyadsl))
67
+ - Upgrade to the latest solidus\_dev\_support [\#60](https://github.com/solidusio-contrib/solidus_easypost/pull/60) ([vassalloandrea](https://github.com/vassalloandrea))
68
+ - Fix CONFIGS constant not being modifiable [\#51](https://github.com/solidusio-contrib/solidus_easypost/pull/51) ([aldesantis](https://github.com/aldesantis))
69
+ - Reorganize and improve tests [\#50](https://github.com/solidusio-contrib/solidus_easypost/pull/50) ([aldesantis](https://github.com/aldesantis))
70
+ - Adopt solidus\_extension\_dev\_tools [\#48](https://github.com/solidusio-contrib/solidus_easypost/pull/48) ([aldesantis](https://github.com/aldesantis))
71
+ - Use different easypost\_address for the stock locations [\#43](https://github.com/solidusio-contrib/solidus_easypost/pull/43) ([vassalloandrea](https://github.com/vassalloandrea))
72
+ - Fix broken Rails 6 build [\#40](https://github.com/solidusio-contrib/solidus_easypost/pull/40) ([aldesantis](https://github.com/aldesantis))
73
+ - Adopt CircleCI instead of Travis [\#39](https://github.com/solidusio-contrib/solidus_easypost/pull/39) ([aldesantis](https://github.com/aldesantis))
74
+ - Fixing Travis [\#38](https://github.com/solidusio-contrib/solidus_easypost/pull/38) ([spaghetticode](https://github.com/spaghetticode))
75
+ - Add Rubocop for linting [\#37](https://github.com/solidusio-contrib/solidus_easypost/pull/37) ([aitbw](https://github.com/aitbw))
76
+ - Lock SQLite3 to version 1.3 [\#34](https://github.com/solidusio-contrib/solidus_easypost/pull/34) ([aitbw](https://github.com/aitbw))
77
+ - Use dynamic attributes on factories [\#33](https://github.com/solidusio-contrib/solidus_easypost/pull/33) ([aitbw](https://github.com/aitbw))
78
+ - add solidus\_easypost file [\#32](https://github.com/solidusio-contrib/solidus_easypost/pull/32) ([peterberkenbosch](https://github.com/peterberkenbosch))
79
+ - Add Solidus v2.8 to Travis config [\#31](https://github.com/solidusio-contrib/solidus_easypost/pull/31) ([aitbw](https://github.com/aitbw))
80
+ - Spec suite maintenance [\#29](https://github.com/solidusio-contrib/solidus_easypost/pull/29) ([aitbw](https://github.com/aitbw))
81
+ - Remove 2.2 from CI \(EOL\) [\#28](https://github.com/solidusio-contrib/solidus_easypost/pull/28) ([jacobherrington](https://github.com/jacobherrington))
82
+ - Remove versions past EOL from .travis.yml [\#26](https://github.com/solidusio-contrib/solidus_easypost/pull/26) ([jacobherrington](https://github.com/jacobherrington))
83
+ - Add Solidus 2.3-2.7 to .travis.yml [\#25](https://github.com/solidusio-contrib/solidus_easypost/pull/25) ([jacobherrington](https://github.com/jacobherrington))
84
+ - Support Solidus 1.3 and beyond [\#19](https://github.com/solidusio-contrib/solidus_easypost/pull/19) ([jhawthorn](https://github.com/jhawthorn))
85
+ - Add the require pry to spec helper [\#7](https://github.com/solidusio-contrib/solidus_easypost/pull/7) ([qr8r](https://github.com/qr8r))
86
+ - Fix multiple version testing [\#5](https://github.com/solidusio-contrib/solidus_easypost/pull/5) ([jhawthorn](https://github.com/jhawthorn))
87
+
88
+ ## [v1.0.4](https://github.com/solidusio-contrib/solidus_easypost/tree/v1.0.4) (2016-10-03)
89
+
90
+ [Full Changelog](https://github.com/solidusio-contrib/solidus_easypost/compare/v1.0.3...v1.0.4)
91
+
92
+ ## [v1.0.3](https://github.com/solidusio-contrib/solidus_easypost/tree/v1.0.3) (2016-07-20)
93
+
94
+ [Full Changelog](https://github.com/solidusio-contrib/solidus_easypost/compare/v1.0.2...v1.0.3)
95
+
96
+ ## [v1.0.2](https://github.com/solidusio-contrib/solidus_easypost/tree/v1.0.2) (2016-03-14)
97
+
98
+ [Full Changelog](https://github.com/solidusio-contrib/solidus_easypost/compare/solidus-1.0.2...v1.0.2)
99
+
100
+ **Merged pull requests:**
101
+
102
+ - Update Gemspec [\#4](https://github.com/solidusio-contrib/solidus_easypost/pull/4) ([qr8r](https://github.com/qr8r))
103
+ - Version 1.0.0 [\#3](https://github.com/solidusio-contrib/solidus_easypost/pull/3) ([qr8r](https://github.com/qr8r))
104
+ - Add a travis config file [\#2](https://github.com/solidusio-contrib/solidus_easypost/pull/2) ([qr8r](https://github.com/qr8r))
105
+ - Fix address decorator spec [\#1](https://github.com/solidusio-contrib/solidus_easypost/pull/1) ([travisp](https://github.com/travisp))
106
+
107
+ ## [solidus-1.0.2](https://github.com/solidusio-contrib/solidus_easypost/tree/solidus-1.0.2) (2015-12-08)
108
+
109
+ [Full Changelog](https://github.com/solidusio-contrib/solidus_easypost/compare/d963686e8d728ec5beec6c04fd4ae99e3cf7450e...solidus-1.0.2)
110
+
111
+
112
+
113
+ \* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/github-changelog-generator/github-changelog-generator)*
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2020 Brendan Deere
1
+ Copyright (c) 2015 Brendan Deere
2
2
  All rights reserved.
3
3
 
4
4
  Redistribution and use in source and binary forms, with or without modification,
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # solidus_easypost
2
2
 
3
- [![CircleCI](https://circleci.com/gh/solidusio-contrib/solidus_easypost.svg?style=svg)](https://circleci.com/gh/solidusio-contrib/solidus_easypost)
3
+
4
4
 
5
5
  This is an extension to integrate EasyPost with Solidus.
6
6
 
@@ -24,31 +24,106 @@ Bundle your dependencies and run the installation generator:
24
24
  bin/rails generate solidus_easypost:install
25
25
  ```
26
26
 
27
- Create an initializer at `config/initializers/solidus_easypost.rb`:
27
+ This will create an initializer at `config/initializers/solidus_easypost.rb`. Read through the
28
+ available configuration options and make sure to adjust the extension for your requirements.
29
+
30
+ Finally, you will need to configure Solidus to use the EasyPost stock estimator:
28
31
 
29
32
  ```ruby
30
- EasyPost.api_key = 'YOUR_API_KEY_HERE'
33
+ # config/initializers/spree.rb
34
+ Spree.config do |config|
35
+ config.stock.estimator_class = 'SolidusEasypost::Estimator'
36
+ end
31
37
  ```
32
38
 
33
39
  ## Usage
34
40
 
35
- This extension hijacks `Spree::Stock::Estimator#shipping_rates` to calculate shipping rates for your
36
- orders. This call happens during the checkout process, once the order's address information has been
37
- provided.
41
+ Once you switch to the EasyPost rate calculator, the extension will start calculating shipping rates
42
+ for all shipments. The cheapest rate will be selected by default, but your users will be able to
43
+ change the selected rate in the `delivery` step of the checkout process, if they wish.
44
+
45
+ Admins will also be able to download the postage label associated to each EasyPost shipment after
46
+ a shipment has been bought.
47
+
48
+ ### Buying labels upon shipping
49
+
50
+ By default, the extension also adds a callback to the `ship` event on the `Spree::Shipment` model,
51
+ automatically buying the selected rate from EasyPost.
52
+
53
+ If you want to disable this logic, you can set `purchase_labels` to `false`.
54
+
55
+ ### Customizing shipping rate calculation
56
+
57
+ By default, the extension will pass the entire cost of shipping to the user (i.e., the shipping cost
58
+ presented to the user will be equal to the rate received from the EasyPost API).
59
+
60
+ If you want to override this logic (e.g., you want to offer your users free shipping, but still buy
61
+ the rates from EasyPost), you can provide your own `shipping_rate_calculator_class`.
38
62
 
39
- The extension also adds a callback to the `ship` event on the `Spree::Shipment` model, telling
40
- EasyPost which rate was selected and "buying" that rate. This can be disabled by setting:
63
+ ### Customizing shipping method selection
64
+
65
+ By default, the extension will create shipping methods for each type of carrier/service for which it
66
+ receives a rate from the EasyPost API. These are not available to users by default, and must be
67
+ enabled before they are visible and selectable in the storefront during the checkout process.
68
+
69
+ If you want to override this logic, you can provide your own `shipping_method_selector_class`.
70
+
71
+ ### Customizing parcel dimension calculator
72
+
73
+ By default, the extension will use the default weight dimension calculator to calculate the parcel dimension that is passed to EasyPost. The default calculator uses the variants weight to calculate the parcel weight without taking into consideration the other package properties like `width`, `height`, and `lenght`.
74
+
75
+ If you want to override this logic, you can provide your own `parcel_dimension_calculator_class`.
76
+
77
+ ### Tracking cartons via EasyPost
78
+
79
+ You can optionally track packages via EasyPost's [Trackers API](https://www.easypost.com/docs/api#trackers).
80
+ In order to do this, you can call the `#easypost_tracker` method on any carton:
81
+
82
+ ```ruby
83
+ carton = Spree::Carton.find(2)
84
+ carton.easypost_tracker # => #<Easypost::Tracker>
85
+ ```
86
+
87
+ This will also save the ID of the tracker on the `easy_post_tracker_id` column, to more easily
88
+ retrieve the tracker in the future.
89
+
90
+ > NOTE: In orders for carton tracking to work, you need to make sure that the `tracking` column
91
+ > in `spree_cartons` contains a valid tracking number, and that the `carrier` column in
92
+ > `spree_shipping_methods` contains a carrier name [that EasyPost will recognize](https://www.easypost.com/docs/api#carrier-tracking-strings).
93
+ > The extension already generates compliant shipping methods by default, but you may need to change
94
+ > the data on your custom shipping methods if you want to track them.
95
+
96
+ You can also enable automatic tracking for all created cartons:
41
97
 
42
98
  ```ruby
43
- # config/initializers/solidus_easypost.rb
44
99
  SolidusEasypost.configure do |config|
45
- config.purchase_labels = false
100
+ config.track_all_cartons = true
46
101
  end
47
102
  ```
48
103
 
49
- This gem will create shipping methods for each type of carrier/service for which it receives a rate
50
- from the EasyPost API. These are set to `display_on: back_end` by default and must be set to
51
- `front_end` or `both` before the rate will be visible on the delivery page of the checkout.
104
+ ### Getting tracking updates via webhooks
105
+
106
+ Once a tracker has been created for a given carton, you can either use it manually or you can use
107
+ EasyPost's [webhooks](https://www.easypost.com/docs/api#webhooks) to have any shipping updates
108
+ forwarded to your application.
109
+
110
+ In order for webhooks to work, you need to install the [solidus_webhooks](https://github.com/solidusio-contrib/solidus_webhooks)
111
+ extension. When the extension is available, a webhook will be automatically configured at
112
+ `/webhooks/easypost_trackers`. Simply add it to your EasyPost dashboard with the following
113
+ configuration:
114
+
115
+ - *Environment:* `Production` or `Test`
116
+ - *Webhook URL:* `https://your-store.com/webhooks/easypost_trackers?token=[YOUR_TOKEN]` (replace`[YOUR_TOKEN]` with the API key of an admin user or, better yet, a[webhook user](https://github.com/solidusio-contrib/solidus_webhooks#restricting-permissions)
117
+
118
+ Now, when Solidus gets a tracking update from EasyPost, a `solidus_easypost.tracker.updated` event
119
+ will be fired. The event's payload will contain the `:carton` and `:payload` keys, with the
120
+ `Spree::Carton` object associated to the tracker and the EasyPost payload respectively.
121
+
122
+ ### Customizing the tracking webhook handler
123
+
124
+ If you want to override default webhook handler, you can provide your own `webhook_handler_class` in your configuration.
125
+
126
+ Note that, if you override the webhook handler, no events will be fired out of the box.
52
127
 
53
128
  ## Development
54
129
 
@@ -58,14 +133,14 @@ First bundle your dependencies, then run `bin/rake`. `bin/rake` will default to
58
133
  app if it does not exist, then it will run specs. The dummy app can be regenerated by using
59
134
  `bin/rake extension:test_app`.
60
135
 
61
- ```console
62
- $ bin/rake
136
+ ```shell
137
+ bin/rake
63
138
  ```
64
139
 
65
140
  To run [Rubocop](https://github.com/bbatsov/rubocop) static code analysis run
66
141
 
67
- ```console
68
- $ bundle exec rubocop
142
+ ```shell
143
+ bundle exec rubocop
69
144
  ```
70
145
 
71
146
  When testing your application's integration with this extension you may use its factories.
@@ -83,7 +158,7 @@ the sandbox app is `./sandbox` and `bin/rails` will forward any Rails commands t
83
158
 
84
159
  Here's an example:
85
160
 
86
- ```console
161
+ ```
87
162
  $ bin/rails server
88
163
  => Booting Puma
89
164
  => Rails 6.0.2.1 application starting in development
@@ -91,14 +166,29 @@ $ bin/rails server
91
166
  Use Ctrl-C to stop
92
167
  ```
93
168
 
169
+ ### Updating the changelog
170
+
171
+ Before and after releases the changelog should be updated to reflect the up-to-date status of
172
+ the project:
173
+
174
+ ```shell
175
+ bin/rake changelog
176
+ git add CHANGELOG.md
177
+ git commit -m "Update the changelog"
178
+ ```
179
+
94
180
  ### Releasing new versions
95
181
 
96
182
  Your new extension version can be released using `gem-release` like this:
97
183
 
98
- ```console
99
- $ bundle exec gem bump -v VERSION --tag --push --remote upstream && gem release
184
+ ```shell
185
+ bundle exec gem bump -v 1.6.0
186
+ bin/rake changelog
187
+ git commit -a --amend
188
+ git push
189
+ bundle exec gem release
100
190
  ```
101
191
 
102
192
  ## License
103
193
 
104
- Copyright (c) 2020 Brendan Deere, released under the New BSD License.
194
+ Copyright (c) 2015 Brendan Deere, released under the New BSD License.
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Spree
4
+ module Admin
5
+ class PostageLabelsController < Spree::Admin::BaseController
6
+ def show
7
+ @shipment = Spree::Shipment.find_by(number: params[:shipment_id])
8
+ authorize! @shipment, :show
9
+
10
+ unless @shipment.easypost_postage_label_url
11
+ flash[:error] = t('.no_postage_label', shipment_number: @shipment.number)
12
+ redirect_back(fallback_location: edit_admin_order_path(@shipment.order))
13
+ return
14
+ end
15
+
16
+ redirect_to @shipment.easypost_postage_label_url
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SolidusEasypost
4
+ module Spree
5
+ module CartonDecorator
6
+ def self.prepended(base)
7
+ base.after_create :track_via_easypost
8
+ end
9
+
10
+ def easypost_tracker
11
+ return @easypost_tracker if @easypost_tracker
12
+
13
+ if easy_post_tracker_id.present?
14
+ @easypost_tracker = EasyPost::Tracker.retrieve(easy_post_tracker_id)
15
+ else
16
+ @easypost_tracker = EasyPost::Tracker.create(
17
+ tracking_code: tracking,
18
+ carrier: shipping_method.carrier,
19
+ )
20
+
21
+ update!(easy_post_tracker_id: @easypost_tracker.id)
22
+ end
23
+
24
+ @easypost_tracker
25
+ end
26
+
27
+ private
28
+
29
+ def track_via_easypost
30
+ return unless SolidusEasypost.configuration.track_all_cartons
31
+
32
+ easypost_tracker
33
+ end
34
+
35
+ ::Spree::Carton.prepend self
36
+ end
37
+ end
38
+ end
@@ -3,46 +3,41 @@
3
3
  module SolidusEasypost
4
4
  module Spree
5
5
  module ShipmentDecorator
6
- def self.prepended(mod)
7
- mod.state_machine.before_transition(
6
+ def self.prepended(base)
7
+ base.state_machine.before_transition(
8
8
  to: :shipped,
9
9
  do: :buy_easypost_rate,
10
10
  if: -> { SolidusEasypost.configuration.purchase_labels }
11
11
  )
12
- end
13
12
 
14
- def easypost_shipment
15
- if selected_easy_post_shipment_id
16
- @ep_shipment ||= ::EasyPost::Shipment.retrieve(selected_easy_post_shipment_id)
17
- else
18
- @ep_shipment = build_easypost_shipment
19
- end
13
+ base.delegate(
14
+ :easy_post_rate_id,
15
+ :easy_post_shipment_id,
16
+ to: :selected_shipping_rate,
17
+ prefix: :selected,
18
+ allow_nil: true,
19
+ )
20
20
  end
21
21
 
22
- private
22
+ def easypost_shipment
23
+ return unless selected_easy_post_shipment_id
23
24
 
24
- def selected_easy_post_rate_id
25
- selected_shipping_rate.easy_post_rate_id
25
+ @easypost_shipment ||= ::EasyPost::Shipment.retrieve(selected_easy_post_shipment_id)
26
26
  end
27
27
 
28
- def selected_easy_post_shipment_id
29
- selected_shipping_rate.easy_post_shipment_id
28
+ def easypost_postage_label_url
29
+ easypost_shipment&.postage_label&.label_url
30
30
  end
31
31
 
32
- def build_easypost_shipment
33
- ::EasyPost::Shipment.create(
34
- to_address: order.ship_address.easypost_address,
35
- from_address: stock_location.easypost_address,
36
- parcel: to_package.easypost_parcel
37
- )
38
- end
32
+ private
39
33
 
40
34
  def buy_easypost_rate
41
- rate = easypost_shipment.rates.find do |sr|
42
- sr.id == selected_easy_post_rate_id
35
+ rate = easypost_shipment.rates.find do |easypost_rate|
36
+ easypost_rate.id == selected_easy_post_rate_id
43
37
  end
44
38
 
45
39
  easypost_shipment.buy(rate)
40
+
46
41
  self.tracking = easypost_shipment.tracking_code
47
42
  end
48
43
 
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SolidusEasypost
4
+ class ParcelDimension
5
+ def initialize(**params)
6
+ raise ArgumentError, 'The weight param is mandatory!' unless valid_value?(value: params[:weight])
7
+
8
+ @weight = params[:weight]
9
+ @width = params[:width]
10
+ @height = params[:height]
11
+ @depth = params[:depth]
12
+ end
13
+
14
+ def to_h
15
+ hash = {
16
+ weight: weight
17
+ }
18
+
19
+ hash[:width] = width if valid_value?(value: width)
20
+ hash[:height] = height if valid_value?(value: height)
21
+ hash[:length] = depth if valid_value?(value: depth)
22
+
23
+ hash
24
+ end
25
+
26
+ private
27
+
28
+ def valid_value?(value:)
29
+ value.present? && !value.zero?
30
+ end
31
+
32
+ attr_reader :width, :height, :depth, :weight
33
+ end
34
+ end
@@ -15,24 +15,13 @@ module SolidusEasypost
15
15
  end
16
16
 
17
17
  def easypost_shipment
18
- @easypost_shipment ||= ::EasyPost::Shipment.create(
19
- from_address: stock_location.easypost_address,
20
- to_address: order.ship_address.easypost_address,
21
- parcel: build_parcel,
22
- is_return: true
23
- )
18
+ @easypost_shipment ||= ShipmentBuilder.from_return_authorization(self)
24
19
  end
25
20
 
26
21
  def return_label(rate)
27
22
  easypost_shipment.buy(rate) unless easypost_shipment.postage_label
28
- easypost_shipment.postage_label
29
- end
30
23
 
31
- private
32
-
33
- def build_parcel
34
- total_weight = inventory_units.joins(:variant).sum(:weight)
35
- ::EasyPost::Parcel.create weight: total_weight
24
+ easypost_shipment.postage_label
36
25
  end
37
26
  end
38
27
  end