zai_payment 2.6.0 → 2.7.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.
- checksums.yaml +4 -4
- data/IMPLEMENTATION_SUMMARY.md +183 -0
- data/RESPONSE_FORMAT_CORRECTION.md +75 -0
- data/badges/coverage.json +1 -1
- data/changelog.md +109 -0
- data/docs/batch_transactions.md +340 -0
- data/docs/direct_api_usage.md +489 -0
- data/docs/users.md +42 -3
- data/docs/wallet_accounts.md +493 -0
- data/examples/batch_transactions.md +450 -0
- data/examples/wallet_accounts.md +733 -0
- data/lib/zai_payment/resources/batch_transaction.rb +302 -0
- data/lib/zai_payment/resources/user.rb +7 -1
- data/lib/zai_payment/resources/wallet_account.rb +176 -0
- data/lib/zai_payment/response.rb +2 -2
- data/lib/zai_payment/version.rb +1 -1
- data/lib/zai_payment.rb +12 -0
- data/readme.md +84 -2
- metadata +10 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 510e8e99ba15a794801fbfa54f066f9c9df8037b2b4439f1e4f2a11b19509899
|
|
4
|
+
data.tar.gz: 5f699a364d1cc0f50a6e6e36e4a5ffea274a8c7e761dfa01f0f78d71043f9578
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ad9010a7ed0538881749587f2ea3cf2a7e3bf8dde51f1f2856b62a13726f25ef55c5174dce276c024df5d3ea9f7352a049ad2da29e15495dc7e4b838d08c963a
|
|
7
|
+
data.tar.gz: 2d33996bd2e78ab91f8c2ee27f02d9d5d5f0f139cda22141d4c5e0d0d9358c3906872236f13131448da217665db28ed7d3df360119981b9ba87cc11a2acf9ec6
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
# Batch Transactions Implementation Summary
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
Successfully implemented prelive-only batch transaction endpoints for the Zai Payment Ruby gem. These endpoints allow testing and simulation of batch transaction processing flows in the prelive environment.
|
|
6
|
+
|
|
7
|
+
## Files Created
|
|
8
|
+
|
|
9
|
+
### 1. Resource Implementation
|
|
10
|
+
**File:** `lib/zai_payment/resources/batch_transaction.rb`
|
|
11
|
+
|
|
12
|
+
Implements the `BatchTransaction` resource class with the following methods:
|
|
13
|
+
- `export_transactions` - Exports pending batch transactions to batched state
|
|
14
|
+
- `update_transaction_states` - Updates batch transaction states (12700 or 12000)
|
|
15
|
+
- `process_to_bank_processing` - Convenience method for state 12700
|
|
16
|
+
- `process_to_successful` - Convenience method for state 12000 (triggers webhooks)
|
|
17
|
+
|
|
18
|
+
**Key Features:**
|
|
19
|
+
- Environment validation (prelive-only)
|
|
20
|
+
- Comprehensive parameter validation
|
|
21
|
+
- Clear error messages
|
|
22
|
+
- Full YARD documentation
|
|
23
|
+
|
|
24
|
+
### 2. Spec File
|
|
25
|
+
**File:** `spec/zai_payment/resources/batch_transaction_spec.rb`
|
|
26
|
+
|
|
27
|
+
Comprehensive test coverage including:
|
|
28
|
+
- Export transactions functionality
|
|
29
|
+
- Update transaction states with both state codes
|
|
30
|
+
- Convenience methods (process_to_bank_processing, process_to_successful)
|
|
31
|
+
- Environment validation (prelive vs production)
|
|
32
|
+
- Parameter validation for all methods
|
|
33
|
+
- Multiple transaction ID handling
|
|
34
|
+
- Integration with ZaiPayment module
|
|
35
|
+
|
|
36
|
+
### 3. Documentation
|
|
37
|
+
|
|
38
|
+
#### Examples
|
|
39
|
+
**File:** `examples/batch_transactions.md`
|
|
40
|
+
- Complete workflow examples
|
|
41
|
+
- Step-by-step usage guide
|
|
42
|
+
- Error handling examples
|
|
43
|
+
- Multiple transaction processing
|
|
44
|
+
- Webhook testing guide
|
|
45
|
+
|
|
46
|
+
#### Technical Documentation
|
|
47
|
+
**File:** `docs/batch_transactions.md`
|
|
48
|
+
- Complete method reference with signatures
|
|
49
|
+
- Parameter descriptions and types
|
|
50
|
+
- Return value specifications
|
|
51
|
+
- Error handling details
|
|
52
|
+
- State code documentation
|
|
53
|
+
- Lifecycle diagrams
|
|
54
|
+
- Integration examples
|
|
55
|
+
|
|
56
|
+
## Files Modified
|
|
57
|
+
|
|
58
|
+
### 1. Main Module
|
|
59
|
+
**File:** `lib/zai_payment.rb`
|
|
60
|
+
- Added require for batch_transaction resource
|
|
61
|
+
- Added `batch_transactions` accessor method
|
|
62
|
+
|
|
63
|
+
### 2. Response Class
|
|
64
|
+
**File:** `lib/zai_payment/response.rb`
|
|
65
|
+
- Added "batches" to RESPONSE_DATA_KEYS array
|
|
66
|
+
|
|
67
|
+
### 3. README
|
|
68
|
+
**File:** `readme.md`
|
|
69
|
+
- Added batch transactions to Features section
|
|
70
|
+
- Added new Quick Start section with example
|
|
71
|
+
- Added to Roadmap as completed feature
|
|
72
|
+
- Added to Examples & Patterns section
|
|
73
|
+
- Added documentation links
|
|
74
|
+
|
|
75
|
+
## API Endpoints Implemented
|
|
76
|
+
|
|
77
|
+
### 1. Export Transactions
|
|
78
|
+
**Method:** `GET /batch_transactions/export_transactions`
|
|
79
|
+
**Purpose:** Move all pending batch_transactions to batched state
|
|
80
|
+
**Returns:** Array of transactions with batch_id and transaction id
|
|
81
|
+
|
|
82
|
+
### 2. Update Transaction States
|
|
83
|
+
**Method:** `PATCH /batches/:id/transaction_states`
|
|
84
|
+
**Purpose:** Move batch transactions between states
|
|
85
|
+
**Supports:**
|
|
86
|
+
- State 12700 (bank_processing)
|
|
87
|
+
- State 12000 (successful - triggers webhooks)
|
|
88
|
+
|
|
89
|
+
## Usage Example
|
|
90
|
+
|
|
91
|
+
```ruby
|
|
92
|
+
# Configure for prelive
|
|
93
|
+
ZaiPayment.configure do |config|
|
|
94
|
+
config.environment = :prelive
|
|
95
|
+
config.client_id = 'your_client_id'
|
|
96
|
+
config.client_secret = 'your_client_secret'
|
|
97
|
+
config.scope = 'your_scope'
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
# Export transactions
|
|
101
|
+
export_response = ZaiPayment.batch_transactions.export_transactions
|
|
102
|
+
batch_id = export_response.data.first['batch_id']
|
|
103
|
+
transaction_ids = export_response.data.map { |t| t['id'] }
|
|
104
|
+
|
|
105
|
+
# Move to bank_processing
|
|
106
|
+
ZaiPayment.batch_transactions.process_to_bank_processing(
|
|
107
|
+
batch_id,
|
|
108
|
+
exported_ids: transaction_ids
|
|
109
|
+
)
|
|
110
|
+
|
|
111
|
+
# Complete processing (triggers webhook)
|
|
112
|
+
ZaiPayment.batch_transactions.process_to_successful(
|
|
113
|
+
batch_id,
|
|
114
|
+
exported_ids: transaction_ids
|
|
115
|
+
)
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## Error Handling
|
|
119
|
+
|
|
120
|
+
### ConfigurationError
|
|
121
|
+
Raised when attempting to use batch transaction endpoints outside prelive environment.
|
|
122
|
+
|
|
123
|
+
### ValidationError
|
|
124
|
+
Raised for:
|
|
125
|
+
- Blank or nil batch_id
|
|
126
|
+
- Empty or nil exported_ids array
|
|
127
|
+
- exported_ids not an array
|
|
128
|
+
- exported_ids containing nil or empty values
|
|
129
|
+
- Invalid state codes (not 12700 or 12000)
|
|
130
|
+
|
|
131
|
+
## Key Design Decisions
|
|
132
|
+
|
|
133
|
+
1. **Prelive-Only Enforcement**: Environment check in every method to prevent accidental production use
|
|
134
|
+
2. **Convenience Methods**: Separate methods for common operations (process_to_bank_processing, process_to_successful)
|
|
135
|
+
3. **Array Support**: All methods support processing multiple transactions at once
|
|
136
|
+
4. **State Code Constants**: Clear documentation of state codes (12700, 12000)
|
|
137
|
+
5. **Comprehensive Validation**: All parameters validated with clear error messages
|
|
138
|
+
6. **Consistent API**: Follows same patterns as other resources in the gem
|
|
139
|
+
|
|
140
|
+
## Testing
|
|
141
|
+
|
|
142
|
+
The implementation includes comprehensive RSpec tests covering:
|
|
143
|
+
- ✅ Happy path for all methods
|
|
144
|
+
- ✅ Error cases (invalid environment, invalid parameters)
|
|
145
|
+
- ✅ Multiple transaction handling
|
|
146
|
+
- ✅ Response structure validation
|
|
147
|
+
- ✅ Integration with main module
|
|
148
|
+
|
|
149
|
+
## Documentation
|
|
150
|
+
|
|
151
|
+
Three levels of documentation provided:
|
|
152
|
+
1. **YARD Comments**: Inline documentation in the code
|
|
153
|
+
2. **Examples**: Practical usage examples (`examples/batch_transactions.md`)
|
|
154
|
+
3. **Technical Guide**: Complete reference documentation (`docs/batch_transactions.md`)
|
|
155
|
+
|
|
156
|
+
## Next Steps
|
|
157
|
+
|
|
158
|
+
The implementation is complete and ready for use. To use it:
|
|
159
|
+
|
|
160
|
+
1. Ensure your environment is set to `:prelive`
|
|
161
|
+
2. Access via `ZaiPayment.batch_transactions`
|
|
162
|
+
3. Follow the workflow: export → bank_processing → successful
|
|
163
|
+
4. Handle webhooks triggered by the successful state
|
|
164
|
+
|
|
165
|
+
## Files Summary
|
|
166
|
+
|
|
167
|
+
**Created:**
|
|
168
|
+
- `lib/zai_payment/resources/batch_transaction.rb` (172 lines)
|
|
169
|
+
- `spec/zai_payment/resources/batch_transaction_spec.rb` (443 lines)
|
|
170
|
+
- `examples/batch_transactions.md` (276 lines)
|
|
171
|
+
- `docs/batch_transactions.md` (434 lines)
|
|
172
|
+
|
|
173
|
+
**Modified:**
|
|
174
|
+
- `lib/zai_payment.rb` (added 2 lines)
|
|
175
|
+
- `lib/zai_payment/response.rb` (added "batches" key)
|
|
176
|
+
- `readme.md` (added sections and examples)
|
|
177
|
+
|
|
178
|
+
**Total:** 1,325+ lines of code, tests, and documentation added.
|
|
179
|
+
|
|
180
|
+
## No Linter Errors
|
|
181
|
+
|
|
182
|
+
All files pass linting checks with no errors or warnings.
|
|
183
|
+
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# Batch Transactions API Response Correction
|
|
2
|
+
|
|
3
|
+
## Response Format for PATCH /batches/:id/transaction_states
|
|
4
|
+
|
|
5
|
+
### ✅ Correct Response Format
|
|
6
|
+
|
|
7
|
+
The actual API response for `PATCH /batches/:id/transaction_states` contains:
|
|
8
|
+
|
|
9
|
+
```json
|
|
10
|
+
{
|
|
11
|
+
"aggregated_jobs_uuid": "c1cbc502-9754-42fd-9731-2330ddd7a41f",
|
|
12
|
+
"msg": "1 jobs have been sent to the queue.",
|
|
13
|
+
"errors": []
|
|
14
|
+
}
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
### Response Fields
|
|
18
|
+
|
|
19
|
+
| Field | Type | Description |
|
|
20
|
+
|-------|------|-------------|
|
|
21
|
+
| `aggregated_jobs_uuid` | String | UUID identifying the batch of jobs sent to the queue |
|
|
22
|
+
| `msg` | String | Success message indicating how many jobs were queued |
|
|
23
|
+
| `errors` | Array | Array of any errors (typically empty on success) |
|
|
24
|
+
|
|
25
|
+
### Ruby Usage Example
|
|
26
|
+
|
|
27
|
+
```ruby
|
|
28
|
+
response = ZaiPayment.batch_transactions.update_transaction_states(
|
|
29
|
+
'batch_id',
|
|
30
|
+
exported_ids: ['439970a2-e0a1-418e-aecf-6b519c115c55'],
|
|
31
|
+
state: 12700
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
# Access response data
|
|
35
|
+
response.body['aggregated_jobs_uuid'] # => "c1cbc502-9754-42fd-9731-2330ddd7a41f"
|
|
36
|
+
response.body['msg'] # => "1 jobs have been sent to the queue."
|
|
37
|
+
response.body['errors'] # => []
|
|
38
|
+
|
|
39
|
+
# Check for success
|
|
40
|
+
if response.success? && response.body['errors'].empty?
|
|
41
|
+
puts "Successfully queued #{response.body['msg']}"
|
|
42
|
+
puts "Job UUID: #{response.body['aggregated_jobs_uuid']}"
|
|
43
|
+
end
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Multiple Transactions
|
|
47
|
+
|
|
48
|
+
When processing multiple transactions, the message reflects the count:
|
|
49
|
+
|
|
50
|
+
```ruby
|
|
51
|
+
response = ZaiPayment.batch_transactions.update_transaction_states(
|
|
52
|
+
'batch_id',
|
|
53
|
+
exported_ids: ['id1', 'id2', 'id3'],
|
|
54
|
+
state: 12000
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
response.body['msg'] # => "3 jobs have been sent to the queue."
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Updated Files
|
|
61
|
+
|
|
62
|
+
All documentation and specs have been updated to reflect the correct response format:
|
|
63
|
+
|
|
64
|
+
1. ✅ `lib/zai_payment/resources/batch_transaction.rb` - YARD documentation
|
|
65
|
+
2. ✅ `spec/zai_payment/resources/batch_transaction_spec.rb` - Test expectations
|
|
66
|
+
3. ✅ `examples/batch_transactions.md` - Example code
|
|
67
|
+
4. ✅ `docs/batch_transactions.md` - Technical documentation
|
|
68
|
+
|
|
69
|
+
## Key Points
|
|
70
|
+
|
|
71
|
+
- The response is **asynchronous** - jobs are queued for processing
|
|
72
|
+
- The `aggregated_jobs_uuid` can be used to track the batch of jobs
|
|
73
|
+
- Check the `errors` array to ensure no errors occurred
|
|
74
|
+
- The `msg` field contains a human-readable description of what was queued
|
|
75
|
+
|
data/badges/coverage.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"schemaVersion": 1, "label": "coverage", "message": "97.
|
|
1
|
+
{"schemaVersion": 1, "label": "coverage", "message": "97.47%", "color": "brightgreen"}
|
data/changelog.md
CHANGED
|
@@ -1,5 +1,114 @@
|
|
|
1
1
|
## [Released]
|
|
2
2
|
|
|
3
|
+
## [2.7.0] - 2025-11-04
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
- **Batch Transactions Resource**: Complete batch transaction management for testing in prelive environment 🔄
|
|
7
|
+
- `ZaiPayment.batch_transactions.export_transactions` - Export pending transactions to batched state
|
|
8
|
+
- `ZaiPayment.batch_transactions.process_to_bank_processing(batch_id, exported_ids:)` - Move batch to bank_processing state
|
|
9
|
+
- `ZaiPayment.batch_transactions.process_to_successful(batch_id, exported_ids:)` - Complete batch processing (triggers webhooks)
|
|
10
|
+
- `ZaiPayment.batch_transactions.show_batches` - List all batches
|
|
11
|
+
- `ZaiPayment.batch_transactions.show_batch(batch_id)` - Get specific batch details
|
|
12
|
+
- `ZaiPayment.batch_transactions.show_transactions(batch_id, limit:, offset:)` - List transactions in a batch with pagination
|
|
13
|
+
- Prelive-only endpoints for testing transaction processing workflows
|
|
14
|
+
- Full RSpec test suite with 20+ test examples
|
|
15
|
+
- Comprehensive documentation in `docs/batch_transactions.md`
|
|
16
|
+
- Practical examples in `examples/batch_transactions.md`
|
|
17
|
+
|
|
18
|
+
- **Wallet Account Resource**: Complete wallet account management for Australian payments 💼
|
|
19
|
+
- `ZaiPayment.wallet_accounts.show(wallet_account_id)` - Get wallet account details including balance
|
|
20
|
+
- `ZaiPayment.wallet_accounts.show_user(wallet_account_id)` - Get user associated with wallet account
|
|
21
|
+
- `ZaiPayment.wallet_accounts.show_npp_details(wallet_account_id)` - Get NPP (New Payments Platform) details including PayID
|
|
22
|
+
- `ZaiPayment.wallet_accounts.show_bpay_details(wallet_account_id)` - Get BPay details including biller code and reference
|
|
23
|
+
- `ZaiPayment.wallet_accounts.pay_bill(wallet_account_id, account_id:, amount:, reference_id:)` - Pay bills via BPay from wallet
|
|
24
|
+
- Support for checking wallet balances before transactions
|
|
25
|
+
- Support for NPP payments with PayID
|
|
26
|
+
- Support for BPay bill payments
|
|
27
|
+
- Validation for payment amounts and reference IDs
|
|
28
|
+
- Full RSpec test suite with 35+ test examples across 5 describe blocks
|
|
29
|
+
- Comprehensive documentation in `docs/wallet_accounts.md`
|
|
30
|
+
- Practical examples in `examples/wallet_accounts.md`
|
|
31
|
+
|
|
32
|
+
### Documentation
|
|
33
|
+
- **Batch Transactions Guide** (`docs/batch_transactions.md`):
|
|
34
|
+
- Complete guide for all 6 batch transaction endpoints
|
|
35
|
+
- Detailed workflow for simulating batch processing
|
|
36
|
+
- State transition diagrams and examples
|
|
37
|
+
- Error handling patterns for batch operations
|
|
38
|
+
- Important notes about prelive-only usage
|
|
39
|
+
|
|
40
|
+
- **Batch Transactions Examples** (`examples/batch_transactions.md`):
|
|
41
|
+
- Export transactions examples (3 examples)
|
|
42
|
+
- Process to bank_processing examples (3 examples)
|
|
43
|
+
- Process to successful examples (3 examples)
|
|
44
|
+
- Show batches and transactions examples (6 examples)
|
|
45
|
+
- Complete workflow patterns
|
|
46
|
+
- Rails integration examples
|
|
47
|
+
- Webhook simulation workflows
|
|
48
|
+
|
|
49
|
+
- **Wallet Accounts Guide** (`docs/wallet_accounts.md`):
|
|
50
|
+
- Complete guide for all 5 wallet account endpoints
|
|
51
|
+
- Balance checking and payment workflows
|
|
52
|
+
- NPP PayID integration examples
|
|
53
|
+
- BPay bill payment patterns
|
|
54
|
+
- Validation rules and error handling
|
|
55
|
+
- Four comprehensive use cases:
|
|
56
|
+
- Balance verification before payment
|
|
57
|
+
- Multiple bill payments workflow
|
|
58
|
+
- User verification for payments
|
|
59
|
+
- Disbursement status monitoring
|
|
60
|
+
|
|
61
|
+
- **Wallet Accounts Examples** (`examples/wallet_accounts.md`):
|
|
62
|
+
- Show wallet account examples (3 examples)
|
|
63
|
+
- Show user examples (3 examples)
|
|
64
|
+
- NPP details examples
|
|
65
|
+
- BPay details examples
|
|
66
|
+
- Pay bill examples (3 examples)
|
|
67
|
+
- Three common patterns:
|
|
68
|
+
- Complete payment workflow
|
|
69
|
+
- Wallet payment service class
|
|
70
|
+
- Rails controller integration
|
|
71
|
+
|
|
72
|
+
### Enhanced
|
|
73
|
+
- **Response Class**: Added `disbursements` to `RESPONSE_DATA_KEYS` for automatic data extraction
|
|
74
|
+
- `response.data` now properly extracts disbursement objects from pay_bill responses
|
|
75
|
+
- Consistent with other resource response handling
|
|
76
|
+
|
|
77
|
+
### Updated
|
|
78
|
+
- **README.md**:
|
|
79
|
+
- Added Wallet Accounts to features section
|
|
80
|
+
- Added Batch Transactions documentation links
|
|
81
|
+
- Updated roadmap to mark Payments as Done
|
|
82
|
+
- Added quick start examples for wallet account operations
|
|
83
|
+
|
|
84
|
+
**Full Changelog**: https://github.com/Sentia/zai-payment/compare/v2.6.1...v2.7.0
|
|
85
|
+
|
|
86
|
+
## [2.6.1] - 2025-11-03
|
|
87
|
+
|
|
88
|
+
### Changed
|
|
89
|
+
- **Wallet Accounts Response Structure**: Updated to match actual API response format 🔄
|
|
90
|
+
- Response now properly returns nested `wallet_accounts` object with complete structure
|
|
91
|
+
- Added `wallet_accounts` to `Response#data` automatic extraction
|
|
92
|
+
- The `Response#data` method now automatically extracts the `wallet_accounts` object for cleaner API usage
|
|
93
|
+
- Updated response includes: `id`, `active`, `created_at`, `updated_at`, `balance`, `currency`
|
|
94
|
+
- Enhanced `links` structure with: `self`, `users`, `batch_transactions`, `transactions`, `bpay_details`, `npp_details`, `virtual_accounts`
|
|
95
|
+
|
|
96
|
+
### Improved
|
|
97
|
+
- **API Consistency**: `response.data` now works consistently across all resources
|
|
98
|
+
- Before: `response.data['wallet_accounts']['balance']` (manual extraction)
|
|
99
|
+
- After: `response.data['balance']` (automatic extraction)
|
|
100
|
+
- **Documentation**: Updated all wallet_account documentation and examples
|
|
101
|
+
- Updated `docs/users.md` with complete wallet account response structure
|
|
102
|
+
- Added note about automatic data extraction in Response class
|
|
103
|
+
- Updated code examples in `lib/zai_payment/resources/user.rb`
|
|
104
|
+
- **Test Coverage**: Enhanced wallet_account test suite
|
|
105
|
+
- Split tests into focused examples for better maintainability
|
|
106
|
+
- Added comprehensive validation for all wallet account fields
|
|
107
|
+
- Tests for active status, timestamps, and all link fields
|
|
108
|
+
- All tests comply with RuboCop standards
|
|
109
|
+
|
|
110
|
+
**Full Changelog**: https://github.com/Sentia/zai-payment/compare/v2.6.0...v2.6.1
|
|
111
|
+
|
|
3
112
|
## [2.6.0] - 2025-11-03
|
|
4
113
|
|
|
5
114
|
### Added
|