Sha256: 69a4b374b8da593cf88385053ac4031433808b79a98cefabf89eadbba695c3a5

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/afterpay/engine'
require 'workarea/afterpay/version'

require 'workarea/afterpay/bogus_gateway'
require 'workarea/afterpay/gateway'
require 'workarea/afterpay/response'


require "faraday"

module Workarea
  module Afterpay
     def self.credentials
      (Rails.application.secrets.afterpay || {}).deep_symbolize_keys
    end

    def self.config
      Workarea.config.afterpay
    end

    def self.merchant_id(location)
      return unless credentials.present?

      country = location.to_sym.downcase

      return unless credentials[country].present?

      credentials[country][:merchant_id]
    end

    def self.secret_key(location)
      return unless credentials.present?

      country = location.to_sym.downcase
      credentials[country][:secret_key]
    end

    def self.test?
      config[:test]
    end

    # Conditionally use the real gateway when secrets are present.
    # Otherwise, use the bogus gateway.
    #
    # @return [Afterpay::Gateway]
    def self.gateway(location, options = {})
      if credentials.present?
        options.merge!(location: location, test: test?)
        Afterpay::Gateway.new(merchant_id(location), secret_key(location), options)
      else
        Afterpay::BogusGateway.new
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
workarea-afterpay-2.0.2 lib/workarea/afterpay.rb