Sha256: efb2645cb1b87e62ad6b3dc1b1da976e890fdc3b3fee53fb732f7ba97edc2629

Contents?: true

Size: 1.32 KB

Versions: 1

Compression:

Stored size: 1.32 KB

Contents

require 'workarea'
require 'workarea/storefront'
require 'workarea/admin'

require 'workarea/checkoutdotcom/engine'
require 'workarea/checkoutdotcom/version'

require 'active_merchant/billing/bogus_checkout_v2_gateway'

module Workarea
  module Checkoutdotcom
    # Credentials for checkoutdotcom from Rails secrets.
    #
    # @return [Hash]
    def self.credentials
      return {} unless Rails.application.secrets.checkoutdotcom.present?
      Rails.application.secrets.checkoutdotcom.symbolize_keys
    end

    # Conditionally use the real gateway when secrets are present.
    # Otherwise, use the bogus gateway.
    #
    # @return [ActiveMerchant::Billing::Gateway]
    def self.gateway
      Workarea.config.gateways.credit_card
    end

    def self.gateway=(gateway)
      Workarea.config.gateways.credit_card = gateway
    end

    def self.auto_initialize_gateway
      if credentials.present?
        if ENV['HTTP_PROXY'].present?
          uri = URI.parse(ENV['HTTP_PROXY'])
          ActiveMerchant::Billing::CheckoutV2Gateway.proxy_address = uri.host
          ActiveMerchant::Billing::CheckoutV2Gateway.proxy_port = uri.port
        end

        self.gateway = ActiveMerchant::Billing::CheckoutV2Gateway.new credentials
      else
        self.gateway = ActiveMerchant::Billing::BogusCheckoutV2Gateway.new
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
workarea-checkoutdotcom-1.2.0 lib/workarea/checkoutdotcom.rb