zai_payment 2.4.0 → 2.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/readme.md CHANGED
@@ -21,12 +21,13 @@ A lightweight and extensible Ruby client for the **Zai (AssemblyPay)** API — s
21
21
  - 🧠 **Smart Token Caching** - Auto-refresh before expiration, thread-safe storage
22
22
  - 👥 **User Management** - Create and manage payin (buyers) & payout (sellers) users
23
23
  - 📦 **Item Management** - Full CRUD for transactions/payments between buyers and sellers
24
+ - 🏦 **Bank Account Management** - Complete CRUD + validation for AU/UK bank accounts
24
25
  - 🎫 **Token Auth** - Generate secure tokens for bank and card account data collection
25
26
  - 🪝 **Webhooks** - Full CRUD + secure signature verification (HMAC SHA256)
26
27
  - ⚙️ **Environment-Aware** - Seamless Pre-live / Production switching
27
28
  - 🧱 **Modular & Extensible** - Clean resource-based architecture
28
29
  - 🧰 **Zero Heavy Dependencies** - Lightweight, fast, and reliable
29
- - 📦 **Production Ready** - 88%+ test coverage, RuboCop compliant
30
+ - 📦 **Production Ready** - 97%+ test coverage, RuboCop compliant
30
31
 
31
32
  ---
32
33
 
@@ -88,82 +89,7 @@ The gem handles OAuth2 Client Credentials flow automatically - tokens are cached
88
89
 
89
90
  ### Users
90
91
 
91
- Manage payin (buyer) and payout (seller/merchant) users:
92
-
93
- ```ruby
94
- # Create a payin user (buyer)
95
- response = ZaiPayment.users.create(
96
- user_type: 'payin',
97
- email: 'buyer@example.com',
98
- first_name: 'John',
99
- last_name: 'Doe',
100
- country: 'USA',
101
- mobile: '+1234567890'
102
- )
103
-
104
- # Create a payout user (seller/merchant)
105
- response = ZaiPayment.users.create(
106
- user_type: 'payout',
107
- email: 'seller@example.com',
108
- first_name: 'Jane',
109
- last_name: 'Smith',
110
- country: 'AUS',
111
- dob: '01/01/1990',
112
- address_line1: '456 Market St',
113
- city: 'Sydney',
114
- state: 'NSW',
115
- zip: '2000'
116
- )
117
-
118
- # Create a business user with company details
119
- response = ZaiPayment.users.create(
120
- user_type: 'payout',
121
- email: 'director@company.com',
122
- first_name: 'John',
123
- last_name: 'Director',
124
- country: 'AUS',
125
- mobile: '+61412345678',
126
- authorized_signer_title: 'Director',
127
- company: {
128
- name: 'My Company',
129
- legal_name: 'My Company Pty Ltd',
130
- tax_number: '123456789',
131
- business_email: 'admin@company.com',
132
- country: 'AUS',
133
- charge_tax: true
134
- }
135
- )
136
-
137
- # List users
138
- response = ZaiPayment.users.list(limit: 10, offset: 0)
139
-
140
- # Get user details
141
- response = ZaiPayment.users.show('user_id')
142
-
143
- # Update user
144
- response = ZaiPayment.users.update('user_id', mobile: '+9876543210')
145
-
146
- # Show user wallet account
147
- response = ZaiPayment.users.wallet_account('user_id')
148
-
149
- # List user items with pagination
150
- response = ZaiPayment.users.items('user_id', limit: 50, offset: 10)
151
-
152
- # Set user disbursement account
153
- response = ZaiPayment.users.set_disbursement_account('user_id', 'bank_account_id')
154
-
155
- # Show user bank account
156
- response = ZaiPayment.users.bank_account('user_id')
157
-
158
- # Verify user (prelive only)
159
- response = ZaiPayment.users.verify('user_id')
160
-
161
- # Show user card account
162
- response = ZaiPayment.users.card_account('user_id')
163
-
164
- # List user's BPay accounts
165
- response = ZaiPayment.users.bpay_accounts('user_id')
166
- ```
92
+ Manage payin (buyer) and payout (seller/merchant) users.
167
93
 
168
94
  **📚 Documentation:**
169
95
  - 📖 [User Management Guide](docs/users.md) - Complete guide for payin and payout users
@@ -173,69 +99,25 @@ response = ZaiPayment.users.bpay_accounts('user_id')
173
99
 
174
100
  ### Items
175
101
 
176
- Manage transactions/payments between buyers and sellers:
177
-
178
- ```ruby
179
- # Create an item
180
- response = ZaiPayment.items.create(
181
- name: "Product Purchase",
182
- amount: 10000, # Amount in cents ($100.00)
183
- payment_type: 2, # Credit card
184
- buyer_id: "buyer-123",
185
- seller_id: "seller-456",
186
- description: "Purchase of premium product",
187
- currency: "AUD",
188
- tax_invoice: true
189
- )
190
-
191
- # List items
192
- response = ZaiPayment.items.list(limit: 20, offset: 0)
193
-
194
- # Get item details
195
- response = ZaiPayment.items.show('item_id')
196
-
197
- # Update item
198
- response = ZaiPayment.items.update('item_id', name: 'Updated Name')
199
-
200
- # Get item status
201
- response = ZaiPayment.items.show_status('item_id')
202
-
203
- # Get buyer/seller details
204
- response = ZaiPayment.items.show_buyer('item_id')
205
- response = ZaiPayment.items.show_seller('item_id')
206
-
207
- # List transactions
208
- response = ZaiPayment.items.list_transactions('item_id')
209
- ```
102
+ Manage transactions/payments between buyers and sellers.
210
103
 
211
104
  **📚 Documentation:**
212
105
  - 📖 [Item Management Guide](docs/items.md) - Complete guide for creating and managing items
213
106
  - 💡 [Item Examples](examples/items.md) - Real-world usage patterns and complete workflows
214
107
  - 🔗 [Zai: Items API Reference](https://developer.hellozai.com/reference/listitems)
215
108
 
216
- ### Token Auth
109
+ ### Bank Accounts
217
110
 
218
- Generate secure tokens for collecting bank and card account information:
111
+ Manage bank accounts for Australian and UK users, with routing number validation.
219
112
 
220
- ```ruby
221
- # Generate a bank token (for collecting bank account details)
222
- response = ZaiPayment.token_auths.generate(
223
- user_id: "seller-68611249",
224
- token_type: "bank"
225
- )
226
-
227
- token = response.data['token_auth']['token']
228
- # Use this token with PromisePay.js on the frontend
229
-
230
- # Generate a card token (for collecting credit card details)
231
- response = ZaiPayment.token_auths.generate(
232
- user_id: "buyer-12345",
233
- token_type: "card"
234
- )
235
-
236
- token = response.data['token_auth']['token']
237
- # Use this token with PromisePay.js on the frontend
238
- ```
113
+ **📚 Documentation:**
114
+ - 📖 [Bank Account Management Guide](docs/bank_accounts.md) - Complete guide for bank accounts
115
+ - 💡 [Bank Account Examples](examples/bank_accounts.md) - Real-world patterns and integration
116
+ - 🔗 [Zai: Bank Accounts API Reference](https://developer.hellozai.com/reference/showbankaccount)
117
+
118
+ ### Token Auth
119
+
120
+ Generate secure tokens for collecting bank and card account information.
239
121
 
240
122
  **📚 Documentation:**
241
123
  - 💡 [Token Auth Examples](examples/token_auths.md) - Complete integration guide with PromisePay.js
@@ -243,24 +125,7 @@ token = response.data['token_auth']['token']
243
125
 
244
126
  ### Webhooks
245
127
 
246
- Manage webhook endpoints:
247
-
248
- ```ruby
249
- # List webhooks
250
- response = ZaiPayment.webhooks.list
251
- webhooks = response.data
252
-
253
- # Create a webhook
254
- response = ZaiPayment.webhooks.create(
255
- url: 'https://example.com/webhooks/zai',
256
- object_type: 'transactions',
257
- enabled: true
258
- )
259
-
260
- # Secure your webhooks with signature verification
261
- secret_key = SecureRandom.alphanumeric(32)
262
- ZaiPayment.webhooks.create_secret_key(secret_key: secret_key)
263
- ```
128
+ Manage webhook endpoints with secure signature verification.
264
129
 
265
130
  **📚 Documentation:**
266
131
  - 📖 [Webhook Examples & Complete Guide](examples/webhooks.md) - Full CRUD operations and patterns
@@ -301,6 +166,7 @@ end
301
166
  | ✅ Webhooks | CRUD for webhook endpoints | Done |
302
167
  | ✅ Users | Manage PayIn / PayOut users | Done |
303
168
  | ✅ Items | Transactions/payments (CRUD) | Done |
169
+ | ✅ Bank Accounts | AU/UK bank accounts + validation | Done |
304
170
  | ✅ Token Auth | Generate bank/card tokens | Done |
305
171
  | 💳 Payments | Single and recurring payments | 🚧 In progress |
306
172
  | 🏦 Virtual Accounts (VA / PIPU) | Manage virtual accounts & PayTo | ⏳ Planned |
@@ -360,12 +226,14 @@ Everyone interacting in the ZaiPayment project's codebases, issue trackers, chat
360
226
  - [**Authentication Guide**](docs/authentication.md) - Two approaches to getting tokens, automatic management
361
227
  - [**User Management Guide**](docs/users.md) - Managing payin and payout users
362
228
  - [**Item Management Guide**](docs/items.md) - Creating and managing transactions/payments
229
+ - [**Bank Account Guide**](docs/bank_accounts.md) - Managing bank accounts for AU/UK users
363
230
  - [**Webhook Examples**](examples/webhooks.md) - Complete webhook usage guide
364
231
  - [**Documentation Index**](docs/readme.md) - Full documentation navigation
365
232
 
366
233
  ### Examples & Patterns
367
234
  - [User Examples](examples/users.md) - Real-world user management patterns
368
235
  - [Item Examples](examples/items.md) - Transaction and payment workflows
236
+ - [Bank Account Examples](examples/bank_accounts.md) - Bank account integration patterns
369
237
  - [Token Auth Examples](examples/token_auths.md) - Secure token generation and integration
370
238
  - [Webhook Examples](examples/webhooks.md) - Webhook integration patterns
371
239
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zai_payment
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.0
4
+ version: 2.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eddy Jaga
@@ -68,6 +68,8 @@ files:
68
68
  - contributing.md
69
69
  - docs/architecture.md
70
70
  - docs/authentication.md
71
+ - docs/bank_accounts.md
72
+ - docs/bpay_accounts.md
71
73
  - docs/items.md
72
74
  - docs/readme.md
73
75
  - docs/token_auths.md
@@ -77,13 +79,13 @@ files:
77
79
  - docs/webhook_security_quickstart.md
78
80
  - docs/webhook_signature.md
79
81
  - docs/webhooks.md
82
+ - examples/bank_accounts.md
83
+ - examples/bpay_accounts.md
80
84
  - examples/items.md
81
85
  - examples/rails_card_payment.md
82
86
  - examples/token_auths.md
83
87
  - examples/users.md
84
88
  - examples/webhooks.md
85
- - implementation.md
86
- - implementation_summary.md
87
89
  - lib/zai_payment.rb
88
90
  - lib/zai_payment/auth/token_provider.rb
89
91
  - lib/zai_payment/auth/token_store.rb
@@ -91,6 +93,8 @@ files:
91
93
  - lib/zai_payment/client.rb
92
94
  - lib/zai_payment/config.rb
93
95
  - lib/zai_payment/errors.rb
96
+ - lib/zai_payment/resources/bank_account.rb
97
+ - lib/zai_payment/resources/bpay_account.rb
94
98
  - lib/zai_payment/resources/item.rb
95
99
  - lib/zai_payment/resources/token_auth.rb
96
100
  - lib/zai_payment/resources/user.rb
data/implementation.md DELETED
@@ -1,304 +0,0 @@
1
- # User Management Implementation Summary
2
-
3
- ## Overview
4
-
5
- This document summarizes the implementation of the User Management feature for the Zai Payment Ruby library.
6
-
7
- ## Implementation Date
8
-
9
- October 23, 2025
10
-
11
- ## What Was Implemented
12
-
13
- ### 1. User Resource Class (`lib/zai_payment/resources/user.rb`)
14
-
15
- A comprehensive User resource that provides CRUD operations for managing both payin (buyer) and payout (seller/merchant) users.
16
-
17
- **Key Features:**
18
- - ✅ List users with pagination
19
- - ✅ Show user details by ID
20
- - ✅ Create payin users (buyers)
21
- - ✅ Create payout users (sellers/merchants)
22
- - ✅ Update user information
23
- - ✅ Comprehensive validation for all user types
24
- - ✅ Support for all Zai API user fields
25
-
26
- **Supported Fields:**
27
- - Email, first name, last name (required)
28
- - Country (ISO 3166-1 alpha-3 code, required)
29
- - Address details (line1, line2, city, state, zip)
30
- - Contact information (mobile, phone)
31
- - Date of birth (DD/MM/YYYY format)
32
- - Government ID number
33
- - Device ID and IP address (for fraud prevention)
34
- - User type designation (payin/payout)
35
-
36
- **Validation:**
37
- - Required field validation
38
- - Email format validation
39
- - Country code validation (3-letter ISO codes)
40
- - Date of birth format validation (DD/MM/YYYY)
41
- - User type validation (payin/payout)
42
-
43
- ### 2. Client Updates (`lib/zai_payment/client.rb`)
44
-
45
- **Changes:**
46
- - Added `base_endpoint` parameter to constructor
47
- - Updated `base_url` method to support multiple API endpoints
48
- - Users API uses `core_base` endpoint
49
- - Webhooks API uses `va_base` endpoint
50
-
51
- ### 3. Response Updates (`lib/zai_payment/response.rb`)
52
-
53
- **Changes:**
54
- - Updated `data` method to handle both `webhooks` and `users` response formats
55
- - Maintains backward compatibility with existing webhook code
56
-
57
- ### 4. Main Module Integration (`lib/zai_payment.rb`)
58
-
59
- **Changes:**
60
- - Added `require` for User resource
61
- - Added `users` accessor method
62
- - Properly configured User resource to use `core_base` endpoint
63
-
64
- ### 5. Comprehensive Test Suite (`spec/zai_payment/resources/user_spec.rb`)
65
-
66
- **Test Coverage:**
67
- - List users with pagination
68
- - Show user details
69
- - Create payin users with various configurations
70
- - Create payout users with required fields
71
- - Validation error handling
72
- - API error handling
73
- - Update operations
74
- - User type validation
75
- - Integration with main module
76
-
77
- **Test Statistics:**
78
- - 40+ test cases
79
- - Covers all CRUD operations
80
- - Tests both success and error scenarios
81
- - Validates all field types
82
- - Tests integration points
83
-
84
- ### 6. Documentation
85
-
86
- #### User Guide (`docs/users.md`)
87
- Comprehensive guide covering:
88
- - Overview of payin vs payout users
89
- - Required fields for each user type
90
- - Complete API reference
91
- - Field reference table
92
- - Error handling patterns
93
- - Best practices
94
- - Response structures
95
- - Complete examples
96
-
97
- #### Usage Examples (`examples/users.md`)
98
- Practical examples including:
99
- - Basic payin user creation
100
- - Complete payin user profiles
101
- - Progressive profile building
102
- - Individual payout users
103
- - International users (AU, UK, US)
104
- - List and pagination
105
- - Update operations
106
- - Error handling patterns
107
- - Rails integration example
108
- - Batch operations
109
- - User profile validation helper
110
- - RSpec integration tests
111
- - Common patterns with retry logic
112
-
113
- #### readme Updates (`readme.md`)
114
- - Added Users section with quick examples
115
- - Updated roadmap to mark Users as "Done"
116
- - Added documentation links
117
- - Updated Getting Started section
118
-
119
- ## API Endpoints
120
-
121
- The implementation works with the following Zai API endpoints:
122
-
123
- - `GET /users` - List users
124
- - `GET /users/:id` - Show user
125
- - `POST /users` - Create user
126
- - `PATCH /users/:id` - Update user
127
-
128
- ## Usage Examples
129
-
130
- ### Create a Payin User (Buyer)
131
-
132
- ```ruby
133
- response = ZaiPayment.users.create(
134
- email: 'buyer@example.com',
135
- first_name: 'John',
136
- last_name: 'Doe',
137
- country: 'USA',
138
- mobile: '+1234567890'
139
- )
140
-
141
- user_id = response.data['id']
142
- ```
143
-
144
- ### Create a Payout User (Seller/Merchant)
145
-
146
- ```ruby
147
- response = ZaiPayment.users.create(
148
- email: 'seller@example.com',
149
- first_name: 'Jane',
150
- last_name: 'Smith',
151
- country: 'AUS',
152
- dob: '01/01/1990',
153
- address_line1: '456 Market St',
154
- city: 'Sydney',
155
- state: 'NSW',
156
- zip: '2000',
157
- mobile: '+61412345678'
158
- )
159
-
160
- seller_id = response.data['id']
161
- ```
162
-
163
- ### List Users
164
-
165
- ```ruby
166
- response = ZaiPayment.users.list(limit: 10, offset: 0)
167
- users = response.data
168
- ```
169
-
170
- ### Show User
171
-
172
- ```ruby
173
- response = ZaiPayment.users.show('user_id')
174
- user = response.data
175
- ```
176
-
177
- ### Update User
178
-
179
- ```ruby
180
- response = ZaiPayment.users.update(
181
- 'user_id',
182
- mobile: '+9876543210',
183
- address_line1: '789 New St'
184
- )
185
- ```
186
-
187
- ## Key Differences: Payin vs Payout Users
188
-
189
- ### Payin User (Buyer) Requirements
190
- **Required:**
191
- - Email, first name, last name, country
192
- - Device ID and IP address (when charging)
193
-
194
- **Recommended:**
195
- - Address, city, state, zip
196
- - Mobile, DOB
197
-
198
- ### Payout User (Seller/Merchant) Requirements
199
- **Required:**
200
- - Email, first name, last name, country
201
- - Address, city, state, zip
202
- - Date of birth (DD/MM/YYYY format)
203
-
204
- **Recommended:**
205
- - Mobile, government number
206
-
207
- ## Validation Rules
208
-
209
- 1. **Email**: Must be valid email format
210
- 2. **Country**: Must be 3-letter ISO 3166-1 alpha-3 code (e.g., USA, AUS, GBR)
211
- 3. **Date of Birth**: Must be DD/MM/YYYY format (e.g., 01/01/1990)
212
- 4. **User Type**: Must be 'payin' or 'payout' (optional field)
213
-
214
- ## Error Handling
215
-
216
- The implementation provides proper error handling for:
217
- - `ValidationError` - Missing or invalid fields
218
- - `UnauthorizedError` - Authentication failures
219
- - `NotFoundError` - User not found
220
- - `ApiError` - General API errors
221
- - `ConnectionError` - Network issues
222
- - `TimeoutError` - Request timeouts
223
-
224
- ## Best Practices Implemented
225
-
226
- 1. **Progressive Profile Building**: Create users with minimal info, update later
227
- 2. **Proper Validation**: Validate data before API calls
228
- 3. **Error Recovery**: Handle errors gracefully with proper error classes
229
- 4. **Type Safety**: Validate user types and field formats
230
- 5. **Documentation**: Comprehensive guides and examples
231
- 6. **Testing**: Extensive test coverage for all scenarios
232
-
233
- ## Files Created/Modified
234
-
235
- ### Created Files:
236
- 1. `/lib/zai_payment/resources/user.rb` - User resource class
237
- 2. `/spec/zai_payment/resources/user_spec.rb` - Test suite
238
- 3. `/docs/users.md` - User management guide
239
- 4. `/examples/users.md` - Usage examples
240
-
241
- ### Modified Files:
242
- 1. `/lib/zai_payment/client.rb` - Added endpoint support
243
- 2. `/lib/zai_payment/response.rb` - Added users data handling
244
- 3. `/lib/zai_payment.rb` - Integrated User resource
245
- 4. `/readme.md` - Added Users section and updated roadmap
246
-
247
- ## Code Quality
248
-
249
- - ✅ No linter errors
250
- - ✅ Follows existing code patterns
251
- - ✅ Comprehensive test coverage
252
- - ✅ Well-documented with YARD comments
253
- - ✅ Follows Ruby best practices
254
- - ✅ Consistent with webhook implementation
255
-
256
- ## Architecture Decisions
257
-
258
- 1. **Endpoint Routing**: Users use `core_base`, webhooks use `va_base`
259
- 2. **Validation Strategy**: Client-side validation before API calls
260
- 3. **Field Mapping**: Direct 1:1 mapping with Zai API fields
261
- 4. **Error Handling**: Leverage existing error class hierarchy
262
- 5. **Testing Approach**: Match webhook test patterns
263
-
264
- ## Integration Points
265
-
266
- The User resource integrates seamlessly with:
267
- - Authentication system (OAuth2 tokens)
268
- - Error handling framework
269
- - Response wrapper
270
- - Configuration management
271
- - Testing infrastructure
272
-
273
- ## Next Steps
274
-
275
- The implementation is complete and ready for use. Recommended next steps:
276
-
277
- 1. ✅ Run the full test suite
278
- 2. ✅ Review documentation
279
- 3. ✅ Try examples in development environment
280
- 4. Consider adding:
281
- - Company user support (for payout users)
282
- - User verification status checking
283
- - Bank account associations
284
- - Payment method attachments
285
-
286
- ## References
287
-
288
- - [Zai: Onboarding a Payin User](https://developer.hellozai.com/docs/onboarding-a-pay-in-user)
289
- - [Zai: Onboarding a Payout User](https://developer.hellozai.com/docs/onboarding-a-pay-out-user)
290
- - [Zai API Reference](https://developer.hellozai.com/reference)
291
-
292
- ## Support
293
-
294
- For questions or issues:
295
- 1. Check the documentation in `/docs/users.md`
296
- 2. Review examples in `/examples/users.md`
297
- 3. Run tests: `bundle exec rspec spec/zai_payment/resources/user_spec.rb`
298
- 4. Refer to Zai Developer Portal: https://developer.hellozai.com/
299
-
300
- ---
301
-
302
- **Implementation completed successfully! 🎉**
303
-
304
- All CRUD operations for User management are now available in the ZaiPayment gem, following best practices and maintaining consistency with the existing codebase.