solidus_backtracs 2.2.1 → 2.2.4
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 +4 -4
- data/.gitignore +2 -0
- data/CHANGELOG.md +14 -0
- data/app/helpers/solidus_backtracs/export_helper.rb +25 -17
- data/app/jobs/solidus_backtracs/api/schedule_shipment_syncs_job.rb +8 -1
- data/lib/generators/solidus_backtracs/install/templates/initializer.rb +2 -1
- data/lib/solidus_backtracs/api/request_runner.rb +51 -29
- data/lib/solidus_backtracs/configuration.rb +2 -1
- data/lib/solidus_backtracs/version.rb +1 -1
- data/{solidus_shipstation.gemspec → solidus_bactracs.gemspec} +3 -3
- data/spec/queries/solidus_backtracs/shipment/pending_api_sync_query_spec.rb +3 -3
- metadata +7 -7
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: d3430b774af9ec754f4c7657dfd160e83ffbeeb898dd29a463a16d7031cc8dad
         | 
| 4 | 
            +
              data.tar.gz: ef7e49cb43f69e6f4e94cea99bdc7805ab92dc096bfd78b970ad94502099b702
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: adcbece7f493aa87d8c20abe19c93072c8f728110ebe8682550e01ff93a7f9a7a4217651d9f05da8b97a024c5ed7908f9732d867a19615a3a06de684bd0b8424
         | 
| 7 | 
            +
              data.tar.gz: 67d823281ed419469d6d3addcc13ee9c670f259eeef29a288d8493c10636b77359bfcc00cb53c45f23cffd378b67fb789381bb17fef1753592cf0a4423bb01e3
         | 
    
        data/.gitignore
    CHANGED
    
    
    
        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 | 
            +
             | 
| @@ -30,23 +30,31 @@ module SolidusBacktracs | |
| 30 30 | 
             
                end
         | 
| 31 31 |  | 
| 32 32 | 
             
                def self.backtracs_address(xml, order, type)
         | 
| 33 | 
            -
                   | 
| 34 | 
            -
             | 
| 35 | 
            -
             | 
| 36 | 
            -
             | 
| 37 | 
            -
                    xml. | 
| 38 | 
            -
             | 
| 39 | 
            -
             | 
| 40 | 
            -
             | 
| 41 | 
            -
             | 
| 42 | 
            -
             | 
| 43 | 
            -
             | 
| 44 | 
            -
             | 
| 45 | 
            -
             | 
| 46 | 
            -
             | 
| 47 | 
            -
             | 
| 48 | 
            -
             | 
| 49 | 
            -
             | 
| 33 | 
            +
                  if type.present?
         | 
| 34 | 
            +
                    name = "#{type.to_s.titleize}To"
         | 
| 35 | 
            +
                    address = order.send("#{type}_address")
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                    xml.__send__(name) {
         | 
| 38 | 
            +
                      xml.CompanyName   address.company ? address.company : address.name
         | 
| 39 | 
            +
                      xml.Contact       address.name
         | 
| 40 | 
            +
                      xml.ContactEmail  order.email
         | 
| 41 | 
            +
                      xml.Address1      address.address1
         | 
| 42 | 
            +
                      xml.Address2      address.address2
         | 
| 43 | 
            +
                      xml.City          address.city
         | 
| 44 | 
            +
                      xml.State         address.state ? address.state.abbr : address.state_name
         | 
| 45 | 
            +
                      xml.Zip           address.zipcode
         | 
| 46 | 
            +
                      xml.Phone         address.phone.present? ? address.phone : "000-000-0000"
         | 
| 47 | 
            +
                      xml.PhoneAlt      address.phone.present? ? address.phone : "000-000-0000"
         | 
| 48 | 
            +
                      xml.Country       address.country.iso
         | 
| 49 | 
            +
                    }
         | 
| 50 | 
            +
                  end
         | 
| 51 | 
            +
                else
         | 
| 52 | 
            +
                  Rails.logger.info {
         | 
| 53 | 
            +
                    message: 'missing address type',
         | 
| 54 | 
            +
                    order: order.id,
         | 
| 55 | 
            +
                    type: type
         | 
| 56 | 
            +
                  }.to_s
         | 
| 57 | 
            +
                end
         | 
| 50 58 | 
             
                # rubocop:enable all
         | 
| 51 59 | 
             
              end
         | 
| 52 60 | 
             
            end
         | 
| @@ -20,7 +20,14 @@ module SolidusBacktracs | |
| 20 20 | 
             
                  end
         | 
| 21 21 |  | 
| 22 22 | 
             
                  def query_shipments
         | 
| 23 | 
            -
                    shipments = SolidusBacktracs::Shipment::PendingApiSyncQuery.apply( | 
| 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 | 
            -
                     | 
| 17 | 
            -
                       | 
| 18 | 
            -
             | 
| 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 | 
            -
             | 
| 21 | 
            -
             | 
| 22 | 
            -
             | 
| 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 | 
            -
             | 
| 27 | 
            -
                       | 
| 28 | 
            -
             | 
| 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 | 
            -
                       | 
| 33 | 
            -
             | 
| 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  | 
| 70 | 
            -
                     | 
| 71 | 
            -
             | 
| 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 | 
            -
             | 
| 75 | 
            -
             | 
| 76 | 
            -
             | 
| 77 | 
            -
             | 
| 78 | 
            -
             | 
| 79 | 
            -
                       | 
| 80 | 
            -
             | 
| 81 | 
            -
             | 
| 82 | 
            -
             | 
| 83 | 
            -
             | 
| 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
         | 
| @@ -9,12 +9,12 @@ Gem::Specification.new do |spec| | |
| 9 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/ | 
| 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/ | 
| 17 | 
            -
              spec.metadata['changelog_uri'] = 'https://github.com/ | 
| 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( | 
| 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( | 
| 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( | 
| 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. | 
| 4 | 
            +
              version: 2.2.4
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Zeryab Ali
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: exe
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2022-05- | 
| 11 | 
            +
            date: 2022-05-19 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: httparty
         | 
| @@ -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 | 
            -
            -  | 
| 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/ | 
| 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/ | 
| 205 | 
            -
              source_code_uri: https://github.com/ | 
| 206 | 
            -
              changelog_uri: https://github.com/ | 
| 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:
         |