zai_payment 2.9.0 → 2.9.1

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.
@@ -1,496 +0,0 @@
1
- # Bank Account Management
2
-
3
- The BankAccount resource provides methods for managing Zai bank accounts for both Australian and UK regions.
4
-
5
- ## Overview
6
-
7
- Bank accounts are used as either a funding source or a disbursement destination. Once created, store the returned `:id` and use it for a `make_payment` Item Action call. The `:id` is also referred to as a `:token` when invoking Bank Accounts.
8
-
9
- For platforms operating in the UK, `iban` and `swift_code` are extra required fields in addition to the standard Australian fields.
10
-
11
- ## References
12
-
13
- - [Create Bank Account API](https://developer.hellozai.com/reference/createbankaccount)
14
- - [Bank Account Formats by Country](https://developer.hellozai.com/docs/bank-account-formats)
15
-
16
- ## Usage
17
-
18
- ### Initialize the BankAccount Resource
19
-
20
- ```ruby
21
- # Using a new instance
22
- bank_accounts = ZaiPayment::Resources::BankAccount.new
23
-
24
- # Or use with custom client
25
- client = ZaiPayment::Client.new
26
- bank_accounts = ZaiPayment::Resources::BankAccount.new(client: client)
27
- ```
28
-
29
- ## Methods
30
-
31
- ### Show Bank Account
32
-
33
- Get details of a specific bank account by ID.
34
-
35
- #### Parameters
36
-
37
- - `bank_account_id` (required) - The bank account ID
38
- - `include_decrypted_fields` (optional) - Boolean. If true, the API will decrypt and return sensitive bank account fields (for example, the full account number). Defaults to false.
39
-
40
- #### Example
41
-
42
- ```ruby
43
- # Basic usage (returns masked account numbers)
44
- response = bank_accounts.show('bank_account_id')
45
-
46
- # Access bank account details
47
- bank_account = response.data
48
- puts bank_account['id']
49
- puts bank_account['active']
50
- puts bank_account['verification_status']
51
- puts bank_account['currency']
52
-
53
- # Access bank details (account numbers are masked)
54
- bank = bank_account['bank']
55
- puts bank['bank_name']
56
- puts bank['account_name']
57
- puts bank['account_type']
58
- puts bank['account_number'] # => "XXX234" (masked)
59
- ```
60
-
61
- #### Example with Decrypted Fields
62
-
63
- ```ruby
64
- # Request with decrypted fields
65
- response = bank_accounts.show('bank_account_id', include_decrypted_fields: true)
66
-
67
- # Access bank details (account numbers are decrypted)
68
- bank = response.data['bank']
69
- puts bank['account_number'] # => "12345678" (full number)
70
- puts bank['routing_number'] # => "111123" (full number)
71
- ```
72
-
73
- ### Redact Bank Account
74
-
75
- Redact a bank account using the given bank_account_id. Redacted bank accounts can no longer be used as a funding source or a disbursement destination.
76
-
77
- #### Parameters
78
-
79
- - `bank_account_id` (required) - The bank account ID
80
-
81
- #### Example
82
-
83
- ```ruby
84
- response = bank_accounts.redact('bank_account_id')
85
-
86
- if response.success?
87
- puts "Bank account successfully redacted"
88
- else
89
- puts "Failed to redact bank account"
90
- end
91
- ```
92
-
93
- #### Response
94
-
95
- ```ruby
96
- {
97
- "bank_account" => "Successfully redacted"
98
- }
99
- ```
100
-
101
- **Important Notes:**
102
- - Once redacted, the bank account cannot be used for payments or disbursements
103
- - This action cannot be undone
104
- - Use with caution
105
-
106
- ### Validate Routing Number
107
-
108
- Validate a US bank routing number before creating an account. This can be used to provide on-demand verification and further information of the bank information a user is providing.
109
-
110
- #### Parameters
111
-
112
- - `routing_number` (required) - The US bank routing number (9 digits)
113
-
114
- #### Example
115
-
116
- ```ruby
117
- response = bank_accounts.validate_routing_number('122235821')
118
-
119
- if response.success?
120
- routing_info = response.data['routing_number']
121
- puts "Routing Number: #{routing_info['routing_number']}"
122
- puts "Bank Name: #{routing_info['customer_name']}"
123
- puts "City: #{routing_info['city']}"
124
- puts "State: #{routing_info['state_code']}"
125
- puts "ZIP: #{routing_info['zip']}"
126
- puts "Phone: #{routing_info['phone_area_code']}-#{routing_info['phone_prefix']}-#{routing_info['phone_suffix']}"
127
- else
128
- puts "Invalid routing number"
129
- end
130
- ```
131
-
132
- #### Response
133
-
134
- ```ruby
135
- {
136
- "routing_number" => {
137
- "routing_number" => "122235821",
138
- "customer_name" => "US BANK NA",
139
- "address" => "EP-MN-WN1A",
140
- "city" => "ST. PAUL",
141
- "state_code" => "MN",
142
- "zip" => "55107",
143
- "zip_extension" => "1419",
144
- "phone_area_code" => "800",
145
- "phone_prefix" => "937",
146
- "phone_suffix" => "631"
147
- }
148
- }
149
- ```
150
-
151
- **Use Cases:**
152
- - Validate routing numbers before bank account creation
153
- - Display bank information to users for confirmation
154
- - Provide real-time feedback during form entry
155
- - Reduce errors in bank account setup
156
-
157
- ### Create Australian Bank Account
158
-
159
- Create a new bank account for an Australian user.
160
-
161
- #### Required Fields
162
-
163
- - `user_id` - User ID (defaults to aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee)
164
- - `bank_name` - Bank name (defaults to Bank of Australia)
165
- - `account_name` - Account name (defaults to Samuel Seller)
166
- - `routing_number` - Routing number / BSB number (defaults to 111123). See [Bank account formats by country](https://developer.hellozai.com/docs/bank-account-formats).
167
- - `account_number` - Account number (defaults to 111234). See [Bank account formats by country](https://developer.hellozai.com/docs/bank-account-formats).
168
- - `account_type` - Bank account type ('savings' or 'checking', defaults to checking)
169
- - `holder_type` - Holder type ('personal' or 'business', defaults to personal)
170
- - `country` - ISO 3166-1 alpha-3 country code (length ≤ 3, defaults to AUS)
171
-
172
- #### Optional Fields
173
-
174
- - `payout_currency` - ISO 4217 alpha-3 currency code for payouts
175
- - `currency` - ISO 4217 alpha-3 currency code. This is an optional field and if not provided, the item will be created with the default currency of the marketplace.
176
-
177
- #### Example
178
-
179
- ```ruby
180
- response = bank_accounts.create_au(
181
- user_id: 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee',
182
- bank_name: 'Bank of Australia',
183
- account_name: 'Samuel Seller',
184
- routing_number: '111123',
185
- account_number: '111234',
186
- account_type: 'checking',
187
- holder_type: 'personal',
188
- country: 'AUS',
189
- payout_currency: 'AUD',
190
- currency: 'AUD'
191
- )
192
-
193
- if response.success?
194
- bank_account = response.data
195
- puts "Bank Account ID: #{bank_account['id']}"
196
- puts "Active: #{bank_account['active']}"
197
- puts "Verification Status: #{bank_account['verification_status']}"
198
- puts "Currency: #{bank_account['currency']}"
199
-
200
- # Access bank details
201
- bank = bank_account['bank']
202
- puts "Bank Name: #{bank['bank_name']}"
203
- puts "Account Name: #{bank['account_name']}"
204
- puts "Account Type: #{bank['account_type']}"
205
- puts "Holder Type: #{bank['holder_type']}"
206
- puts "Routing Number: #{bank['routing_number']}"
207
- puts "Direct Debit Status: #{bank['direct_debit_authority_status']}"
208
-
209
- # Access links
210
- links = bank_account['links']
211
- puts "Self Link: #{links['self']}"
212
- puts "Users Link: #{links['users']}"
213
- end
214
- ```
215
-
216
- ### Create UK Bank Account
217
-
218
- Create a new bank account for a UK user. UK bank accounts require additional fields: `iban` and `swift_code`.
219
-
220
- #### Required Fields
221
-
222
- All fields from Australian bank accounts plus:
223
-
224
- - `iban` - International Bank Account Number (required for UK)
225
- - `swift_code` - SWIFT Code / BIC (required for UK)
226
-
227
- #### Example
228
-
229
- ```ruby
230
- response = bank_accounts.create_uk(
231
- user_id: 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee',
232
- bank_name: 'Bank of UK',
233
- account_name: 'Samuel Seller',
234
- routing_number: '111123',
235
- account_number: '111234',
236
- account_type: 'checking',
237
- holder_type: 'personal',
238
- country: 'GBR',
239
- iban: 'GB25QHWM02498765432109',
240
- swift_code: 'BUKBGB22',
241
- payout_currency: 'GBP',
242
- currency: 'GBP'
243
- )
244
-
245
- if response.success?
246
- bank_account = response.data
247
- puts "Bank Account ID: #{bank_account['id']}"
248
-
249
- bank = bank_account['bank']
250
- puts "IBAN: #{bank['iban']}"
251
- puts "SWIFT Code: #{bank['swift_code']}"
252
- end
253
- ```
254
-
255
- ## Response Structure
256
-
257
- Both methods return a `ZaiPayment::Response` object with the following structure:
258
-
259
- ```ruby
260
- {
261
- "bank_accounts" => {
262
- "id" => "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
263
- "active" => true,
264
- "verification_status" => "not_verified",
265
- "currency" => "AUD",
266
- "bank" => {
267
- "bank_name" => "Bank of Australia",
268
- "country" => "AUS",
269
- "account_name" => "Samuel Seller",
270
- "routing_number" => "XXXXX3", # Masked for security
271
- "account_number" => "XXX234", # Masked for security
272
- "iban" => "null,", # Or actual IBAN for UK
273
- "swift_code" => "null,", # Or actual SWIFT for UK
274
- "holder_type" => "personal",
275
- "account_type" => "checking",
276
- "direct_debit_authority_status" => "approved"
277
- },
278
- "links" => {
279
- "self" => "/bank_accounts/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
280
- "users" => "/bank_accounts/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee/users",
281
- "direct_debit_authorities" => "/bank_accounts/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee/direct_debit_authorities"
282
- }
283
- }
284
- }
285
- ```
286
-
287
- ## Validation Rules
288
-
289
- ### Account Type
290
-
291
- Must be one of:
292
- - `savings` - Savings account
293
- - `checking` - Checking/current account
294
-
295
- ### Holder Type
296
-
297
- Must be one of:
298
- - `personal` - Personal/individual account
299
- - `business` - Business/company account
300
-
301
- ### Country Code
302
-
303
- Must be a valid ISO 3166-1 alpha-3 code (3 letters):
304
- - Australia: `AUS`
305
- - United Kingdom: `GBR`
306
-
307
- ### Currency Code
308
-
309
- When provided, must be a valid ISO 4217 alpha-3 code:
310
- - Australian Dollar: `AUD`
311
- - British Pound: `GBP`
312
- - US Dollar: `USD`
313
-
314
- ## Error Handling
315
-
316
- The BankAccount resource raises the following errors:
317
-
318
- ### ValidationError
319
-
320
- Raised when required fields are missing or invalid:
321
-
322
- ```ruby
323
- begin
324
- bank_accounts.create_au(
325
- user_id: 'user_123',
326
- bank_name: 'Test Bank'
327
- # Missing required fields
328
- )
329
- rescue ZaiPayment::Errors::ValidationError => e
330
- puts "Validation failed: #{e.message}"
331
- # => "Missing required fields: account_name, routing_number, account_number, account_type, holder_type, country"
332
- end
333
- ```
334
-
335
- ### Invalid Account Type
336
-
337
- ```ruby
338
- begin
339
- bank_accounts.create_au(
340
- user_id: 'user_123',
341
- bank_name: 'Test Bank',
342
- account_name: 'Test',
343
- routing_number: '111123',
344
- account_number: '111234',
345
- account_type: 'invalid',
346
- holder_type: 'personal',
347
- country: 'AUS'
348
- )
349
- rescue ZaiPayment::Errors::ValidationError => e
350
- puts e.message
351
- # => "account_type must be one of: savings, checking"
352
- end
353
- ```
354
-
355
- ### Invalid Holder Type
356
-
357
- ```ruby
358
- begin
359
- bank_accounts.create_au(
360
- user_id: 'user_123',
361
- bank_name: 'Test Bank',
362
- account_name: 'Test',
363
- routing_number: '111123',
364
- account_number: '111234',
365
- account_type: 'checking',
366
- holder_type: 'invalid',
367
- country: 'AUS'
368
- )
369
- rescue ZaiPayment::Errors::ValidationError => e
370
- puts e.message
371
- # => "holder_type must be one of: personal, business"
372
- end
373
- ```
374
-
375
- ### Invalid Country Code
376
-
377
- ```ruby
378
- begin
379
- bank_accounts.create_au(
380
- user_id: 'user_123',
381
- bank_name: 'Test Bank',
382
- account_name: 'Test',
383
- routing_number: '111123',
384
- account_number: '111234',
385
- account_type: 'checking',
386
- holder_type: 'personal',
387
- country: 'INVALID'
388
- )
389
- rescue ZaiPayment::Errors::ValidationError => e
390
- puts e.message
391
- # => "country must be a valid ISO 3166-1 alpha-3 code (e.g., AUS, GBR)"
392
- end
393
- ```
394
-
395
- ## Use Cases
396
-
397
- ### Use Case 1: Disbursement Account Setup
398
-
399
- After creating a payout user (seller), create a bank account for receiving payments:
400
-
401
- ```ruby
402
- # Step 1: Create payout user
403
- users = ZaiPayment::Resources::User.new
404
- user_response = users.create(
405
- user_type: 'payout',
406
- email: 'seller@example.com',
407
- first_name: 'Jane',
408
- last_name: 'Seller',
409
- country: 'AUS',
410
- dob: '01/01/1990',
411
- address_line1: '123 Main St',
412
- city: 'Sydney',
413
- state: 'NSW',
414
- zip: '2000'
415
- )
416
-
417
- user_id = user_response.data['id']
418
-
419
- # Step 2: Create bank account
420
- bank_accounts = ZaiPayment::Resources::BankAccount.new
421
- bank_response = bank_accounts.create_au(
422
- user_id: user_id,
423
- bank_name: 'Commonwealth Bank',
424
- account_name: 'Jane Seller',
425
- routing_number: '062000',
426
- account_number: '12345678',
427
- account_type: 'savings',
428
- holder_type: 'personal',
429
- country: 'AUS',
430
- payout_currency: 'AUD'
431
- )
432
-
433
- account_id = bank_response.data['id']
434
-
435
- # Step 3: Set as disbursement account
436
- users.set_disbursement_account(user_id, account_id)
437
- ```
438
-
439
- ### Use Case 2: Multi-Currency Business Account
440
-
441
- Create business bank accounts for different currencies:
442
-
443
- ```ruby
444
- bank_accounts = ZaiPayment::Resources::BankAccount.new
445
-
446
- # Australian business account
447
- au_response = bank_accounts.create_au(
448
- user_id: 'business_user_123',
449
- bank_name: 'Westpac',
450
- account_name: 'ABC Pty Ltd',
451
- routing_number: '032000',
452
- account_number: '87654321',
453
- account_type: 'checking',
454
- holder_type: 'business',
455
- country: 'AUS',
456
- payout_currency: 'AUD'
457
- )
458
-
459
- # UK business account
460
- uk_response = bank_accounts.create_uk(
461
- user_id: 'business_user_123',
462
- bank_name: 'Barclays',
463
- account_name: 'ABC Limited',
464
- routing_number: '200000',
465
- account_number: '55779911',
466
- account_type: 'checking',
467
- holder_type: 'business',
468
- country: 'GBR',
469
- iban: 'GB33BUKB20000055779911',
470
- swift_code: 'BARCGB22',
471
- payout_currency: 'GBP'
472
- )
473
- ```
474
-
475
- ## Important Notes
476
-
477
- 1. **Security**: Account numbers and routing numbers are masked in API responses for security
478
- 2. **Verification**: New bank accounts typically have `verification_status: "not_verified"` until verified by Zai
479
- 3. **Direct Debit**: The `direct_debit_authority_status` indicates if direct debit is available for the account
480
- 4. **Token Usage**: The returned `id` can be used as a token for payment operations
481
- 5. **Region Differences**:
482
- - Australia: Only requires standard banking details
483
- - UK: Additionally requires IBAN and SWIFT code
484
-
485
- ## Related Resources
486
-
487
- - [User Management](users.md) - Creating and managing users
488
- - [Item Management](items.md) - Creating transactions/payments
489
- - [Disbursement Accounts](users.md#set-disbursement-account) - Setting default payout accounts
490
-
491
- ## Further Reading
492
-
493
- - [Bank Account Formats by Country](https://developer.hellozai.com/docs/bank-account-formats)
494
- - [Payment Methods Guide](https://developer.hellozai.com/docs/payment-methods)
495
- - [Verification Process](https://developer.hellozai.com/docs/verification)
496
-