Sha256: 4cc3d8ab33fe8ab6b7ef54321a3161305d11aad38931373d3092824e7fcafbf5

Contents?: true

Size: 896 Bytes

Versions: 1

Compression:

Stored size: 896 Bytes

Contents

# frozen_string_literal: true

require_relative "http_client"
require "base64"

module ActAsApiClient
  module Clients
    module AuthorizeNetWebhooksClient
      include HttpClient
      DEFAULT_OPTIONS = {
        mode: :production
      }.freeze

      def initialize
        @options = DEFAULT_OPTIONS.merge(options)
      end

      def find(uuid)
        raise StandardError, "uuid is not provided" if uuid.empty?

        get("https://#{base_uri}/rest/v1/webhooks/#{uuid}",
            headers: { "Authorization" => auth })
      end

      private

      def base_uri
        if @options[:mode] == :test
          "apitest.authorize.net"
        else
          "authorize.net"
        end
      end

      def auth
        if options[:payment_user]
          "Basic #{Base64.strict_encode64("#{options[:payment_user]}:#{options[:payment_pass]}")}"
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
act_as_api_client-0.2.0 lib/act_as_api_client/clients/authorize_net_webhooks_client.rb