solidus_bactracs 3.1.1 → 3.1.2

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: ce11ad638edb1316dea6b8a6865e655bc39329d56ac6ba954171b006e4c12904
4
- data.tar.gz: 20e2c5829661277c6d99e9adb95a2e8653e12a5963c790de276690e2cca10bfb
3
+ metadata.gz: 57358a842b15f8f01b4ef06b6e665d3da2d1e71c2cb9d0c963a53cf790329431
4
+ data.tar.gz: 50ec2b26961894f93f194047564ffc09df92337fcbcc2ef924d241dda879bb84
5
5
  SHA512:
6
- metadata.gz: a91017ed15087d8a88f02d1a8efab5cbf839792664f3bc8dc9bf3a826ef931c208b1da963cb755839c6e3742d557ef5e0d8805dc022f607313b0178dd15738de
7
- data.tar.gz: 7dc6cff4a8e9feed90087cea6aa4838e4db707218bc711f67d5f752aef977e6c060474df36b7d3b4c84e143509202d4303a4f580370103ea7804cc0a73b7fdef
6
+ metadata.gz: 61b6d5945b5bea4a67e85b44bb2cd719740466d0737599d1e77bb4aad035ce488e7cbb0df89ddedf1307d958dff901f01d0c9f66bb2006d4df06deb62836473e
7
+ data.tar.gz: 9db512ac8470045e746d5afada89e2634845d175c4bbb45aca29cb6196d8199c5e65aeef0123cd0e5b75e1cfb6b483cbc0e186143e26fedfc5ceadb81b19089d
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
@@ -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
@@ -2,7 +2,8 @@
2
2
 
3
3
  class BactracsTypoCorrection < ActiveRecord::Migration[5.2]
4
4
  def change
5
- if ActiveRecord::Base.connection.column_exists?(:spree_shipments, :backtracs_synced_at)
5
+ if ( ActiveRecord::Base.connection.column_exists?(:spree_shipments, :backtracs_synced_at) &&
6
+ !ActiveRecord::Base.connection.column_exists?(:spree_shipments, :bactracs_synced_at))
6
7
  rename_column :spree_shipments, :backtracs_synced_at, :bactracs_synced_at
7
8
  end
8
9
  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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SolidusBactracs
4
- VERSION = '3.1.1'
4
+ VERSION = '3.1.2'
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.1
4
+ version: 3.1.2
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-07-26 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
@@ -166,6 +167,8 @@ files:
166
167
  - config/routes.rb
167
168
  - db/migrate/20210220093010_add_bactracs_api_sync_fields.rb
168
169
  - db/migrate/20220701000001_bactracs_typo_correction.rb
170
+ - db/migrate/20220704144504_rename_bactracs_columns_in_spree_shipment.rb
171
+ - lib/bactracs_service.rb
169
172
  - lib/generators/solidus_bactracs/install/install_generator.rb
170
173
  - lib/generators/solidus_bactracs/install/templates/initializer.rb
171
174
  - lib/solidus_backtracs/version.rb
@@ -183,6 +186,7 @@ files:
183
186
  - lib/solidus_bactracs/shipment_notice.rb
184
187
  - lib/solidus_bactracs/testing_support/factories.rb
185
188
  - lib/solidus_bactracs/version.rb
189
+ - lib/tasks/solidus_bactracs.rake
186
190
  - solidus_bactracs.gemspec
187
191
  - spec/controllers/spree/bactracs_controller_spec.rb
188
192
  - spec/fixtures/bactracs_xml_schema.xsd
@@ -214,7 +218,7 @@ metadata:
214
218
  source_code_uri: https://github.com/suvie-eng/solidus_bactracs/
215
219
  changelog_uri: https://github.com/suvie-eng/solidus_bactracs/blob/master/CHANGELOG.md
216
220
  allowed_push_host: https://rubygems.org
217
- post_install_message:
221
+ post_install_message:
218
222
  rdoc_options: []
219
223
  require_paths:
220
224
  - lib
@@ -230,7 +234,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
230
234
  version: '0'
231
235
  requirements: []
232
236
  rubygems_version: 3.1.4
233
- signing_key:
237
+ signing_key:
234
238
  specification_version: 4
235
239
  summary: A Solidus extension for integrating the Bactracs API.
236
240
  test_files: