zai_payment 2.1.0 → 2.3.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.
@@ -68,6 +68,7 @@ module ZaiPayment
68
68
  #
69
69
  # @param limit [Integer] number of records to return (default: 10)
70
70
  # @param offset [Integer] number of records to skip (default: 0)
71
+ # @param search [String] text value to be used for searching users
71
72
  # @return [Response] the API response containing users array
72
73
  #
73
74
  # @example
@@ -75,12 +76,16 @@ module ZaiPayment
75
76
  # response = users.list
76
77
  # response.data # => [{"id" => "...", "email" => "..."}, ...]
77
78
  #
79
+ # @example with search
80
+ # response = users.list(search: "john@example.com")
81
+ #
78
82
  # @see https://developer.hellozai.com/reference/getallusers
79
- def list(limit: 10, offset: 0)
83
+ def list(limit: 10, offset: 0, search: nil)
80
84
  params = {
81
85
  limit: limit,
82
86
  offset: offset
83
87
  }
88
+ params[:search] = search if search
84
89
 
85
90
  client.get('/users', params: params)
86
91
  end
@@ -107,7 +112,7 @@ module ZaiPayment
107
112
  # @option attributes [String] :id Optional unique ID for the user. If not provided,
108
113
  # Zai will generate one automatically. Cannot contain '.' character.
109
114
  # Useful for mapping to your existing system's user IDs.
110
- # @option attributes [String] :user_type User type ('payin' or 'payout').
115
+ # @option attributes [String] :user_type (Required) User type ('payin' or 'payout').
111
116
  # This determines which fields are required.
112
117
  # @option attributes [String] :email (Required) user's email address
113
118
  # @option attributes [String] :first_name (Required) user's first name
@@ -264,6 +269,134 @@ module ZaiPayment
264
269
  client.patch("/users/#{user_id}", body: body)
265
270
  end
266
271
 
272
+ # Show the user's wallet account
273
+ #
274
+ # @param user_id [String] the user ID
275
+ # @return [Response] the API response containing wallet account details
276
+ #
277
+ # @example
278
+ # users = ZaiPayment::Resources::User.new
279
+ # response = users.wallet_account("user_id")
280
+ # response.data # => {"id" => "...", "balance" => ..., ...}
281
+ #
282
+ # @see https://developer.hellozai.com/reference/showuserwalletaccounts
283
+ def wallet_account(user_id)
284
+ validate_id!(user_id, 'user_id')
285
+ client.get("/users/#{user_id}/wallet_accounts")
286
+ end
287
+
288
+ # List items associated with the user
289
+ #
290
+ # @param user_id [String] the user ID
291
+ # @param limit [Integer] number of records to return (default: 10, max: 200)
292
+ # @param offset [Integer] number of records to skip (default: 0)
293
+ # @return [Response] the API response containing items array
294
+ #
295
+ # @example
296
+ # users = ZaiPayment::Resources::User.new
297
+ # response = users.items("user_id")
298
+ # response.data # => [{"id" => "...", "name" => "..."}, ...]
299
+ #
300
+ # @example with custom pagination
301
+ # response = users.items("user_id", limit: 50, offset: 10)
302
+ #
303
+ # @see https://developer.hellozai.com/reference/listuseritems
304
+ def items(user_id, limit: 10, offset: 0)
305
+ validate_id!(user_id, 'user_id')
306
+ params = {
307
+ limit: limit,
308
+ offset: offset
309
+ }
310
+
311
+ client.get("/users/#{user_id}/items", params: params)
312
+ end
313
+
314
+ # Set the user's disbursement account
315
+ #
316
+ # @param user_id [String] the user ID
317
+ # @param account_id [String] the bank account ID to use for disbursements
318
+ # @return [Response] the API response
319
+ #
320
+ # @example
321
+ # users = ZaiPayment::Resources::User.new
322
+ # response = users.set_disbursement_account("user_id", "account_id")
323
+ #
324
+ # @see https://developer.hellozai.com/reference/setuserdisbursementaccount
325
+ def set_disbursement_account(user_id, account_id)
326
+ validate_id!(user_id, 'user_id')
327
+ validate_id!(account_id, 'account_id')
328
+
329
+ body = { account_id: account_id }
330
+ client.patch("/users/#{user_id}/disbursement_account", body: body)
331
+ end
332
+
333
+ # Show the user's bank account
334
+ #
335
+ # @param user_id [String] the user ID
336
+ # @return [Response] the API response containing bank account details
337
+ #
338
+ # @example
339
+ # users = ZaiPayment::Resources::User.new
340
+ # response = users.bank_account("user_id")
341
+ # response.data # => {"id" => "...", "account_name" => "...", ...}
342
+ #
343
+ # @see https://developer.hellozai.com/reference/showuserbankaccount
344
+ def bank_account(user_id)
345
+ validate_id!(user_id, 'user_id')
346
+ client.get("/users/#{user_id}/bank_accounts")
347
+ end
348
+
349
+ # Verify user (Prelive Only)
350
+ # Sets a user's verification state to approved on pre-live environment
351
+ #
352
+ # @param user_id [String] the user ID
353
+ # @return [Response] the API response
354
+ #
355
+ # @example
356
+ # users = ZaiPayment::Resources::User.new
357
+ # response = users.verify("user_id")
358
+ #
359
+ # @note This endpoint only works in the pre-live environment.
360
+ # The user verification workflow holds for all users in production.
361
+ #
362
+ # @see https://developer.hellozai.com/reference/verifyuser
363
+ def verify(user_id)
364
+ validate_id!(user_id, 'user_id')
365
+ client.patch("/users/#{user_id}/identity_verified")
366
+ end
367
+
368
+ # Show the user's card account
369
+ #
370
+ # @param user_id [String] the user ID
371
+ # @return [Response] the API response containing card account details
372
+ #
373
+ # @example
374
+ # users = ZaiPayment::Resources::User.new
375
+ # response = users.card_account("user_id")
376
+ # response.data # => {"id" => "...", "card" => {...}, ...}
377
+ #
378
+ # @see https://developer.hellozai.com/reference/showusercardaccount
379
+ def card_account(user_id)
380
+ validate_id!(user_id, 'user_id')
381
+ client.get("/users/#{user_id}/card_accounts")
382
+ end
383
+
384
+ # List BPay accounts associated with the user
385
+ #
386
+ # @param user_id [String] the user ID
387
+ # @return [Response] the API response containing BPay accounts array
388
+ #
389
+ # @example
390
+ # users = ZaiPayment::Resources::User.new
391
+ # response = users.bpay_accounts("user_id")
392
+ # response.data # => [{"id" => "...", "biller_code" => "..."}, ...]
393
+ #
394
+ # @see https://developer.hellozai.com/reference/listuserbpayaccounts
395
+ def bpay_accounts(user_id)
396
+ validate_id!(user_id, 'user_id')
397
+ client.get("/users/#{user_id}/bpay_accounts")
398
+ end
399
+
267
400
  private
268
401
 
269
402
  def validate_id!(value, field_name)
@@ -280,7 +413,7 @@ module ZaiPayment
280
413
 
281
414
  def validate_create_attributes!(attributes) # rubocop:disable Metrics/AbcSize
282
415
  validate_required_attributes!(attributes)
283
- validate_user_type!(attributes[:user_type]) if attributes[:user_type]
416
+ validate_user_type!(attributes[:user_type])
284
417
  validate_email!(attributes[:email])
285
418
  validate_country!(attributes[:country])
286
419
  validate_dob!(attributes[:dob]) if attributes[:dob]
@@ -290,7 +423,7 @@ module ZaiPayment
290
423
 
291
424
  def validate_required_attributes!(attributes)
292
425
  # Base required fields for all users
293
- required_fields = %i[email first_name last_name country]
426
+ required_fields = %i[email first_name last_name country user_type]
294
427
 
295
428
  # Additional required fields for payout users
296
429
  user_type = attributes[:user_type]&.to_s&.downcase
@@ -5,6 +5,11 @@ module ZaiPayment
5
5
  class Response
6
6
  attr_reader :status, :body, :headers, :raw_response
7
7
 
8
+ RESPONSE_DATA_KEYS = %w[
9
+ webhooks users items fees transactions
10
+ batch_transactions bpay_accounts bank_accounts card_accounts
11
+ ].freeze
12
+
8
13
  def initialize(faraday_response)
9
14
  @raw_response = faraday_response
10
15
  @status = faraday_response.status
@@ -30,14 +35,15 @@ module ZaiPayment
30
35
  end
31
36
 
32
37
  # Get the data from the response body
33
- # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
34
38
  def data
35
39
  return body unless body.is_a?(Hash)
36
40
 
37
- body['webhooks'] || body['users'] || body['items'] || body['fees'] ||
38
- body['transactions'] || body['batch_transactions'] || body
41
+ RESPONSE_DATA_KEYS.each do |key|
42
+ return body[key] if body[key]
43
+ end
44
+
45
+ body
39
46
  end
40
- # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity
41
47
 
42
48
  # Get pagination or metadata info
43
49
  def meta
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ZaiPayment
4
- VERSION = '2.1.0'
4
+ VERSION = '2.3.0'
5
5
  end
data/readme.md CHANGED
@@ -88,6 +88,7 @@ Manage payin (buyer) and payout (seller/merchant) users:
88
88
  ```ruby
89
89
  # Create a payin user (buyer)
90
90
  response = ZaiPayment.users.create(
91
+ user_type: 'payin',
91
92
  email: 'buyer@example.com',
92
93
  first_name: 'John',
93
94
  last_name: 'Doe',
@@ -97,6 +98,7 @@ response = ZaiPayment.users.create(
97
98
 
98
99
  # Create a payout user (seller/merchant)
99
100
  response = ZaiPayment.users.create(
101
+ user_type: 'payout',
100
102
  email: 'seller@example.com',
101
103
  first_name: 'Jane',
102
104
  last_name: 'Smith',
@@ -110,6 +112,7 @@ response = ZaiPayment.users.create(
110
112
 
111
113
  # Create a business user with company details
112
114
  response = ZaiPayment.users.create(
115
+ user_type: 'payout',
113
116
  email: 'director@company.com',
114
117
  first_name: 'John',
115
118
  last_name: 'Director',
@@ -134,6 +137,27 @@ response = ZaiPayment.users.show('user_id')
134
137
 
135
138
  # Update user
136
139
  response = ZaiPayment.users.update('user_id', mobile: '+9876543210')
140
+
141
+ # Show user wallet account
142
+ response = ZaiPayment.users.wallet_account('user_id')
143
+
144
+ # List user items with pagination
145
+ response = ZaiPayment.users.items('user_id', limit: 50, offset: 10)
146
+
147
+ # Set user disbursement account
148
+ response = ZaiPayment.users.set_disbursement_account('user_id', 'bank_account_id')
149
+
150
+ # Show user bank account
151
+ response = ZaiPayment.users.bank_account('user_id')
152
+
153
+ # Verify user (prelive only)
154
+ response = ZaiPayment.users.verify('user_id')
155
+
156
+ # Show user card account
157
+ response = ZaiPayment.users.card_account('user_id')
158
+
159
+ # List user's BPay accounts
160
+ response = ZaiPayment.users.bpay_accounts('user_id')
137
161
  ```
138
162
 
139
163
  **📚 Documentation:**
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zai_payment
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eddy Jaga
@@ -78,6 +78,7 @@ files:
78
78
  - docs/webhook_signature.md
79
79
  - docs/webhooks.md
80
80
  - examples/items.md
81
+ - examples/rails_card_payment.md
81
82
  - examples/token_auths.md
82
83
  - examples/users.md
83
84
  - examples/webhooks.md