zai_payment 1.1.0 → 1.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +108 -0
- data/CONTRIBUTING.md +383 -0
- data/IMPLEMENTATION.md +280 -177
- data/IMPLEMENTATION_SUMMARY.md +195 -0
- data/README.md +124 -44
- data/badges/.gitkeep +2 -0
- data/badges/coverage.json +1 -0
- data/docs/AUTHENTICATION.md +647 -0
- data/docs/README.md +81 -0
- data/docs/USERS.md +414 -0
- data/docs/USER_ID_FIELD.md +284 -0
- data/docs/USER_QUICK_REFERENCE.md +230 -0
- data/docs/WEBHOOKS.md +261 -1
- data/docs/WEBHOOK_SECURITY_QUICKSTART.md +136 -0
- data/docs/WEBHOOK_SIGNATURE.md +244 -0
- data/examples/users.md +746 -0
- data/examples/webhooks.md +489 -0
- data/lib/zai_payment/client.rb +10 -3
- data/lib/zai_payment/resources/user.rb +383 -0
- data/lib/zai_payment/resources/webhook.rb +174 -0
- data/lib/zai_payment/response.rb +1 -1
- data/lib/zai_payment/version.rb +1 -1
- data/lib/zai_payment.rb +6 -0
- metadata +42 -1
data/docs/README.md
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# Documentation Index
|
|
2
|
+
|
|
3
|
+
Welcome to the Zai Payment Ruby gem documentation. This guide will help you find the information you need.
|
|
4
|
+
|
|
5
|
+
## 📖 Getting Started
|
|
6
|
+
|
|
7
|
+
**New to the gem?** Start here:
|
|
8
|
+
1. [Main README](../README.md) - Installation and basic configuration
|
|
9
|
+
2. [Authentication Guide](AUTHENTICATION.md) - Get tokens with two approaches (short & long way)
|
|
10
|
+
3. [Webhook Quick Start](WEBHOOK_SECURITY_QUICKSTART.md) - Set up secure webhooks in 5 minutes
|
|
11
|
+
4. [Webhook Examples](../examples/webhooks.md) - Complete usage examples
|
|
12
|
+
|
|
13
|
+
## 🏗️ Architecture & Design
|
|
14
|
+
|
|
15
|
+
- [**ARCHITECTURE.md**](ARCHITECTURE.md) - System architecture and design principles
|
|
16
|
+
- [**AUTHENTICATION.md**](AUTHENTICATION.md) - OAuth2 implementation, token management, two approaches
|
|
17
|
+
- [**WEBHOOKS.md**](WEBHOOKS.md) - Webhook implementation details, best practices, and patterns
|
|
18
|
+
|
|
19
|
+
## 🔐 Security Guides
|
|
20
|
+
|
|
21
|
+
- [**WEBHOOK_SECURITY_QUICKSTART.md**](WEBHOOK_SECURITY_QUICKSTART.md) - Quick 5-minute security setup guide
|
|
22
|
+
- [**WEBHOOK_SIGNATURE.md**](WEBHOOK_SIGNATURE.md) - Detailed signature verification implementation
|
|
23
|
+
|
|
24
|
+
## 📝 Examples
|
|
25
|
+
|
|
26
|
+
- [**Webhook Examples**](../examples/webhooks.md) - Comprehensive webhook usage examples including:
|
|
27
|
+
- Basic CRUD operations
|
|
28
|
+
- Rails controller implementation
|
|
29
|
+
- Sinatra example
|
|
30
|
+
- Rack middleware
|
|
31
|
+
- Background job processing
|
|
32
|
+
- Idempotency patterns
|
|
33
|
+
|
|
34
|
+
## 🔗 Quick Links
|
|
35
|
+
|
|
36
|
+
### Authentication
|
|
37
|
+
- **Getting Started**: [Authentication Guide](AUTHENTICATION.md)
|
|
38
|
+
- **Short Way**: `ZaiPayment.token` (one-liner)
|
|
39
|
+
- **Long Way**: `TokenProvider.new(config: config).bearer_token` (full control)
|
|
40
|
+
|
|
41
|
+
### Webhooks
|
|
42
|
+
- **Setup**: [Quick Start Guide](WEBHOOK_SECURITY_QUICKSTART.md)
|
|
43
|
+
- **Examples**: [Complete Examples](../examples/webhooks.md)
|
|
44
|
+
- **Details**: [Technical Documentation](WEBHOOKS.md)
|
|
45
|
+
- **Security**: [Signature Verification](WEBHOOK_SIGNATURE.md)
|
|
46
|
+
|
|
47
|
+
### External Resources
|
|
48
|
+
- [Zai Developer Portal](https://developer.hellozai.com/)
|
|
49
|
+
- [Zai API Reference](https://developer.hellozai.com/reference)
|
|
50
|
+
- [Webhook Signature Docs](https://developer.hellozai.com/docs/verify-webhook-signatures)
|
|
51
|
+
|
|
52
|
+
## 📚 Documentation Structure
|
|
53
|
+
|
|
54
|
+
```
|
|
55
|
+
docs/
|
|
56
|
+
├── README.md # This file - documentation index
|
|
57
|
+
├── AUTHENTICATION.md # OAuth2 authentication guide (NEW!)
|
|
58
|
+
├── ARCHITECTURE.md # System architecture
|
|
59
|
+
├── WEBHOOKS.md # Webhook technical docs
|
|
60
|
+
├── WEBHOOK_SECURITY_QUICKSTART.md # Quick security setup
|
|
61
|
+
└── WEBHOOK_SIGNATURE.md # Signature implementation
|
|
62
|
+
|
|
63
|
+
examples/
|
|
64
|
+
└── webhooks.md # Complete webhook examples
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## 💡 Tips
|
|
68
|
+
|
|
69
|
+
- **Getting tokens?** Check [AUTHENTICATION.md](AUTHENTICATION.md) for both approaches
|
|
70
|
+
- **Looking for code examples?** Check [examples/webhooks.md](../examples/webhooks.md)
|
|
71
|
+
- **Need quick setup?** See [WEBHOOK_SECURITY_QUICKSTART.md](WEBHOOK_SECURITY_QUICKSTART.md)
|
|
72
|
+
- **Want to understand the design?** Read [ARCHITECTURE.md](ARCHITECTURE.md)
|
|
73
|
+
- **Security details?** Review [WEBHOOK_SIGNATURE.md](WEBHOOK_SIGNATURE.md)
|
|
74
|
+
|
|
75
|
+
## 🆘 Need Help?
|
|
76
|
+
|
|
77
|
+
1. Check the relevant documentation section above
|
|
78
|
+
2. Review the [examples](../examples/webhooks.md)
|
|
79
|
+
3. Consult the [Zai API documentation](https://developer.hellozai.com/)
|
|
80
|
+
4. Open an issue on GitHub
|
|
81
|
+
|
data/docs/USERS.md
ADDED
|
@@ -0,0 +1,414 @@
|
|
|
1
|
+
# User Management
|
|
2
|
+
|
|
3
|
+
The User resource provides methods for managing Zai users (both payin and payout users).
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
Zai supports two types of user onboarding:
|
|
8
|
+
- **Payin User (Buyer)**: A user who makes payments
|
|
9
|
+
- **Payout User (Seller/Merchant)**: A user who receives payments
|
|
10
|
+
|
|
11
|
+
Both user types use the same endpoints but have different required information based on their role and verification requirements.
|
|
12
|
+
|
|
13
|
+
## References
|
|
14
|
+
|
|
15
|
+
- [Onboarding a Payin User](https://developer.hellozai.com/docs/onboarding-a-payin-user)
|
|
16
|
+
- [Onboarding a Payout User](https://developer.hellozai.com/docs/onboarding-a-payout-user)
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
|
|
20
|
+
### Initialize the User Resource
|
|
21
|
+
|
|
22
|
+
```ruby
|
|
23
|
+
# Using the singleton instance
|
|
24
|
+
users = ZaiPayment.users
|
|
25
|
+
|
|
26
|
+
# Or create a new instance
|
|
27
|
+
users = ZaiPayment::Resources::User.new
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Methods
|
|
31
|
+
|
|
32
|
+
### List Users
|
|
33
|
+
|
|
34
|
+
Retrieve a list of all users with pagination support.
|
|
35
|
+
|
|
36
|
+
```ruby
|
|
37
|
+
# List users with default pagination (limit: 10, offset: 0)
|
|
38
|
+
response = ZaiPayment.users.list
|
|
39
|
+
|
|
40
|
+
# List users with custom pagination
|
|
41
|
+
response = ZaiPayment.users.list(limit: 20, offset: 10)
|
|
42
|
+
|
|
43
|
+
# Access the data
|
|
44
|
+
response.data # => Array of user objects
|
|
45
|
+
response.meta # => Pagination metadata
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Show User
|
|
49
|
+
|
|
50
|
+
Get details of a specific user by ID.
|
|
51
|
+
|
|
52
|
+
```ruby
|
|
53
|
+
response = ZaiPayment.users.show('user_id')
|
|
54
|
+
|
|
55
|
+
# Access user details
|
|
56
|
+
user = response.data
|
|
57
|
+
puts user['email']
|
|
58
|
+
puts user['first_name']
|
|
59
|
+
puts user['last_name']
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Create Payin User (Buyer)
|
|
63
|
+
|
|
64
|
+
Create a new payin user who will make payments on your platform.
|
|
65
|
+
|
|
66
|
+
#### Required Fields for Payin Users
|
|
67
|
+
|
|
68
|
+
- `email` - User's email address
|
|
69
|
+
- `first_name` - User's first name
|
|
70
|
+
- `last_name` - User's last name
|
|
71
|
+
- `country` - Country code (ISO 3166-1 alpha-3, e.g., USA, AUS, GBR)
|
|
72
|
+
- `device_id` - Required when an item is created and card is charged
|
|
73
|
+
- `ip_address` - Required when an item is created and card is charged
|
|
74
|
+
|
|
75
|
+
#### Recommended Fields
|
|
76
|
+
|
|
77
|
+
- `address_line1` - Street address
|
|
78
|
+
- `city` - City
|
|
79
|
+
- `state` - State/Province
|
|
80
|
+
- `zip` - Postal/ZIP code
|
|
81
|
+
- `mobile` - Mobile phone number
|
|
82
|
+
- `dob` - Date of birth (YYYYMMDD format)
|
|
83
|
+
|
|
84
|
+
#### Example
|
|
85
|
+
|
|
86
|
+
```ruby
|
|
87
|
+
response = ZaiPayment.users.create(
|
|
88
|
+
email: 'buyer@example.com',
|
|
89
|
+
first_name: 'John',
|
|
90
|
+
last_name: 'Doe',
|
|
91
|
+
country: 'USA',
|
|
92
|
+
mobile: '+1234567890',
|
|
93
|
+
address_line1: '123 Main St',
|
|
94
|
+
city: 'New York',
|
|
95
|
+
state: 'NY',
|
|
96
|
+
zip: '10001',
|
|
97
|
+
device_id: 'device_12345',
|
|
98
|
+
ip_address: '192.168.1.1'
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
user = response.data
|
|
102
|
+
puts user['id'] # => "user_payin_123"
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### Create Payout User (Seller/Merchant)
|
|
106
|
+
|
|
107
|
+
Create a new payout user who will receive payments. Payout users must undergo verification and provide more detailed information.
|
|
108
|
+
|
|
109
|
+
#### Required Fields for Payout Users (Individuals)
|
|
110
|
+
|
|
111
|
+
- `email` - User's email address
|
|
112
|
+
- `first_name` - User's first name
|
|
113
|
+
- `last_name` - User's last name
|
|
114
|
+
- `address_line1` - Street address (Required for payout)
|
|
115
|
+
- `city` - City (Required for payout)
|
|
116
|
+
- `state` - State/Province (Required for payout)
|
|
117
|
+
- `zip` - Postal/ZIP code (Required for payout)
|
|
118
|
+
- `country` - Country code (ISO 3166-1 alpha-3)
|
|
119
|
+
- `dob` - Date of birth (YYYYMMDD format, Required for payout)
|
|
120
|
+
|
|
121
|
+
#### Example
|
|
122
|
+
|
|
123
|
+
```ruby
|
|
124
|
+
response = ZaiPayment.users.create(
|
|
125
|
+
email: 'seller@example.com',
|
|
126
|
+
first_name: 'Jane',
|
|
127
|
+
last_name: 'Smith',
|
|
128
|
+
country: 'AUS',
|
|
129
|
+
dob: '19900101',
|
|
130
|
+
address_line1: '456 Market St',
|
|
131
|
+
city: 'Sydney',
|
|
132
|
+
state: 'NSW',
|
|
133
|
+
zip: '2000',
|
|
134
|
+
mobile: '+61412345678',
|
|
135
|
+
government_number: 'TFN123456789'
|
|
136
|
+
)
|
|
137
|
+
|
|
138
|
+
user = response.data
|
|
139
|
+
puts user['id'] # => "user_payout_456"
|
|
140
|
+
puts user['verification_state'] # => "pending" or "approved"
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### Update User
|
|
144
|
+
|
|
145
|
+
Update an existing user's information.
|
|
146
|
+
|
|
147
|
+
```ruby
|
|
148
|
+
response = ZaiPayment.users.update(
|
|
149
|
+
'user_id',
|
|
150
|
+
mobile: '+9876543210',
|
|
151
|
+
address_line1: '789 New St',
|
|
152
|
+
city: 'Los Angeles',
|
|
153
|
+
state: 'CA',
|
|
154
|
+
zip: '90001'
|
|
155
|
+
)
|
|
156
|
+
|
|
157
|
+
updated_user = response.data
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### Create Business User with Company
|
|
161
|
+
|
|
162
|
+
Create a payout user representing a business entity with full company details. This is useful for merchants, marketplace sellers, or any business that needs to receive payments.
|
|
163
|
+
|
|
164
|
+
#### Required Company Fields
|
|
165
|
+
|
|
166
|
+
When the `company` parameter is provided, the following fields are required:
|
|
167
|
+
- `name` - Company name
|
|
168
|
+
- `legal_name` - Legal business name
|
|
169
|
+
- `tax_number` - Tax/ABN/TFN number
|
|
170
|
+
- `business_email` - Business email address
|
|
171
|
+
- `country` - Country code (ISO 3166-1 alpha-3)
|
|
172
|
+
|
|
173
|
+
#### Example
|
|
174
|
+
|
|
175
|
+
```ruby
|
|
176
|
+
response = ZaiPayment.users.create(
|
|
177
|
+
# Personal details (authorized signer)
|
|
178
|
+
email: 'john.director@example.com',
|
|
179
|
+
first_name: 'John',
|
|
180
|
+
last_name: 'Smith',
|
|
181
|
+
country: 'AUS',
|
|
182
|
+
mobile: '+61412345678',
|
|
183
|
+
|
|
184
|
+
# Job title (required for AMEX merchants)
|
|
185
|
+
authorized_signer_title: 'Director',
|
|
186
|
+
|
|
187
|
+
# Company details
|
|
188
|
+
company: {
|
|
189
|
+
name: 'Smith Trading Co',
|
|
190
|
+
legal_name: 'Smith Trading Company Pty Ltd',
|
|
191
|
+
tax_number: '53004085616', # ABN for Australian companies
|
|
192
|
+
business_email: 'accounts@smithtrading.com',
|
|
193
|
+
country: 'AUS',
|
|
194
|
+
charge_tax: true, # GST registered
|
|
195
|
+
|
|
196
|
+
# Optional company fields
|
|
197
|
+
address_line1: '123 Business Street',
|
|
198
|
+
address_line2: 'Suite 5',
|
|
199
|
+
city: 'Melbourne',
|
|
200
|
+
state: 'VIC',
|
|
201
|
+
zip: '3000',
|
|
202
|
+
phone: '+61398765432'
|
|
203
|
+
}
|
|
204
|
+
)
|
|
205
|
+
|
|
206
|
+
user = response.data
|
|
207
|
+
puts "Business user created: #{user['id']}"
|
|
208
|
+
puts "Company: #{user['company']['name']}"
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
## Field Reference
|
|
212
|
+
|
|
213
|
+
### All User Fields
|
|
214
|
+
|
|
215
|
+
| Field | Type | Description | Payin Required | Payout Required |
|
|
216
|
+
|-------|------|-------------|----------------|-----------------|
|
|
217
|
+
| `email` | String | User's email address | ✓ | ✓ |
|
|
218
|
+
| `first_name` | String | User's first name | ✓ | ✓ |
|
|
219
|
+
| `last_name` | String | User's last name | ✓ | ✓ |
|
|
220
|
+
| `country` | String | ISO 3166-1 alpha-3 country code | ✓ | ✓ |
|
|
221
|
+
| `address_line1` | String | Street address | Recommended | ✓ |
|
|
222
|
+
| `address_line2` | String | Additional address info | Optional | Optional |
|
|
223
|
+
| `city` | String | City | Recommended | ✓ |
|
|
224
|
+
| `state` | String | State/Province | Recommended | ✓ |
|
|
225
|
+
| `zip` | String | Postal/ZIP code | Recommended | ✓ |
|
|
226
|
+
| `mobile` | String | Mobile phone number (international format) | Recommended | Recommended |
|
|
227
|
+
| `phone` | String | Phone number | Optional | Optional |
|
|
228
|
+
| `dob` | String | Date of birth (DD/MM/YYYY) | Recommended | ✓ |
|
|
229
|
+
| `government_number` | String | Tax/Government ID (SSN, TFN, etc.) | Optional | Recommended |
|
|
230
|
+
| `drivers_license_number` | String | Driving license number | Optional | Optional |
|
|
231
|
+
| `drivers_license_state` | String | State section of driving license | Optional | Optional |
|
|
232
|
+
| `logo_url` | String | URL link to logo | Optional | Optional |
|
|
233
|
+
| `color_1` | String | Color code number 1 | Optional | Optional |
|
|
234
|
+
| `color_2` | String | Color code number 2 | Optional | Optional |
|
|
235
|
+
| `custom_descriptor` | String | Custom text for bank statements | Optional | Optional |
|
|
236
|
+
| `authorized_signer_title` | String | Job title (e.g., Director) - Required for AMEX | Optional | AMEX Required |
|
|
237
|
+
| `company` | Object | Company details (see below) | Optional | Optional |
|
|
238
|
+
| `device_id` | String | Device ID for fraud prevention | When charging* | N/A |
|
|
239
|
+
| `ip_address` | String | IP address for fraud prevention | When charging* | N/A |
|
|
240
|
+
| `user_type` | String | 'payin' or 'payout' | Optional | Optional |
|
|
241
|
+
|
|
242
|
+
\* Required when an item is created and a card is charged
|
|
243
|
+
|
|
244
|
+
### Company Object Fields
|
|
245
|
+
|
|
246
|
+
When creating a business user, you can provide a `company` object with the following fields:
|
|
247
|
+
|
|
248
|
+
| Field | Type | Description | Required |
|
|
249
|
+
|-------|------|-------------|----------|
|
|
250
|
+
| `name` | String | Company name | ✓ |
|
|
251
|
+
| `legal_name` | String | Legal business name | ✓ |
|
|
252
|
+
| `tax_number` | String | ABN/TFN/Tax number | ✓ |
|
|
253
|
+
| `business_email` | String | Business email address | ✓ |
|
|
254
|
+
| `country` | String | Country code (ISO 3166-1 alpha-3) | ✓ |
|
|
255
|
+
| `charge_tax` | Boolean | Charge GST/tax? (true/false) | Optional |
|
|
256
|
+
| `address_line1` | String | Business address line 1 | Optional |
|
|
257
|
+
| `address_line2` | String | Business address line 2 | Optional |
|
|
258
|
+
| `city` | String | Business city | Optional |
|
|
259
|
+
| `state` | String | Business state | Optional |
|
|
260
|
+
| `zip` | String | Business postal code | Optional |
|
|
261
|
+
| `phone` | String | Business phone number | Optional |
|
|
262
|
+
|
|
263
|
+
## Error Handling
|
|
264
|
+
|
|
265
|
+
The User resource will raise validation errors for:
|
|
266
|
+
|
|
267
|
+
- Missing required fields
|
|
268
|
+
- Invalid email format
|
|
269
|
+
- Invalid country code (must be ISO 3166-1 alpha-3)
|
|
270
|
+
- Invalid date of birth format (must be YYYYMMDD)
|
|
271
|
+
- Invalid user type (must be 'payin' or 'payout')
|
|
272
|
+
|
|
273
|
+
```ruby
|
|
274
|
+
begin
|
|
275
|
+
response = ZaiPayment.users.create(
|
|
276
|
+
email: 'invalid-email',
|
|
277
|
+
first_name: 'John',
|
|
278
|
+
last_name: 'Doe',
|
|
279
|
+
country: 'USA'
|
|
280
|
+
)
|
|
281
|
+
rescue ZaiPayment::Errors::ValidationError => e
|
|
282
|
+
puts "Validation error: #{e.message}"
|
|
283
|
+
rescue ZaiPayment::Errors::ApiError => e
|
|
284
|
+
puts "API error: #{e.message}"
|
|
285
|
+
end
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
## Best Practices
|
|
289
|
+
|
|
290
|
+
### For Payin Users
|
|
291
|
+
|
|
292
|
+
1. **Collect information progressively**: You can create a payin user with minimal information and update it later as needed.
|
|
293
|
+
2. **Capture device information**: Use Hosted Forms and Hosted Fields to capture device ID and IP address when processing payments.
|
|
294
|
+
3. **Store device_id and ip_address**: These are required when creating items and charging cards for fraud prevention.
|
|
295
|
+
|
|
296
|
+
### For Payout Users
|
|
297
|
+
|
|
298
|
+
1. **Collect complete information upfront**: Payout users require more detailed information for verification and underwriting.
|
|
299
|
+
2. **Verify date of birth format**: Ensure DOB is in YYYYMMDD format (e.g., 19900101).
|
|
300
|
+
3. **Provide accurate address**: Complete address information is required for payout users to pass verification.
|
|
301
|
+
4. **Handle verification states**: Payout users go through verification (`pending`, `pending_check`, `approved`, etc.).
|
|
302
|
+
|
|
303
|
+
## Response Structure
|
|
304
|
+
|
|
305
|
+
### Successful Response
|
|
306
|
+
|
|
307
|
+
```ruby
|
|
308
|
+
response.success? # => true
|
|
309
|
+
response.status # => 200 or 201
|
|
310
|
+
response.data # => User object hash
|
|
311
|
+
response.meta # => Pagination metadata (for list)
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
### User Object
|
|
315
|
+
|
|
316
|
+
```ruby
|
|
317
|
+
{
|
|
318
|
+
"id" => "user_123",
|
|
319
|
+
"email" => "user@example.com",
|
|
320
|
+
"first_name" => "John",
|
|
321
|
+
"last_name" => "Doe",
|
|
322
|
+
"country" => "USA",
|
|
323
|
+
"address_line1" => "123 Main St",
|
|
324
|
+
"city" => "New York",
|
|
325
|
+
"state" => "NY",
|
|
326
|
+
"zip" => "10001",
|
|
327
|
+
"mobile" => "+1234567890",
|
|
328
|
+
"dob" => "19900101",
|
|
329
|
+
"verification_state" => "approved",
|
|
330
|
+
"created_at" => "2025-01-01T00:00:00Z",
|
|
331
|
+
"updated_at" => "2025-01-01T00:00:00Z"
|
|
332
|
+
}
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
## Complete Examples
|
|
336
|
+
|
|
337
|
+
### Example 1: Create and Update a Payin User
|
|
338
|
+
|
|
339
|
+
```ruby
|
|
340
|
+
# Step 1: Create a payin user with minimal info
|
|
341
|
+
response = ZaiPayment.users.create(
|
|
342
|
+
email: 'buyer@example.com',
|
|
343
|
+
first_name: 'John',
|
|
344
|
+
last_name: 'Doe',
|
|
345
|
+
country: 'USA'
|
|
346
|
+
)
|
|
347
|
+
|
|
348
|
+
user_id = response.data['id']
|
|
349
|
+
|
|
350
|
+
# Step 2: Update with additional info later
|
|
351
|
+
ZaiPayment.users.update(
|
|
352
|
+
user_id,
|
|
353
|
+
address_line1: '123 Main St',
|
|
354
|
+
city: 'New York',
|
|
355
|
+
state: 'NY',
|
|
356
|
+
zip: '10001',
|
|
357
|
+
mobile: '+1234567890'
|
|
358
|
+
)
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
### Example 2: Create a Payout User with Complete Information
|
|
362
|
+
|
|
363
|
+
```ruby
|
|
364
|
+
response = ZaiPayment.users.create(
|
|
365
|
+
# Required fields
|
|
366
|
+
email: 'seller@example.com',
|
|
367
|
+
first_name: 'Jane',
|
|
368
|
+
last_name: 'Smith',
|
|
369
|
+
country: 'AUS',
|
|
370
|
+
dob: '19900101',
|
|
371
|
+
address_line1: '456 Market St',
|
|
372
|
+
city: 'Sydney',
|
|
373
|
+
state: 'NSW',
|
|
374
|
+
zip: '2000',
|
|
375
|
+
|
|
376
|
+
# Additional recommended fields
|
|
377
|
+
mobile: '+61412345678',
|
|
378
|
+
government_number: 'TFN123456789',
|
|
379
|
+
user_type: 'payout'
|
|
380
|
+
)
|
|
381
|
+
|
|
382
|
+
user = response.data
|
|
383
|
+
puts "Created payout user: #{user['id']}"
|
|
384
|
+
puts "Verification state: #{user['verification_state']}"
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
### Example 3: List and Filter Users
|
|
388
|
+
|
|
389
|
+
```ruby
|
|
390
|
+
# Get first page of users
|
|
391
|
+
response = ZaiPayment.users.list(limit: 10, offset: 0)
|
|
392
|
+
|
|
393
|
+
response.data.each do |user|
|
|
394
|
+
puts "#{user['email']} - #{user['first_name']} #{user['last_name']}"
|
|
395
|
+
end
|
|
396
|
+
|
|
397
|
+
# Get next page
|
|
398
|
+
next_response = ZaiPayment.users.list(limit: 10, offset: 10)
|
|
399
|
+
```
|
|
400
|
+
|
|
401
|
+
## Testing
|
|
402
|
+
|
|
403
|
+
The User resource includes comprehensive test coverage. Run the tests with:
|
|
404
|
+
|
|
405
|
+
```bash
|
|
406
|
+
bundle exec rspec spec/zai_payment/resources/user_spec.rb
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
## See Also
|
|
410
|
+
|
|
411
|
+
- [Webhook Documentation](WEBHOOKS.md)
|
|
412
|
+
- [Authentication Documentation](AUTHENTICATION.md)
|
|
413
|
+
- [Architecture Documentation](ARCHITECTURE.md)
|
|
414
|
+
|