Sha256: 5a400c45cc047612538384e0fb8f446f62cff9f92cbbe41b35f755580206405e

Contents?: true

Size: 1.25 KB

Versions: 17

Compression:

Stored size: 1.25 KB

Contents

module RockRMS
  class Client
    module Refund
      PATH = 'FinancialTransactionRefunds'.freeze

      def create_refund(
        batch_id:,
        date:,
        reason_id:,
        transaction_id:
      )
        old_transaction = list_transactions(
          '$expand' => 'TransactionDetails',
          '$filter' => "Id eq #{transaction_id}"
        ).first

        params = {
          'OriginalTransactionId' => transaction_id,
          'RefundReasonValueId' => reason_id,
          'FinancialTransaction' => {
            'AuthorizedPersonAliasId' => old_transaction[:person_id],
            'BatchId' => batch_id,
            'FinancialPaymentDetailId' => old_transaction[:payment_detail_id],
            'TransactionDateTime' => date,
            'TransactionDetails'  => translate_negative(old_transaction[:details]),
            'TransactionTypeValueId' => old_transaction[:transaction_type_id]
          }
        }
        post(refund_path, params)
      end

      private

      def translate_negative(details)
        details.map do |dt|
          {
            'Amount' => -dt[:amount],
            'AccountId' => dt[:fund_id]
          }
        end
      end

      def refund_path(id = nil)
        id ? "#{PATH}/#{id}" : PATH
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
rock_rms-4.2.1 lib/rock_rms/resources/refund.rb
rock_rms-4.2.0 lib/rock_rms/resources/refund.rb
rock_rms-4.1.1 lib/rock_rms/resources/refund.rb
rock_rms-4.1.0 lib/rock_rms/resources/refund.rb
rock_rms-4.0.0 lib/rock_rms/resources/refund.rb
rock_rms-3.9.0 lib/rock_rms/resources/refund.rb
rock_rms-3.8.0 lib/rock_rms/resources/refund.rb
rock_rms-3.7.0 lib/rock_rms/resources/refund.rb
rock_rms-3.6.3 lib/rock_rms/resources/refund.rb
rock_rms-3.6.2 lib/rock_rms/resources/refund.rb
rock_rms-3.6.1 lib/rock_rms/resources/refund.rb
rock_rms-3.6.0 lib/rock_rms/resources/refund.rb
rock_rms-3.5.0 lib/rock_rms/resources/refund.rb
rock_rms-3.4.1 lib/rock_rms/resources/refund.rb
rock_rms-3.4.0 lib/rock_rms/resources/refund.rb
rock_rms-3.2.0 lib/rock_rms/resources/refund.rb
rock_rms-3.1.0 lib/rock_rms/resources/refund.rb