zai_payment 2.3.2 → 2.5.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 +73 -0
- data/docs/bank_accounts.md +494 -0
- data/docs/items.md +575 -0
- data/examples/bank_accounts.md +637 -0
- data/examples/items.md +2115 -0
- data/examples/rails_card_payment.md +550 -14
- data/lib/zai_payment/resources/bank_account.rb +295 -0
- data/lib/zai_payment/resources/item.rb +257 -0
- data/lib/zai_payment/response.rb +1 -0
- data/lib/zai_payment/version.rb +1 -1
- data/lib/zai_payment.rb +6 -0
- data/readme.md +18 -150
- metadata +4 -2
- data/token_auth_implementation_summary.md +0 -249
data/readme.md
CHANGED
|
@@ -21,12 +21,13 @@ A lightweight and extensible Ruby client for the **Zai (AssemblyPay)** API — s
|
|
|
21
21
|
- 🧠 **Smart Token Caching** - Auto-refresh before expiration, thread-safe storage
|
|
22
22
|
- 👥 **User Management** - Create and manage payin (buyers) & payout (sellers) users
|
|
23
23
|
- 📦 **Item Management** - Full CRUD for transactions/payments between buyers and sellers
|
|
24
|
+
- 🏦 **Bank Account Management** - Complete CRUD + validation for AU/UK bank accounts
|
|
24
25
|
- 🎫 **Token Auth** - Generate secure tokens for bank and card account data collection
|
|
25
26
|
- 🪝 **Webhooks** - Full CRUD + secure signature verification (HMAC SHA256)
|
|
26
27
|
- ⚙️ **Environment-Aware** - Seamless Pre-live / Production switching
|
|
27
28
|
- 🧱 **Modular & Extensible** - Clean resource-based architecture
|
|
28
29
|
- 🧰 **Zero Heavy Dependencies** - Lightweight, fast, and reliable
|
|
29
|
-
- 📦 **Production Ready** -
|
|
30
|
+
- 📦 **Production Ready** - 97%+ test coverage, RuboCop compliant
|
|
30
31
|
|
|
31
32
|
---
|
|
32
33
|
|
|
@@ -88,82 +89,7 @@ The gem handles OAuth2 Client Credentials flow automatically - tokens are cached
|
|
|
88
89
|
|
|
89
90
|
### Users
|
|
90
91
|
|
|
91
|
-
Manage payin (buyer) and payout (seller/merchant) users
|
|
92
|
-
|
|
93
|
-
```ruby
|
|
94
|
-
# Create a payin user (buyer)
|
|
95
|
-
response = ZaiPayment.users.create(
|
|
96
|
-
user_type: 'payin',
|
|
97
|
-
email: 'buyer@example.com',
|
|
98
|
-
first_name: 'John',
|
|
99
|
-
last_name: 'Doe',
|
|
100
|
-
country: 'USA',
|
|
101
|
-
mobile: '+1234567890'
|
|
102
|
-
)
|
|
103
|
-
|
|
104
|
-
# Create a payout user (seller/merchant)
|
|
105
|
-
response = ZaiPayment.users.create(
|
|
106
|
-
user_type: 'payout',
|
|
107
|
-
email: 'seller@example.com',
|
|
108
|
-
first_name: 'Jane',
|
|
109
|
-
last_name: 'Smith',
|
|
110
|
-
country: 'AUS',
|
|
111
|
-
dob: '01/01/1990',
|
|
112
|
-
address_line1: '456 Market St',
|
|
113
|
-
city: 'Sydney',
|
|
114
|
-
state: 'NSW',
|
|
115
|
-
zip: '2000'
|
|
116
|
-
)
|
|
117
|
-
|
|
118
|
-
# Create a business user with company details
|
|
119
|
-
response = ZaiPayment.users.create(
|
|
120
|
-
user_type: 'payout',
|
|
121
|
-
email: 'director@company.com',
|
|
122
|
-
first_name: 'John',
|
|
123
|
-
last_name: 'Director',
|
|
124
|
-
country: 'AUS',
|
|
125
|
-
mobile: '+61412345678',
|
|
126
|
-
authorized_signer_title: 'Director',
|
|
127
|
-
company: {
|
|
128
|
-
name: 'My Company',
|
|
129
|
-
legal_name: 'My Company Pty Ltd',
|
|
130
|
-
tax_number: '123456789',
|
|
131
|
-
business_email: 'admin@company.com',
|
|
132
|
-
country: 'AUS',
|
|
133
|
-
charge_tax: true
|
|
134
|
-
}
|
|
135
|
-
)
|
|
136
|
-
|
|
137
|
-
# List users
|
|
138
|
-
response = ZaiPayment.users.list(limit: 10, offset: 0)
|
|
139
|
-
|
|
140
|
-
# Get user details
|
|
141
|
-
response = ZaiPayment.users.show('user_id')
|
|
142
|
-
|
|
143
|
-
# Update user
|
|
144
|
-
response = ZaiPayment.users.update('user_id', mobile: '+9876543210')
|
|
145
|
-
|
|
146
|
-
# Show user wallet account
|
|
147
|
-
response = ZaiPayment.users.wallet_account('user_id')
|
|
148
|
-
|
|
149
|
-
# List user items with pagination
|
|
150
|
-
response = ZaiPayment.users.items('user_id', limit: 50, offset: 10)
|
|
151
|
-
|
|
152
|
-
# Set user disbursement account
|
|
153
|
-
response = ZaiPayment.users.set_disbursement_account('user_id', 'bank_account_id')
|
|
154
|
-
|
|
155
|
-
# Show user bank account
|
|
156
|
-
response = ZaiPayment.users.bank_account('user_id')
|
|
157
|
-
|
|
158
|
-
# Verify user (prelive only)
|
|
159
|
-
response = ZaiPayment.users.verify('user_id')
|
|
160
|
-
|
|
161
|
-
# Show user card account
|
|
162
|
-
response = ZaiPayment.users.card_account('user_id')
|
|
163
|
-
|
|
164
|
-
# List user's BPay accounts
|
|
165
|
-
response = ZaiPayment.users.bpay_accounts('user_id')
|
|
166
|
-
```
|
|
92
|
+
Manage payin (buyer) and payout (seller/merchant) users.
|
|
167
93
|
|
|
168
94
|
**📚 Documentation:**
|
|
169
95
|
- 📖 [User Management Guide](docs/users.md) - Complete guide for payin and payout users
|
|
@@ -173,69 +99,25 @@ response = ZaiPayment.users.bpay_accounts('user_id')
|
|
|
173
99
|
|
|
174
100
|
### Items
|
|
175
101
|
|
|
176
|
-
Manage transactions/payments between buyers and sellers
|
|
177
|
-
|
|
178
|
-
```ruby
|
|
179
|
-
# Create an item
|
|
180
|
-
response = ZaiPayment.items.create(
|
|
181
|
-
name: "Product Purchase",
|
|
182
|
-
amount: 10000, # Amount in cents ($100.00)
|
|
183
|
-
payment_type: 2, # Credit card
|
|
184
|
-
buyer_id: "buyer-123",
|
|
185
|
-
seller_id: "seller-456",
|
|
186
|
-
description: "Purchase of premium product",
|
|
187
|
-
currency: "AUD",
|
|
188
|
-
tax_invoice: true
|
|
189
|
-
)
|
|
190
|
-
|
|
191
|
-
# List items
|
|
192
|
-
response = ZaiPayment.items.list(limit: 20, offset: 0)
|
|
193
|
-
|
|
194
|
-
# Get item details
|
|
195
|
-
response = ZaiPayment.items.show('item_id')
|
|
196
|
-
|
|
197
|
-
# Update item
|
|
198
|
-
response = ZaiPayment.items.update('item_id', name: 'Updated Name')
|
|
199
|
-
|
|
200
|
-
# Get item status
|
|
201
|
-
response = ZaiPayment.items.show_status('item_id')
|
|
202
|
-
|
|
203
|
-
# Get buyer/seller details
|
|
204
|
-
response = ZaiPayment.items.show_buyer('item_id')
|
|
205
|
-
response = ZaiPayment.items.show_seller('item_id')
|
|
206
|
-
|
|
207
|
-
# List transactions
|
|
208
|
-
response = ZaiPayment.items.list_transactions('item_id')
|
|
209
|
-
```
|
|
102
|
+
Manage transactions/payments between buyers and sellers.
|
|
210
103
|
|
|
211
104
|
**📚 Documentation:**
|
|
212
105
|
- 📖 [Item Management Guide](docs/items.md) - Complete guide for creating and managing items
|
|
213
106
|
- 💡 [Item Examples](examples/items.md) - Real-world usage patterns and complete workflows
|
|
214
107
|
- 🔗 [Zai: Items API Reference](https://developer.hellozai.com/reference/listitems)
|
|
215
108
|
|
|
216
|
-
###
|
|
109
|
+
### Bank Accounts
|
|
217
110
|
|
|
218
|
-
|
|
111
|
+
Manage bank accounts for Australian and UK users, with routing number validation.
|
|
219
112
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
# Use this token with PromisePay.js on the frontend
|
|
229
|
-
|
|
230
|
-
# Generate a card token (for collecting credit card details)
|
|
231
|
-
response = ZaiPayment.token_auths.generate(
|
|
232
|
-
user_id: "buyer-12345",
|
|
233
|
-
token_type: "card"
|
|
234
|
-
)
|
|
235
|
-
|
|
236
|
-
token = response.data['token_auth']['token']
|
|
237
|
-
# Use this token with PromisePay.js on the frontend
|
|
238
|
-
```
|
|
113
|
+
**📚 Documentation:**
|
|
114
|
+
- 📖 [Bank Account Management Guide](docs/bank_accounts.md) - Complete guide for bank accounts
|
|
115
|
+
- 💡 [Bank Account Examples](examples/bank_accounts.md) - Real-world patterns and integration
|
|
116
|
+
- 🔗 [Zai: Bank Accounts API Reference](https://developer.hellozai.com/reference/showbankaccount)
|
|
117
|
+
|
|
118
|
+
### Token Auth
|
|
119
|
+
|
|
120
|
+
Generate secure tokens for collecting bank and card account information.
|
|
239
121
|
|
|
240
122
|
**📚 Documentation:**
|
|
241
123
|
- 💡 [Token Auth Examples](examples/token_auths.md) - Complete integration guide with PromisePay.js
|
|
@@ -243,24 +125,7 @@ token = response.data['token_auth']['token']
|
|
|
243
125
|
|
|
244
126
|
### Webhooks
|
|
245
127
|
|
|
246
|
-
Manage webhook endpoints
|
|
247
|
-
|
|
248
|
-
```ruby
|
|
249
|
-
# List webhooks
|
|
250
|
-
response = ZaiPayment.webhooks.list
|
|
251
|
-
webhooks = response.data
|
|
252
|
-
|
|
253
|
-
# Create a webhook
|
|
254
|
-
response = ZaiPayment.webhooks.create(
|
|
255
|
-
url: 'https://example.com/webhooks/zai',
|
|
256
|
-
object_type: 'transactions',
|
|
257
|
-
enabled: true
|
|
258
|
-
)
|
|
259
|
-
|
|
260
|
-
# Secure your webhooks with signature verification
|
|
261
|
-
secret_key = SecureRandom.alphanumeric(32)
|
|
262
|
-
ZaiPayment.webhooks.create_secret_key(secret_key: secret_key)
|
|
263
|
-
```
|
|
128
|
+
Manage webhook endpoints with secure signature verification.
|
|
264
129
|
|
|
265
130
|
**📚 Documentation:**
|
|
266
131
|
- 📖 [Webhook Examples & Complete Guide](examples/webhooks.md) - Full CRUD operations and patterns
|
|
@@ -301,6 +166,7 @@ end
|
|
|
301
166
|
| ✅ Webhooks | CRUD for webhook endpoints | Done |
|
|
302
167
|
| ✅ Users | Manage PayIn / PayOut users | Done |
|
|
303
168
|
| ✅ Items | Transactions/payments (CRUD) | Done |
|
|
169
|
+
| ✅ Bank Accounts | AU/UK bank accounts + validation | Done |
|
|
304
170
|
| ✅ Token Auth | Generate bank/card tokens | Done |
|
|
305
171
|
| 💳 Payments | Single and recurring payments | 🚧 In progress |
|
|
306
172
|
| 🏦 Virtual Accounts (VA / PIPU) | Manage virtual accounts & PayTo | ⏳ Planned |
|
|
@@ -360,12 +226,14 @@ Everyone interacting in the ZaiPayment project's codebases, issue trackers, chat
|
|
|
360
226
|
- [**Authentication Guide**](docs/authentication.md) - Two approaches to getting tokens, automatic management
|
|
361
227
|
- [**User Management Guide**](docs/users.md) - Managing payin and payout users
|
|
362
228
|
- [**Item Management Guide**](docs/items.md) - Creating and managing transactions/payments
|
|
229
|
+
- [**Bank Account Guide**](docs/bank_accounts.md) - Managing bank accounts for AU/UK users
|
|
363
230
|
- [**Webhook Examples**](examples/webhooks.md) - Complete webhook usage guide
|
|
364
231
|
- [**Documentation Index**](docs/readme.md) - Full documentation navigation
|
|
365
232
|
|
|
366
233
|
### Examples & Patterns
|
|
367
234
|
- [User Examples](examples/users.md) - Real-world user management patterns
|
|
368
235
|
- [Item Examples](examples/items.md) - Transaction and payment workflows
|
|
236
|
+
- [Bank Account Examples](examples/bank_accounts.md) - Bank account integration patterns
|
|
369
237
|
- [Token Auth Examples](examples/token_auths.md) - Secure token generation and integration
|
|
370
238
|
- [Webhook Examples](examples/webhooks.md) - Webhook integration patterns
|
|
371
239
|
|
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.5.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Eddy Jaga
|
|
@@ -68,6 +68,7 @@ files:
|
|
|
68
68
|
- contributing.md
|
|
69
69
|
- docs/architecture.md
|
|
70
70
|
- docs/authentication.md
|
|
71
|
+
- docs/bank_accounts.md
|
|
71
72
|
- docs/items.md
|
|
72
73
|
- docs/readme.md
|
|
73
74
|
- docs/token_auths.md
|
|
@@ -77,6 +78,7 @@ files:
|
|
|
77
78
|
- docs/webhook_security_quickstart.md
|
|
78
79
|
- docs/webhook_signature.md
|
|
79
80
|
- docs/webhooks.md
|
|
81
|
+
- examples/bank_accounts.md
|
|
80
82
|
- examples/items.md
|
|
81
83
|
- examples/rails_card_payment.md
|
|
82
84
|
- examples/token_auths.md
|
|
@@ -91,6 +93,7 @@ files:
|
|
|
91
93
|
- lib/zai_payment/client.rb
|
|
92
94
|
- lib/zai_payment/config.rb
|
|
93
95
|
- lib/zai_payment/errors.rb
|
|
96
|
+
- lib/zai_payment/resources/bank_account.rb
|
|
94
97
|
- lib/zai_payment/resources/item.rb
|
|
95
98
|
- lib/zai_payment/resources/token_auth.rb
|
|
96
99
|
- lib/zai_payment/resources/user.rb
|
|
@@ -99,7 +102,6 @@ files:
|
|
|
99
102
|
- lib/zai_payment/version.rb
|
|
100
103
|
- readme.md
|
|
101
104
|
- sig/zai_payment.rbs
|
|
102
|
-
- token_auth_implementation_summary.md
|
|
103
105
|
homepage: https://github.com/Sentia/zai-payment
|
|
104
106
|
licenses:
|
|
105
107
|
- MIT
|
|
@@ -1,249 +0,0 @@
|
|
|
1
|
-
# Token Auth API Implementation Summary
|
|
2
|
-
|
|
3
|
-
## Overview
|
|
4
|
-
|
|
5
|
-
Successfully implemented the **Generate Token** endpoint from the Zai API (https://developer.hellozai.com/reference/generatetoken) to enable secure bank and card account data collection.
|
|
6
|
-
|
|
7
|
-
## What Was Implemented
|
|
8
|
-
|
|
9
|
-
### 1. Core Resource Implementation
|
|
10
|
-
|
|
11
|
-
**File:** `lib/zai_payment/resources/token_auth.rb`
|
|
12
|
-
|
|
13
|
-
- Created `TokenAuth` resource class following the project's resource pattern
|
|
14
|
-
- Implemented `generate(user_id:, token_type:)` method
|
|
15
|
-
- Added token type validation (bank or card)
|
|
16
|
-
- Added user ID validation
|
|
17
|
-
- Support for case-insensitive token types
|
|
18
|
-
- Default token type: 'bank'
|
|
19
|
-
|
|
20
|
-
**Key Features:**
|
|
21
|
-
```ruby
|
|
22
|
-
# Generate a bank token (default)
|
|
23
|
-
ZaiPayment.token_auths.generate(user_id: "seller-123")
|
|
24
|
-
|
|
25
|
-
# Generate a card token
|
|
26
|
-
ZaiPayment.token_auths.generate(user_id: "buyer-123", token_type: "card")
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
### 2. Module Integration
|
|
30
|
-
|
|
31
|
-
**File:** `lib/zai_payment.rb`
|
|
32
|
-
|
|
33
|
-
- Added `require_relative` for token_auth resource
|
|
34
|
-
- Added `token_auths` accessor method
|
|
35
|
-
- Configured to use `core_base` endpoint (https://test.api.promisepay.com)
|
|
36
|
-
|
|
37
|
-
### 3. Test Suite
|
|
38
|
-
|
|
39
|
-
**File:** `spec/zai_payment/resources/token_auth_spec.rb`
|
|
40
|
-
|
|
41
|
-
- 15 comprehensive test cases covering:
|
|
42
|
-
- Bank token generation
|
|
43
|
-
- Card token generation
|
|
44
|
-
- Default token type behavior
|
|
45
|
-
- Validation errors (nil, empty, whitespace, invalid types)
|
|
46
|
-
- Case-insensitive token types
|
|
47
|
-
- Client initialization
|
|
48
|
-
- Constants verification
|
|
49
|
-
- All tests passing with 95.22% line coverage
|
|
50
|
-
- Follows project's testing pattern using Faraday test stubs
|
|
51
|
-
- RuboCop compliant
|
|
52
|
-
|
|
53
|
-
### 4. Documentation
|
|
54
|
-
|
|
55
|
-
**File:** `examples/token_auths.md` (600+ lines)
|
|
56
|
-
|
|
57
|
-
Comprehensive examples including:
|
|
58
|
-
- Basic usage patterns
|
|
59
|
-
- Bank token collection workflows
|
|
60
|
-
- Card token collection workflows
|
|
61
|
-
- Rails controller integration
|
|
62
|
-
- Service object pattern
|
|
63
|
-
- Frontend integration with PromisePay.js
|
|
64
|
-
- Complete payment flow examples
|
|
65
|
-
- Error handling strategies
|
|
66
|
-
- Retry logic with exponential backoff
|
|
67
|
-
- Security best practices:
|
|
68
|
-
- Token expiry management
|
|
69
|
-
- Audit logging
|
|
70
|
-
- Rate limiting protection
|
|
71
|
-
|
|
72
|
-
**File:** `docs/token_auths.md` (500+ lines)
|
|
73
|
-
|
|
74
|
-
Complete technical guide covering:
|
|
75
|
-
- When to use Token Auth
|
|
76
|
-
- How it works (flow diagram)
|
|
77
|
-
- API methods reference
|
|
78
|
-
- Token types (bank vs card) with use cases
|
|
79
|
-
- Security considerations (PCI compliance, token lifecycle)
|
|
80
|
-
- Integration guide (backend + frontend)
|
|
81
|
-
- Error handling patterns
|
|
82
|
-
- Best practices with code examples
|
|
83
|
-
- Related resources and API references
|
|
84
|
-
|
|
85
|
-
### 5. Version Updates
|
|
86
|
-
|
|
87
|
-
**File:** `lib/zai_payment/version.rb`
|
|
88
|
-
|
|
89
|
-
- Updated version from `2.0.2` to `2.1.0`
|
|
90
|
-
- Follows semantic versioning (minor version bump for new feature)
|
|
91
|
-
|
|
92
|
-
### 6. Changelog
|
|
93
|
-
|
|
94
|
-
**File:** `changelog.md`
|
|
95
|
-
|
|
96
|
-
Added comprehensive release notes for version 2.1.0:
|
|
97
|
-
- Feature description
|
|
98
|
-
- API methods
|
|
99
|
-
- Documentation additions
|
|
100
|
-
- Testing coverage
|
|
101
|
-
- Link to full changelog
|
|
102
|
-
|
|
103
|
-
### 7. README Updates
|
|
104
|
-
|
|
105
|
-
**File:** `readme.md`
|
|
106
|
-
|
|
107
|
-
- Added Token Auth to features list (🎫 emoji)
|
|
108
|
-
- Added Token Auth section with quick examples
|
|
109
|
-
- Updated roadmap (marked Token Auth as Done ✅)
|
|
110
|
-
- Added documentation links in Examples & Patterns section
|
|
111
|
-
|
|
112
|
-
### 8. Documentation Index
|
|
113
|
-
|
|
114
|
-
**File:** `docs/readme.md`
|
|
115
|
-
|
|
116
|
-
- Added token_auths.md to Architecture & Design section
|
|
117
|
-
- Added Token Auth Examples to Examples section
|
|
118
|
-
- Added Token Auth to Quick Links with guide, examples, and API reference
|
|
119
|
-
- Updated documentation structure tree
|
|
120
|
-
- Added tips for collecting payment data
|
|
121
|
-
|
|
122
|
-
## API Endpoint
|
|
123
|
-
|
|
124
|
-
**POST** `https://test.api.promisepay.com/token_auths`
|
|
125
|
-
|
|
126
|
-
**Request Body:**
|
|
127
|
-
```json
|
|
128
|
-
{
|
|
129
|
-
"token_type": "bank", // or "card"
|
|
130
|
-
"user_id": "seller-68611249"
|
|
131
|
-
}
|
|
132
|
-
```
|
|
133
|
-
|
|
134
|
-
**Response:**
|
|
135
|
-
```json
|
|
136
|
-
{
|
|
137
|
-
"token_auth": {
|
|
138
|
-
"token": "tok_bank_abc123...",
|
|
139
|
-
"user_id": "seller-68611249",
|
|
140
|
-
"token_type": "bank",
|
|
141
|
-
"created_at": "2025-10-24T12:00:00Z",
|
|
142
|
-
"expires_at": "2025-10-24T13:00:00Z"
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
```
|
|
146
|
-
|
|
147
|
-
## Usage Example
|
|
148
|
-
|
|
149
|
-
```ruby
|
|
150
|
-
# Configure the gem
|
|
151
|
-
ZaiPayment.configure do |c|
|
|
152
|
-
c.environment = :prelive
|
|
153
|
-
c.client_id = ENV['ZAI_CLIENT_ID']
|
|
154
|
-
c.client_secret = ENV['ZAI_CLIENT_SECRET']
|
|
155
|
-
c.scope = ENV['ZAI_OAUTH_SCOPE']
|
|
156
|
-
end
|
|
157
|
-
|
|
158
|
-
# Generate a card token for buyer
|
|
159
|
-
response = ZaiPayment.token_auths.generate(
|
|
160
|
-
user_id: "buyer-12345",
|
|
161
|
-
token_type: "card"
|
|
162
|
-
)
|
|
163
|
-
|
|
164
|
-
token = response.data['token_auth']['token']
|
|
165
|
-
# Send token to frontend for use with PromisePay.js
|
|
166
|
-
```
|
|
167
|
-
|
|
168
|
-
## Integration with PromisePay.js
|
|
169
|
-
|
|
170
|
-
```javascript
|
|
171
|
-
// Frontend (JavaScript)
|
|
172
|
-
PromisePay.setToken(token_from_backend);
|
|
173
|
-
|
|
174
|
-
PromisePay.createCardAccount({
|
|
175
|
-
card_number: '4111111111111111',
|
|
176
|
-
expiry_month: '12',
|
|
177
|
-
expiry_year: '2025',
|
|
178
|
-
cvv: '123'
|
|
179
|
-
}, function(response) {
|
|
180
|
-
if (response.error) {
|
|
181
|
-
console.error('Error:', response.error);
|
|
182
|
-
} else {
|
|
183
|
-
const cardAccountId = response.card_accounts.id;
|
|
184
|
-
// Send cardAccountId back to backend
|
|
185
|
-
}
|
|
186
|
-
});
|
|
187
|
-
```
|
|
188
|
-
|
|
189
|
-
## Test Results
|
|
190
|
-
|
|
191
|
-
- **Total Tests:** 272 examples
|
|
192
|
-
- **Failures:** 0
|
|
193
|
-
- **Line Coverage:** 95.22% (518 / 544)
|
|
194
|
-
- **Branch Coverage:** 80.79% (143 / 177)
|
|
195
|
-
- **RuboCop:** No offenses detected
|
|
196
|
-
|
|
197
|
-
## Files Created
|
|
198
|
-
|
|
199
|
-
1. `lib/zai_payment/resources/token_auth.rb` - Core resource implementation
|
|
200
|
-
2. `spec/zai_payment/resources/token_auth_spec.rb` - Test suite
|
|
201
|
-
3. `examples/token_auths.md` - Comprehensive usage examples
|
|
202
|
-
4. `docs/token_auths.md` - Technical documentation
|
|
203
|
-
|
|
204
|
-
## Files Modified
|
|
205
|
-
|
|
206
|
-
1. `lib/zai_payment.rb` - Added token_auths accessor
|
|
207
|
-
2. `lib/zai_payment/version.rb` - Version bump to 2.1.0
|
|
208
|
-
3. `changelog.md` - Added 2.1.0 release notes
|
|
209
|
-
4. `readme.md` - Added Token Auth documentation
|
|
210
|
-
5. `docs/readme.md` - Updated documentation index
|
|
211
|
-
|
|
212
|
-
## Security Considerations
|
|
213
|
-
|
|
214
|
-
- **PCI Compliance:** Tokens enable PCI-compliant card data collection without sensitive data touching your server
|
|
215
|
-
- **Token Expiration:** Tokens have limited lifespan (typically 1 hour)
|
|
216
|
-
- **Single-use:** Tokens should be generated fresh for each session
|
|
217
|
-
- **User-specific:** Each token is tied to a specific user ID
|
|
218
|
-
- **Type-specific:** Bank tokens only for bank accounts, card tokens only for cards
|
|
219
|
-
- **HTTPS Required:** All communication over secure HTTPS
|
|
220
|
-
|
|
221
|
-
## Next Steps
|
|
222
|
-
|
|
223
|
-
The Token Auth implementation is complete and ready for use. Developers can now:
|
|
224
|
-
|
|
225
|
-
1. Generate tokens for buyers to collect credit card information
|
|
226
|
-
2. Generate tokens for sellers to collect bank account details
|
|
227
|
-
3. Integrate with PromisePay.js for secure frontend data collection
|
|
228
|
-
4. Process payments without handling sensitive payment data directly
|
|
229
|
-
|
|
230
|
-
## Related APIs
|
|
231
|
-
|
|
232
|
-
This implementation complements existing resources:
|
|
233
|
-
- **Users API** - Create users before generating tokens
|
|
234
|
-
- **Items API** - Use payment accounts to create transactions
|
|
235
|
-
- **Webhooks API** - Receive notifications about payment events
|
|
236
|
-
|
|
237
|
-
## Documentation Links
|
|
238
|
-
|
|
239
|
-
- **API Reference:** https://developer.hellozai.com/reference/generatetoken
|
|
240
|
-
- **Examples:** [examples/token_auths.md](examples/token_auths.md)
|
|
241
|
-
- **Guide:** [docs/token_auths.md](docs/token_auths.md)
|
|
242
|
-
- **PromisePay.js:** https://developer.hellozai.com/docs/promisepay-js
|
|
243
|
-
|
|
244
|
-
---
|
|
245
|
-
|
|
246
|
-
**Implementation Date:** October 24, 2025
|
|
247
|
-
**Version:** 2.1.0
|
|
248
|
-
**Status:** ✅ Complete and tested
|
|
249
|
-
|