From d0906d491d8e155c9f46dc4b8bf8f9e1a9f31e83 Mon Sep 17 00:00:00 2001 From: Trevor Nelson Date: Tue, 3 Sep 2024 17:13:25 -0400 Subject: [PATCH] Add CounterParty API resource --- Gemfile.lock | 2 +- lib/unit-ruby.rb | 1 + lib/unit-ruby/ach_counterparty.rb | 22 +++++++++++++++ lib/unit-ruby/version.rb | 2 +- spec/features/ach_counterparty_spec.rb | 39 ++++++++++++++++++++++++++ spec/version_spec.rb | 2 +- 6 files changed, 65 insertions(+), 3 deletions(-) create mode 100644 lib/unit-ruby/ach_counterparty.rb create mode 100644 spec/features/ach_counterparty_spec.rb diff --git a/Gemfile.lock b/Gemfile.lock index a8b448c..970133e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - unit-ruby (0.5.0) + unit-ruby (0.6.0) activesupport (>= 6.1.5, < 7.1.0) faraday (~> 1.8.0) faraday_middleware (~> 1.0.0) diff --git a/lib/unit-ruby.rb b/lib/unit-ruby.rb index 900e63b..ba444d5 100644 --- a/lib/unit-ruby.rb +++ b/lib/unit-ruby.rb @@ -24,6 +24,7 @@ require 'unit-ruby/application_form' require 'unit-ruby/atm_location' require 'unit-ruby/authorization' +require 'unit-ruby/ach_counterparty' require 'unit-ruby/customer_token_verification' require 'unit-ruby/customer_token' require 'unit-ruby/deposit_account' diff --git a/lib/unit-ruby/ach_counterparty.rb b/lib/unit-ruby/ach_counterparty.rb new file mode 100644 index 0000000..6e7671e --- /dev/null +++ b/lib/unit-ruby/ach_counterparty.rb @@ -0,0 +1,22 @@ +module Unit + class AchCounterparty < APIResource + path '/counterparties' + + attribute :idempotency_key, Types::String # Optional + attribute :tags, Types::Hash # Optional + + attribute :name, Types::String # Name of the account holder + attribute :created_at, Types::DateTime + attribute :routing_number, Types::String # Routing number of account. + attribute :account_number, Types::String # Account number, together with the routingNumber forms the identifier of the account on the ACH network. + attribute :account_type, Types::String # Account type, either Checking, Savings or Loan. Default is Checking. + attribute :type, Types::String # Type of the counterparty, either Business, Person or Unknown. + + belongs_to :customer, class_name: 'Unit::IndividualCustomer' + + include ResourceOperations::List + include ResourceOperations::Create + include ResourceOperations::Save + include ResourceOperations::Find + end +end diff --git a/lib/unit-ruby/version.rb b/lib/unit-ruby/version.rb index 09d251c..ce4c148 100644 --- a/lib/unit-ruby/version.rb +++ b/lib/unit-ruby/version.rb @@ -1,3 +1,3 @@ module Unit - VERSION = '0.5.0' + VERSION = '0.6.0' end diff --git a/spec/features/ach_counterparty_spec.rb b/spec/features/ach_counterparty_spec.rb new file mode 100644 index 0000000..7efd1ee --- /dev/null +++ b/spec/features/ach_counterparty_spec.rb @@ -0,0 +1,39 @@ +require 'spec_helper' +require 'securerandom' + +RSpec.describe Unit::AchCounterparty do + before do + establish_connection_to_api! + end + + let(:new_individual_customer) do + Factory.create_individual_customer + end + + it 'creates a counter party' do + counterparty = Unit::AchCounterparty.create( + idempotency_key: SecureRandom.uuid, + name: 'Jane Doe', + routing_number: '812345678', + account_number: '12345569', + account_type: 'Checking', + type: 'Person', + tags: { tag1: 'value1', tag2: 'value2' }, + customer: new_individual_customer + ) + + expect(counterparty.name).to eq 'Jane Doe' + expect(counterparty.routing_number).to eq '812345678' + expect(counterparty.account_number).to eq '12345569' + expect(counterparty.account_type).to eq 'Checking' + expect(counterparty.type).to eq 'Person' + expect(counterparty.tags[:tag1]).to eq 'value1' + expect(counterparty.tags[:tag2]).to eq 'value2' + expect(counterparty.customer.id).to eq new_individual_customer.id + + expect(Unit::AchCounterparty.find(counterparty.id).id).to eq counterparty.id + expect( + Unit::AchCounterparty.list(where: { customer_id: new_individual_customer.id }) + ).not_to be_empty + end +end diff --git a/spec/version_spec.rb b/spec/version_spec.rb index 8f16ba1..e69b1c5 100644 --- a/spec/version_spec.rb +++ b/spec/version_spec.rb @@ -2,6 +2,6 @@ RSpec.describe Unit do it 'returns the correct version' do - expect(Unit::VERSION).to eq '0.5.0' + expect(Unit::VERSION).to eq '0.6.0' end end