diff --git a/Gemfile.lock b/Gemfile.lock index 79ad990..70913c9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) diff --git a/changelog.md b/changelog.md index ca9c9a4..9f2d501 100644 --- a/changelog.md +++ b/changelog.md @@ -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 diff --git a/docs/users.md b/docs/users.md index 560ada0..65ec511 100644 --- a/docs/users.md +++ b/docs/users.md @@ -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. diff --git a/lib/zai_payment/resources/user.rb b/lib/zai_payment/resources/user.rb index 3922050..130fee5 100644 --- a/lib/zai_payment/resources/user.rb +++ b/lib/zai_payment/resources/user.rb @@ -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) diff --git a/lib/zai_payment/response.rb b/lib/zai_payment/response.rb index 88a7413..41fdf17 100644 --- a/lib/zai_payment/response.rb +++ b/lib/zai_payment/response.rb @@ -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) diff --git a/lib/zai_payment/version.rb b/lib/zai_payment/version.rb index 43ac7ce..d9776f7 100644 --- a/lib/zai_payment/version.rb +++ b/lib/zai_payment/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module ZaiPayment - VERSION = '2.6.0' + VERSION = '2.6.1' end diff --git a/spec/zai_payment/resources/user_spec.rb b/spec/zai_payment/resources/user_spec.rb index b87e878..eb1d3b2 100644 --- a/spec/zai_payment/resources/user_spec.rb +++ b/spec/zai_payment/resources/user_spec.rb @@ -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 @@ -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