@talosjs/payment 1.0.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.
- package/LICENSE +21 -0
- package/README.md +240 -0
- package/dist/index.d.ts +562 -0
- package/dist/index.js +843 -0
- package/dist/index.js.map +17 -0
- package/package.json +50 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Talos
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
# @talosjs/payment
|
|
2
|
+
|
|
3
|
+
Payment and pricing type definitions with currency handling, product categorization, and billing metadata for e-commerce integrations.
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+

|
|
7
|
+

|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
✅ **Polar Integration** - Full Polar SDK integration for products, checkouts, customers, discounts, and analytics
|
|
12
|
+
|
|
13
|
+
✅ **Checkout Flow** - Create and retrieve checkout sessions with customer and discount support
|
|
14
|
+
|
|
15
|
+
✅ **Product Management** - Create, update, and archive products with pricing, benefits, and custom fields
|
|
16
|
+
|
|
17
|
+
✅ **Customer Management** - Create, update, list, and delete customers with billing address and metadata
|
|
18
|
+
|
|
19
|
+
✅ **Discount System** - Percentage and fixed discounts with duration, redemption limits, and product scoping
|
|
20
|
+
|
|
21
|
+
✅ **Subscription Support** - Plans, credits, and recurring billing with trial periods
|
|
22
|
+
|
|
23
|
+
✅ **Analytics** - Revenue, order, and subscription analytics with configurable time intervals
|
|
24
|
+
|
|
25
|
+
✅ **Customer Portal** - Create customer portal sessions for self-service account management
|
|
26
|
+
|
|
27
|
+
✅ **Type-Safe** - Comprehensive TypeScript types for all payment entities and API responses
|
|
28
|
+
|
|
29
|
+
## Installation
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
bun add @talosjs/payment
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Usage
|
|
36
|
+
|
|
37
|
+
### Creating a Checkout
|
|
38
|
+
|
|
39
|
+
```typescript
|
|
40
|
+
import { PolarCheckout } from '@talosjs/payment';
|
|
41
|
+
|
|
42
|
+
// Requires POLAR_ACCESS_TOKEN environment variable
|
|
43
|
+
const checkout = new PolarCheckout();
|
|
44
|
+
|
|
45
|
+
const session = await checkout.create({
|
|
46
|
+
products: ['product-id-1'],
|
|
47
|
+
customerEmail: 'user@example.com',
|
|
48
|
+
successUrl: 'https://example.com/success',
|
|
49
|
+
allowDiscountCodes: true,
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
console.log(session.url); // Redirect user to this URL
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Managing Products
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
import { PolarProduct } from '@talosjs/payment';
|
|
59
|
+
|
|
60
|
+
const products = new PolarProduct();
|
|
61
|
+
|
|
62
|
+
// Create a product
|
|
63
|
+
const product = await products.create({
|
|
64
|
+
name: 'Pro Plan',
|
|
65
|
+
description: 'Full access to all features',
|
|
66
|
+
recurringInterval: 'monthly',
|
|
67
|
+
prices: [
|
|
68
|
+
{ type: 'fixed', priceCurrency: 'usd', priceAmount: 2900 },
|
|
69
|
+
],
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
// Update a product
|
|
73
|
+
await products.update('product-id', {
|
|
74
|
+
name: 'Pro Plan (Updated)',
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
// Archive a product
|
|
78
|
+
await products.remove('product-id');
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Customer Management
|
|
82
|
+
|
|
83
|
+
```typescript
|
|
84
|
+
import { PolarCustomer } from '@talosjs/payment';
|
|
85
|
+
|
|
86
|
+
const customers = new PolarCustomer();
|
|
87
|
+
|
|
88
|
+
// Create a customer
|
|
89
|
+
const customer = await customers.create({
|
|
90
|
+
email: 'user@example.com',
|
|
91
|
+
name: 'John Doe',
|
|
92
|
+
metadata: { plan: 'pro' },
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
// List customers
|
|
96
|
+
const result = await customers.list({
|
|
97
|
+
query: 'john',
|
|
98
|
+
limit: 20,
|
|
99
|
+
});
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Managing Discounts
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
import { PolarDiscount } from '@talosjs/payment';
|
|
106
|
+
|
|
107
|
+
const discounts = new PolarDiscount();
|
|
108
|
+
|
|
109
|
+
// Create a percentage discount
|
|
110
|
+
const discount = await discounts.create({
|
|
111
|
+
name: '20% Off',
|
|
112
|
+
code: 'SAVE20',
|
|
113
|
+
type: 'percentage',
|
|
114
|
+
amount: 2000, // basis points (20%)
|
|
115
|
+
duration: 'once',
|
|
116
|
+
});
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### Revenue Analytics
|
|
120
|
+
|
|
121
|
+
```typescript
|
|
122
|
+
import { PolarAnalytics } from '@talosjs/payment';
|
|
123
|
+
|
|
124
|
+
const analytics = new PolarAnalytics();
|
|
125
|
+
|
|
126
|
+
const data = await analytics.get({
|
|
127
|
+
startDate: new Date('2024-01-01'),
|
|
128
|
+
endDate: new Date('2024-12-31'),
|
|
129
|
+
interval: 'month',
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
for (const period of data.periods) {
|
|
133
|
+
console.log(`${period.timestamp}: $${period.revenue / 100}`);
|
|
134
|
+
}
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## API Reference
|
|
138
|
+
|
|
139
|
+
### Classes
|
|
140
|
+
|
|
141
|
+
#### `PolarCheckout`
|
|
142
|
+
|
|
143
|
+
Create and retrieve Polar checkout sessions.
|
|
144
|
+
|
|
145
|
+
**Methods:**
|
|
146
|
+
- `create(data: CheckoutCreateType): Promise<CheckoutType>` - Create a checkout session
|
|
147
|
+
- `get(id: string): Promise<CheckoutType>` - Retrieve a checkout by ID
|
|
148
|
+
|
|
149
|
+
#### `PolarProduct`
|
|
150
|
+
|
|
151
|
+
Manage products via the Polar API.
|
|
152
|
+
|
|
153
|
+
**Methods:**
|
|
154
|
+
- `create(data: IProduct): Promise<Omit<IProduct, 'id'>>` - Create a product
|
|
155
|
+
- `update(id: string, data: Partial<IProduct>): Promise<Omit<IProduct, 'id'>>` - Update a product
|
|
156
|
+
- `remove(id: string): Promise<void>` - Archive a product
|
|
157
|
+
|
|
158
|
+
#### `PolarCustomer`
|
|
159
|
+
|
|
160
|
+
Manage customers via the Polar API.
|
|
161
|
+
|
|
162
|
+
**Methods:**
|
|
163
|
+
- `create(data: CustomerCreateType): Promise<CustomerType>` - Create a customer
|
|
164
|
+
- `update(id: string, data: CustomerUpdateType): Promise<CustomerType>` - Update a customer
|
|
165
|
+
- `get(id: string): Promise<CustomerType>` - Get a customer by ID
|
|
166
|
+
- `list(options?: CustomerListOptionsType): Promise<CustomerListResultType>` - List customers
|
|
167
|
+
- `remove(id: string): Promise<void>` - Delete a customer
|
|
168
|
+
|
|
169
|
+
#### `PolarCustomerPortal`
|
|
170
|
+
|
|
171
|
+
Create customer portal sessions for self-service management.
|
|
172
|
+
|
|
173
|
+
#### `PolarDiscount`
|
|
174
|
+
|
|
175
|
+
Create and manage discounts.
|
|
176
|
+
|
|
177
|
+
#### `PolarAnalytics`
|
|
178
|
+
|
|
179
|
+
Retrieve revenue and order analytics.
|
|
180
|
+
|
|
181
|
+
### Key Types
|
|
182
|
+
|
|
183
|
+
#### `IProduct`
|
|
184
|
+
|
|
185
|
+
Product interface with name, description, prices, benefits, recurring interval, and metadata.
|
|
186
|
+
|
|
187
|
+
#### `CheckoutCreateType`
|
|
188
|
+
|
|
189
|
+
Checkout creation options including products, customer info, discount, and success URL.
|
|
190
|
+
|
|
191
|
+
#### `IDiscount`
|
|
192
|
+
|
|
193
|
+
Discount interface with type (percentage/fixed), duration, amount, and redemption limits.
|
|
194
|
+
|
|
195
|
+
#### `ISubscription`
|
|
196
|
+
|
|
197
|
+
Subscription interface with plans, credits, discounts, and billing dates.
|
|
198
|
+
|
|
199
|
+
### Enums
|
|
200
|
+
|
|
201
|
+
| Enum | Values |
|
|
202
|
+
|------|--------|
|
|
203
|
+
| `EPriceType` | `FIXED`, `CUSTOM`, `FREE` |
|
|
204
|
+
| `EDiscountType` | `PERCENTAGE`, `FIXED` |
|
|
205
|
+
| `EDiscountDuration` | `ONCE`, `REPEATING`, `FOREVER` |
|
|
206
|
+
| `ESubscriptionPeriod` | `MONTHLY`, `YEARLY`, `WEEKLY`, `DAILY` |
|
|
207
|
+
| `EBenefitType` | `CREDITS`, `LICENSE_KEYS`, `FILE_DOWNLOADS`, `GITHUB_REPOSITORY_ACCESS`, `DISCORD_ACCESS`, `CUSTOM` |
|
|
208
|
+
| `ECheckoutStatus` | `OPEN`, `EXPIRED`, `CONFIRMED`, `SUCCEEDED`, `FAILED` |
|
|
209
|
+
| `EAnalyticsInterval` | `YEAR`, `MONTH`, `WEEK`, `DAY`, `HOUR` |
|
|
210
|
+
|
|
211
|
+
## Environment Variables
|
|
212
|
+
|
|
213
|
+
- `POLAR_ACCESS_TOKEN` - Polar API access token (required)
|
|
214
|
+
- `POLAR_ENVIRONMENT` - `"sandbox"` or `"production"` (default: `"production"`)
|
|
215
|
+
|
|
216
|
+
## License
|
|
217
|
+
|
|
218
|
+
This project is licensed under the MIT License - see the [LICENSE](./LICENSE) file for details.
|
|
219
|
+
|
|
220
|
+
## Contributing
|
|
221
|
+
|
|
222
|
+
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
|
|
223
|
+
|
|
224
|
+
### Development Setup
|
|
225
|
+
|
|
226
|
+
1. Clone the repository
|
|
227
|
+
2. Install dependencies: `bun install`
|
|
228
|
+
3. Run tests: `bun run test`
|
|
229
|
+
4. Build the project: `bun run build`
|
|
230
|
+
|
|
231
|
+
### Guidelines
|
|
232
|
+
|
|
233
|
+
- Write tests for new features
|
|
234
|
+
- Follow the existing code style
|
|
235
|
+
- Update documentation for API changes
|
|
236
|
+
- Ensure all tests pass before submitting PR
|
|
237
|
+
|
|
238
|
+
---
|
|
239
|
+
|
|
240
|
+
Made with ❤️ by the Talos team
|