zai_payment 2.4.0 → 2.5.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/badges/coverage.json +1 -1
- data/changelog.md +41 -0
- data/docs/bank_accounts.md +494 -0
- data/examples/bank_accounts.md +637 -0
- data/lib/zai_payment/resources/bank_account.rb +295 -0
- data/lib/zai_payment/response.rb +1 -0
- data/lib/zai_payment/version.rb +1 -1
- data/lib/zai_payment.rb +6 -0
- data/readme.md +18 -150
- metadata +4 -1
|
@@ -0,0 +1,637 @@
|
|
|
1
|
+
# Bank Account Management Examples
|
|
2
|
+
|
|
3
|
+
This document provides practical examples for managing bank accounts in Zai Payment.
|
|
4
|
+
|
|
5
|
+
## Table of Contents
|
|
6
|
+
|
|
7
|
+
- [Setup](#setup)
|
|
8
|
+
- [Show Bank Account Example](#show-bank-account-example)
|
|
9
|
+
- [Redact Bank Account Example](#redact-bank-account-example)
|
|
10
|
+
- [Validate Routing Number Example](#validate-routing-number-example)
|
|
11
|
+
- [Australian Bank Account Examples](#australian-bank-account-examples)
|
|
12
|
+
- [UK Bank Account Examples](#uk-bank-account-examples)
|
|
13
|
+
- [Common Patterns](#common-patterns)
|
|
14
|
+
|
|
15
|
+
## Setup
|
|
16
|
+
|
|
17
|
+
```ruby
|
|
18
|
+
require 'zai_payment'
|
|
19
|
+
|
|
20
|
+
# Configure ZaiPayment
|
|
21
|
+
ZaiPayment.configure do |config|
|
|
22
|
+
config.environment = :prelive # or :production
|
|
23
|
+
config.client_id = ENV['ZAI_CLIENT_ID']
|
|
24
|
+
config.client_secret = ENV['ZAI_CLIENT_SECRET']
|
|
25
|
+
config.scope = ENV['ZAI_SCOPE']
|
|
26
|
+
end
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Show Bank Account Example
|
|
30
|
+
|
|
31
|
+
### Example 1: Get Bank Account Details
|
|
32
|
+
|
|
33
|
+
Retrieve details of a specific bank account.
|
|
34
|
+
|
|
35
|
+
```ruby
|
|
36
|
+
# Get bank account details
|
|
37
|
+
bank_accounts = ZaiPayment::Resources::BankAccount.new
|
|
38
|
+
|
|
39
|
+
response = bank_accounts.show('aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee')
|
|
40
|
+
|
|
41
|
+
if response.success?
|
|
42
|
+
bank_account = response.data
|
|
43
|
+
puts "Bank Account ID: #{bank_account['id']}"
|
|
44
|
+
puts "Active: #{bank_account['active']}"
|
|
45
|
+
puts "Verification Status: #{bank_account['verification_status']}"
|
|
46
|
+
puts "Currency: #{bank_account['currency']}"
|
|
47
|
+
|
|
48
|
+
# Access bank details (numbers are masked by default)
|
|
49
|
+
bank = bank_account['bank']
|
|
50
|
+
puts "\nBank Details:"
|
|
51
|
+
puts " Bank Name: #{bank['bank_name']}"
|
|
52
|
+
puts " Country: #{bank['country']}"
|
|
53
|
+
puts " Account Name: #{bank['account_name']}"
|
|
54
|
+
puts " Account Type: #{bank['account_type']}"
|
|
55
|
+
puts " Holder Type: #{bank['holder_type']}"
|
|
56
|
+
puts " Account Number: #{bank['account_number']}" # => "XXX234" (masked)
|
|
57
|
+
puts " Routing Number: #{bank['routing_number']}" # => "XXXXX3" (masked)
|
|
58
|
+
puts " Direct Debit Status: #{bank['direct_debit_authority_status']}"
|
|
59
|
+
|
|
60
|
+
# Access links
|
|
61
|
+
links = bank_account['links']
|
|
62
|
+
puts "\nLinks:"
|
|
63
|
+
puts " Self: #{links['self']}"
|
|
64
|
+
puts " Users: #{links['users']}"
|
|
65
|
+
else
|
|
66
|
+
puts "Failed to retrieve bank account"
|
|
67
|
+
puts "Error: #{response.error}"
|
|
68
|
+
end
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Example 2: Get Bank Account with Decrypted Fields
|
|
72
|
+
|
|
73
|
+
Retrieve full, unmasked bank account details for secure operations.
|
|
74
|
+
|
|
75
|
+
```ruby
|
|
76
|
+
# Get bank account details with decrypted fields
|
|
77
|
+
bank_accounts = ZaiPayment::Resources::BankAccount.new
|
|
78
|
+
|
|
79
|
+
response = bank_accounts.show('aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee',
|
|
80
|
+
include_decrypted_fields: true)
|
|
81
|
+
|
|
82
|
+
if response.success?
|
|
83
|
+
bank_account = response.data
|
|
84
|
+
bank = bank_account['bank']
|
|
85
|
+
|
|
86
|
+
puts "Bank Account Details (Decrypted):"
|
|
87
|
+
puts " Account Name: #{bank['account_name']}"
|
|
88
|
+
puts " Full Account Number: #{bank['account_number']}" # => "12345678" (full number)
|
|
89
|
+
puts " Full Routing Number: #{bank['routing_number']}" # => "111123" (full number)
|
|
90
|
+
|
|
91
|
+
# Important: Handle decrypted data securely
|
|
92
|
+
# - Don't log in production
|
|
93
|
+
# - Don't store in logs
|
|
94
|
+
# - Use for immediate processing only
|
|
95
|
+
else
|
|
96
|
+
puts "Failed to retrieve bank account"
|
|
97
|
+
end
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## Redact Bank Account Example
|
|
101
|
+
|
|
102
|
+
### Example 9: Redact a Bank Account
|
|
103
|
+
|
|
104
|
+
Redact (deactivate) a bank account so it can no longer be used.
|
|
105
|
+
|
|
106
|
+
```ruby
|
|
107
|
+
# Redact a bank account
|
|
108
|
+
bank_accounts = ZaiPayment::Resources::BankAccount.new
|
|
109
|
+
|
|
110
|
+
response = bank_accounts.redact('aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee')
|
|
111
|
+
|
|
112
|
+
if response.success?
|
|
113
|
+
puts "Bank account successfully redacted"
|
|
114
|
+
puts "Response: #{response.data}"
|
|
115
|
+
# => {"bank_account"=>"Successfully redacted"}
|
|
116
|
+
|
|
117
|
+
# The bank account can no longer be used for:
|
|
118
|
+
# - Funding source for payments
|
|
119
|
+
# - Disbursement destination
|
|
120
|
+
else
|
|
121
|
+
puts "Failed to redact bank account"
|
|
122
|
+
puts "Error: #{response.error}"
|
|
123
|
+
end
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### Example 10: Redact with Error Handling
|
|
127
|
+
|
|
128
|
+
Handle edge cases when redacting a bank account.
|
|
129
|
+
|
|
130
|
+
```ruby
|
|
131
|
+
bank_accounts = ZaiPayment::Resources::BankAccount.new
|
|
132
|
+
|
|
133
|
+
begin
|
|
134
|
+
# Attempt to redact the bank account
|
|
135
|
+
response = bank_accounts.redact('bank_account_id_here')
|
|
136
|
+
|
|
137
|
+
if response.success?
|
|
138
|
+
puts "Bank account redacted successfully"
|
|
139
|
+
|
|
140
|
+
# Log the action for audit purposes
|
|
141
|
+
Rails.logger.info("Bank account #{bank_account_id} was redacted at #{Time.now}")
|
|
142
|
+
else
|
|
143
|
+
puts "Redaction failed: #{response.error}"
|
|
144
|
+
end
|
|
145
|
+
rescue ZaiPayment::Errors::NotFoundError => e
|
|
146
|
+
puts "Bank account not found: #{e.message}"
|
|
147
|
+
rescue ZaiPayment::Errors::ValidationError => e
|
|
148
|
+
puts "Invalid bank account ID: #{e.message}"
|
|
149
|
+
rescue ZaiPayment::Errors::ApiError => e
|
|
150
|
+
puts "API error occurred: #{e.message}"
|
|
151
|
+
end
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## Validate Routing Number Example
|
|
155
|
+
|
|
156
|
+
### Example 11: Validate US Bank Routing Number
|
|
157
|
+
|
|
158
|
+
Validate a US bank routing number to get bank information.
|
|
159
|
+
|
|
160
|
+
```ruby
|
|
161
|
+
# Validate a routing number
|
|
162
|
+
bank_accounts = ZaiPayment::Resources::BankAccount.new
|
|
163
|
+
|
|
164
|
+
response = bank_accounts.validate_routing_number('122235821')
|
|
165
|
+
|
|
166
|
+
if response.success?
|
|
167
|
+
routing_info = response.data
|
|
168
|
+
|
|
169
|
+
puts "Routing Number Validation Results:"
|
|
170
|
+
puts " Routing Number: #{routing_info['routing_number']}"
|
|
171
|
+
puts " Bank Name: #{routing_info['customer_name']}"
|
|
172
|
+
puts " Address: #{routing_info['address']}"
|
|
173
|
+
puts " City: #{routing_info['city']}"
|
|
174
|
+
puts " State: #{routing_info['state_code']}"
|
|
175
|
+
puts " ZIP: #{routing_info['zip']}-#{routing_info['zip_extension']}"
|
|
176
|
+
|
|
177
|
+
# Format phone number
|
|
178
|
+
phone = "#{routing_info['phone_area_code']}-#{routing_info['phone_prefix']}-#{routing_info['phone_suffix']}"
|
|
179
|
+
puts " Phone: #{phone}"
|
|
180
|
+
else
|
|
181
|
+
puts "Invalid routing number"
|
|
182
|
+
puts "Error: #{response.error}"
|
|
183
|
+
end
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
### Example 12: Validate Routing Number Before Account Creation
|
|
187
|
+
|
|
188
|
+
Use routing number validation as part of the account creation flow.
|
|
189
|
+
|
|
190
|
+
```ruby
|
|
191
|
+
bank_accounts = ZaiPayment::Resources::BankAccount.new
|
|
192
|
+
|
|
193
|
+
# Step 1: Validate the routing number
|
|
194
|
+
routing_number = '122235821'
|
|
195
|
+
|
|
196
|
+
begin
|
|
197
|
+
validation_response = bank_accounts.validate_routing_number(routing_number)
|
|
198
|
+
|
|
199
|
+
if validation_response.success?
|
|
200
|
+
bank_info = validation_response.data
|
|
201
|
+
|
|
202
|
+
# Show user the bank information for confirmation
|
|
203
|
+
puts "You are creating an account with:"
|
|
204
|
+
puts " Bank: #{bank_info['customer_name']}"
|
|
205
|
+
puts " Location: #{bank_info['city']}, #{bank_info['state_code']}"
|
|
206
|
+
|
|
207
|
+
# Step 2: Create the bank account if validation passes
|
|
208
|
+
account_response = bank_accounts.create_au(
|
|
209
|
+
user_id: 'user_123',
|
|
210
|
+
bank_name: bank_info['customer_name'],
|
|
211
|
+
account_name: 'John Doe',
|
|
212
|
+
routing_number: routing_number,
|
|
213
|
+
account_number: '12345678',
|
|
214
|
+
account_type: 'checking',
|
|
215
|
+
holder_type: 'personal',
|
|
216
|
+
country: 'USA'
|
|
217
|
+
)
|
|
218
|
+
|
|
219
|
+
if account_response.success?
|
|
220
|
+
puts "Bank account created successfully!"
|
|
221
|
+
puts "Account ID: #{account_response.data['id']}"
|
|
222
|
+
end
|
|
223
|
+
else
|
|
224
|
+
puts "Invalid routing number. Please check and try again."
|
|
225
|
+
end
|
|
226
|
+
rescue ZaiPayment::Errors::NotFoundError
|
|
227
|
+
puts "Routing number not found. Please verify the number."
|
|
228
|
+
rescue ZaiPayment::Errors::ValidationError => e
|
|
229
|
+
puts "Validation error: #{e.message}"
|
|
230
|
+
end
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
### Example 13: Real-time Routing Number Validation in Forms
|
|
234
|
+
|
|
235
|
+
Implement real-time validation for user input.
|
|
236
|
+
|
|
237
|
+
```ruby
|
|
238
|
+
# In a Rails controller or form handler
|
|
239
|
+
class BankAccountsController < ApplicationController
|
|
240
|
+
def validate_routing_number
|
|
241
|
+
routing_number = params[:routing_number]
|
|
242
|
+
|
|
243
|
+
bank_accounts = ZaiPayment::Resources::BankAccount.new
|
|
244
|
+
|
|
245
|
+
begin
|
|
246
|
+
response = bank_accounts.validate_routing_number(routing_number)
|
|
247
|
+
|
|
248
|
+
if response.success?
|
|
249
|
+
bank_info = response.data
|
|
250
|
+
|
|
251
|
+
# Return bank info to display in the form
|
|
252
|
+
render json: {
|
|
253
|
+
valid: true,
|
|
254
|
+
bank_name: bank_info['customer_name'],
|
|
255
|
+
city: bank_info['city'],
|
|
256
|
+
state: bank_info['state_code'],
|
|
257
|
+
message: "Valid routing number for #{bank_info['customer_name']}"
|
|
258
|
+
}
|
|
259
|
+
else
|
|
260
|
+
render json: {
|
|
261
|
+
valid: false,
|
|
262
|
+
message: 'Invalid routing number'
|
|
263
|
+
}, status: :unprocessable_entity
|
|
264
|
+
end
|
|
265
|
+
rescue ZaiPayment::Errors::NotFoundError
|
|
266
|
+
render json: {
|
|
267
|
+
valid: false,
|
|
268
|
+
message: 'Routing number not found'
|
|
269
|
+
}, status: :not_found
|
|
270
|
+
rescue ZaiPayment::Errors::ValidationError => e
|
|
271
|
+
render json: {
|
|
272
|
+
valid: false,
|
|
273
|
+
message: e.message
|
|
274
|
+
}, status: :bad_request
|
|
275
|
+
end
|
|
276
|
+
end
|
|
277
|
+
end
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
## Australian Bank Account Examples
|
|
281
|
+
|
|
282
|
+
### Example 1: Create Basic Australian Bank Account
|
|
283
|
+
|
|
284
|
+
Create a bank account for an Australian user with personal account details.
|
|
285
|
+
|
|
286
|
+
```ruby
|
|
287
|
+
# Create an Australian bank account
|
|
288
|
+
bank_accounts = ZaiPayment::Resources::BankAccount.new
|
|
289
|
+
|
|
290
|
+
response = bank_accounts.create_au(
|
|
291
|
+
user_id: 'user_abc123',
|
|
292
|
+
bank_name: 'Bank of Australia',
|
|
293
|
+
account_name: 'Samuel Seller',
|
|
294
|
+
routing_number: '111123', # BSB number
|
|
295
|
+
account_number: '111234',
|
|
296
|
+
account_type: 'checking',
|
|
297
|
+
holder_type: 'personal',
|
|
298
|
+
country: 'AUS'
|
|
299
|
+
)
|
|
300
|
+
|
|
301
|
+
if response.success?
|
|
302
|
+
bank_account = response.data
|
|
303
|
+
puts "Bank account created successfully!"
|
|
304
|
+
puts "Account ID: #{bank_account['id']}"
|
|
305
|
+
puts "Verification Status: #{bank_account['verification_status']}"
|
|
306
|
+
puts "Account Name: #{bank_account['bank']['account_name']}"
|
|
307
|
+
else
|
|
308
|
+
puts "Failed to create bank account"
|
|
309
|
+
puts "Error: #{response.error}"
|
|
310
|
+
end
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
### Example 4: Australian Business Bank Account
|
|
314
|
+
|
|
315
|
+
Create a business bank account for an Australian company.
|
|
316
|
+
|
|
317
|
+
```ruby
|
|
318
|
+
bank_accounts = ZaiPayment::Resources::BankAccount.new
|
|
319
|
+
|
|
320
|
+
response = bank_accounts.create_au(
|
|
321
|
+
user_id: 'user_company456',
|
|
322
|
+
bank_name: 'Commonwealth Bank',
|
|
323
|
+
account_name: 'ABC Company Pty Ltd',
|
|
324
|
+
routing_number: '062000', # BSB for Commonwealth Bank
|
|
325
|
+
account_number: '12345678',
|
|
326
|
+
account_type: 'checking',
|
|
327
|
+
holder_type: 'business', # Business account
|
|
328
|
+
country: 'AUS',
|
|
329
|
+
payout_currency: 'AUD'
|
|
330
|
+
)
|
|
331
|
+
|
|
332
|
+
if response.success?
|
|
333
|
+
bank_account = response.data
|
|
334
|
+
puts "Business bank account created: #{bank_account['id']}"
|
|
335
|
+
puts "Holder Type: #{bank_account['bank']['holder_type']}"
|
|
336
|
+
puts "Direct Debit Status: #{bank_account['bank']['direct_debit_authority_status']}"
|
|
337
|
+
end
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
### Example 5: Australian Savings Account
|
|
341
|
+
|
|
342
|
+
Create a savings account for disbursements.
|
|
343
|
+
|
|
344
|
+
```ruby
|
|
345
|
+
bank_accounts = ZaiPayment::Resources::BankAccount.new
|
|
346
|
+
|
|
347
|
+
response = bank_accounts.create_au(
|
|
348
|
+
user_id: 'user_saver789',
|
|
349
|
+
bank_name: 'National Australia Bank',
|
|
350
|
+
account_name: 'John Savings',
|
|
351
|
+
routing_number: '083000', # NAB BSB
|
|
352
|
+
account_number: '87654321',
|
|
353
|
+
account_type: 'savings', # Savings account
|
|
354
|
+
holder_type: 'personal',
|
|
355
|
+
country: 'AUS',
|
|
356
|
+
payout_currency: 'AUD',
|
|
357
|
+
currency: 'AUD'
|
|
358
|
+
)
|
|
359
|
+
|
|
360
|
+
if response.success?
|
|
361
|
+
bank_account = response.data
|
|
362
|
+
puts "Savings account created: #{bank_account['id']}"
|
|
363
|
+
puts "Currency: #{bank_account['currency']}"
|
|
364
|
+
end
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
## UK Bank Account Examples
|
|
368
|
+
|
|
369
|
+
### Example 6: Create Basic UK Bank Account
|
|
370
|
+
|
|
371
|
+
Create a bank account for a UK user with IBAN and SWIFT code.
|
|
372
|
+
|
|
373
|
+
```ruby
|
|
374
|
+
# Create a UK bank account
|
|
375
|
+
bank_accounts = ZaiPayment::Resources::BankAccount.new
|
|
376
|
+
|
|
377
|
+
response = bank_accounts.create_uk(
|
|
378
|
+
user_id: 'user_uk123',
|
|
379
|
+
bank_name: 'Bank of UK',
|
|
380
|
+
account_name: 'Samuel Seller',
|
|
381
|
+
routing_number: '111123', # Sort code
|
|
382
|
+
account_number: '111234',
|
|
383
|
+
account_type: 'checking',
|
|
384
|
+
holder_type: 'personal',
|
|
385
|
+
country: 'GBR',
|
|
386
|
+
iban: 'GB25QHWM02498765432109', # Required for UK
|
|
387
|
+
swift_code: 'BUKBGB22' # Required for UK
|
|
388
|
+
)
|
|
389
|
+
|
|
390
|
+
if response.success?
|
|
391
|
+
bank_account = response.data
|
|
392
|
+
puts "UK bank account created successfully!"
|
|
393
|
+
puts "Account ID: #{bank_account['id']}"
|
|
394
|
+
puts "IBAN: #{bank_account['bank']['iban']}"
|
|
395
|
+
puts "SWIFT: #{bank_account['bank']['swift_code']}"
|
|
396
|
+
else
|
|
397
|
+
puts "Failed to create UK bank account"
|
|
398
|
+
puts "Error: #{response.error}"
|
|
399
|
+
end
|
|
400
|
+
```
|
|
401
|
+
|
|
402
|
+
### Example 7: UK Business Bank Account
|
|
403
|
+
|
|
404
|
+
Create a business bank account for a UK company with full details.
|
|
405
|
+
|
|
406
|
+
```ruby
|
|
407
|
+
bank_accounts = ZaiPayment::Resources::BankAccount.new
|
|
408
|
+
|
|
409
|
+
response = bank_accounts.create_uk(
|
|
410
|
+
user_id: 'user_uk_company456',
|
|
411
|
+
bank_name: 'Barclays Bank',
|
|
412
|
+
account_name: 'XYZ Limited',
|
|
413
|
+
routing_number: '200000', # Barclays sort code
|
|
414
|
+
account_number: '55779911',
|
|
415
|
+
account_type: 'checking',
|
|
416
|
+
holder_type: 'business',
|
|
417
|
+
country: 'GBR',
|
|
418
|
+
iban: 'GB33BUKB20000055779911',
|
|
419
|
+
swift_code: 'BARCGB22',
|
|
420
|
+
payout_currency: 'GBP',
|
|
421
|
+
currency: 'GBP'
|
|
422
|
+
)
|
|
423
|
+
|
|
424
|
+
if response.success?
|
|
425
|
+
bank_account = response.data
|
|
426
|
+
puts "UK business account created: #{bank_account['id']}"
|
|
427
|
+
puts "Bank Name: #{bank_account['bank']['bank_name']}"
|
|
428
|
+
puts "Currency: #{bank_account['currency']}"
|
|
429
|
+
end
|
|
430
|
+
```
|
|
431
|
+
|
|
432
|
+
### Example 8: UK Savings Account with Full Details
|
|
433
|
+
|
|
434
|
+
Create a UK savings account with all available information.
|
|
435
|
+
|
|
436
|
+
```ruby
|
|
437
|
+
bank_accounts = ZaiPayment::Resources::BankAccount.new
|
|
438
|
+
|
|
439
|
+
response = bank_accounts.create_uk(
|
|
440
|
+
user_id: 'user_uk_saver789',
|
|
441
|
+
bank_name: 'HSBC UK Bank',
|
|
442
|
+
account_name: 'Jane Smith',
|
|
443
|
+
routing_number: '400000',
|
|
444
|
+
account_number: '12345678',
|
|
445
|
+
account_type: 'savings',
|
|
446
|
+
holder_type: 'personal',
|
|
447
|
+
country: 'GBR',
|
|
448
|
+
iban: 'GB82HBUK40000012345678',
|
|
449
|
+
swift_code: 'HBUKGB4B',
|
|
450
|
+
payout_currency: 'GBP',
|
|
451
|
+
currency: 'GBP'
|
|
452
|
+
)
|
|
453
|
+
|
|
454
|
+
if response.success?
|
|
455
|
+
bank_account = response.data
|
|
456
|
+
puts "UK savings account created: #{bank_account['id']}"
|
|
457
|
+
puts "Active: #{bank_account['active']}"
|
|
458
|
+
puts "Verification Status: #{bank_account['verification_status']}"
|
|
459
|
+
end
|
|
460
|
+
```
|
|
461
|
+
|
|
462
|
+
## Common Patterns
|
|
463
|
+
|
|
464
|
+
### Pattern 1: Creating Bank Account After User Registration
|
|
465
|
+
|
|
466
|
+
Typical workflow when onboarding a seller.
|
|
467
|
+
|
|
468
|
+
```ruby
|
|
469
|
+
# Step 1: Create a payout user (seller)
|
|
470
|
+
users = ZaiPayment::Resources::User.new
|
|
471
|
+
|
|
472
|
+
user_response = users.create(
|
|
473
|
+
user_type: 'payout',
|
|
474
|
+
email: 'seller@example.com',
|
|
475
|
+
first_name: 'Sarah',
|
|
476
|
+
last_name: 'Seller',
|
|
477
|
+
country: 'AUS',
|
|
478
|
+
dob: '15/01/1990',
|
|
479
|
+
address_line1: '123 Market St',
|
|
480
|
+
city: 'Sydney',
|
|
481
|
+
state: 'NSW',
|
|
482
|
+
zip: '2000',
|
|
483
|
+
mobile: '+61412345678'
|
|
484
|
+
)
|
|
485
|
+
|
|
486
|
+
user_id = user_response.data['id']
|
|
487
|
+
puts "User created: #{user_id}"
|
|
488
|
+
|
|
489
|
+
# Step 2: Create bank account for the seller
|
|
490
|
+
bank_accounts = ZaiPayment::Resources::BankAccount.new
|
|
491
|
+
|
|
492
|
+
bank_response = bank_accounts.create_au(
|
|
493
|
+
user_id: user_id,
|
|
494
|
+
bank_name: 'Bank of Australia',
|
|
495
|
+
account_name: 'Sarah Seller',
|
|
496
|
+
routing_number: '111123',
|
|
497
|
+
account_number: '111234',
|
|
498
|
+
account_type: 'checking',
|
|
499
|
+
holder_type: 'personal',
|
|
500
|
+
country: 'AUS',
|
|
501
|
+
payout_currency: 'AUD'
|
|
502
|
+
)
|
|
503
|
+
|
|
504
|
+
if bank_response.success?
|
|
505
|
+
bank_account_id = bank_response.data['id']
|
|
506
|
+
puts "Bank account created: #{bank_account_id}"
|
|
507
|
+
|
|
508
|
+
# Step 3: Set as disbursement account
|
|
509
|
+
users.set_disbursement_account(user_id, bank_account_id)
|
|
510
|
+
puts "Disbursement account set successfully"
|
|
511
|
+
end
|
|
512
|
+
```
|
|
513
|
+
|
|
514
|
+
### Pattern 2: Error Handling
|
|
515
|
+
|
|
516
|
+
Handle validation errors when creating bank accounts.
|
|
517
|
+
|
|
518
|
+
```ruby
|
|
519
|
+
bank_accounts = ZaiPayment::Resources::BankAccount.new
|
|
520
|
+
|
|
521
|
+
begin
|
|
522
|
+
response = bank_accounts.create_au(
|
|
523
|
+
user_id: 'user_123',
|
|
524
|
+
bank_name: 'Test Bank',
|
|
525
|
+
account_name: 'Test User',
|
|
526
|
+
routing_number: '111123',
|
|
527
|
+
account_number: '111234',
|
|
528
|
+
account_type: 'invalid_type', # This will cause an error
|
|
529
|
+
holder_type: 'personal',
|
|
530
|
+
country: 'AUS'
|
|
531
|
+
)
|
|
532
|
+
rescue ZaiPayment::Errors::ValidationError => e
|
|
533
|
+
puts "Validation error: #{e.message}"
|
|
534
|
+
rescue ZaiPayment::Errors::ApiError => e
|
|
535
|
+
puts "API error: #{e.message}"
|
|
536
|
+
puts "Status code: #{e.status_code}"
|
|
537
|
+
end
|
|
538
|
+
```
|
|
539
|
+
|
|
540
|
+
### Pattern 3: Multi-Region Setup
|
|
541
|
+
|
|
542
|
+
Create bank accounts for users in different regions.
|
|
543
|
+
|
|
544
|
+
```ruby
|
|
545
|
+
bank_accounts = ZaiPayment::Resources::BankAccount.new
|
|
546
|
+
|
|
547
|
+
# Helper method to create region-specific bank account
|
|
548
|
+
def create_bank_account_for_region(bank_accounts, user_id, region, account_details)
|
|
549
|
+
case region
|
|
550
|
+
when :australia
|
|
551
|
+
bank_accounts.create_au(
|
|
552
|
+
user_id: user_id,
|
|
553
|
+
**account_details
|
|
554
|
+
)
|
|
555
|
+
when :uk
|
|
556
|
+
bank_accounts.create_uk(
|
|
557
|
+
user_id: user_id,
|
|
558
|
+
**account_details
|
|
559
|
+
)
|
|
560
|
+
else
|
|
561
|
+
raise "Unsupported region: #{region}"
|
|
562
|
+
end
|
|
563
|
+
end
|
|
564
|
+
|
|
565
|
+
# Australian user
|
|
566
|
+
aus_response = create_bank_account_for_region(
|
|
567
|
+
bank_accounts,
|
|
568
|
+
'user_aus_123',
|
|
569
|
+
:australia,
|
|
570
|
+
{
|
|
571
|
+
bank_name: 'Bank of Australia',
|
|
572
|
+
account_name: 'AU User',
|
|
573
|
+
routing_number: '111123',
|
|
574
|
+
account_number: '111234',
|
|
575
|
+
account_type: 'checking',
|
|
576
|
+
holder_type: 'personal',
|
|
577
|
+
country: 'AUS',
|
|
578
|
+
payout_currency: 'AUD'
|
|
579
|
+
}
|
|
580
|
+
)
|
|
581
|
+
|
|
582
|
+
puts "Australian account: #{aus_response.data['id']}" if aus_response.success?
|
|
583
|
+
|
|
584
|
+
# UK user
|
|
585
|
+
uk_response = create_bank_account_for_region(
|
|
586
|
+
bank_accounts,
|
|
587
|
+
'user_uk_456',
|
|
588
|
+
:uk,
|
|
589
|
+
{
|
|
590
|
+
bank_name: 'UK Bank',
|
|
591
|
+
account_name: 'UK User',
|
|
592
|
+
routing_number: '111123',
|
|
593
|
+
account_number: '111234',
|
|
594
|
+
account_type: 'checking',
|
|
595
|
+
holder_type: 'personal',
|
|
596
|
+
country: 'GBR',
|
|
597
|
+
iban: 'GB25QHWM02498765432109',
|
|
598
|
+
swift_code: 'BUKBGB22',
|
|
599
|
+
payout_currency: 'GBP'
|
|
600
|
+
}
|
|
601
|
+
)
|
|
602
|
+
|
|
603
|
+
puts "UK account: #{uk_response.data['id']}" if uk_response.success?
|
|
604
|
+
```
|
|
605
|
+
|
|
606
|
+
## Important Notes
|
|
607
|
+
|
|
608
|
+
1. **Required Fields for Australia**:
|
|
609
|
+
- `user_id`, `bank_name`, `account_name`, `routing_number` (BSB), `account_number`, `account_type`, `holder_type`, `country`
|
|
610
|
+
|
|
611
|
+
2. **Required Fields for UK** (includes all AU fields plus):
|
|
612
|
+
- `iban` - International Bank Account Number
|
|
613
|
+
- `swift_code` - SWIFT/BIC code
|
|
614
|
+
|
|
615
|
+
3. **Account Types**:
|
|
616
|
+
- `checking` - Current/checking account
|
|
617
|
+
- `savings` - Savings account
|
|
618
|
+
|
|
619
|
+
4. **Holder Types**:
|
|
620
|
+
- `personal` - Personal/individual account
|
|
621
|
+
- `business` - Business/company account
|
|
622
|
+
|
|
623
|
+
5. **Country Codes**:
|
|
624
|
+
- Use ISO 3166-1 alpha-3 codes (3 letters)
|
|
625
|
+
- Australia: `AUS`
|
|
626
|
+
- United Kingdom: `GBR`
|
|
627
|
+
|
|
628
|
+
6. **Currency Codes**:
|
|
629
|
+
- Use ISO 4217 alpha-3 codes
|
|
630
|
+
- Australian Dollar: `AUD`
|
|
631
|
+
- British Pound: `GBP`
|
|
632
|
+
|
|
633
|
+
7. **Bank Account Usage**:
|
|
634
|
+
- Store the returned `:id` for future use in disbursements
|
|
635
|
+
- Use `set_disbursement_account` to set the default payout account
|
|
636
|
+
- The `:id` is also referred to as a `:token` when invoking bank accounts
|
|
637
|
+
|