Sha256: cc4710b569aa4207ebd93ea97768ac9fc01a90d063957141b055b95ad3d85a7c

Contents?: true

Size: 1.93 KB

Versions: 12

Compression:

Stored size: 1.93 KB

Contents

# frozen_string_literal: true

module Bckbn
  module Transaction
    REQUEST_BASE = %i[
      id
      report_group
    ].freeze

    AUTHORIZATION_REQUEST_MEMBERS = [
      *REQUEST_BASE,
      :amount,
      :bill_to_address,
      :cardholder_authentication,
      :card,
      :order_id,
      :order_source,
      :partial
    ].freeze

    ECHECK_SALE_REQUEST_MEMBERS = [
      *REQUEST_BASE,
      :amount,
      :bill_to_address,
      :echeck,
      :order_id,
      :order_source
    ].freeze

    CAPTURE_REQUEST_MEMBERS = [*REQUEST_BASE, :litle_txn_id, :partial].freeze
    VOID_REQUEST_MEMBERS    = [*REQUEST_BASE, :litle_txn_id].freeze
    CREDIT_REQUEST_MEMBERS  = [*REQUEST_BASE, :litle_txn_id, :amount].freeze

    module RequestShared
      def initialize(opts)
        valid_opts = opts.slice(*members)
        valid_opts.each { |key, value| public_send("#{key}=", value) }
      end

      # use to_h for any necessary key formatting
      def to_h
        h = super
        h.delete(:cardholder_authentication) if h[:cardholder_authentication].nil?
        h
      end
    end

    AuthorizationRequest = Struct.new(*AUTHORIZATION_REQUEST_MEMBERS, keyword_init: true)
    SaleRequest          = Struct.new(*AUTHORIZATION_REQUEST_MEMBERS, keyword_init: true)
    CaptureRequest       = Struct.new(*CAPTURE_REQUEST_MEMBERS, keyword_init: true)
    CreditRequest        = Struct.new(*CREDIT_REQUEST_MEMBERS, keyword_init: true)
    EcheckCreditRequest  = Struct.new(*CREDIT_REQUEST_MEMBERS, keyword_init: true)
    VoidRequest          = Struct.new(*VOID_REQUEST_MEMBERS, keyword_init: true)
    EcheckVoidRequest    = Struct.new(*VOID_REQUEST_MEMBERS, keyword_init: true)
    EcheckSaleRequest    = Struct.new(*ECHECK_SALE_REQUEST_MEMBERS, keyword_init: true)
    [
      AuthorizationRequest,
      CaptureRequest,
      CreditRequest,
      EcheckSaleRequest,
      SaleRequest,
      VoidRequest
    ].each { |rc| rc.send(:include, RequestShared) }
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
bckbn-3.0.1 lib/bckbn/resources/transactions/models/requests.rb
bckbn-3.0.0 lib/bckbn/resources/transaction/models/requests.rb
bckbn-2.2.1 lib/bckbn/resources/transaction/models/requests.rb
bckbn-2.1.1 lib/bckbn/resources/transaction/models/requests.rb
bckbn-2.1.0 lib/bckbn/resources/transaction/models/requests.rb
bckbn-2.0.0 lib/bckbn/resources/transaction/models/requests.rb
bckbn-1.1.0 lib/bckbn/resources/transaction/models/requests.rb
bckbn-1.0.0 lib/bckbn/resources/transaction/models/requests.rb
bckbn-0.2.0 lib/bckbn/resources/transaction/models/requests.rb
bckbn-0.1.2 lib/bckbn/resources/transaction/models/requests.rb
bckbn-0.1.1 lib/bckbn/resources/transaction/models/requests.rb
bckbn-0.1.0 lib/bckbn/resources/transaction/models/requests.rb