Sha256: c76b6a437fff441bbf75e49fa1e1b9cb4a30e9f4705c6b3e6a52ddf52569d541

Contents?: true

Size: 1.85 KB

Versions: 1

Compression:

Stored size: 1.85 KB

Contents

# frozen_string_literal: true

module Bckbn
  module Transaction
    ENDPOINTS = {
      authorization: "/transactions/authorization",
      capture: "/transactions/capture",
      credit: "/transactions/credit",
      sale: "/transactions/sale",
      void: "/transactions/void",
      echeck_credit: "/transactions/echeck_credit",
      echeck_sale: "/transactions/echeck_sale",
      echeck_void: "/transactions/echeck_void"
    }.freeze
    private_constant :ENDPOINTS

    class << self
      def authorization(body, config = {})
        process_transaction(__method__, body, config, AuthorizationRequest, AuthorizationResponse)
      end

      def capture(body, config = {})
        process_transaction(__method__, body, config, CaptureRequest, CaptureResponse)
      end

      def credit(body, config = {})
        process_transaction(__method__, body, config, CreditRequest, CreditResponse)
      end

      def sale(body, config = {})
        process_transaction(__method__, body, config, SaleRequest, SaleResponse)
      end

      def void(body, config = {})
        process_transaction(__method__, body, config, VoidRequest, VoidResponse)
      end

      def echeck_credit(body, config = {})
        process_transaction(__method__, body, config, EcheckCreditRequest, EcheckCreditResponse)
      end

      def echeck_sale(body, config = {})
        process_transaction(__method__, body, config, EcheckSaleRequest, EcheckSaleResponse)
      end

      def echeck_void(body, config = {})
        process_transaction(__method__, body, config, EcheckVoidRequest, EcheckVoidResponse)
      end

      private

      def process_transaction(method, body, config, request_klass, response_klass)
        request = request_klass.new(body)
        conn = Bckbn::Connection.new(config)
        conn.post_to_api(ENDPOINTS.fetch(method), request.to_h, response_klass)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
bckbn-3.0.1 lib/bckbn/resources/transactions/api.rb