zai_payment 2.5.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3d7ca693c80c9ef5cf02c4c07413ec8aa07fe2673a4b93ef018b56e717667db2
4
- data.tar.gz: dc622e6eb05dc41eb317de509ebe78e62d19feba959da1d60833f4f53fb3e55b
3
+ metadata.gz: 5c0f57b605f7a885cb3fcbb0e8b4554d782fd298444d49b57732d0214b0a8a14
4
+ data.tar.gz: 014e39994a1d9051b28d90deaec6407cd638de2ed7995509c0196ec25da6805a
5
5
  SHA512:
6
- metadata.gz: 5a676cd3d131d3683bba6421ca355982183b9959bf9747a42b0f0cf9192a4a33dc3cbc0ccce3d88baf75103ad6f8226fb9fec11ecd46dd2ee3ec0c0fc50d2821
7
- data.tar.gz: c6004742e5f57f207ecf6753450c203384fe0d8854cc64eb851556ecf22467de74bb9ff44cb5e9108d73b1ef0210358cf9c94e432a3c421223494ff8b0aba8eb
6
+ metadata.gz: 24b3058ec5ee8e06b06f9444175a6a86e455a3ba08b2a5f40df990f5ab7beae812d05225e62802b1fd2e69acc37f9364f33d1dc89f37fb045c150c52ae18fd04
7
+ data.tar.gz: a2e4715f2f8e8630fe4ea03d13ad83318acf4fd09737266de497ecc889af22af84fc7edd0b8d6846658ebc50d4c49ed8d36ae0144190a0d79aeae88d6e398bce
data/badges/coverage.json CHANGED
@@ -1 +1 @@
1
- {"schemaVersion": 1, "label": "coverage", "message": "97.34%", "color": "brightgreen"}
1
+ {"schemaVersion": 1, "label": "coverage", "message": "97.39%", "color": "brightgreen"}
data/changelog.md CHANGED
@@ -1,5 +1,65 @@
1
1
  ## [Released]
2
2
 
3
+ ## [2.6.0] - 2025-11-03
4
+
5
+ ### Added
6
+ - **BPay Account Resource**: Complete BPay account management for Australian bill payments 💰
7
+ - `ZaiPayment.bpay_accounts.show(bpay_account_id)` - Get BPay account details including biller information
8
+ - `ZaiPayment.bpay_accounts.create(user_id:, account_name:, biller_code:, bpay_crn:)` - Create BPay account for disbursement destinations
9
+ - `ZaiPayment.bpay_accounts.redact(bpay_account_id)` - Redact (deactivate) a BPay account
10
+ - `ZaiPayment.bpay_accounts.show_user(bpay_account_id)` - Get user associated with a BPay account
11
+ - Validation for biller code (3-10 digits)
12
+ - Validation for BPay CRN (Customer Reference Number, 2-20 digits)
13
+ - Support for Australian bill payment disbursements
14
+ - Full RSpec test suite with 12 test examples across 4 describe blocks
15
+ - Comprehensive documentation in `docs/bpay_accounts.md`
16
+ - Practical examples in `examples/bpay_accounts.md`
17
+
18
+ ### Documentation
19
+ - **BPay Accounts Guide** (`docs/bpay_accounts.md`):
20
+ - Complete guide for showing, creating, redacting BPay accounts, and retrieving associated users
21
+ - Detailed API reference for all four endpoints
22
+ - Response structure documentation with example payloads
23
+ - Validation rules for biller codes and BPay CRN formats
24
+ - Error handling documentation (ValidationError, NotFoundError)
25
+ - Four comprehensive use cases:
26
+ - Disbursement account setup for bill payments
27
+ - User verification before disbursement
28
+ - Deactivating old BPay accounts
29
+ - Managing multiple utility BPay accounts
30
+ - Important notes about BPay account usage and restrictions
31
+ - **BPay Accounts Examples** (`examples/bpay_accounts.md`):
32
+ - Show BPay account examples (3 examples):
33
+ - Basic account retrieval with full details
34
+ - Error handling and status verification
35
+ - Pre-disbursement verification workflow
36
+ - Show BPay account user examples (3 examples):
37
+ - User information retrieval
38
+ - User verification before disbursement
39
+ - Contact information extraction for notifications
40
+ - Redact BPay account examples (3 examples):
41
+ - Basic redaction with response handling
42
+ - Comprehensive error handling
43
+ - Verification before redacting workflow
44
+ - Create BPay account examples (3 examples):
45
+ - Basic account creation
46
+ - Error handling patterns
47
+ - Multiple utility account setup
48
+ - Four common patterns:
49
+ - Retrieve and verify before disbursement
50
+ - Complete onboarding workflow with user creation
51
+ - BPay account form handler for Rails applications
52
+ - BPay details validation helper
53
+
54
+ ### Features
55
+ - BPay accounts work as disbursement destinations for Australian bill payments
56
+ - Supports all major Australian billers (utilities, telecommunications, financial services, government)
57
+ - Automatic biller name lookup based on biller code
58
+ - Full lifecycle management (create, show, show_user, redact)
59
+ - Secure validation of BPay-specific formats
60
+
61
+ **Full Changelog**: https://github.com/Sentia/zai-payment/compare/v2.5.0...v2.6.0
62
+
3
63
  ## [2.5.0] - 2025-11-03
4
64
 
5
65
  ### Added
@@ -0,0 +1,519 @@
1
+ # BPay Account Management
2
+
3
+ The BpayAccount resource provides methods for managing Zai BPay accounts for Australian bill payments.
4
+
5
+ ## Overview
6
+
7
+ BPay accounts are used as disbursement destinations for Australian bill payments. BPay is a popular Australian electronic bill payment system that allows payments to be made through the customer's internet or telephone banking facility.
8
+
9
+ Once created, store the returned `:id` and use it for disbursement operations. The `:id` is also referred to as a `:token` when invoking BPay Accounts.
10
+
11
+ ## References
12
+
13
+ - [Create BPay Account API](https://developer.hellozai.com/reference/createbpayaccount)
14
+ - [BPay Overview](https://developer.hellozai.com/docs/bpay)
15
+
16
+ ## Usage
17
+
18
+ ### Initialize the BpayAccount Resource
19
+
20
+ ```ruby
21
+ # Using a new instance
22
+ bpay_accounts = ZaiPayment::Resources::BpayAccount.new
23
+
24
+ # Or use with custom client
25
+ client = ZaiPayment::Client.new
26
+ bpay_accounts = ZaiPayment::Resources::BpayAccount.new(client: client)
27
+ ```
28
+
29
+ ## Methods
30
+
31
+ ### Show BPay Account
32
+
33
+ Get details of a specific BPay account by ID.
34
+
35
+ #### Parameters
36
+
37
+ - `bpay_account_id` (required) - The BPay account ID
38
+
39
+ #### Example
40
+
41
+ ```ruby
42
+ # Get BPay account details
43
+ response = bpay_accounts.show('bpay_account_id')
44
+
45
+ # Access BPay account details
46
+ bpay_account = response.data
47
+ puts bpay_account['id']
48
+ puts bpay_account['active']
49
+ puts bpay_account['verification_status']
50
+ puts bpay_account['currency']
51
+
52
+ # Access BPay details
53
+ bpay_details = bpay_account['bpay_details']
54
+ puts bpay_details['account_name']
55
+ puts bpay_details['biller_code']
56
+ puts bpay_details['biller_name']
57
+ puts bpay_details['crn']
58
+ ```
59
+
60
+ #### Response
61
+
62
+ ```ruby
63
+ {
64
+ "bpay_accounts" => {
65
+ "id" => "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
66
+ "active" => true,
67
+ "created_at" => "2020-04-03T07:59:00.379Z",
68
+ "updated_at" => "2020-04-03T07:59:00.379Z",
69
+ "verification_status" => "not_verified",
70
+ "currency" => "AUD",
71
+ "bpay_details" => {
72
+ "account_name" => "My Water Bill Company",
73
+ "biller_code" => 123456,
74
+ "biller_name" => "ABC Water",
75
+ "crn" => 987654321
76
+ },
77
+ "links" => {
78
+ "self" => "/bpay_accounts/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
79
+ "users" => "/bpay_accounts/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee/users"
80
+ }
81
+ }
82
+ }
83
+ ```
84
+
85
+ **Use Cases:**
86
+ - Retrieve BPay account details before disbursement
87
+ - Verify account status and verification
88
+ - Check biller information
89
+ - Validate account is active
90
+
91
+ ### Show BPay Account User
92
+
93
+ Get the User the BPay Account is associated with using a given bpay_account_id.
94
+
95
+ #### Parameters
96
+
97
+ - `bpay_account_id` (required) - The BPay account ID
98
+
99
+ #### Example
100
+
101
+ ```ruby
102
+ # Get user associated with BPay account
103
+ response = bpay_accounts.show_user('bpay_account_id')
104
+
105
+ # Access user details
106
+ user = response.data
107
+ puts user['id']
108
+ puts user['full_name']
109
+ puts user['email']
110
+ puts user['verification_state']
111
+ puts user['held_state']
112
+ ```
113
+
114
+ #### Response
115
+
116
+ ```ruby
117
+ {
118
+ "users" => {
119
+ "created_at" => "2020-04-03T07:59:00.379Z",
120
+ "updated_at" => "2020-04-03T07:59:00.379Z",
121
+ "id" => "Seller_1234",
122
+ "full_name" => "Samuel Seller",
123
+ "email" => "sam@example.com",
124
+ "mobile" => 69543131,
125
+ "first_name" => "Samuel",
126
+ "last_name" => "Seller",
127
+ "custom_descriptor" => "Sam Garden Jobs",
128
+ "location" => "AUS",
129
+ "verification_state" => "pending",
130
+ "held_state" => false,
131
+ "roles" => ["customer"],
132
+ "dob" => "encrypted",
133
+ "government_number" => "encrypted",
134
+ "flags" => {},
135
+ "related" => {
136
+ "addresses" => "11111111-2222-3333-4444-55555555555,"
137
+ },
138
+ "links" => {
139
+ "self" => "/bpay_accounts/901d8cd0-6af3-0138-967d-0a58a9feac04/users",
140
+ "items" => "/users/e6bc0480-57ae-0138-c46e-0a58a9feac03/items",
141
+ "card_accounts" => "/users/e6bc0480-57ae-0138-c46e-0a58a9feac03/card_accounts",
142
+ "bpay_accounts" => "/users/e6bc0480-57ae-0138-c46e-0a58a9feac03/bpay_accounts",
143
+ "wallet_accounts" => "/users/e6bc0480-57ae-0138-c46e-0a58a9feac03/wallet_accounts"
144
+ }
145
+ }
146
+ }
147
+ ```
148
+
149
+ **Use Cases:**
150
+ - Retrieve user information for a BPay account
151
+ - Verify user identity before disbursement
152
+ - Check user verification status
153
+ - Get user contact details for notifications
154
+
155
+ ### Redact BPay Account
156
+
157
+ Redact a BPay account using the given bpay_account_id. Redacted BPay accounts can no longer be used as a disbursement destination.
158
+
159
+ **Note**: This is marked as a "Future Feature" in the Zai API documentation but is implemented for forward compatibility.
160
+
161
+ #### Parameters
162
+
163
+ - `bpay_account_id` (required) - The BPay account ID
164
+
165
+ #### Example
166
+
167
+ ```ruby
168
+ response = bpay_accounts.redact('bpay_account_id')
169
+
170
+ if response.success?
171
+ puts "BPay account successfully redacted"
172
+ else
173
+ puts "Failed to redact BPay account"
174
+ end
175
+ ```
176
+
177
+ #### Response
178
+
179
+ ```ruby
180
+ {
181
+ "bpay_account" => "Successfully redacted"
182
+ }
183
+ ```
184
+
185
+ **Important Notes:**
186
+ - Once redacted, the BPay account cannot be used for disbursements
187
+ - This action cannot be undone
188
+ - Use with caution
189
+
190
+ ### Create BPay Account
191
+
192
+ Create a BPay Account to be used as a Disbursement destination.
193
+
194
+ #### Required Fields
195
+
196
+ - `user_id` - User ID (UUID format)
197
+ - `account_name` - Name assigned by the platform/marketplace to identify the account (similar to a nickname). Defaults to "My Water Bill Company"
198
+ - `biller_code` - The Biller Code for the biller that will receive the payment. Must be a numeric value with 3 to 10 digits.
199
+ - `bpay_crn` - Customer reference number (crn) to be used for this BPay account. The CRN must contain between 2 and 20 digits. Defaults to "987654321"
200
+
201
+ #### Example
202
+
203
+ ```ruby
204
+ bpay_accounts = ZaiPayment::Resources::BpayAccount.new
205
+
206
+ response = bpay_accounts.create(
207
+ user_id: 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee',
208
+ account_name: 'My Water Bill Company',
209
+ biller_code: 123456,
210
+ bpay_crn: '987654321'
211
+ )
212
+
213
+ if response.success?
214
+ bpay_account = response.data
215
+ puts "BPay Account ID: #{bpay_account['id']}"
216
+ puts "Active: #{bpay_account['active']}"
217
+ puts "Verification Status: #{bpay_account['verification_status']}"
218
+ puts "Currency: #{bpay_account['currency']}"
219
+
220
+ # Access BPay details
221
+ bpay_details = bpay_account['bpay_details']
222
+ puts "Account Name: #{bpay_details['account_name']}"
223
+ puts "Biller Code: #{bpay_details['biller_code']}"
224
+ puts "Biller Name: #{bpay_details['biller_name']}"
225
+ puts "CRN: #{bpay_details['crn']}"
226
+
227
+ # Access links
228
+ links = bpay_account['links']
229
+ puts "Self Link: #{links['self']}"
230
+ puts "Users Link: #{links['users']}"
231
+ end
232
+ ```
233
+
234
+ ## Response Structure
235
+
236
+ The methods return a `ZaiPayment::Response` object with the following structure:
237
+
238
+ ```ruby
239
+ {
240
+ "bpay_accounts" => {
241
+ "id" => "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
242
+ "created_at" => "2020-04-03T07:59:00.379Z",
243
+ "updated_at" => "2020-04-03T07:59:00.379Z",
244
+ "active" => true,
245
+ "verification_status" => "not_verified",
246
+ "currency" => "AUD",
247
+ "bpay_details" => {
248
+ "account_name" => "My Water Bill Company",
249
+ "biller_code" => 123456,
250
+ "biller_name" => "ABC Water",
251
+ "crn" => 987654321
252
+ },
253
+ "links" => {
254
+ "self" => "/bpay_accounts/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
255
+ "users" => "/bpay_accounts/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee/users"
256
+ }
257
+ }
258
+ }
259
+ ```
260
+
261
+ ## Validation Rules
262
+
263
+ ### Biller Code
264
+
265
+ - Must be a numeric value
266
+ - Must contain between 3 and 10 digits
267
+ - Examples: `123`, `123456`, `1234567890`
268
+
269
+ ### BPay CRN (Customer Reference Number)
270
+
271
+ - Must be numeric
272
+ - Must contain between 2 and 20 digits
273
+ - Examples: `12`, `987654321`, `12345678901234567890`
274
+
275
+ ### Account Name
276
+
277
+ - Required field
278
+ - Used to identify the account (similar to a nickname)
279
+ - Should be descriptive (e.g., "Water Bill", "Electricity Account")
280
+
281
+ ### User ID
282
+
283
+ - Required field
284
+ - Must be a valid UUID
285
+ - Must reference an existing user in the system
286
+
287
+ ## Error Handling
288
+
289
+ The BpayAccount resource raises the following errors:
290
+
291
+ ### NotFoundError
292
+
293
+ Raised when the BPay account does not exist:
294
+
295
+ ```ruby
296
+ begin
297
+ bpay_accounts.show('invalid_id')
298
+ rescue ZaiPayment::Errors::NotFoundError => e
299
+ puts "BPay account not found: #{e.message}"
300
+ end
301
+ ```
302
+
303
+ ### ValidationError
304
+
305
+ Raised when required fields are missing or invalid:
306
+
307
+ ```ruby
308
+ begin
309
+ bpay_accounts.create(
310
+ user_id: 'user_123',
311
+ account_name: 'Test Account'
312
+ # Missing required fields
313
+ )
314
+ rescue ZaiPayment::Errors::ValidationError => e
315
+ puts "Validation failed: #{e.message}"
316
+ # => "Missing required fields: biller_code, bpay_crn"
317
+ end
318
+ ```
319
+
320
+ ### Invalid Biller Code
321
+
322
+ ```ruby
323
+ begin
324
+ bpay_accounts.create(
325
+ user_id: 'user_123',
326
+ account_name: 'Test Account',
327
+ biller_code: 12, # Only 2 digits (requires 3-10)
328
+ bpay_crn: '987654321'
329
+ )
330
+ rescue ZaiPayment::Errors::ValidationError => e
331
+ puts e.message
332
+ # => "biller_code must be a numeric value with 3 to 10 digits"
333
+ end
334
+ ```
335
+
336
+ ### Invalid BPay CRN
337
+
338
+ ```ruby
339
+ begin
340
+ bpay_accounts.create(
341
+ user_id: 'user_123',
342
+ account_name: 'Test Account',
343
+ biller_code: 123456,
344
+ bpay_crn: '1' # Only 1 digit (requires 2-20)
345
+ )
346
+ rescue ZaiPayment::Errors::ValidationError => e
347
+ puts e.message
348
+ # => "bpay_crn must contain between 2 and 20 digits"
349
+ end
350
+ ```
351
+
352
+ ### Blank BPay Account ID
353
+
354
+ Raised when trying to show or redact a BPay account with blank/nil ID:
355
+
356
+ ```ruby
357
+ begin
358
+ bpay_accounts.show('')
359
+ # or
360
+ bpay_accounts.redact(nil)
361
+ rescue ZaiPayment::Errors::ValidationError => e
362
+ puts "Invalid ID: #{e.message}"
363
+ # => "bpay_account_id is required and cannot be blank"
364
+ end
365
+ ```
366
+
367
+ ## Use Cases
368
+
369
+ ### Use Case 1: Disbursement Account for Bill Payments
370
+
371
+ After creating a payout user, create a BPay account for receiving bill payments:
372
+
373
+ ```ruby
374
+ # Step 1: Create payout user
375
+ users = ZaiPayment::Resources::User.new
376
+ user_response = users.create(
377
+ user_type: 'payout',
378
+ email: 'biller@example.com',
379
+ first_name: 'Water',
380
+ last_name: 'Company',
381
+ country: 'AUS',
382
+ dob: '01/01/1990',
383
+ address_line1: '123 Main St',
384
+ city: 'Sydney',
385
+ state: 'NSW',
386
+ zip: '2000'
387
+ )
388
+
389
+ user_id = user_response.data['id']
390
+
391
+ # Step 2: Create BPay account
392
+ bpay_accounts = ZaiPayment::Resources::BpayAccount.new
393
+ bpay_response = bpay_accounts.create(
394
+ user_id: user_id,
395
+ account_name: 'Water Bill Payment',
396
+ biller_code: 123456,
397
+ bpay_crn: '987654321'
398
+ )
399
+
400
+ account_id = bpay_response.data['id']
401
+
402
+ # Step 3: Set as disbursement account
403
+ users.set_disbursement_account(user_id, account_id)
404
+ ```
405
+
406
+ ### Use Case 2: Get User Details for BPay Account
407
+
408
+ Retrieve user information associated with a BPay account:
409
+
410
+ ```ruby
411
+ bpay_accounts = ZaiPayment::Resources::BpayAccount.new
412
+
413
+ # Step 1: Get user details
414
+ user_response = bpay_accounts.show_user('bpay_account_id')
415
+
416
+ if user_response.success?
417
+ user = user_response.data
418
+
419
+ # Step 2: Verify user is eligible for disbursement
420
+ if user['verification_state'] == 'verified' && !user['held_state']
421
+ puts "User eligible for disbursement"
422
+ puts "Name: #{user['full_name']}"
423
+ puts "Email: #{user['email']}"
424
+
425
+ # Proceed with disbursement
426
+ else
427
+ puts "User not eligible"
428
+ puts "Verification: #{user['verification_state']}"
429
+ puts "Held: #{user['held_state']}"
430
+ end
431
+ end
432
+ ```
433
+
434
+ ### Use Case 3: Deactivate Old BPay Account
435
+
436
+ Redact an old BPay account that is no longer needed:
437
+
438
+ ```ruby
439
+ bpay_accounts = ZaiPayment::Resources::BpayAccount.new
440
+
441
+ # Step 1: Verify the account before redacting
442
+ response = bpay_accounts.show('old_bpay_account_id')
443
+
444
+ if response.success?
445
+ bpay_account = response.data
446
+ puts "Redacting: #{bpay_account['bpay_details']['account_name']}"
447
+
448
+ # Step 2: Redact the account
449
+ redact_response = bpay_accounts.redact('old_bpay_account_id')
450
+
451
+ if redact_response.success?
452
+ puts "BPay account successfully redacted"
453
+ end
454
+ end
455
+ ```
456
+
457
+ ### Use Case 4: Multiple Utility BPay Accounts
458
+
459
+ Create multiple BPay accounts for different utility bills:
460
+
461
+ ```ruby
462
+ bpay_accounts = ZaiPayment::Resources::BpayAccount.new
463
+
464
+ # Water bill
465
+ water_response = bpay_accounts.create(
466
+ user_id: 'user_123',
467
+ account_name: 'Sydney Water Bill',
468
+ biller_code: 12345,
469
+ bpay_crn: '1122334455'
470
+ )
471
+
472
+ # Electricity bill
473
+ electricity_response = bpay_accounts.create(
474
+ user_id: 'user_123',
475
+ account_name: 'Energy Australia Bill',
476
+ biller_code: 67890,
477
+ bpay_crn: '9988776655'
478
+ )
479
+
480
+ # Gas bill
481
+ gas_response = bpay_accounts.create(
482
+ user_id: 'user_123',
483
+ account_name: 'AGL Gas Bill',
484
+ biller_code: 54321,
485
+ bpay_crn: '5566778899'
486
+ )
487
+ ```
488
+
489
+ ## Important Notes
490
+
491
+ 1. **Australian Only**: BPay is an Australian payment system and typically uses AUD currency
492
+ 2. **Disbursement Use**: BPay accounts are used as disbursement destinations, not funding sources
493
+ 3. **Verification**: New BPay accounts typically have `verification_status: "not_verified"` until verified by Zai
494
+ 4. **Biller Information**: The API returns `biller_name` which is retrieved based on the `biller_code`
495
+ 5. **Token Usage**: The returned `id` can be used as a token for disbursement operations
496
+ 6. **CRN Format**: The CRN (Customer Reference Number) format may vary by biller - check with the specific biller for their format requirements
497
+
498
+ ## Common BPay Billers
499
+
500
+ BPay biller codes are assigned by BPAY. Some common categories include:
501
+
502
+ - **Utilities**: Water, electricity, gas
503
+ - **Telecommunications**: Phone, internet, mobile
504
+ - **Financial Services**: Credit cards, loans, insurance
505
+ - **Government**: Council rates, fines, taxes
506
+
507
+ **Note**: Always verify the biller code with the actual biller before creating a BPay account.
508
+
509
+ ## Related Resources
510
+
511
+ - [User Management](users.md) - Creating and managing users
512
+ - [Disbursement Accounts](users.md#set-disbursement-account) - Setting default payout accounts
513
+
514
+ ## Further Reading
515
+
516
+ - [BPay Overview](https://www.bpay.com.au/)
517
+ - [Payment Methods Guide](https://developer.hellozai.com/docs/payment-methods)
518
+ - [Verification Process](https://developer.hellozai.com/docs/verification)
519
+