Sha256: 31a909bf9f757c67e54d5f4921392c5fca0af66cca92d154f6b88204c1621d31

Contents?: true

Size: 1.4 KB

Versions: 3

Compression:

Stored size: 1.4 KB

Contents

# frozen_string_literal: true

require 'credit_gateway/base_repository'
require 'credit_gateway/bank_subject'
require 'credit_gateway/bank_connection'
require 'credit_gateway/bank_connection_params'

module CreditGateway
  class BankRepository < BaseRepository
    def create_subject(company_id)
      result = post('/bank/subjects', params: { companyId: company_id })

      BankSubject.build(json: result.body)
    end

    def lookup_subjects(company_id)
      result = get('/bank/subjects', params: { companyId: company_id })

      result.body.fetch(:data, []).map do |subject|
        BankSubject.build(json: subject)
      end
    end

    # connection_params - CreditGateway::BankConnectionParams
    def create_connection(subject_id, connection_params:)
      url = format_url(
        '/bank/subjects/:subject_id/connections',
        subject_id: subject_id.to_s
      )
      result = post(url, params: connection_params.as_json)

      BankConnection.build(json: result.body)
    end

    # Submits bank data to prepare the report
    # bank_data_request - CreditGateway::BankDataRequest
    def upload_bank_data(subject_id, connection_id, bank_data_request)
      url = format_url(
        '/bank/subjects/:subject_id/connections/:connection_id/upload',
        subject_id: subject_id.to_s,
        connection_id: connection_id.to_s
      )
      post(url, params: bank_data_request.as_json)

      true
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
credit_gateway-0.3.2 lib/credit_gateway/bank_repository.rb
credit_gateway-0.3.1 lib/credit_gateway/bank_repository.rb
credit_gateway-0.3.0 lib/credit_gateway/bank_repository.rb