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/README.md
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
# Zai Payment Ruby Library
|
|
2
2
|
|
|
3
|
+

|
|
4
|
+
[](./CODE_OF_CONDUCT.md)
|
|
5
|
+
[](https://badge.fury.io/rb/zai_payment)
|
|
6
|
+
[](https://github.com/Sentia/zai-payment/releases)
|
|
7
|
+
[](https://rubygems.org/gems/zai_payment)
|
|
3
8
|
[](https://github.com/Sentia/zai-payment/actions/workflows/ci.yml)
|
|
9
|
+

|
|
10
|
+

|
|
11
|
+
[](https://rubydoc.info/gems/zai_payment)
|
|
12
|
+
[](./CONTRIBUTING.md)
|
|
4
13
|
|
|
5
14
|
A lightweight and extensible Ruby client for the **Zai (AssemblyPay)** API — starting with secure OAuth2 authentication, and ready for Payments, Virtual Accounts, Webhooks, and more.
|
|
6
15
|
|
|
@@ -8,22 +17,23 @@ A lightweight and extensible Ruby client for the **Zai (AssemblyPay)** API — s
|
|
|
8
17
|
|
|
9
18
|
## ✨ Features
|
|
10
19
|
|
|
11
|
-
- 🔐 OAuth2 Client Credentials
|
|
12
|
-
- 🧠 Smart
|
|
13
|
-
-
|
|
14
|
-
-
|
|
15
|
-
-
|
|
16
|
-
-
|
|
20
|
+
- 🔐 **OAuth2 Authentication** - Client Credentials flow with automatic token management
|
|
21
|
+
- 🧠 **Smart Token Caching** - Auto-refresh before expiration, thread-safe storage
|
|
22
|
+
- 👥 **User Management** - Create and manage payin (buyers) & payout (sellers) users
|
|
23
|
+
- 🪝 **Webhooks** - Full CRUD + secure signature verification (HMAC SHA256)
|
|
24
|
+
- ⚙️ **Environment-Aware** - Seamless Pre-live / Production switching
|
|
25
|
+
- 🧱 **Modular & Extensible** - Clean resource-based architecture
|
|
26
|
+
- 🧰 **Zero Heavy Dependencies** - Lightweight, fast, and reliable
|
|
27
|
+
- 📦 **Production Ready** - 88%+ test coverage, RuboCop compliant
|
|
17
28
|
|
|
18
29
|
---
|
|
19
30
|
|
|
20
31
|
## 🧭 Installation
|
|
21
32
|
|
|
22
|
-
### From GitHub (private repo)
|
|
23
33
|
Add this line to your Gemfile:
|
|
24
34
|
|
|
25
35
|
```ruby
|
|
26
|
-
gem 'zai_payment'
|
|
36
|
+
gem 'zai_payment'
|
|
27
37
|
```
|
|
28
38
|
|
|
29
39
|
Then install
|
|
@@ -44,67 +54,118 @@ ZaiPayment.configure do |c|
|
|
|
44
54
|
end
|
|
45
55
|
```
|
|
46
56
|
|
|
47
|
-
## 🚀
|
|
57
|
+
## 🚀 Quick Start
|
|
48
58
|
|
|
49
|
-
|
|
59
|
+
### Authentication
|
|
50
60
|
|
|
51
|
-
|
|
61
|
+
Get an OAuth2 token with automatic caching and refresh:
|
|
52
62
|
|
|
53
|
-
|
|
63
|
+
```ruby
|
|
64
|
+
# Simple one-liner (recommended)
|
|
65
|
+
token = ZaiPayment.token
|
|
66
|
+
|
|
67
|
+
# Or with full control (advanced)
|
|
68
|
+
config = ZaiPayment::Config.new
|
|
69
|
+
config.environment = :prelive
|
|
70
|
+
config.client_id = 'your_client_id'
|
|
71
|
+
config.client_secret = 'your_client_secret'
|
|
72
|
+
config.scope = 'your_scope'
|
|
73
|
+
|
|
74
|
+
token_provider = ZaiPayment::Auth::TokenProvider.new(config: config)
|
|
75
|
+
token = token_provider.bearer_token
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
The gem handles OAuth2 Client Credentials flow automatically - tokens are cached and refreshed before expiration.
|
|
79
|
+
|
|
80
|
+
📖 **[Complete Authentication Guide](docs/AUTHENTICATION.md)** - Two approaches, examples, and best practices
|
|
81
|
+
|
|
82
|
+
### Users
|
|
54
83
|
|
|
55
|
-
|
|
84
|
+
Manage payin (buyer) and payout (seller/merchant) users:
|
|
56
85
|
|
|
57
86
|
```ruby
|
|
58
|
-
|
|
87
|
+
# Create a payin user (buyer)
|
|
88
|
+
response = ZaiPayment.users.create(
|
|
89
|
+
email: 'buyer@example.com',
|
|
90
|
+
first_name: 'John',
|
|
91
|
+
last_name: 'Doe',
|
|
92
|
+
country: 'USA',
|
|
93
|
+
mobile: '+1234567890'
|
|
94
|
+
)
|
|
59
95
|
|
|
60
|
-
|
|
61
|
-
|
|
96
|
+
# Create a payout user (seller/merchant)
|
|
97
|
+
response = ZaiPayment.users.create(
|
|
98
|
+
email: 'seller@example.com',
|
|
99
|
+
first_name: 'Jane',
|
|
100
|
+
last_name: 'Smith',
|
|
101
|
+
country: 'AUS',
|
|
102
|
+
dob: '19900101',
|
|
103
|
+
address_line1: '456 Market St',
|
|
104
|
+
city: 'Sydney',
|
|
105
|
+
state: 'NSW',
|
|
106
|
+
zip: '2000'
|
|
107
|
+
)
|
|
62
108
|
|
|
63
|
-
|
|
109
|
+
# Create a business user with company details
|
|
110
|
+
response = ZaiPayment.users.create(
|
|
111
|
+
email: 'director@company.com',
|
|
112
|
+
first_name: 'John',
|
|
113
|
+
last_name: 'Director',
|
|
114
|
+
country: 'AUS',
|
|
115
|
+
mobile: '+61412345678',
|
|
116
|
+
authorized_signer_title: 'Director',
|
|
117
|
+
company: {
|
|
118
|
+
name: 'My Company',
|
|
119
|
+
legal_name: 'My Company Pty Ltd',
|
|
120
|
+
tax_number: '123456789',
|
|
121
|
+
business_email: 'admin@company.com',
|
|
122
|
+
country: 'AUS',
|
|
123
|
+
charge_tax: true
|
|
124
|
+
}
|
|
125
|
+
)
|
|
64
126
|
|
|
127
|
+
# List users
|
|
128
|
+
response = ZaiPayment.users.list(limit: 10, offset: 0)
|
|
65
129
|
|
|
66
|
-
|
|
67
|
-
ZaiPayment.
|
|
130
|
+
# Get user details
|
|
131
|
+
response = ZaiPayment.users.show('user_id')
|
|
132
|
+
|
|
133
|
+
# Update user
|
|
134
|
+
response = ZaiPayment.users.update('user_id', mobile: '+9876543210')
|
|
68
135
|
```
|
|
69
136
|
|
|
70
|
-
|
|
137
|
+
**📚 Documentation:**
|
|
138
|
+
- 📖 [User Management Guide](docs/USERS.md) - Complete guide for payin and payout users
|
|
139
|
+
- 💡 [User Examples](examples/users.md) - Real-world usage patterns and Rails integration
|
|
140
|
+
- 🔗 [Zai: Onboarding a Payin User](https://developer.hellozai.com/docs/onboarding-a-payin-user)
|
|
141
|
+
- 🔗 [Zai: Onboarding a Payout User](https://developer.hellozai.com/docs/onboarding-a-payout-user)
|
|
71
142
|
|
|
72
143
|
### Webhooks
|
|
73
144
|
|
|
74
|
-
|
|
145
|
+
Manage webhook endpoints:
|
|
75
146
|
|
|
76
147
|
```ruby
|
|
77
|
-
# List
|
|
148
|
+
# List webhooks
|
|
78
149
|
response = ZaiPayment.webhooks.list
|
|
79
150
|
webhooks = response.data
|
|
80
151
|
|
|
81
|
-
# List with pagination
|
|
82
|
-
response = ZaiPayment.webhooks.list(limit: 20, offset: 10)
|
|
83
|
-
|
|
84
|
-
# Get a specific webhook
|
|
85
|
-
response = ZaiPayment.webhooks.show('webhook_id')
|
|
86
|
-
webhook = response.data
|
|
87
|
-
|
|
88
152
|
# Create a webhook
|
|
89
153
|
response = ZaiPayment.webhooks.create(
|
|
90
154
|
url: 'https://example.com/webhooks/zai',
|
|
91
155
|
object_type: 'transactions',
|
|
92
|
-
enabled: true
|
|
93
|
-
description: 'Production webhook for transactions'
|
|
94
|
-
)
|
|
95
|
-
|
|
96
|
-
# Update a webhook
|
|
97
|
-
response = ZaiPayment.webhooks.update(
|
|
98
|
-
'webhook_id',
|
|
99
|
-
enabled: false,
|
|
100
|
-
description: 'Temporarily disabled'
|
|
156
|
+
enabled: true
|
|
101
157
|
)
|
|
102
158
|
|
|
103
|
-
#
|
|
104
|
-
|
|
159
|
+
# Secure your webhooks with signature verification
|
|
160
|
+
secret_key = SecureRandom.alphanumeric(32)
|
|
161
|
+
ZaiPayment.webhooks.create_secret_key(secret_key: secret_key)
|
|
105
162
|
```
|
|
106
163
|
|
|
107
|
-
|
|
164
|
+
**📚 Documentation:**
|
|
165
|
+
- 📖 [Webhook Examples & Complete Guide](examples/webhooks.md) - Full CRUD operations and patterns
|
|
166
|
+
- 🔒 [Security Quick Start](docs/WEBHOOK_SECURITY_QUICKSTART.md) - 5-minute webhook security setup
|
|
167
|
+
- 🏗️ [Architecture & Implementation](docs/WEBHOOKS.md) - Detailed technical documentation
|
|
168
|
+
- 🔐 [Signature Verification Details](docs/WEBHOOK_SIGNATURE.md) - Security implementation specs
|
|
108
169
|
|
|
109
170
|
### Error Handling
|
|
110
171
|
|
|
@@ -137,9 +198,9 @@ end
|
|
|
137
198
|
| ------------------------------- | --------------------------------- | -------------- |
|
|
138
199
|
| ✅ Authentication | OAuth2 Client Credentials flow | Done |
|
|
139
200
|
| ✅ Webhooks | CRUD for webhook endpoints | Done |
|
|
201
|
+
| ✅ Users | Manage PayIn / PayOut users | Done |
|
|
140
202
|
| 💳 Payments | Single and recurring payments | 🚧 In progress |
|
|
141
203
|
| 🏦 Virtual Accounts (VA / PIPU) | Manage virtual accounts & PayTo | ⏳ Planned |
|
|
142
|
-
| 👤 Users | Manage PayIn / PayOut users | ⏳ Planned |
|
|
143
204
|
| 💼 Wallets | Create and manage wallet accounts | ⏳ Planned |
|
|
144
205
|
|
|
145
206
|
## 🧪 Development
|
|
@@ -190,8 +251,27 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
|
190
251
|
|
|
191
252
|
Everyone interacting in the ZaiPayment project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/Sentia/zai-payment/blob/main/CODE_OF_CONDUCT.md).
|
|
192
253
|
|
|
193
|
-
##
|
|
254
|
+
## 📚 Documentation
|
|
255
|
+
|
|
256
|
+
### Getting Started
|
|
257
|
+
- [**Authentication Guide**](docs/AUTHENTICATION.md) - Two approaches to getting tokens, automatic management
|
|
258
|
+
- [**User Management Guide**](docs/USERS.md) - Managing payin and payout users
|
|
259
|
+
- [**Webhook Examples**](examples/webhooks.md) - Complete webhook usage guide
|
|
260
|
+
- [**Documentation Index**](docs/README.md) - Full documentation navigation
|
|
261
|
+
|
|
262
|
+
### Examples & Patterns
|
|
263
|
+
- [User Examples](examples/users.md) - Real-world user management patterns
|
|
264
|
+
- [Webhook Examples](examples/webhooks.md) - Webhook integration patterns
|
|
265
|
+
|
|
266
|
+
### Technical Guides
|
|
267
|
+
- [Webhook Architecture](docs/WEBHOOKS.md) - Technical implementation details
|
|
268
|
+
- [Architecture Overview](docs/ARCHITECTURE.md) - System architecture and design
|
|
269
|
+
|
|
270
|
+
### Security
|
|
271
|
+
- [Webhook Security Quick Start](docs/WEBHOOK_SECURITY_QUICKSTART.md) - 5-minute setup guide
|
|
272
|
+
- [Signature Verification](docs/WEBHOOK_SIGNATURE.md) - Implementation details
|
|
194
273
|
|
|
274
|
+
### External Resources
|
|
195
275
|
- [Zai Developer Portal](https://developer.hellozai.com/)
|
|
196
276
|
- [Zai API Reference](https://developer.hellozai.com/reference)
|
|
197
|
-
- [
|
|
277
|
+
- [Zai OAuth Documentation](https://developer.hellozai.com/docs/introduction)
|
data/badges/.gitkeep
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"schemaVersion": 1, "label": "coverage", "message": "95.18%", "color": "brightgreen"}
|