zai_payment 2.1.0 → 2.2.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 +47 -0
- data/docs/users.md +300 -3
- data/examples/rails_card_payment.md +716 -0
- data/lib/zai_payment/resources/user.rb +131 -3
- data/lib/zai_payment/response.rb +10 -4
- data/lib/zai_payment/version.rb +1 -1
- data/readme.md +24 -0
- metadata +3 -2
|
@@ -107,7 +107,7 @@ module ZaiPayment
|
|
|
107
107
|
# @option attributes [String] :id Optional unique ID for the user. If not provided,
|
|
108
108
|
# Zai will generate one automatically. Cannot contain '.' character.
|
|
109
109
|
# Useful for mapping to your existing system's user IDs.
|
|
110
|
-
# @option attributes [String] :user_type User type ('payin' or 'payout').
|
|
110
|
+
# @option attributes [String] :user_type (Required) User type ('payin' or 'payout').
|
|
111
111
|
# This determines which fields are required.
|
|
112
112
|
# @option attributes [String] :email (Required) user's email address
|
|
113
113
|
# @option attributes [String] :first_name (Required) user's first name
|
|
@@ -264,6 +264,134 @@ module ZaiPayment
|
|
|
264
264
|
client.patch("/users/#{user_id}", body: body)
|
|
265
265
|
end
|
|
266
266
|
|
|
267
|
+
# Show the user's wallet account
|
|
268
|
+
#
|
|
269
|
+
# @param user_id [String] the user ID
|
|
270
|
+
# @return [Response] the API response containing wallet account details
|
|
271
|
+
#
|
|
272
|
+
# @example
|
|
273
|
+
# users = ZaiPayment::Resources::User.new
|
|
274
|
+
# response = users.wallet_account("user_id")
|
|
275
|
+
# response.data # => {"id" => "...", "balance" => ..., ...}
|
|
276
|
+
#
|
|
277
|
+
# @see https://developer.hellozai.com/reference/showuserwalletaccounts
|
|
278
|
+
def wallet_account(user_id)
|
|
279
|
+
validate_id!(user_id, 'user_id')
|
|
280
|
+
client.get("/users/#{user_id}/wallet_accounts")
|
|
281
|
+
end
|
|
282
|
+
|
|
283
|
+
# List items associated with the user
|
|
284
|
+
#
|
|
285
|
+
# @param user_id [String] the user ID
|
|
286
|
+
# @param limit [Integer] number of records to return (default: 10, max: 200)
|
|
287
|
+
# @param offset [Integer] number of records to skip (default: 0)
|
|
288
|
+
# @return [Response] the API response containing items array
|
|
289
|
+
#
|
|
290
|
+
# @example
|
|
291
|
+
# users = ZaiPayment::Resources::User.new
|
|
292
|
+
# response = users.items("user_id")
|
|
293
|
+
# response.data # => [{"id" => "...", "name" => "..."}, ...]
|
|
294
|
+
#
|
|
295
|
+
# @example with custom pagination
|
|
296
|
+
# response = users.items("user_id", limit: 50, offset: 10)
|
|
297
|
+
#
|
|
298
|
+
# @see https://developer.hellozai.com/reference/listuseritems
|
|
299
|
+
def items(user_id, limit: 10, offset: 0)
|
|
300
|
+
validate_id!(user_id, 'user_id')
|
|
301
|
+
params = {
|
|
302
|
+
limit: limit,
|
|
303
|
+
offset: offset
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
client.get("/users/#{user_id}/items", params: params)
|
|
307
|
+
end
|
|
308
|
+
|
|
309
|
+
# Set the user's disbursement account
|
|
310
|
+
#
|
|
311
|
+
# @param user_id [String] the user ID
|
|
312
|
+
# @param account_id [String] the bank account ID to use for disbursements
|
|
313
|
+
# @return [Response] the API response
|
|
314
|
+
#
|
|
315
|
+
# @example
|
|
316
|
+
# users = ZaiPayment::Resources::User.new
|
|
317
|
+
# response = users.set_disbursement_account("user_id", "account_id")
|
|
318
|
+
#
|
|
319
|
+
# @see https://developer.hellozai.com/reference/setuserdisbursementaccount
|
|
320
|
+
def set_disbursement_account(user_id, account_id)
|
|
321
|
+
validate_id!(user_id, 'user_id')
|
|
322
|
+
validate_id!(account_id, 'account_id')
|
|
323
|
+
|
|
324
|
+
body = { account_id: account_id }
|
|
325
|
+
client.patch("/users/#{user_id}/disbursement_account", body: body)
|
|
326
|
+
end
|
|
327
|
+
|
|
328
|
+
# Show the user's bank account
|
|
329
|
+
#
|
|
330
|
+
# @param user_id [String] the user ID
|
|
331
|
+
# @return [Response] the API response containing bank account details
|
|
332
|
+
#
|
|
333
|
+
# @example
|
|
334
|
+
# users = ZaiPayment::Resources::User.new
|
|
335
|
+
# response = users.bank_account("user_id")
|
|
336
|
+
# response.data # => {"id" => "...", "account_name" => "...", ...}
|
|
337
|
+
#
|
|
338
|
+
# @see https://developer.hellozai.com/reference/showuserbankaccount
|
|
339
|
+
def bank_account(user_id)
|
|
340
|
+
validate_id!(user_id, 'user_id')
|
|
341
|
+
client.get("/users/#{user_id}/bank_accounts")
|
|
342
|
+
end
|
|
343
|
+
|
|
344
|
+
# Verify user (Prelive Only)
|
|
345
|
+
# Sets a user's verification state to approved on pre-live environment
|
|
346
|
+
#
|
|
347
|
+
# @param user_id [String] the user ID
|
|
348
|
+
# @return [Response] the API response
|
|
349
|
+
#
|
|
350
|
+
# @example
|
|
351
|
+
# users = ZaiPayment::Resources::User.new
|
|
352
|
+
# response = users.verify("user_id")
|
|
353
|
+
#
|
|
354
|
+
# @note This endpoint only works in the pre-live environment.
|
|
355
|
+
# The user verification workflow holds for all users in production.
|
|
356
|
+
#
|
|
357
|
+
# @see https://developer.hellozai.com/reference/verifyuser
|
|
358
|
+
def verify(user_id)
|
|
359
|
+
validate_id!(user_id, 'user_id')
|
|
360
|
+
client.patch("/users/#{user_id}/identity_verified")
|
|
361
|
+
end
|
|
362
|
+
|
|
363
|
+
# Show the user's card account
|
|
364
|
+
#
|
|
365
|
+
# @param user_id [String] the user ID
|
|
366
|
+
# @return [Response] the API response containing card account details
|
|
367
|
+
#
|
|
368
|
+
# @example
|
|
369
|
+
# users = ZaiPayment::Resources::User.new
|
|
370
|
+
# response = users.card_account("user_id")
|
|
371
|
+
# response.data # => {"id" => "...", "card" => {...}, ...}
|
|
372
|
+
#
|
|
373
|
+
# @see https://developer.hellozai.com/reference/showusercardaccount
|
|
374
|
+
def card_account(user_id)
|
|
375
|
+
validate_id!(user_id, 'user_id')
|
|
376
|
+
client.get("/users/#{user_id}/card_accounts")
|
|
377
|
+
end
|
|
378
|
+
|
|
379
|
+
# List BPay accounts associated with the user
|
|
380
|
+
#
|
|
381
|
+
# @param user_id [String] the user ID
|
|
382
|
+
# @return [Response] the API response containing BPay accounts array
|
|
383
|
+
#
|
|
384
|
+
# @example
|
|
385
|
+
# users = ZaiPayment::Resources::User.new
|
|
386
|
+
# response = users.bpay_accounts("user_id")
|
|
387
|
+
# response.data # => [{"id" => "...", "biller_code" => "..."}, ...]
|
|
388
|
+
#
|
|
389
|
+
# @see https://developer.hellozai.com/reference/listuserbpayaccounts
|
|
390
|
+
def bpay_accounts(user_id)
|
|
391
|
+
validate_id!(user_id, 'user_id')
|
|
392
|
+
client.get("/users/#{user_id}/bpay_accounts")
|
|
393
|
+
end
|
|
394
|
+
|
|
267
395
|
private
|
|
268
396
|
|
|
269
397
|
def validate_id!(value, field_name)
|
|
@@ -280,7 +408,7 @@ module ZaiPayment
|
|
|
280
408
|
|
|
281
409
|
def validate_create_attributes!(attributes) # rubocop:disable Metrics/AbcSize
|
|
282
410
|
validate_required_attributes!(attributes)
|
|
283
|
-
validate_user_type!(attributes[:user_type])
|
|
411
|
+
validate_user_type!(attributes[:user_type])
|
|
284
412
|
validate_email!(attributes[:email])
|
|
285
413
|
validate_country!(attributes[:country])
|
|
286
414
|
validate_dob!(attributes[:dob]) if attributes[:dob]
|
|
@@ -290,7 +418,7 @@ module ZaiPayment
|
|
|
290
418
|
|
|
291
419
|
def validate_required_attributes!(attributes)
|
|
292
420
|
# Base required fields for all users
|
|
293
|
-
required_fields = %i[email first_name last_name country]
|
|
421
|
+
required_fields = %i[email first_name last_name country user_type]
|
|
294
422
|
|
|
295
423
|
# Additional required fields for payout users
|
|
296
424
|
user_type = attributes[:user_type]&.to_s&.downcase
|
data/lib/zai_payment/response.rb
CHANGED
|
@@ -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
|
-
|
|
38
|
-
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
|
data/lib/zai_payment/version.rb
CHANGED
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.
|
|
4
|
+
version: 2.2.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
|
|
@@ -124,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
124
125
|
- !ruby/object:Gem::Version
|
|
125
126
|
version: '0'
|
|
126
127
|
requirements: []
|
|
127
|
-
rubygems_version: 3.7
|
|
128
|
+
rubygems_version: 3.6.7
|
|
128
129
|
specification_version: 4
|
|
129
130
|
summary: Ruby gem for Zai payment integration
|
|
130
131
|
test_files: []
|