Sha256: 7fbe9d71dbe5378cc7cea2db611b2fa496b98739bbc1f0b0edf6b2432a7c8daf

Contents?: true

Size: 1.65 KB

Versions: 7

Compression:

Stored size: 1.65 KB

Contents

# frozen_string_literal: true

require 'solidus_core'
require 'solidus_support'

module SolidusBolt
  class Engine < Rails::Engine
    include SolidusSupport::EngineExtensions

    isolate_namespace ::Spree

    engine_name 'solidus_bolt'

    initializer "solidus_bolt.add_static_preference", after: "spree.register.payment_methods" do |app|
      app.config.spree.payment_methods << SolidusBolt::PaymentMethod
      Spree::Config.static_model_preferences.add(
        SolidusBolt::PaymentMethod,
        'bolt_credentials',
        bolt_credentials_hash
      )
      Spree::Config.static_model_preferences.add(
        SolidusBolt::PaymentMethod,
        'bolt_config_credentials',
        bolt_config_credentials_hash
      )

      Spree::PermittedAttributes.source_attributes.concat(%i[
        card_token card_last4 card_bin card_number card_expiration card_postal_code create_bolt_account
      ])
    end

    # use rspec for tests
    config.generators do |g|
      g.test_framework :rspec
    end

    private

    def bolt_credentials_hash
      {
        bolt_api_key: ENV['BOLT_API_KEY'],
        bolt_signing_secret: ENV['BOLT_SIGNING_SECRET'],
        bolt_publishable_key: ENV['BOLT_PUBLISHABLE_KEY'],
      }
    end

    def bolt_config_credentials_hash
      begin
        bolt_config = SolidusBolt::BoltConfiguration.fetch
      rescue ActiveRecord::StatementInvalid
        bolt_config = nil
      ensure
        bolt_config_hash = {
          bolt_api_key: bolt_config&.api_key,
          bolt_signing_secret: bolt_config&.signing_secret,
          bolt_publishable_key: bolt_config&.publishable_key,
        }
      end
      bolt_config_hash
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
solidus_bolt-0.6.0 lib/solidus_bolt/engine.rb
solidus_bolt-0.5.0 lib/solidus_bolt/engine.rb
solidus_bolt-0.4.0 lib/solidus_bolt/engine.rb
solidus_bolt-0.3.0 lib/solidus_bolt/engine.rb
solidus_bolt-0.2.0 lib/solidus_bolt/engine.rb
solidus_bolt-0.1.0 lib/solidus_bolt/engine.rb
solidus_bolt-0.0.1 lib/solidus_bolt/engine.rb