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.
data/README.md CHANGED
@@ -1,6 +1,15 @@
1
1
  # Zai Payment Ruby Library
2
2
 
3
+ ![GitHub License](https://img.shields.io/github/license/Sentia/zai-payment)
4
+ [![Code of Conduct](https://img.shields.io/badge/code%20of%20conduct-MIT-blue.svg)](./CODE_OF_CONDUCT.md)
5
+ [![Gem Version](https://badge.fury.io/rb/zai_payment.svg)](https://badge.fury.io/rb/zai_payment)
6
+ [![GitHub release](https://img.shields.io/github/release/Sentia/zai-payment.svg)](https://github.com/Sentia/zai-payment/releases)
7
+ [![Gem](https://img.shields.io/gem/dt/zai_payment.svg)](https://rubygems.org/gems/zai_payment)
3
8
  [![CI](https://github.com/Sentia/zai-payment/actions/workflows/ci.yml/badge.svg)](https://github.com/Sentia/zai-payment/actions/workflows/ci.yml)
9
+ ![Endpoint Badge](https://img.shields.io/endpoint?url=https%3A%2F%2Fraw.githubusercontent.com%2FSentia%2Fzai-payment%2Fmain%2Fbadges%2Fcoverage.json)
10
+ ![GitHub top language](https://img.shields.io/github/languages/top/Sentia/zai-payment)
11
+ [![Documentation](https://img.shields.io/badge/docs-rubydoc.info-blue.svg)](https://rubydoc.info/gems/zai_payment)
12
+ [![Contributing](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](./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 authentication with automatic token management
12
- - 🧠 Smart token caching and refresh
13
- - ⚙️ Environment-aware (Pre-live / Production)
14
- - 🧱 Modular structure: easy to extend to Payments, Wallets, Webhooks, etc.
15
- - 🧩 Thread-safe in-memory store (Redis support coming soon)
16
- - 🧰 Simple Ruby API, no heavy dependencies
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', '~> 1.0', '>= 1.0.2'
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
- ## 🚀 Authentication
57
+ ## 🚀 Quick Start
48
58
 
49
- The Zai Payment gem implements OAuth2 Client Credentials flow for secure authentication with the Zai API. The gem intelligently manages your authentication tokens behind the scenes, so you don't have to worry about token expiration or manual refreshes.
59
+ ### Authentication
50
60
 
51
- When you request a token, the gem automatically caches it and reuses it for subsequent requests. Since Zai tokens expire after 60 minutes, the gem monitors the token lifetime and seamlessly refreshes it before expiration — ensuring your API calls never fail due to stale credentials.
61
+ Get an OAuth2 token with automatic caching and refresh:
52
62
 
53
- This automatic token management means you can focus on building your integration while the gem handles all the authentication complexity for you. Simply configure your credentials once, and the gem takes care of the rest.
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
- For more details about Zai's OAuth2 authentication, see the [official documentation](https://developer.hellozai.com/reference/overview#authentication).
84
+ Manage payin (buyer) and payout (seller/merchant) users:
56
85
 
57
86
  ```ruby
58
- client = ZaiPayment::Auth::TokenProvider.new(config: ZaiPayment.config)
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
- client.bearer_token
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
- Or, more easily, you can get a token with the convenience one-liner:
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
- ```ruby
67
- ZaiPayment.token
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
- ## 🚀 Usage
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
- The gem provides a comprehensive interface for managing Zai webhooks:
145
+ Manage webhook endpoints:
75
146
 
76
147
  ```ruby
77
- # List all webhooks
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
- # Delete a webhook
104
- response = ZaiPayment.webhooks.delete('webhook_id')
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
- For more examples, see [examples/webhooks.md](examples/webhooks.md).
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
- ## 🔗 Resources
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
- - [AssemblyPay Auth Documentation](https://developer.hellozai.com/docs/introduction)
277
+ - [Zai OAuth Documentation](https://developer.hellozai.com/docs/introduction)
data/badges/.gitkeep ADDED
@@ -0,0 +1,2 @@
1
+ # This directory stores coverage badge JSON
2
+
@@ -0,0 +1 @@
1
+ {"schemaVersion": 1, "label": "coverage", "message": "95.18%", "color": "brightgreen"}