zai_payment 2.6.1 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 21a2f54b50cab4893520a396d33149bd53daf27aa6023fcc2b720fd2c2100e89
4
- data.tar.gz: 736516f787ba6acb1d3c40222530606dae8be04e0c2ac222d2f5a367815ad26d
3
+ metadata.gz: 510e8e99ba15a794801fbfa54f066f9c9df8037b2b4439f1e4f2a11b19509899
4
+ data.tar.gz: 5f699a364d1cc0f50a6e6e36e4a5ffea274a8c7e761dfa01f0f78d71043f9578
5
5
  SHA512:
6
- metadata.gz: 0c05de5aa53f36e794f65e0dfb421b997db67c039700b9ea62d96d38abace81d44f6bd7f22e2b98ed2885365c78c3c8ebdb2fde14a737844784379a3f64874d6
7
- data.tar.gz: 3731f8af6454bf2ae233e47a8716e06c1290912989a2ba4d9a728341845ebb5d01d0a9e7d903e0fd6f07c38cbbccd9a3931f56d6b1cb84f3e20cb5c0d50f2307
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.39%", "color": "brightgreen"}
1
+ {"schemaVersion": 1, "label": "coverage", "message": "97.47%", "color": "brightgreen"}
data/changelog.md CHANGED
@@ -1,5 +1,88 @@
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
+
3
86
  ## [2.6.1] - 2025-11-03
4
87
 
5
88
  ### Changed
@@ -0,0 +1,340 @@
1
+ # Batch Transactions (Prelive Only)
2
+
3
+ ## Overview
4
+
5
+ The Batch Transaction resource provides methods to simulate batch transaction processing in the prelive environment. These endpoints are designed for testing and allow you to move transactions through different states of the batch processing lifecycle.
6
+
7
+ **Important:** These endpoints are only available when the gem is configured for the `:prelive` environment. Attempting to use them in production will raise a `ConfigurationError`.
8
+
9
+ ## When to Use
10
+
11
+ Use the batch transaction endpoints when you need to:
12
+
13
+ 1. Test the full lifecycle of batch transaction processing
14
+ 2. Simulate bank processing states in your test environment
15
+ 3. Trigger batch transaction webhooks for testing webhook handlers
16
+ 4. Verify your application's handling of different batch transaction states
17
+
18
+ ## Authentication & Configuration
19
+
20
+ Ensure your configuration uses the prelive environment:
21
+
22
+ ```ruby
23
+ ZaiPayment.configure do |config|
24
+ config.environment = :prelive # Required!
25
+ config.client_id = 'your_client_id'
26
+ config.client_secret = 'your_client_secret'
27
+ config.scope = 'your_scope'
28
+ end
29
+ ```
30
+
31
+ ## Resource Access
32
+
33
+ Access the batch transaction resource through the main module:
34
+
35
+ ```ruby
36
+ batch_transactions = ZaiPayment.batch_transactions
37
+ ```
38
+
39
+ ## The Batch Transaction Lifecycle
40
+
41
+ In prelive, batch transactions go through these states:
42
+
43
+ 1. **pending** → Initial state when a batch transaction is created
44
+ 2. **batched** → Transactions grouped into a batch (via `export_transactions`)
45
+ 3. **bank_processing** (state 12700) → Batch is being processed by the bank
46
+ 4. **successful** (state 12000) → Processing complete, webhook triggered
47
+
48
+ ## Method Reference
49
+
50
+ ### `export_transactions`
51
+
52
+ Moves all pending batch transactions to the "batched" state and returns them with their assigned `batch_id`.
53
+
54
+ **Signature:**
55
+ ```ruby
56
+ export_transactions() → Response
57
+ ```
58
+
59
+ **Returns:**
60
+ - `Response` object with transactions array
61
+ - Each transaction includes: `id`, `batch_id`, `status`, `type`, `type_method`
62
+
63
+ **Raises:**
64
+ - `ConfigurationError` - if not in prelive environment
65
+
66
+ **Example:**
67
+ ```ruby
68
+ response = ZaiPayment.batch_transactions.export_transactions
69
+
70
+ response.data
71
+ # => [
72
+ # {
73
+ # "id" => "439970a2-e0a1-418e-aecf-6b519c115c55",
74
+ # "batch_id" => "dabcfd50-bf5a-0138-7b40-0a58a9feac03",
75
+ # "status" => "batched",
76
+ # "type" => "payment_funding",
77
+ # "type_method" => "credit_card"
78
+ # }
79
+ # ]
80
+ ```
81
+
82
+ **Note:** Store the returned `batch_id` - you'll need it for the next steps. Transaction IDs may be cleared after 24 hours in prelive.
83
+
84
+ ---
85
+
86
+ ### `update_transaction_states`
87
+
88
+ Updates the state of one or more batch transactions within a batch.
89
+
90
+ **Signature:**
91
+ ```ruby
92
+ update_transaction_states(batch_id, exported_ids:, state:) → Response
93
+ ```
94
+
95
+ **Parameters:**
96
+ - `batch_id` (String) - The batch ID from `export_transactions` response
97
+ - `exported_ids` (Array<String>) - Array of transaction IDs to update
98
+ - `state` (Integer) - Target state code: `12700` (bank_processing) or `12000` (successful)
99
+
100
+ **Returns:**
101
+ - `Response` object with `aggregated_jobs_uuid`, `msg`, and `errors` array
102
+
103
+ **Raises:**
104
+ - `ConfigurationError` - if not in prelive environment
105
+ - `ValidationError` - if batch_id is blank
106
+ - `ValidationError` - if exported_ids is nil, empty, not an array, or contains nil/empty values
107
+ - `ValidationError` - if state is not 12700 or 12000
108
+
109
+ **Example:**
110
+ ```ruby
111
+ response = ZaiPayment.batch_transactions.update_transaction_states(
112
+ 'batch_id',
113
+ exported_ids: ['439970a2-e0a1-418e-aecf-6b519c115c55'],
114
+ state: 12700
115
+ )
116
+
117
+ response.body
118
+ # => {
119
+ # "aggregated_jobs_uuid" => "c1cbc502-9754-42fd-9731-2330ddd7a41f",
120
+ # "msg" => "1 jobs have been sent to the queue.",
121
+ # "errors" => []
122
+ # }
123
+ ```
124
+
125
+ ---
126
+
127
+ ### `process_to_bank_processing`
128
+
129
+ Convenience method to move transactions to the "bank_processing" state (12700).
130
+
131
+ **Signature:**
132
+ ```ruby
133
+ process_to_bank_processing(batch_id, exported_ids:) → Response
134
+ ```
135
+
136
+ **Parameters:**
137
+ - `batch_id` (String) - The batch ID from `export_transactions` response
138
+ - `exported_ids` (Array<String>) - Array of transaction IDs to update
139
+
140
+ **Returns:**
141
+ - `Response` object with `aggregated_jobs_uuid`, `msg`, and `errors` (12700)
142
+
143
+ **Raises:**
144
+ - Same as `update_transaction_states`
145
+
146
+ **Example:**
147
+ ```ruby
148
+ response = ZaiPayment.batch_transactions.process_to_bank_processing(
149
+ 'batch_id',
150
+ exported_ids: ['transaction_id_1', 'transaction_id_2']
151
+ )
152
+ ```
153
+
154
+ **Note:** This is equivalent to calling `update_transaction_states` with `state: 12700`.
155
+
156
+ ---
157
+
158
+ ### `process_to_successful`
159
+
160
+ Convenience method to move transactions to the "successful" state (12000). This triggers batch transaction webhooks.
161
+
162
+ **Signature:**
163
+ ```ruby
164
+ process_to_successful(batch_id, exported_ids:) → Response
165
+ ```
166
+
167
+ **Parameters:**
168
+ - `batch_id` (String) - The batch ID from `export_transactions` response
169
+ - `exported_ids` (Array<String>) - Array of transaction IDs to update
170
+
171
+ **Returns:**
172
+ - `Response` object with `aggregated_jobs_uuid`, `msg`, and `errors` (12000)
173
+
174
+ **Raises:**
175
+ - Same as `update_transaction_states`
176
+
177
+ **Example:**
178
+ ```ruby
179
+ response = ZaiPayment.batch_transactions.process_to_successful(
180
+ 'batch_id',
181
+ exported_ids: ['transaction_id_1']
182
+ )
183
+
184
+ # This will trigger a batch_transactions webhook
185
+ ```
186
+
187
+ **Note:** This is equivalent to calling `update_transaction_states` with `state: 12000`.
188
+
189
+ ---
190
+
191
+ ## Complete Workflow Example
192
+
193
+ Here's the typical workflow for testing batch transactions in prelive:
194
+
195
+ ```ruby
196
+ # Step 1: Export pending transactions
197
+ export_response = ZaiPayment.batch_transactions.export_transactions
198
+
199
+ batch_id = export_response.data.first['batch_id']
200
+ transaction_ids = export_response.data.map { |t| t['id'] }
201
+
202
+ puts "Exported #{transaction_ids.length} transactions to batch #{batch_id}"
203
+
204
+ # Step 2: Move to bank_processing state
205
+ processing_response = ZaiPayment.batch_transactions.process_to_bank_processing(
206
+ batch_id,
207
+ exported_ids: transaction_ids
208
+ )
209
+
210
+ puts "Transactions moved to bank_processing (12700)"
211
+
212
+ # Step 3: Move to successful state (triggers webhook)
213
+ success_response = ZaiPayment.batch_transactions.process_to_successful(
214
+ batch_id,
215
+ exported_ids: transaction_ids
216
+ )
217
+
218
+ puts "Transactions completed successfully (12000)"
219
+ puts "Webhook should now be triggered"
220
+ ```
221
+
222
+ ## State Codes
223
+
224
+ | Code | State | Description |
225
+ |------|-------|-------------|
226
+ | 12700 | bank_processing | Transactions are being processed by the bank |
227
+ | 12000 | successful | Final state - processing complete, webhooks triggered |
228
+
229
+ ## Error Handling
230
+
231
+ ### ConfigurationError
232
+
233
+ Raised when attempting to use batch transaction endpoints outside of prelive:
234
+
235
+ ```ruby
236
+ ZaiPayment.configure do |config|
237
+ config.environment = :production # Wrong environment!
238
+ end
239
+
240
+ begin
241
+ ZaiPayment.batch_transactions.export_transactions
242
+ rescue ZaiPayment::Errors::ConfigurationError => e
243
+ puts e.message
244
+ # => "Batch transaction endpoints are only available in prelive environment.
245
+ # Current environment: production"
246
+ end
247
+ ```
248
+
249
+ ### ValidationError
250
+
251
+ Raised when parameters are invalid:
252
+
253
+ ```ruby
254
+ # Blank batch_id
255
+ ZaiPayment.batch_transactions.process_to_bank_processing(
256
+ '',
257
+ exported_ids: ['id']
258
+ )
259
+ # => ValidationError: batch_id is required and cannot be blank
260
+
261
+ # Empty exported_ids
262
+ ZaiPayment.batch_transactions.process_to_bank_processing(
263
+ 'batch_id',
264
+ exported_ids: []
265
+ )
266
+ # => ValidationError: exported_ids is required and must be a non-empty array
267
+
268
+ # exported_ids contains nil
269
+ ZaiPayment.batch_transactions.process_to_bank_processing(
270
+ 'batch_id',
271
+ exported_ids: ['valid_id', nil]
272
+ )
273
+ # => ValidationError: exported_ids cannot contain nil or empty values
274
+
275
+ # Invalid state code
276
+ ZaiPayment.batch_transactions.update_transaction_states(
277
+ 'batch_id',
278
+ exported_ids: ['id'],
279
+ state: 99999
280
+ )
281
+ # => ValidationError: state must be 12700 (bank_processing) or 12000 (successful), got: 99999
282
+ ```
283
+
284
+ ## Testing Webhooks
285
+
286
+ The `process_to_successful` method triggers batch transaction webhooks, allowing you to test your webhook handlers:
287
+
288
+ ```ruby
289
+ # Set up webhook handler to receive batch_transactions events
290
+ # Then complete the batch transaction flow:
291
+
292
+ export_response = ZaiPayment.batch_transactions.export_transactions
293
+ batch_id = export_response.data.first['batch_id']
294
+ transaction_ids = export_response.data.map { |t| t['id'] }
295
+
296
+ # Process through states
297
+ ZaiPayment.batch_transactions.process_to_bank_processing(batch_id, exported_ids: transaction_ids)
298
+ ZaiPayment.batch_transactions.process_to_successful(batch_id, exported_ids: transaction_ids)
299
+
300
+ # Your webhook handler should now receive the batch_transactions webhook
301
+ ```
302
+
303
+ ## Querying Batch Transactions
304
+
305
+ After exporting and processing transactions, you can query them using the item's transaction endpoints:
306
+
307
+ ```ruby
308
+ # List transactions for an item
309
+ item_id = 'your_item_id'
310
+ response = ZaiPayment.items.list_transactions(item_id)
311
+
312
+ # List batch transactions for an item
313
+ response = ZaiPayment.items.list_batch_transactions(item_id)
314
+ ```
315
+
316
+ You can also query batch transactions directly via the API using cURL:
317
+
318
+ ```bash
319
+ curl https://test.api.promisepay.com/batch_transactions/dabcfd50-bf5a-0138-7b40-0a58a9feac03 \
320
+ -H "Authorization: Bearer YOUR_TOKEN"
321
+ ```
322
+
323
+ ## Important Notes
324
+
325
+ 1. **Prelive Only**: These endpoints only work in prelive environment
326
+ 2. **24-Hour Limit**: Transaction IDs may be cleared after 24 hours in prelive
327
+ 3. **Webhook Trigger**: Only the successful state (12000) triggers webhooks
328
+ 4. **Batch ID Required**: You must save the `batch_id` from `export_transactions` for subsequent calls
329
+ 5. **Array Support**: You can process multiple transactions at once by passing multiple IDs
330
+
331
+ ## Related Resources
332
+
333
+ - [Items](./items.md) - For creating items that generate transactions
334
+ - [Webhooks](./webhooks.md) - For handling batch transaction webhooks
335
+ - [Webhook Security](./webhook_security_quickstart.md) - For securing your webhook endpoints
336
+
337
+ ## API Reference
338
+
339
+ For more details on the underlying API endpoints, see the [Zai API Documentation](https://developer.hellozai.com/reference).
340
+