Sha256: 30903989a97d87c806bde19a368d2beccaf6add0eb1018cd0d72951a29d0235f

Contents?: true

Size: 1.7 KB

Versions: 4

Compression:

Stored size: 1.7 KB

Contents

# frozen_string_literal: true

module Killbill
  module Deposit
    class DepositClient < KillBillClient::Model::Resource
      KILLBILL_DEPOSIT_PREFIX = '/plugins/killbill-deposit'

      class << self
        def record_payments(account_id, effective_date, payment_reference_number, deposit_type, invoice_payments, user = nil, reason = nil, comment = nil, options = {})
          payments = []
          invoice_payments.each do |invoice_number, payment_amount|
            payments << { invoiceNumber: invoice_number, paymentAmount: payment_amount }
          end

          body = {
            accountId: account_id,
            effectiveDate: effective_date,
            paymentReferenceNumber: payment_reference_number,
            depositType: deposit_type,
            payments: payments
          }.to_json

          path = "#{KILLBILL_DEPOSIT_PREFIX}/record"
          response = KillBillClient::API.post path,
                                              body,
                                              {},
                                              {
                                                user: user,
                                                reason: reason,
                                                comment: comment
                                              }.merge(options)
          response.body
        end

        def deposit_plugin_available?(options = nil)
          path = "#{KILLBILL_DEPOSIT_PREFIX}/healthcheck"
          KillBillClient::API.get path, nil, options

          [true, nil]
          # Response error if the deposit plugin is not listening
        rescue KillBillClient::API::ResponseError => e
          [false, e.message.to_s]
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
killbill-deposit-1.0.3 lib/deposit/client.rb
killbill-deposit-1.0.2 lib/deposit/client.rb
killbill-deposit-0.1.1 lib/deposit/client.rb
killbill-deposit-1.0.1 lib/deposit/client.rb