Sha256: fe431a8663edafeeb0d8718889d308cb914f6967689441860c51768c0d4e2cc3

Contents?: true

Size: 1.74 KB

Versions: 37

Compression:

Stored size: 1.74 KB

Contents

module RockRMS
  class Client
    module PaymentDetail
      def list_payment_details(options = {})
        res = get(payment_detail_path, options)
        Response::PaymentDetail.format(res)
      end

      def create_payment_detail(payment_type:, foreign_key: nil, card_type: nil, last_4: nil)
        options = {
          'CurrencyTypeValueId' => cast_payment_type(payment_type),
          'CreditCardTypeValueId' => cast_card_type(card_type),
          'ForeignKey' => foreign_key
        }
        options['AccountNumberMasked'] = "************#{last_4}" if last_4

        post(payment_detail_path, options)
      end

      def update_payment_detail(id, foreign_key: nil, card_type: nil, last_4: nil)
        options = {}

        options['CreditCardTypeValueId'] = cast_card_type(card_type) if card_type
        options['ForeignKey'] = foreign_key if foreign_key
        options['AccountNumberMasked'] = "************#{last_4}" if last_4

        patch(payment_detail_path(id), options)
      end

      def delete_payment_detail(id)
        delete(payment_detail_path(id))
      end

      private

      def cast_payment_type(payment_type)
        case payment_type
        when 'cash'
          6
        when 'check'
          9
        when 'card'
          156
        when 'bank account', 'ach'
          157
        end
      end

      def cast_card_type(card_type)
        case card_type
        when 'visa'
          7
        when 'mastercard'
          8
        when 'amex'
          159
        when 'discover'
          160
        when 'diner'
          161
        when 'jcb'
          162
        end
      end

      def payment_detail_path(id = nil)
        id ? "FinancialPaymentDetails/#{id}" : 'FinancialPaymentDetails'
      end
    end
  end
end

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
rock_rms-8.20.0 lib/rock_rms/resources/payment_detail.rb
rock_rms-8.19.0 lib/rock_rms/resources/payment_detail.rb
rock_rms-8.18.0 lib/rock_rms/resources/payment_detail.rb
rock_rms-8.17.0 lib/rock_rms/resources/payment_detail.rb
rock_rms-8.16.0 lib/rock_rms/resources/payment_detail.rb
rock_rms-8.15.2 lib/rock_rms/resources/payment_detail.rb
rock_rms-8.15.1 lib/rock_rms/resources/payment_detail.rb
rock_rms-8.15.0 lib/rock_rms/resources/payment_detail.rb
rock_rms-8.14.0 lib/rock_rms/resources/payment_detail.rb
rock_rms-8.13.0 lib/rock_rms/resources/payment_detail.rb
rock_rms-8.12.0 lib/rock_rms/resources/payment_detail.rb
rock_rms-8.11.0 lib/rock_rms/resources/payment_detail.rb
rock_rms-8.10.0 lib/rock_rms/resources/payment_detail.rb
rock_rms-8.9.0 lib/rock_rms/resources/payment_detail.rb
rock_rms-8.8.0 lib/rock_rms/resources/payment_detail.rb
rock_rms-8.7.0 lib/rock_rms/resources/payment_detail.rb
rock_rms-8.6.0 lib/rock_rms/resources/payment_detail.rb
rock_rms-8.5.0 lib/rock_rms/resources/payment_detail.rb
rock_rms-8.4.0 lib/rock_rms/resources/payment_detail.rb
rock_rms-8.3.0 lib/rock_rms/resources/payment_detail.rb