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.6.0)
zai_payment (2.6.1)
base64 (~> 0.3.0)
faraday (~> 2.0)
openssl (~> 3.3)
Expand Down
26 changes: 26 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
## [Released]

## [2.6.1] - 2025-11-03

### Changed
- **Wallet Accounts Response Structure**: Updated to match actual API response format 🔄
- Response now properly returns nested `wallet_accounts` object with complete structure
- Added `wallet_accounts` to `Response#data` automatic extraction
- The `Response#data` method now automatically extracts the `wallet_accounts` object for cleaner API usage
- Updated response includes: `id`, `active`, `created_at`, `updated_at`, `balance`, `currency`
- Enhanced `links` structure with: `self`, `users`, `batch_transactions`, `transactions`, `bpay_details`, `npp_details`, `virtual_accounts`

### Improved
- **API Consistency**: `response.data` now works consistently across all resources
- Before: `response.data['wallet_accounts']['balance']` (manual extraction)
- After: `response.data['balance']` (automatic extraction)
- **Documentation**: Updated all wallet_account documentation and examples
- Updated `docs/users.md` with complete wallet account response structure
- Added note about automatic data extraction in Response class
- Updated code examples in `lib/zai_payment/resources/user.rb`
- **Test Coverage**: Enhanced wallet_account test suite
- Split tests into focused examples for better maintainability
- Added comprehensive validation for all wallet account fields
- Tests for active status, timestamps, and all link fields
- All tests comply with RuboCop standards

**Full Changelog**: https://github.com/Sentia/zai-payment/compare/v2.6.0...v2.6.1

## [2.6.0] - 2025-11-03

### Added
Expand Down
45 changes: 42 additions & 3 deletions docs/users.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,51 @@ Show the user's wallet account using a given user ID.
```ruby
response = ZaiPayment.users.wallet_account('user_id')

# Access wallet account details (automatically extracted from response)
wallet = response.data
puts wallet['id']
puts wallet['balance']
puts wallet['currency']
puts "Wallet Account ID: #{wallet['id']}"
puts "Active: #{wallet['active']}"
puts "Balance: #{wallet['balance']}"
puts "Currency: #{wallet['currency']}"
puts "Created At: #{wallet['created_at']}"
puts "Updated At: #{wallet['updated_at']}"

# Access related resource links
puts "Self URL: #{wallet['links']['self']}"
puts "Users URL: #{wallet['links']['users']}"
puts "Batch Transactions URL: #{wallet['links']['batch_transactions']}"
puts "Transactions URL: #{wallet['links']['transactions']}"
puts "BPay Details URL: #{wallet['links']['bpay_details']}"
puts "NPP Details URL: #{wallet['links']['npp_details']}"
puts "Virtual Accounts URL: #{wallet['links']['virtual_accounts']}"
```

**Response Structure:**

```ruby
{
"wallet_accounts" => {
"id" => "5c1c6b10-4c56-0137-8cd7-0242ac110002",
"active" => true,
"created_at" => "2019-04-29T02:42:31.536Z",
"updated_at" => "2020-05-03T12:01:02.254Z",
"balance" => 663337,
"currency" => "AUD",
"links" => {
"self" => "/transactions/aed45af0-6f63-0138-901c-0a58a9feac03/wallet_accounts",
"users" => "/wallet_accounts/5c1c6b10-4c56-0137-8cd7-0242ac110002/users",
"batch_transactions" => "/wallet_accounts/5c1c6b10-4c56-0137-8cd7-0242ac110002/batch_transactions",
"transactions" => "/wallet_accounts/5c1c6b10-4c56-0137-8cd7-0242ac110002/transactions",
"bpay_details" => "/wallet_accounts/5c1c6b10-4c56-0137-8cd7-0242ac110002/bpay_details",
"npp_details" => "/wallet_accounts/5c1c6b10-4c56-0137-8cd7-0242ac110002/npp_details",
"virtual_accounts" => "/wallet_accounts/5c1c6b10-4c56-0137-8cd7-0242ac110002/virtual_accounts"
}
}
}
```

**Note:** The `response.data` method automatically extracts the `wallet_accounts` object from the response, so you can access the wallet account fields directly without needing to access `response.data['wallet_accounts']`.

### List User Items

Retrieve an ordered and paginated list of existing items the user is associated with.
Expand Down
8 changes: 7 additions & 1 deletion lib/zai_payment/resources/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,13 @@ def update(user_id, **attributes)
# @example
# users = ZaiPayment::Resources::User.new
# response = users.wallet_account("user_id")
# response.data # => {"id" => "...", "balance" => ..., ...}
# # The response.data method automatically extracts the wallet_accounts object
# wallet = response.data
# wallet["id"] # => "5c1c6b10-4c56-0137-8cd7-0242ac110002"
# wallet["balance"] # => 663337
# wallet["currency"] # => "AUD"
# wallet["active"] # => true
# wallet["links"]["transactions"] # => "/wallet_accounts/.../transactions"
#
# @see https://developer.hellozai.com/reference/showuserwalletaccounts
def wallet_account(user_id)
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 bpay_accounts bank_accounts card_accounts
routing_number
wallet_accounts routing_number
].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.6.0'
VERSION = '2.6.1'
end
61 changes: 56 additions & 5 deletions spec/zai_payment/resources/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -861,9 +861,23 @@

let(:wallet_account_data) do
{
'id' => 'wallet_acc_123',
'balance' => 1000,
'currency' => 'USD'
'wallet_accounts' => {
'id' => '5c1c6b10-4c56-0137-8cd7-0242ac110002',
'active' => true,
'created_at' => '2019-04-29T02:42:31.536Z',
'updated_at' => '2020-05-03T12:01:02.254Z',
'balance' => 663_337,
'currency' => 'AUD',
'links' => {
'self' => '/transactions/aed45af0-6f63-0138-901c-0a58a9feac03/wallet_accounts',
'users' => '/wallet_accounts/5c1c6b10-4c56-0137-8cd7-0242ac110002/users',
'batch_transactions' => '/wallet_accounts/5c1c6b10-4c56-0137-8cd7-0242ac110002/batch_transactions',
'transactions' => '/wallet_accounts/5c1c6b10-4c56-0137-8cd7-0242ac110002/transactions',
'bpay_details' => '/wallet_accounts/5c1c6b10-4c56-0137-8cd7-0242ac110002/bpay_details',
'npp_details' => '/wallet_accounts/5c1c6b10-4c56-0137-8cd7-0242ac110002/npp_details',
'virtual_accounts' => '/wallet_accounts/5c1c6b10-4c56-0137-8cd7-0242ac110002/virtual_accounts'
}
}
}
end

Expand All @@ -875,8 +889,45 @@

it 'returns the wallet account details' do
response = user_resource.wallet_account('user_123')
expect(response.data['id']).to eq('wallet_acc_123')
expect(response.data['balance']).to eq(1000)
wallet_data = response.data
expect(wallet_data['id']).to eq('5c1c6b10-4c56-0137-8cd7-0242ac110002')
expect(wallet_data['balance']).to eq(663_337)
expect(wallet_data['currency']).to eq('AUD')
end

it 'returns the wallet account active status' do
response = user_resource.wallet_account('user_123')
wallet_data = response.data
expect(wallet_data['active']).to be true
end

it 'returns the wallet account timestamps' do
response = user_resource.wallet_account('user_123')
wallet_data = response.data
expect(wallet_data['created_at']).to eq('2019-04-29T02:42:31.536Z')
expect(wallet_data['updated_at']).to eq('2020-05-03T12:01:02.254Z')
end

it 'returns the wallet account self and users links' do
response = user_resource.wallet_account('user_123')
links = response.data['links']
expect(links['self']).not_to be_nil
expect(links['users']).not_to be_nil
end

it 'returns the wallet account transaction related links' do
response = user_resource.wallet_account('user_123')
links = response.data['links']
expect(links['batch_transactions']).not_to be_nil
expect(links['transactions']).not_to be_nil
end

it 'returns the wallet account payment method links' do
response = user_resource.wallet_account('user_123')
links = response.data['links']
expect(links['bpay_details']).not_to be_nil
expect(links['npp_details']).not_to be_nil
expect(links['virtual_accounts']).not_to be_nil
end
end

Expand Down