solidus_bactracs 3.1.0 → 3.2.0

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: dc8997f6f0e758dad7788168d7277d6995338887221e16eaf5173c5f8e56a93a
4
- data.tar.gz: 1e8e6ce7ecba59996b70cebbd91f49153074eb5cad64af726ba3f0bca3aa40c8
3
+ metadata.gz: e67ac9974b0c0fb6e097172f14667e73c99c5d4ccd948423e48dcdd5820becde
4
+ data.tar.gz: a7fb4b01e858278ab263373d087aa5a4c63222f9389d2f2a8087566e50f42270
5
5
  SHA512:
6
- metadata.gz: 86bd10aa960cf5e863e71df839786a7b960a88eb846bf615688ca47d005207d40cd7249e313260888ec35eb496473159539720c66346e622062f613ed4d54a66
7
- data.tar.gz: 7ee9d87aec037766f6c92d5696e66213fcd10183d09ea0e193cce4253c99743c96fcfacc857e0998d87a652079aae58cd4dc46cd2139804d24fb9fcea6cb15f6
6
+ metadata.gz: d6232847569c2a6166959fcfdd3791597d8e32aaa71f68def3d4eff77b8b8269857c0973143f5c8af3b33cf47ffcd326b209a43f8c36d6ae07c0542db3255205
7
+ data.tar.gz: d61675ac31273aa2751b300350d3b3b20ce8d4c23c62c39192a9a90c489762c4d6ff5179abefbcb53ce17031c4f9a68c976663599b49194078a3857d49cf6116
data/CHANGELOG.md CHANGED
@@ -1,9 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## 3.1.2
4
+ Fully include retry support tables and methods within the gem. Earlier in 3.1.x some migrations, etc, were expected to be handled by the host rails app.
5
+
3
6
  ## 3.1.0
4
7
  Different retry support for CreateRMA, as well as more logging
5
8
 
6
- ## 3.0.0
9
+ ## 3.0.x
7
10
  Re-release the gem under a new non-forked repo, since this gem is a non-mergeable divergence from the solidus_shipstation gem
8
11
 
9
12
  ## 2.2.0
data/README.md CHANGED
@@ -28,7 +28,8 @@ used by the extension.
28
28
 
29
29
  ## Usage
30
30
 
31
- This extension can integrate with ShipStation in two ways.
31
+ This extension can integrate with Bactracs via SOAP-based XML API integration. The gem currently makes SOAP 1.1 format calls, though the API support SOAP 1.2
32
+
32
33
 
33
34
  ### XML integration
34
35
 
data/Rakefile CHANGED
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ import "./lib/tasks/solidus_bactracs.rake"
3
4
  require 'solidus_dev_support/rake_tasks'
4
5
  SolidusDevSupport::RakeTasks.install
5
6
 
@@ -7,6 +7,19 @@ module SolidusBactracs
7
7
  base.singleton_class.prepend ClassMethods
8
8
  end
9
9
 
10
+ def verify_bactracs_sync!
11
+ if bactracs_sync_verified_at.nil?
12
+ # API call to verify RMAs of shipments
13
+ if BactracsService.new.rma_was_synced?(self)
14
+ self.update_column(:bactracs_sync_verified_at, Time.now)
15
+ else
16
+ self.update_column(:bactracs_synced_at, nil)
17
+ end
18
+ end
19
+ rescue => e
20
+ Rails.logger.error({ message: "#{e.message}, file: shipment_decorator.rb", shipment_number: number })
21
+ end
22
+
10
23
  module ClassMethods
11
24
  def exportable
12
25
  ::Spree::Deprecation.warn <<~DEPRECATION
@@ -21,16 +21,17 @@ module SolidusBactracs
21
21
  end
22
22
 
23
23
  def query_shipments
24
- shipments = SolidusBactracs::Shipment::PendingApiSyncQuery.apply(
25
- ::Spree::Shipment
24
+ shipments = SolidusBactracs::Shipment::PendingApiSyncQuery.apply(all_elegible_shipments)
25
+ end
26
+
27
+ def all_elegible_shipments(skus: SolidusBactracs.config.shippable_skus, state: :ready)
28
+ ::Spree::Shipment
26
29
  .joins(inventory_units: [:variant])
27
- .where("spree_variants.sku" => SolidusBactracs.config.shippable_skus)
28
- .where("spree_shipments.state" => :ready)
30
+ .where("spree_variants.sku" => skus)
31
+ .where("spree_shipments.state" => state)
29
32
  .where(bactracs_synced_at: nil)
30
33
  .distinct
31
- )
32
34
  end
33
35
  end
34
36
  end
35
37
  end
36
-
@@ -10,6 +10,10 @@ module SolidusBactracs
10
10
  return if shipments.empty?
11
11
 
12
12
  sync_shipments(shipments)
13
+
14
+ # Verify bactracs sync
15
+ shipments.each { |shipment| VerifyBactracsSyncWorker.perform_async(shipment.id) }
16
+
13
17
  rescue RateLimitedError => e
14
18
  self.class.set(wait: e.retry_in).perform_later
15
19
  rescue StandardError => e
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ class VerifyBactracsSyncWorker
4
+ include Sidekiq::Worker
5
+
6
+ sidekiq_options queue: 'default'
7
+
8
+ def perform(shipment_id)
9
+ shipment = Spree::Shipment.find_by(id: shipment_id)
10
+ if shipment
11
+ shipment.verify_bactracs_sync!
12
+ end
13
+ end
14
+ end
@@ -1,8 +1,11 @@
1
+ # frozen_string_literal: true
1
2
  # NOTE: This migration is only required if you use the API integration strategy.
2
3
  # If you're using the XML file instead, you can safely skip these columns.
3
4
 
4
5
  class AddBactracsApiSyncFields < ActiveRecord::Migration[5.2]
5
6
  def change
6
- add_column :spree_shipments, :bactracs_synced_at, :datetime
7
+ if !ActiveRecord::Base.connection.column_exists?(:spree_shipments, :bactracs_synced_at)
8
+ add_column :spree_shipments, :bactracs_synced_at, :datetime
9
+ end
7
10
  end
8
11
  end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ class BactracsTypoCorrection < ActiveRecord::Migration[5.2]
4
+ def change
5
+ if ( ActiveRecord::Base.connection.column_exists?(:spree_shipments, :backtracs_synced_at) &&
6
+ !ActiveRecord::Base.connection.column_exists?(:spree_shipments, :bactracs_synced_at))
7
+ rename_column :spree_shipments, :backtracs_synced_at, :bactracs_synced_at
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ class RenameBactracsColumnsInSpreeShipment < ActiveRecord::Migration[5.2]
4
+ def change
5
+ if ( ActiveRecord::Base.connection.column_exists?(:spree_shipments, :backtracs_sync_verified_at) &&
6
+ !ActiveRecord::Base.connection.column_exists?(:spree_shipments, :bactracs_sync_verified_at))
7
+ rename_column :spree_shipments, :backtracs_sync_verified_at, :bactracs_sync_verified_at
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "uri"
4
+ require "net/http"
5
+
6
+ class BactracsService
7
+ attr_accessor :token
8
+
9
+ def initialize
10
+ @username = SolidusBactracs.configuration.authentication_username
11
+ @password = SolidusBactracs.configuration.authentication_password
12
+ @runner = SolidusBactracs::Api::RequestRunner.new
13
+ # Authenticate account
14
+ authenticate!
15
+ end
16
+
17
+ def rma_was_synced?(shipment)
18
+ if @token.present?
19
+
20
+ response =
21
+ @runner.call(
22
+ method: :post,
23
+ path: "/webservices/rma/rmaservice.asmx?op=Read",
24
+ params:
25
+ "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n
26
+ <soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n
27
+ <soap:Body>
28
+ <Read xmlns=\"http://bactracs.andlor.com/rmaservice\">\n
29
+ <sGuid>#{@token}</sGuid>\n
30
+ <sRMANumber>#{shipment.number}</sRMANumber>\n
31
+ </Read>\n
32
+ </soap:Body>\n
33
+ </soap:Envelope>"
34
+ )
35
+
36
+ if response
37
+ return response.dig("Envelope", "Body", "ReadResponse", "ReadResult", "oRMA").present? rescue false
38
+ end
39
+ end
40
+
41
+ return false
42
+
43
+ rescue => e
44
+ Rails.logger.error({ message: e.message.to_s, file: "bactracs_service.rb" })
45
+
46
+ return false
47
+ end
48
+
49
+ private
50
+
51
+ def authenticate!
52
+
53
+ response =
54
+ @runner.call(
55
+ method: :get,
56
+ path: "/webservices/user/Authentication.asmx/Login?sUserName=#{@username}&sPassword=#{@password}"
57
+ )
58
+
59
+ if response.dig("AuthenticationResponse", "Result") == "true"
60
+ @token = response.dig("AuthenticationResponse", "Message")
61
+ end
62
+
63
+ rescue => e
64
+ Rails.logger.error({ message: "#{e.message}, file: bactracs_service.rb" })
65
+ end
66
+ end
@@ -13,18 +13,18 @@ module SolidusBactracs
13
13
  @retries = SolidusBactracs.configuration.api_retries
14
14
  end
15
15
 
16
- def authenticated_call(method: nil, path: nil, serializer: nil, shipment: nil, count: 0)
16
+ def authenticated_call(serializer: nil, shipment: nil, method: :post, path: '/webservices/rma/rmaservice.asmx', count: 0)
17
17
  if count <= @retries
18
18
  sguid = authenticate! rescue nil
19
19
 
20
20
  if !sguid.presence
21
21
  clear_cache
22
22
  count += 1
23
- self.authenticated_call(method: :post, path: '/webservices/rma/rmaservice.asmx', serializer: serializer, shipment: shipment, count: count)
23
+ self.authenticated_call(method: method, path: path, serializer: serializer, shipment: shipment, count: count)
24
24
  else
25
25
  params = serializer.call(shipment, sguid)
26
26
 
27
- rma_response = call(method: :post, path: path, params: params)
27
+ rma_response = call(method: method, path: path, params: params)
28
28
  if create_rma_success?(rma_response)
29
29
  Rails.logger.info({ event: 'success CreateRMA', rma: shipment.number, response: parse_rma_creation_response(rma_response, "Message")})
30
30
  shipment_synced(shipment)
@@ -35,11 +35,12 @@ module SolidusBactracs
35
35
  clear_cache
36
36
  count += 1
37
37
  Rails.logger.warn({ event: 'bactracs failed CreateRMA', error: parse_rma_creation_response(rma_response, "Message")})
38
- self.authenticated_call(method: :post, path: '/webservices/rma/rmaservice.asmx', serializer: serializer, shipment: shipment, count: count)
38
+ self.authenticated_call(method: method, path: path, serializer: serializer, shipment: shipment, count: count)
39
39
  end
40
40
  end
41
41
  else
42
42
  shipment_sync_failed(shipment)
43
+ return false
43
44
  end
44
45
  end
45
46
 
@@ -77,7 +78,7 @@ module SolidusBactracs
77
78
  @response = nil
78
79
  end
79
80
 
80
- def authenticate!()
81
+ def authenticate!
81
82
  unless @username.present? || @password.present? || @api_base.present?
82
83
  raise "Credentials not defined for Authentication"
83
84
  end
@@ -110,7 +111,7 @@ module SolidusBactracs
110
111
 
111
112
  def rma_exists?(response)
112
113
  if parse_rma_creation_response(response, "Message").match(/rma .* already exists/)
113
- Rails.logger.warn({ event: 'bactracs failed CreateRMA', error: parse_rma_creation_response(rma_response, "Message")})
114
+ Rails.logger.warn({ event: 'bactracs failed CreateRMA', error: parse_rma_creation_response(response, "Message")})
114
115
  return true
115
116
  end
116
117
  end
@@ -0,0 +1,53 @@
1
+ module SolidusBactracs
2
+ class ConsoleHarness
3
+ attr_reader :runner, :syncer, :sync, :shipments, :shipments_elegible
4
+
5
+ attr_accessor :cursor, :batch
6
+
7
+ def initialize
8
+ @runner = SolidusBactracs::Api::RequestRunner.new
9
+ @syncer = SolidusBactracs::Api::BatchSyncer.from_config
10
+ @sync = SolidusBactracs::Api::ScheduleShipmentSyncsJob.new
11
+ @shipments = SolidusBactracs::Api::ScheduleShipmentSyncsJob.new.query_shipments
12
+ @shipments_elegible = SolidusBactracs::Api::ScheduleShipmentSyncsJob.new.all_elegible_shipments
13
+ @cursor = 0
14
+ @batch = 4
15
+ end
16
+
17
+ def refresh
18
+ @shipments = SolidusBactracs::Api::ScheduleShipmentSyncsJob.new.query_shipments
19
+ end
20
+
21
+ def shipment(id)
22
+ @shipments.find_by(id: id)
23
+ end
24
+
25
+ def shipment_number(ship_number)
26
+ @shipments.find_by(number: ship_number)
27
+ end
28
+
29
+ def serialize(shipment)
30
+ # SolidusShipstation::Api::ApplianceShipmentSerializer.new(shipment)
31
+ @syncer.client.shipment_serializer.call(shipment, @runner.authenticate!)
32
+ end
33
+
34
+ def try_one
35
+ puts "trying shipment #{(shipment = @shipments[@cursor]).id}"
36
+ # resp = @runner.call(:post, '/orders/createorders', [serialize(shipment)])
37
+ resp = @runner.authenticated_call(shipment: shipment, serializer: @syncer.client.shipment_serializer)
38
+ if resp
39
+ @cursor += 1
40
+ return resp
41
+ end
42
+ ensure
43
+ puts resp
44
+ end
45
+
46
+ def try_batch(batch_size=nil)
47
+ b = [batch_size.to_i, @batch].max
48
+ b.times do
49
+ break unless try_one
50
+ end
51
+ end
52
+ end
53
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SolidusBactracs
4
- VERSION = '3.1.0'
4
+ VERSION = '3.2.0'
5
5
  end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ namespace :solidus_bactracs do
4
+ desc 'Run export jobs to send shipments to Bactracs'
5
+ task export: :environment do
6
+ SolidusBactracs::Api::ScheduleShipmentSyncsJob.perform_later
7
+ end
8
+
9
+ desc "Verify bactracs RMA creation"
10
+ task verify_bactracs_sync: :environment do
11
+ Spree::Shipment.not_bactracs_sync_verified.find_each(batch_size: 200) do |shipment|
12
+ # set shipment sync at and bactracs_sync_verified_at attributes by verifying RMA
13
+ shipment.verify_bactracs_sync!
14
+ end
15
+ end
16
+ end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solidus_bactracs
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0
4
+ version: 3.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zeryab Ali
8
8
  - Zachary Jones
9
- autorequire:
9
+ autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2022-07-01 00:00:00.000000000 Z
12
+ date: 2022-08-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty
@@ -115,7 +115,7 @@ dependencies:
115
115
  - - ">="
116
116
  - !ruby/object:Gem::Version
117
117
  version: '0'
118
- description:
118
+ description:
119
119
  email: techbilling@suvie.com
120
120
  executables: []
121
121
  extensions: []
@@ -155,6 +155,7 @@ files:
155
155
  - app/queries/solidus_bactracs/shipment/exportable_query.rb
156
156
  - app/queries/solidus_bactracs/shipment/pending_api_sync_query.rb
157
157
  - app/views/spree/bactracs/export.xml.builder
158
+ - app/workers/verify_bactracs_sync_worker.rb
158
159
  - bin/console
159
160
  - bin/rails
160
161
  - bin/rails-engine
@@ -165,9 +166,11 @@ files:
165
166
  - config/locales/en.yml
166
167
  - config/routes.rb
167
168
  - db/migrate/20210220093010_add_bactracs_api_sync_fields.rb
169
+ - db/migrate/20220701000001_bactracs_typo_correction.rb
170
+ - db/migrate/20220704144504_rename_bactracs_columns_in_spree_shipment.rb
171
+ - lib/bactracs_service.rb
168
172
  - lib/generators/solidus_bactracs/install/install_generator.rb
169
173
  - lib/generators/solidus_bactracs/install/templates/initializer.rb
170
- - lib/solidus_backtracs/version.rb
171
174
  - lib/solidus_bactracs.rb
172
175
  - lib/solidus_bactracs/api/batch_syncer.rb
173
176
  - lib/solidus_bactracs/api/client.rb
@@ -177,11 +180,13 @@ files:
177
180
  - lib/solidus_bactracs/api/shipment_serializer.rb
178
181
  - lib/solidus_bactracs/api/threshold_verifier.rb
179
182
  - lib/solidus_bactracs/configuration.rb
183
+ - lib/solidus_bactracs/console_harness.rb
180
184
  - lib/solidus_bactracs/engine.rb
181
185
  - lib/solidus_bactracs/errors.rb
182
186
  - lib/solidus_bactracs/shipment_notice.rb
183
187
  - lib/solidus_bactracs/testing_support/factories.rb
184
188
  - lib/solidus_bactracs/version.rb
189
+ - lib/tasks/solidus_bactracs.rake
185
190
  - solidus_bactracs.gemspec
186
191
  - spec/controllers/spree/bactracs_controller_spec.rb
187
192
  - spec/fixtures/bactracs_xml_schema.xsd
@@ -213,7 +218,7 @@ metadata:
213
218
  source_code_uri: https://github.com/suvie-eng/solidus_bactracs/
214
219
  changelog_uri: https://github.com/suvie-eng/solidus_bactracs/blob/master/CHANGELOG.md
215
220
  allowed_push_host: https://rubygems.org
216
- post_install_message:
221
+ post_install_message:
217
222
  rdoc_options: []
218
223
  require_paths:
219
224
  - lib
@@ -229,7 +234,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
229
234
  version: '0'
230
235
  requirements: []
231
236
  rubygems_version: 3.1.4
232
- signing_key:
237
+ signing_key:
233
238
  specification_version: 4
234
239
  summary: A Solidus extension for integrating the Bactracs API.
235
240
  test_files:
@@ -1,5 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module SolidusBacktracs
4
- VERSION = '3.1.0'
5
- end