Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
zai_payment (2.8.0)
zai_payment (2.8.1)
base64 (~> 0.3.0)
faraday (~> 2.0)
openssl (~> 3.3)
Expand Down
19 changes: 19 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
## [Released]

## [2.8.1] - 2025-11-07

### Fixed
- **Response Data Extraction Bug**: Fixed `.data` method returning only `routing_number` value instead of full object 🐛
- Removed `routing_number` from `RESPONSE_DATA_KEYS` constant - it's a field within responses, not a collection wrapper key
- The `.data` method was incorrectly treating `routing_number` as a top-level data key
- This caused `response.data` to return just `"803320"` (the routing number) instead of the complete virtual account object
- Now properly returns the full response object when no wrapper key is found
- Affected resources: Virtual Accounts (and potentially other resources with `routing_number` field)
- Updated test mocks to match actual API response format (flat objects for single resources)

### Changed
- **Virtual Account Test Fixtures**: Updated response structure to match actual Zai API format
- Single resource responses (show, create, update) now return flat objects without wrapper keys
- Collection responses (list) continue to use `virtual_accounts` wrapper key
- All 87 virtual account tests passing with corrected response structure

**Full Changelog**: https://github.com/Sentia/zai-payment/compare/v2.8.0...v2.8.1

## [2.8.0] - 2025-11-07

### Added
Expand Down
24 changes: 13 additions & 11 deletions docs/bank_accounts.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ Validate a US bank routing number before creating an account. This can be used t
response = bank_accounts.validate_routing_number('122235821')

if response.success?
routing_info = response.data
routing_info = response.data['routing_number']
puts "Routing Number: #{routing_info['routing_number']}"
puts "Bank Name: #{routing_info['customer_name']}"
puts "City: #{routing_info['city']}"
Expand All @@ -133,16 +133,18 @@ end

```ruby
{
"routing_number" => "122235821",
"customer_name" => "US BANK NA",
"address" => "EP-MN-WN1A",
"city" => "ST. PAUL",
"state_code" => "MN",
"zip" => "55107",
"zip_extension" => "1419",
"phone_area_code" => "800",
"phone_prefix" => "937",
"phone_suffix" => "631"
"routing_number" => {
"routing_number" => "122235821",
"customer_name" => "US BANK NA",
"address" => "EP-MN-WN1A",
"city" => "ST. PAUL",
"state_code" => "MN",
"zip" => "55107",
"zip_extension" => "1419",
"phone_area_code" => "800",
"phone_prefix" => "937",
"phone_suffix" => "631"
}
}
```

Expand Down
6 changes: 3 additions & 3 deletions examples/bank_accounts.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ bank_accounts = ZaiPayment::Resources::BankAccount.new
response = bank_accounts.validate_routing_number('122235821')

if response.success?
routing_info = response.data
routing_info = response.data['routing_number']

puts "Routing Number Validation Results:"
puts " Routing Number: #{routing_info['routing_number']}"
Expand Down Expand Up @@ -197,7 +197,7 @@ begin
validation_response = bank_accounts.validate_routing_number(routing_number)

if validation_response.success?
bank_info = validation_response.data
bank_info = validation_response.data['routing_number']

# Show user the bank information for confirmation
puts "You are creating an account with:"
Expand Down Expand Up @@ -246,7 +246,7 @@ class BankAccountsController < ApplicationController
response = bank_accounts.validate_routing_number(routing_number)

if response.success?
bank_info = response.data
bank_info = response.data['routing_number']

# Return bank info to display in the form
render json: {
Expand Down
2 changes: 1 addition & 1 deletion lib/zai_payment/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Response
RESPONSE_DATA_KEYS = %w[
webhooks users items fees transactions
batch_transactions batches bpay_accounts bank_accounts card_accounts
wallet_accounts virtual_accounts routing_number disbursements pay_ids
wallet_accounts virtual_accounts disbursements pay_ids
].freeze

def initialize(faraday_response)
Expand Down
2 changes: 1 addition & 1 deletion lib/zai_payment/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module ZaiPayment
VERSION = '2.8.0'
VERSION = '2.8.1'
end
12 changes: 10 additions & 2 deletions spec/zai_payment/resources/bank_account_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,16 @@
it 'returns routing number details' do
response = bank_account_resource.validate_routing_number('122235821')

expect(response.data['routing_number']).to eq('122235821')
expect(response.data['customer_name']).to eq('US BANK NA')
expect(response.data).to be_a(Hash)
expect(response.data['routing_number']['routing_number']).to eq('122235821')
end

it 'returns city, state, and zip' do
response = bank_account_resource.validate_routing_number('122235821')

expect(response.data['routing_number']['customer_name']).to eq('US BANK NA')
expect(response.data['routing_number']['city']).to eq('ST. PAUL')
expect(response.data['routing_number']['state_code']).to eq('MN')
end
end

Expand Down
133 changes: 62 additions & 71 deletions spec/zai_payment/resources/virtual_account_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -207,22 +207,20 @@
describe '#show' do
let(:virtual_account_data) do
{
'virtual_accounts' => {
'id' => '46deb476-c1a6-41eb-8eb7-26a695bbe5bc',
'routing_number' => '123456',
'account_number' => '100000017',
'currency' => 'AUD',
'user_external_id' => '46deb476-c1a6-41eb-8eb7-26a695bbe5bc',
'wallet_account_id' => '46deb476-c1a6-41eb-8eb7-26a695bbe5bc',
'status' => 'active',
'created_at' => '2020-04-27T20:28:22.378Z',
'updated_at' => '2020-04-27T20:28:22.378Z',
'account_type' => 'NIND',
'full_legal_account_name' => 'Prop Tech Marketplace',
'account_name' => 'Real Estate Agency X',
'aka_names' => ['Realestate Agency X', 'Realestate Agency X of PropTech Marketplace'],
'merchant_id' => '46deb476c1a641eb8eb726a695bbe5bc'
}
'id' => '46deb476-c1a6-41eb-8eb7-26a695bbe5bc',
'routing_number' => '123456',
'account_number' => '100000017',
'currency' => 'AUD',
'user_external_id' => '46deb476-c1a6-41eb-8eb7-26a695bbe5bc',
'wallet_account_id' => '46deb476-c1a6-41eb-8eb7-26a695bbe5bc',
'status' => 'active',
'created_at' => '2020-04-27T20:28:22.378Z',
'updated_at' => '2020-04-27T20:28:22.378Z',
'account_type' => 'NIND',
'full_legal_account_name' => 'Prop Tech Marketplace',
'account_name' => 'Real Estate Agency X',
'aka_names' => ['Realestate Agency X', 'Realestate Agency X of PropTech Marketplace'],
'merchant_id' => '46deb476c1a641eb8eb726a695bbe5bc'
}
end

Expand Down Expand Up @@ -337,22 +335,20 @@
describe '#update_aka_names' do
let(:updated_virtual_account_data) do
{
'virtual_accounts' => {
'id' => '46deb476-c1a6-41eb-8eb7-26a695bbe5bc',
'routing_number' => '123456',
'account_number' => '100000017',
'currency' => 'AUD',
'user_external_id' => '46deb476-c1a6-41eb-8eb7-26a695bbe5bc',
'wallet_account_id' => '46deb476-c1a6-41eb-8eb7-26a695bbe5bc',
'status' => 'active',
'created_at' => '2020-04-27T20:28:22.378Z',
'updated_at' => '2020-04-27T20:28:22.378Z',
'account_type' => 'NIND',
'full_legal_account_name' => 'Prop Tech Marketplace',
'account_name' => 'Real Estate Agency X',
'aka_names' => ['Updated Name 1', 'Updated Name 2'],
'merchant_id' => '46deb476c1a641eb8eb726a695bbe5bc'
}
'id' => '46deb476-c1a6-41eb-8eb7-26a695bbe5bc',
'routing_number' => '123456',
'account_number' => '100000017',
'currency' => 'AUD',
'user_external_id' => '46deb476-c1a6-41eb-8eb7-26a695bbe5bc',
'wallet_account_id' => '46deb476-c1a6-41eb-8eb7-26a695bbe5bc',
'status' => 'active',
'created_at' => '2020-04-27T20:28:22.378Z',
'updated_at' => '2020-04-27T20:28:22.378Z',
'account_type' => 'NIND',
'full_legal_account_name' => 'Prop Tech Marketplace',
'account_name' => 'Real Estate Agency X',
'aka_names' => ['Updated Name 1', 'Updated Name 2'],
'merchant_id' => '46deb476c1a641eb8eb726a695bbe5bc'
}
end

Expand Down Expand Up @@ -388,7 +384,7 @@
before do
stubs.patch('/virtual_accounts/46deb476-c1a6-41eb-8eb7-26a695bbe5bc/aka_names') do
[200, { 'Content-Type' => 'application/json' },
{ 'virtual_accounts' => updated_virtual_account_data['virtual_accounts'].merge('aka_names' => []) }]
updated_virtual_account_data.merge('aka_names' => [])]
end
end

Expand All @@ -407,8 +403,8 @@
context 'with single aka_name' do
before do
stubs.patch('/virtual_accounts/46deb476-c1a6-41eb-8eb7-26a695bbe5bc/aka_names') do
updated_data = updated_virtual_account_data['virtual_accounts'].merge('aka_names' => ['Single Name'])
[200, { 'Content-Type' => 'application/json' }, { 'virtual_accounts' => updated_data }]
updated_data = updated_virtual_account_data.merge('aka_names' => ['Single Name'])
[200, { 'Content-Type' => 'application/json' }, updated_data]
end
end

Expand All @@ -426,8 +422,7 @@
before do
stubs.patch('/virtual_accounts/46deb476-c1a6-41eb-8eb7-26a695bbe5bc/aka_names') do
[200, { 'Content-Type' => 'application/json' },
{ 'virtual_accounts' => updated_virtual_account_data['virtual_accounts']
.merge('aka_names' => ['Name 1', 'Name 2', 'Name 3']) }]
updated_virtual_account_data.merge('aka_names' => ['Name 1', 'Name 2', 'Name 3'])]
end
end

Expand Down Expand Up @@ -531,22 +526,20 @@
describe '#update_account_name' do
let(:updated_account_data) do
{
'virtual_accounts' => {
'id' => '46deb476-c1a6-41eb-8eb7-26a695bbe5bc',
'routing_number' => '123456',
'account_number' => '100000017',
'currency' => 'AUD',
'user_external_id' => '46deb476-c1a6-41eb-8eb7-26a695bbe5bc',
'wallet_account_id' => '46deb476-c1a6-41eb-8eb7-26a695bbe5bc',
'status' => 'active',
'created_at' => '2020-04-27T20:28:22.378Z',
'updated_at' => '2020-04-27T20:28:22.378Z',
'account_type' => 'NIND',
'full_legal_account_name' => 'Prop Tech Marketplace',
'account_name' => 'Updated Account Name',
'aka_names' => ['Realestate Agency X'],
'merchant_id' => '46deb476c1a641eb8eb726a695bbe5bc'
}
'id' => '46deb476-c1a6-41eb-8eb7-26a695bbe5bc',
'routing_number' => '123456',
'account_number' => '100000017',
'currency' => 'AUD',
'user_external_id' => '46deb476-c1a6-41eb-8eb7-26a695bbe5bc',
'wallet_account_id' => '46deb476-c1a6-41eb-8eb7-26a695bbe5bc',
'status' => 'active',
'created_at' => '2020-04-27T20:28:22.378Z',
'updated_at' => '2020-04-27T20:28:22.378Z',
'account_type' => 'NIND',
'full_legal_account_name' => 'Prop Tech Marketplace',
'account_name' => 'Updated Account Name',
'aka_names' => ['Realestate Agency X'],
'merchant_id' => '46deb476c1a641eb8eb726a695bbe5bc'
}
end

Expand Down Expand Up @@ -582,8 +575,8 @@
before do
stubs.patch('/virtual_accounts/46deb476-c1a6-41eb-8eb7-26a695bbe5bc/account_name') do
long_name = 'A' * 140
updated_data = updated_account_data['virtual_accounts'].merge('account_name' => long_name)
[202, { 'Content-Type' => 'application/json' }, { 'virtual_accounts' => updated_data }]
updated_data = updated_account_data.merge('account_name' => long_name)
[202, { 'Content-Type' => 'application/json' }, updated_data]
end
end

Expand Down Expand Up @@ -850,22 +843,20 @@
describe '#create' do
let(:virtual_account_data) do
{
'virtual_accounts' => {
'id' => 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee',
'routing_number' => '123456',
'account_number' => '100000017',
'currency' => 'AUD',
'wallet_account_id' => 'ae07556e-22ef-11eb-adc1-0242ac120002',
'user_external_id' => 'ca12346e-22ef-11eb-adc1-0242ac120002',
'status' => 'pending_activation',
'created_at' => '2020-04-27T20:28:22.378Z',
'updated_at' => '2020-04-27T20:28:22.378Z',
'account_type' => 'NIND',
'full_legal_account_name' => 'Prop Tech Marketplace',
'account_name' => 'Real Estate Agency X',
'aka_names' => ['Realestate agency X'],
'merchant_id' => '46deb476c1a641eb8eb726a695bbe5bc'
}
'id' => 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee',
'routing_number' => '123456',
'account_number' => '100000017',
'currency' => 'AUD',
'wallet_account_id' => 'ae07556e-22ef-11eb-adc1-0242ac120002',
'user_external_id' => 'ca12346e-22ef-11eb-adc1-0242ac120002',
'status' => 'pending_activation',
'created_at' => '2020-04-27T20:28:22.378Z',
'updated_at' => '2020-04-27T20:28:22.378Z',
'account_type' => 'NIND',
'full_legal_account_name' => 'Prop Tech Marketplace',
'account_name' => 'Real Estate Agency X',
'aka_names' => ['Realestate agency X'],
'merchant_id' => '46deb476c1a641eb8eb726a695bbe5bc'
}
end

Expand Down