solidus_backtracs 2.2.0 → 2.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7e943693a25b935abcf72d941f4f38c891761c3afae537f108e211041ccdc6e2
4
- data.tar.gz: 87c9e1870799e0b007a8e2011a3460086b0aa9ccb39fa8a34bd1942bdf38e3ba
3
+ metadata.gz: ccacbc5731b470aa3dd924c0035d026948ecd49042199644ad5050e9793288be
4
+ data.tar.gz: dc1e92c7d93540ce5d7cd5a6ceba48cebc49d2f79f1da8a37dba76288a78dfca
5
5
  SHA512:
6
- metadata.gz: c43355431c15e927961f74576d56e80bf7e56f6a14233bdf0ade847e833624c60cdf110c377952014e2007a0cb4d4138e8c5300e3e444a9d77f39c83effda44f
7
- data.tar.gz: 95ce5f1c0d8d86a5a07eb884154caeecb9ca3c69a634594964d795aaa80439bb6a0bec00074dcf9151eeb16d02099fbea21a47fdcb560a9e98975e1f69892f1e
6
+ metadata.gz: f2a8a34c29deb725c01147894988c25c24783f6fd03e23a51d268abbf6b819cef0619889697f485989e870f52839a8047838cb9a7f159bfee369782f9e0e5bc7
7
+ data.tar.gz: c8d78430bc2311f1484e93c1244b83d6a80f4d4d63c5e91fe1bb7080912deea64d96c23789beba0bea9a9c1a185d2dabfc4647fec0524070d4baa71c553d41e1
data/.gitignore CHANGED
@@ -18,3 +18,5 @@ spec/examples.txt
18
18
  .rvmrc
19
19
  .ruby-version
20
20
  .ruby-gemset
21
+ .tool-versions
22
+ TAGS
data/CHANGELOG.md CHANGED
@@ -1,2 +1,16 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.2.0
4
+
5
+ Support the Solidus Assembly gem, consider allowed SKUs within assemblies/bundles
6
+ Retry logic for the authenticated request
7
+
8
+ ## 2.1.0
9
+
10
+ New auth and API patterns for Backtracs
11
+ Support specific SKUs to be mapped
12
+
13
+ ## 2.0.0
14
+
15
+ Diverged the gem from Shipstation to the Bactracs API
16
+
@@ -20,7 +20,14 @@ module SolidusBacktracs
20
20
  end
21
21
 
22
22
  def query_shipments
23
- shipments = SolidusBacktracs::Shipment::PendingApiSyncQuery.apply(::Spree::Shipment.joins(inventory_units: [:variant]).where("spree_variants.sku" => SolidusBacktracs.config.shippable_skus).where("spree_shipments.state" => :ready).where.not(shipstation_order_id: nil).distinct)
23
+ shipments = SolidusBacktracs::Shipment::PendingApiSyncQuery.apply(
24
+ ::Spree::Shipment
25
+ .joins(inventory_units: [:variant])
26
+ .where("spree_variants.sku" => SolidusBacktracs.config.shippable_skus)
27
+ .where("spree_shipments.state" => :ready)
28
+ .where(backtracs_synced_at: nil)
29
+ .distinct
30
+ )
24
31
  end
25
32
  end
26
33
  end
@@ -11,6 +11,7 @@ SolidusBacktracs.configure do |config|
11
11
 
12
12
  ## API Configuration
13
13
  config.api_base = ENV['BACKTRACS_API_BASE'] || 'https://bactracstest.andlor.com'
14
+ config.api_retries = ENV['BACKTRACS_API_RETRIES'] || 3
14
15
 
15
16
  # Backtracs expects the endpoint to be protected by HTTP Basic Auth.
16
17
  # Set the username and password you desire for Backtracs to use.
@@ -32,7 +33,7 @@ SolidusBacktracs.configure do |config|
32
33
  config.sku_map = {}
33
34
  config.default_rma_type = "W"
34
35
  config.default_carrier = "FedExGrnd"
35
- config.default_ship_method = "GROUND"
36
+ config.default_ship_method = "GROUND"
36
37
  config.default_status = "OPEN"
37
38
  config.default_rp_location = "FG-NEW"
38
39
  config.shippable_skus = []
@@ -10,27 +10,41 @@ module SolidusBacktracs
10
10
  @username = SolidusBacktracs.configuration.authentication_username
11
11
  @password = SolidusBacktracs.configuration.authentication_password
12
12
  @api_base = SolidusBacktracs.configuration.api_base
13
+ @retries = SolidusBacktracs.configuration.api_retries
13
14
  end
14
15
 
15
- def authenticated_call(method: nil, path: nil, serializer: nil, shipment: nil)
16
- unless @username.present? || @password.present? || @api_base.present?
17
- raise "Credentials not defined for Authentication"
18
- end
16
+ def authenticated_call(method: nil, path: nil, serializer: nil, shipment: nil, count: 0)
17
+ if count <= @retries
18
+ unless @username.present? || @password.present? || @api_base.present?
19
+ raise "Credentials not defined for Authentication"
20
+ end
19
21
 
20
- Rails.cache.fetch("backtracks_cache_key", expires_in: 1.hour) do
21
- @response = self.call(method: :get, path: "/webservices/user/Authentication.asmx/Login?sUserName=#{@username}&sPassword=#{@password}")
22
- end
23
-
24
- authenticted = parse_authentication_response(@response, "Result")
22
+ @response = Rails.cache.fetch("backtracks_cache_key", expires_in: 1.hour, skip_nil: true) do
23
+ self.call(method: :get, path: "/webservices/user/Authentication.asmx/Login?sUserName=#{@username}&sPassword=#{@password}")
24
+ end
25
25
 
26
- if authenticted == 'false'
27
- raise RequestError.from_response(@response)
28
- else
26
+ raise RequestError.from_response(@response) unless @response # just try again for @retries?
27
+ authenticted = parse_authentication_response(@response, "Result")
28
+ raise RequestError.from_response(@response) if authenticted == "false"
29
29
  sguid = parse_authentication_response(@response, "Message")
30
- params = serializer.call(shipment, sguid)
31
30
 
32
- rma_response = call(method: :post, path: path, params: params)
33
- sync_shipment(shipment, rma_response)
31
+ if authenticted == 'false'
32
+ clear_cache
33
+ raise "User Not Authenticated"
34
+ else
35
+ sguid = parse_authentication_response(@response, "Message")
36
+ params = serializer.call(shipment, sguid)
37
+
38
+ rma_response = call(method: :post, path: path, params: params)
39
+ unless parse_rma_creation_response(rma_response) == 'true'
40
+ clear_cache
41
+ count += 1
42
+ self.authenticated_call(method: :post, path: '/webservices/rma/rmaservice.asmx', serializer: serializer, shipment: shipment, count: count)
43
+ end
44
+ shipment_synced(shipment)
45
+ end
46
+ else
47
+ shipment_sync_failed(shipment)
34
48
  end
35
49
  end
36
50
 
@@ -62,25 +76,33 @@ module SolidusBacktracs
62
76
  end
63
77
  end
64
78
 
79
+ def clear_cache
80
+ Rails.cache.delete('backtracks_cache_key')
81
+ @response = nil
82
+ end
83
+
65
84
  def parse_authentication_response(response, type)
66
85
  response.dig("AuthenticationResponse", type)
67
86
  end
68
87
 
69
- def sync_shipment(shipment, response)
70
- result = response.dig("Envelope", "Body", "CreateNewResponse", "CreateNewResult", "Result")
71
- if result == 'true'
72
- shipment.update_column(:backtracs_synced_at, Time.zone.now)
88
+ def parse_rma_creation_response(response)
89
+ response.dig("Envelope", "Body", "CreateNewResponse", "CreateNewResult", "Result")
90
+ end
73
91
 
74
- ::Spree::Event.fire(
75
- 'solidus_backtracs.api.sync_completed',
76
- shipment: shipment
77
- )
78
- else
79
- ::Spree::Event.fire(
80
- 'solidus_backtracs.api.sync_failed',
81
- shipment: shipment
82
- )
83
- end
92
+ def shipment_synced(shipment)
93
+ shipment.update_column(:backtracs_synced_at, Time.zone.now)
94
+
95
+ ::Spree::Event.fire(
96
+ 'solidus_backtracs.api.sync_completed',
97
+ shipment: shipment
98
+ )
99
+ end
100
+
101
+ def shipment_sync_failed(shipment)
102
+ ::Spree::Event.fire(
103
+ 'solidus_backtracs.api.sync_failed',
104
+ shipment: shipment
105
+ )
84
106
  end
85
107
  end
86
108
  end
@@ -19,7 +19,8 @@ module SolidusBacktracs
19
19
  :shipment_notice_class,
20
20
  :authentication_username,
21
21
  :authentication_password,
22
- :api_base,
22
+ :api_base,
23
+ :api_retries,
23
24
  :proxy_address,
24
25
  :proxy_port,
25
26
  :proxy_username,
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SolidusBacktracs
4
- VERSION = '2.2.0'
4
+ VERSION = '2.2.3'
5
5
  end
@@ -5,16 +5,16 @@ require_relative 'lib/solidus_backtracs/version'
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = 'solidus_backtracs'
7
7
  spec.version = SolidusBacktracs::VERSION
8
- spec.authors = ['Stephen Puiszis']
9
- spec.email = 'steve@tablexi.com'
8
+ spec.authors = ['Zeryab Ali']
9
+ spec.email = 'zkhan@suvie.com'
10
10
 
11
11
  spec.summary = 'A Solidus extension for integrating the Backtracs API.'
12
- spec.homepage = 'https://github.com/solidusio-contrib/solidus_backtracs'
12
+ spec.homepage = 'https://github.com/suvie-eng/solidus_backtracs'
13
13
  spec.license = 'BSD-3-Clause'
14
14
 
15
15
  spec.metadata['homepage_uri'] = spec.homepage
16
- spec.metadata['source_code_uri'] = 'https://github.com/solidusio-contrib/solidus_backtracs'
17
- spec.metadata['changelog_uri'] = 'https://github.com/solidusio-contrib/solidus_backtracs/blob/master/CHANGELOG.md'
16
+ spec.metadata['source_code_uri'] = 'https://github.com/suvie-eng/solidus_backtracs/'
17
+ spec.metadata['changelog_uri'] = 'https://github.com/suvie-eng/solidus_backtracs/blob/master/CHANGELOG.md'
18
18
 
19
19
  spec.required_ruby_version = Gem::Requirement.new('>= 2.5')
20
20
 
@@ -19,15 +19,15 @@ RSpec.describe SolidusBacktracs::Shipment::PendingApiSyncQuery do
19
19
  stub_configuration(api_sync_threshold: 10.minutes)
20
20
  shipment = create(:order_ready_to_ship).shipments.first.tap do |s|
21
21
  s.order.update_columns(updated_at: 7.minutes.ago)
22
- s.update_columns(shipstation_synced_at: 8.minutes.ago)
22
+ s.update_columns(backtracs_synced_at: 8.minutes.ago)
23
23
  end
24
24
  create(:order_ready_to_ship).shipments.first.tap do |s|
25
25
  s.order.update_columns(updated_at: 9.minutes.ago)
26
- s.update_columns(shipstation_synced_at: 8.minutes.ago)
26
+ s.update_columns(backtracs_synced_at: 8.minutes.ago)
27
27
  end
28
28
  create(:order_ready_to_ship).shipments.first.tap do |s|
29
29
  s.order.update_columns(updated_at: 11.minutes.ago)
30
- s.update_columns(shipstation_synced_at: 10.minutes.ago)
30
+ s.update_columns(backtracs_synced_at: 10.minutes.ago)
31
31
  end
32
32
 
33
33
  expect(described_class.apply(Spree::Shipment.all)).to match_array([shipment])
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solidus_backtracs
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.2.3
5
5
  platform: ruby
6
6
  authors:
7
- - Stephen Puiszis
7
+ - Zeryab Ali
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-05-13 00:00:00.000000000 Z
11
+ date: 2022-05-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -115,7 +115,7 @@ dependencies:
115
115
  - !ruby/object:Gem::Version
116
116
  version: '0'
117
117
  description:
118
- email: steve@tablexi.com
118
+ email: zkhan@suvie.com
119
119
  executables: []
120
120
  extensions: []
121
121
  extra_rdoc_files: []
@@ -174,7 +174,7 @@ files:
174
174
  - lib/solidus_backtracs/shipment_notice.rb
175
175
  - lib/solidus_backtracs/testing_support/factories.rb
176
176
  - lib/solidus_backtracs/version.rb
177
- - solidus_shipstation.gemspec
177
+ - solidus_bactracs.gemspec
178
178
  - spec/controllers/spree/backtracs_controller_spec.rb
179
179
  - spec/fixtures/backtracs_xml_schema.xsd
180
180
  - spec/jobs/solidus_backtracs/api/schedule_shipment_syncs_job_spec.rb
@@ -197,13 +197,13 @@ files:
197
197
  - spec/support/controllers.rb
198
198
  - spec/support/webmock.rb
199
199
  - spec/support/xsd.rb
200
- homepage: https://github.com/solidusio-contrib/solidus_backtracs
200
+ homepage: https://github.com/suvie-eng/solidus_backtracs
201
201
  licenses:
202
202
  - BSD-3-Clause
203
203
  metadata:
204
- homepage_uri: https://github.com/solidusio-contrib/solidus_backtracs
205
- source_code_uri: https://github.com/solidusio-contrib/solidus_backtracs
206
- changelog_uri: https://github.com/solidusio-contrib/solidus_backtracs/blob/master/CHANGELOG.md
204
+ homepage_uri: https://github.com/suvie-eng/solidus_backtracs
205
+ source_code_uri: https://github.com/suvie-eng/solidus_backtracs/
206
+ changelog_uri: https://github.com/suvie-eng/solidus_backtracs/blob/master/CHANGELOG.md
207
207
  post_install_message:
208
208
  rdoc_options: []
209
209
  require_paths: