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.
@@ -0,0 +1,493 @@
1
+ # Wallet Account Management
2
+
3
+ The WalletAccount resource provides methods for managing Zai wallet accounts for Australian payments and bill payments.
4
+
5
+ ## Overview
6
+
7
+ Wallet accounts are digital wallets that hold funds and can be used for various payment operations including bill payments via BPay, withdrawals, and other disbursements. Each user in the Zai platform can have a wallet account with a balance that can be topped up and used for payments.
8
+
9
+ Once created by Zai, store the returned `:id` and use it for payment operations. The wallet account maintains a balance in the specified currency (typically AUD for Australian marketplaces).
10
+
11
+ ## References
12
+
13
+ - [Wallet Accounts API](https://developer.hellozai.com/reference)
14
+ - [Payment Methods Guide](https://developer.hellozai.com/docs/payment-methods)
15
+
16
+ ## Usage
17
+
18
+ ### Initialize the WalletAccount Resource
19
+
20
+ ```ruby
21
+ # Using a new instance
22
+ wallet_accounts = ZaiPayment::Resources::WalletAccount.new
23
+
24
+ # Or use with custom client
25
+ client = ZaiPayment::Client.new
26
+ wallet_accounts = ZaiPayment::Resources::WalletAccount.new(client: client)
27
+ ```
28
+
29
+ ## Methods
30
+
31
+ ### Show Wallet Account
32
+
33
+ Get details of a specific wallet account by ID.
34
+
35
+ #### Parameters
36
+
37
+ - `wallet_account_id` (required) - The wallet account ID
38
+
39
+ #### Example
40
+
41
+ ```ruby
42
+ # Get wallet account details
43
+ response = wallet_accounts.show('5c1c6b10-4c56-0137-8cd7-0242ac110002')
44
+
45
+ # Access wallet account details
46
+ wallet_account = response.data
47
+ puts wallet_account['id']
48
+ puts wallet_account['active']
49
+ puts wallet_account['balance']
50
+ puts wallet_account['currency']
51
+ puts wallet_account['created_at']
52
+ puts wallet_account['updated_at']
53
+
54
+ # Access links
55
+ links = wallet_account['links']
56
+ puts links['users']
57
+ puts links['transactions']
58
+ puts links['bpay_details']
59
+ puts links['npp_details']
60
+ ```
61
+
62
+ #### Response
63
+
64
+ ```ruby
65
+ {
66
+ "wallet_accounts" => {
67
+ "id" => "5c1c6b10-4c56-0137-8cd7-0242ac110002",
68
+ "active" => true,
69
+ "created_at" => "2019-04-29T02:42:31.536Z",
70
+ "updated_at" => "2020-05-03T12:01:02.254Z",
71
+ "balance" => 663337,
72
+ "currency" => "AUD",
73
+ "links" => {
74
+ "self" => "/transactions/aed45af0-6f63-0138-901c-0a58a9feac03/wallet_accounts",
75
+ "users" => "/wallet_accounts/5c1c6b10-4c56-0137-8cd7-0242ac110002/users",
76
+ "batch_transactions" => "/wallet_accounts/5c1c6b10-4c56-0137-8cd7-0242ac110002/batch_transactions",
77
+ "transactions" => "/wallet_accounts/5c1c6b10-4c56-0137-8cd7-0242ac110002/transactions",
78
+ "bpay_details" => "/wallet_accounts/5c1c6b10-4c56-0137-8cd7-0242ac110002/bpay_details",
79
+ "npp_details" => "/wallet_accounts/5c1c6b10-4c56-0137-8cd7-0242ac110002/npp_details",
80
+ "virtual_accounts" => "/wallet_accounts/5c1c6b10-4c56-0137-8cd7-0242ac110002/virtual_accounts"
81
+ }
82
+ }
83
+ }
84
+ ```
85
+
86
+ **Use Cases:**
87
+ - Check wallet balance before initiating payments
88
+ - Verify account status and activity
89
+ - Monitor wallet account details
90
+ - Access related resources via links
91
+
92
+ ### Show Wallet Account User
93
+
94
+ Get the User the Wallet Account is associated with using a given wallet_account_id.
95
+
96
+ #### Parameters
97
+
98
+ - `wallet_account_id` (required) - The wallet account ID
99
+
100
+ #### Example
101
+
102
+ ```ruby
103
+ # Get user associated with wallet account
104
+ response = wallet_accounts.show_user('5c1c6b10-4c56-0137-8cd7-0242ac110002')
105
+
106
+ # Access user details
107
+ user = response.data
108
+ puts user['id']
109
+ puts user['full_name']
110
+ puts user['email']
111
+ puts user['verification_state']
112
+ puts user['held_state']
113
+ ```
114
+
115
+ #### Response
116
+
117
+ ```ruby
118
+ {
119
+ "users" => {
120
+ "created_at" => "2020-04-03T07:59:00.379Z",
121
+ "updated_at" => "2020-04-03T07:59:00.379Z",
122
+ "id" => "Seller_1234",
123
+ "full_name" => "Samuel Seller",
124
+ "email" => "sam@example.com",
125
+ "mobile" => 69543131,
126
+ "first_name" => "Samuel",
127
+ "last_name" => "Seller",
128
+ "custom_descriptor" => "Sam Garden Jobs",
129
+ "location" => "AUS",
130
+ "verification_state" => "pending",
131
+ "held_state" => false,
132
+ "roles" => ["customer"],
133
+ "dob" => "encrypted",
134
+ "government_number" => "encrypted",
135
+ "flags" => {},
136
+ "related" => {
137
+ "addresses" => "11111111-2222-3333-4444-55555555555,"
138
+ },
139
+ "links" => {
140
+ "self" => "/wallet_accounts/901d8cd0-6af3-0138-967d-0a58a9feac04/users",
141
+ "items" => "/users/e6bc0480-57ae-0138-c46e-0a58a9feac03/items",
142
+ "wallet_accounts" => "/users/e6bc0480-57ae-0138-c46e-0a58a9feac03/wallet_accounts"
143
+ }
144
+ }
145
+ }
146
+ ```
147
+
148
+ **Use Cases:**
149
+ - Retrieve user information for a wallet account
150
+ - Verify user identity before payment
151
+ - Check user verification status
152
+ - Get user contact details for notifications
153
+
154
+ ### Pay a Bill
155
+
156
+ Pay a bill by withdrawing funds from a Wallet Account to a specified BPay account.
157
+
158
+ #### Required Fields
159
+
160
+ - `wallet_account_id` (path parameter) - The wallet account ID to withdraw from
161
+ - `account_id` - BPay account ID to withdraw to (must be a valid `bpay_account_id`)
162
+ - `amount` - Amount in cents to withdraw (must be a positive integer)
163
+
164
+ #### Optional Fields
165
+
166
+ - `reference_id` - Unique reference information for the payment (cannot contain single quote character)
167
+
168
+ #### Example
169
+
170
+ ```ruby
171
+ wallet_accounts = ZaiPayment::Resources::WalletAccount.new
172
+
173
+ response = wallet_accounts.pay_bill(
174
+ '901d8cd0-6af3-0138-967d-0a58a9feac04',
175
+ account_id: 'c1824ad0-73f1-0138-3700-0a58a9feac09',
176
+ amount: 173,
177
+ reference_id: 'test100'
178
+ )
179
+
180
+ if response.success?
181
+ disbursement = response.data
182
+ puts "Disbursement ID: #{disbursement['id']}"
183
+ puts "Amount: #{disbursement['amount']}"
184
+ puts "State: #{disbursement['state']}"
185
+ puts "Reference: #{disbursement['reference_id']}"
186
+ puts "To: #{disbursement['to']}"
187
+ puts "Account Name: #{disbursement['account_name']}"
188
+ puts "Biller Name: #{disbursement['biller_name']}"
189
+ puts "Biller Code: #{disbursement['biller_code']}"
190
+ puts "CRN: #{disbursement['crn']}"
191
+ end
192
+ ```
193
+
194
+ #### Response
195
+
196
+ ```ruby
197
+ {
198
+ "disbursements" => {
199
+ "reference_id" => "test100",
200
+ "id" => "8a31ebfa-421b-4cbb-9241-632f71b3778a",
201
+ "amount" => 173,
202
+ "currency" => "AUD",
203
+ "created_at" => "2020-05-09T07:09:03.383Z",
204
+ "updated_at" => "2020-05-09T07:09:04.585Z",
205
+ "state" => "pending",
206
+ "to" => "BPay Account",
207
+ "account_name" => "My Water Company",
208
+ "biller_name" => "ABC Water",
209
+ "biller_code" => 123456,
210
+ "crn" => "0987654321",
211
+ "links" => {
212
+ "transactions" => "/disbursements/8a31ebfa-421b-4cbb-9241-632f71b3778a/transactions",
213
+ "wallet_accounts" => "/disbursements/8a31ebfa-421b-4cbb-9241-632f71b3778a/wallet_accounts",
214
+ "bank_accounts" => "/disbursements/8a31ebfa-421b-4cbb-9241-632f71b3778a/bank_accounts",
215
+ "bpay_accounts" => "/disbursements/8a31ebfa-421b-4cbb-9241-632f71b3778a/bpay_accounts",
216
+ "paypal_accounts" => "/disbursements/8a31ebfa-421b-4cbb-9241-632f71b3778a/paypal_accounts",
217
+ "items" => "/disbursements/8a31ebfa-421b-4cbb-9241-632f71b3778a/items",
218
+ "users" => "/disbursements/8a31ebfa-421b-4cbb-9241-632f71b3778a/users"
219
+ }
220
+ }
221
+ }
222
+ ```
223
+
224
+ **Important Notes:**
225
+ - Amount is in cents (e.g., 173 = $1.73 AUD)
226
+ - The wallet must have sufficient balance to cover the payment
227
+ - Disbursement state will be "pending" initially, then transitions to "successful" or "failed"
228
+ - Reference ID is optional but recommended for tracking purposes
229
+
230
+ ## Validation Rules
231
+
232
+ ### Wallet Account ID
233
+
234
+ - Required for all methods
235
+ - Must not be blank or nil
236
+ - Must be a valid UUID format
237
+
238
+ ### Amount (for pay_bill)
239
+
240
+ - Required field
241
+ - Must be a positive integer
242
+ - Specified in cents (e.g., 100 = $1.00)
243
+ - Must not exceed wallet balance
244
+
245
+ ### Account ID (for pay_bill)
246
+
247
+ - Required field
248
+ - Must be a valid BPay account ID
249
+ - The BPay account must be active and verified
250
+
251
+ ### Reference ID (for pay_bill)
252
+
253
+ - Optional field
254
+ - Cannot contain single quote (') character
255
+ - Used for tracking and reconciliation
256
+ - Should be unique for each payment
257
+
258
+ ## Error Handling
259
+
260
+ The WalletAccount resource raises the following errors:
261
+
262
+ ### NotFoundError
263
+
264
+ Raised when the wallet account does not exist:
265
+
266
+ ```ruby
267
+ begin
268
+ wallet_accounts.show('invalid_id')
269
+ rescue ZaiPayment::Errors::NotFoundError => e
270
+ puts "Wallet account not found: #{e.message}"
271
+ end
272
+ ```
273
+
274
+ ### ValidationError
275
+
276
+ Raised when required fields are missing or invalid:
277
+
278
+ ```ruby
279
+ begin
280
+ wallet_accounts.pay_bill(
281
+ '901d8cd0-6af3-0138-967d-0a58a9feac04',
282
+ account_id: 'test123'
283
+ # Missing required field: amount
284
+ )
285
+ rescue ZaiPayment::Errors::ValidationError => e
286
+ puts "Validation failed: #{e.message}"
287
+ # => "Missing required fields: amount"
288
+ end
289
+ ```
290
+
291
+ ### Invalid Amount
292
+
293
+ ```ruby
294
+ begin
295
+ wallet_accounts.pay_bill(
296
+ '901d8cd0-6af3-0138-967d-0a58a9feac04',
297
+ account_id: 'bpay_account_123',
298
+ amount: -100 # Negative amount
299
+ )
300
+ rescue ZaiPayment::Errors::ValidationError => e
301
+ puts e.message
302
+ # => "amount must be a positive integer"
303
+ end
304
+ ```
305
+
306
+ ### Invalid Reference ID
307
+
308
+ ```ruby
309
+ begin
310
+ wallet_accounts.pay_bill(
311
+ '901d8cd0-6af3-0138-967d-0a58a9feac04',
312
+ account_id: 'bpay_account_123',
313
+ amount: 173,
314
+ reference_id: "test'100" # Contains single quote
315
+ )
316
+ rescue ZaiPayment::Errors::ValidationError => e
317
+ puts e.message
318
+ # => "reference_id cannot contain single quote (') character"
319
+ end
320
+ ```
321
+
322
+ ### Blank Wallet Account ID
323
+
324
+ ```ruby
325
+ begin
326
+ wallet_accounts.show('')
327
+ # or
328
+ wallet_accounts.pay_bill(nil, account_id: 'test', amount: 100)
329
+ rescue ZaiPayment::Errors::ValidationError => e
330
+ puts "Invalid ID: #{e.message}"
331
+ # => "wallet_account_id is required and cannot be blank"
332
+ end
333
+ ```
334
+
335
+ ## Use Cases
336
+
337
+ ### Use Case 1: Check Balance Before Payment
338
+
339
+ Check wallet balance before initiating a bill payment:
340
+
341
+ ```ruby
342
+ wallet_accounts = ZaiPayment::Resources::WalletAccount.new
343
+
344
+ # Step 1: Check wallet balance
345
+ response = wallet_accounts.show('wallet_account_id')
346
+
347
+ if response.success?
348
+ wallet = response.data
349
+ balance = wallet['balance'] # in cents
350
+
351
+ # Step 2: Verify sufficient funds
352
+ payment_amount = 17300 # $173.00
353
+
354
+ if balance >= payment_amount
355
+ puts "Sufficient balance: $#{balance / 100.0}"
356
+
357
+ # Step 3: Process payment
358
+ payment_response = wallet_accounts.pay_bill(
359
+ 'wallet_account_id',
360
+ account_id: 'bpay_account_id',
361
+ amount: payment_amount,
362
+ reference_id: 'bill_#{Time.now.to_i}'
363
+ )
364
+
365
+ puts "Payment initiated" if payment_response.success?
366
+ else
367
+ puts "Insufficient funds: $#{balance / 100.0} < $#{payment_amount / 100.0}"
368
+ end
369
+ end
370
+ ```
371
+
372
+ ### Use Case 2: Pay Multiple Bills
373
+
374
+ Process multiple bill payments from a wallet account:
375
+
376
+ ```ruby
377
+ wallet_accounts = ZaiPayment::Resources::WalletAccount.new
378
+ wallet_id = '901d8cd0-6af3-0138-967d-0a58a9feac04'
379
+
380
+ bills = [
381
+ { account_id: 'bpay_water', amount: 15000, ref: 'water_202411' },
382
+ { account_id: 'bpay_electricity', amount: 22000, ref: 'elec_202411' },
383
+ { account_id: 'bpay_gas', amount: 8500, ref: 'gas_202411' }
384
+ ]
385
+
386
+ bills.each do |bill|
387
+ response = wallet_accounts.pay_bill(
388
+ wallet_id,
389
+ account_id: bill[:account_id],
390
+ amount: bill[:amount],
391
+ reference_id: bill[:ref]
392
+ )
393
+
394
+ if response.success?
395
+ puts "Paid #{bill[:ref]}: $#{bill[:amount] / 100.0}"
396
+ else
397
+ puts "Failed to pay #{bill[:ref]}"
398
+ end
399
+ end
400
+ ```
401
+
402
+ ### Use Case 3: Get User Details for Wallet Account
403
+
404
+ Retrieve user information for notification purposes:
405
+
406
+ ```ruby
407
+ wallet_accounts = ZaiPayment::Resources::WalletAccount.new
408
+
409
+ # Step 1: Get user details
410
+ user_response = wallet_accounts.show_user('wallet_account_id')
411
+
412
+ if user_response.success?
413
+ user = user_response.data
414
+
415
+ # Step 2: Verify user eligibility
416
+ if user['verification_state'] == 'verified' && !user['held_state']
417
+ puts "User verified: #{user['full_name']}"
418
+ puts "Email: #{user['email']}"
419
+
420
+ # Step 3: Send notification
421
+ # NotificationService.send_payment_confirmation(user['email'])
422
+ else
423
+ puts "User not eligible for payments"
424
+ puts "Verification: #{user['verification_state']}"
425
+ puts "On Hold: #{user['held_state']}"
426
+ end
427
+ end
428
+ ```
429
+
430
+ ### Use Case 4: Monitor Disbursement Status
431
+
432
+ Track the status of a bill payment:
433
+
434
+ ```ruby
435
+ wallet_accounts = ZaiPayment::Resources::WalletAccount.new
436
+
437
+ # Initiate payment
438
+ payment_response = wallet_accounts.pay_bill(
439
+ 'wallet_account_id',
440
+ account_id: 'bpay_account_id',
441
+ amount: 17300,
442
+ reference_id: 'bill_123'
443
+ )
444
+
445
+ if payment_response.success?
446
+ disbursement = payment_response.data
447
+ disbursement_id = disbursement['id']
448
+
449
+ puts "Payment initiated: #{disbursement_id}"
450
+ puts "State: #{disbursement['state']}"
451
+ puts "To: #{disbursement['account_name']}"
452
+ puts "Biller: #{disbursement['biller_name']}"
453
+
454
+ # Monitor using disbursement ID
455
+ # Later check status via transactions or webhooks
456
+ end
457
+ ```
458
+
459
+ ## Important Notes
460
+
461
+ 1. **Currency**: Wallet accounts typically use AUD (Australian Dollars) for Australian marketplaces
462
+ 2. **Balance**: The balance is returned in cents (e.g., 663337 = $6,633.37)
463
+ 3. **Payment Amount**: Amounts must be specified in cents
464
+ 4. **BPay Integration**: The `pay_bill` method integrates with BPay for Australian bill payments
465
+ 5. **Disbursement State**: Payment states include `pending`, `successful`, and `failed`
466
+ 6. **Reference Tracking**: Use `reference_id` for payment tracking and reconciliation
467
+ 7. **Sufficient Funds**: Ensure wallet has sufficient balance before initiating payments
468
+ 8. **Account Status**: Only active wallet accounts can be used for payments
469
+
470
+ ## Disbursement States
471
+
472
+ - **pending**: Payment has been initiated but not yet processed
473
+ - **successful**: Payment completed successfully
474
+ - **failed**: Payment failed (check error details)
475
+
476
+ Monitor payment status through:
477
+ - Webhook notifications
478
+ - Transaction queries
479
+ - Disbursement status checks
480
+
481
+ ## Related Resources
482
+
483
+ - [User Management](users.md) - Creating and managing users
484
+ - [BPay Accounts](bpay_accounts.md) - Managing BPay accounts for bill payments
485
+ - [Items](items.md) - Creating items for payments
486
+
487
+ ## Further Reading
488
+
489
+ - [Payment Methods Guide](https://developer.hellozai.com/docs/payment-methods)
490
+ - [Wallet Account API Reference](https://developer.hellozai.com/reference)
491
+ - [BPay Overview](https://developer.hellozai.com/docs/bpay)
492
+ - [Verification Process](https://developer.hellozai.com/docs/verification)
493
+