@vulog/aima-billing 1.1.89 → 1.1.92

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.
Files changed (2) hide show
  1. package/README.md +181 -0
  2. package/package.json +3 -3
package/README.md CHANGED
@@ -1 +1,182 @@
1
1
  # @vulog/aima-billing
2
+
3
+ Billing and credit management module for the AIMA platform. This module provides functionality to manage user credits, invoices, and billing operations.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @vulog/aima-client @vulog/aima-core @vulog/aima-billing
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ### Initialize Client
14
+
15
+ ```javascript
16
+ import { getClient } from '@vulog/aima-client';
17
+ import { addCredits, getUserCreditsByEntityId, getInvoiceById, chargeProduct } from '@vulog/aima-billing';
18
+
19
+ const client = getClient({
20
+ apiKey: 'your-api-key',
21
+ baseUrl: 'https://your-api-base-url',
22
+ clientId: 'your-client-id',
23
+ clientSecret: 'your-client-secret',
24
+ fleetId: 'your-fleet-id',
25
+ });
26
+ ```
27
+
28
+ ## API Reference
29
+
30
+ ### addCredits
31
+
32
+ Add credits to a user's account.
33
+
34
+ ```javascript
35
+ const credits = await addCredits(client, {
36
+ initialAmount: 100,
37
+ validityStartDate: '2024-01-01T00:00:00Z',
38
+ validityEndDate: '2024-12-31T23:59:59Z',
39
+ notes: 'Welcome bonus',
40
+ discountCategory: 'CREDITS',
41
+ oneTimeUsage: false,
42
+ entityId: 'user-uuid-here',
43
+ type: 'LOCAL',
44
+ usage: 'ALL'
45
+ });
46
+ ```
47
+
48
+ **Parameters:**
49
+ - `client`: AIMA client instance
50
+ - `payload`: Credit configuration object
51
+ - `initialAmount`: Number of credits to add
52
+ - `validityStartDate`: Start date in ISO format
53
+ - `validityEndDate`: End date in ISO format
54
+ - `notes`: Optional notes
55
+ - `discountCategory`: 'CREDITS' or 'PERCENTAGE'
56
+ - `oneTimeUsage`: Boolean for one-time usage
57
+ - `entityId`: User UUID
58
+ - `type`: 'LOCAL', 'GLOBAL', or 'PERIODIC'
59
+ - `usage`: 'TRIP', 'REGISTRATION', 'PRODUCTS', or 'ALL'
60
+
61
+ ### getUserCreditsByEntityId
62
+
63
+ Retrieve user credits by entity ID.
64
+
65
+ ```javascript
66
+ const userCredits = await getUserCreditsByEntityId(client, 'user-uuid-here');
67
+ ```
68
+
69
+ **Parameters:**
70
+ - `client`: AIMA client instance
71
+ - `entityId`: User UUID
72
+
73
+ ### getInvoiceById
74
+
75
+ Get invoice details by ID.
76
+
77
+ ```javascript
78
+ const invoice = await getInvoiceById(client, 'invoice-id-here');
79
+ ```
80
+
81
+ **Parameters:**
82
+ - `client`: AIMA client instance
83
+ - `invoiceId`: Invoice identifier
84
+
85
+ ### chargeProduct
86
+
87
+ Charge a product to a user.
88
+
89
+ ```javascript
90
+ const charge = await chargeProduct(client, {
91
+ entityId: 'user-uuid-here',
92
+ productId: 'product-id-here',
93
+ amount: 50
94
+ });
95
+ ```
96
+
97
+ **Parameters:**
98
+ - `client`: AIMA client instance
99
+ - `payload`: Charge configuration object
100
+ - `entityId`: User UUID
101
+ - `productId`: Product identifier
102
+ - `amount`: Amount to charge
103
+
104
+ ## Types
105
+
106
+ ### Credit
107
+
108
+ ```typescript
109
+ interface Credit {
110
+ id: string;
111
+ initialAmount: number;
112
+ availableAmount: number;
113
+ usedAmount: number;
114
+ originId: string;
115
+ creditAlreadyUsed: boolean;
116
+ validityStartDate: string;
117
+ validityEndDate: string;
118
+ notes: string | null;
119
+ discountCategory: 'CREDITS' | 'PERCENTAGE';
120
+ oneTimeUsage: boolean;
121
+ entityId: string;
122
+ type: 'LOCAL' | 'GLOBAL' | 'PERIODIC';
123
+ usage: 'TRIP' | 'REGISTRATION' | 'PRODUCTS' | 'ALL';
124
+ updateDate: string;
125
+ }
126
+ ```
127
+
128
+ ## Error Handling
129
+
130
+ All functions include validation using Zod schemas and will throw `TypeError` with detailed error information if validation fails. Network errors are handled by the underlying client.
131
+
132
+ ## Examples
133
+
134
+ ### Complete Billing Workflow
135
+
136
+ ```javascript
137
+ import { getClient } from '@vulog/aima-client';
138
+ import { addCredits, getUserCreditsByEntityId, chargeProduct } from '@vulog/aima-billing';
139
+
140
+ const client = getClient({
141
+ apiKey: 'your-api-key',
142
+ baseUrl: 'https://your-api-base-url',
143
+ clientId: 'your-client-id',
144
+ clientSecret: 'your-client-secret',
145
+ fleetId: 'your-fleet-id',
146
+ });
147
+
148
+ async function billingWorkflow() {
149
+ try {
150
+ // Add credits to user
151
+ const credits = await addCredits(client, {
152
+ initialAmount: 100,
153
+ validityStartDate: '2024-01-01T00:00:00Z',
154
+ validityEndDate: '2024-12-31T23:59:59Z',
155
+ notes: 'Welcome bonus',
156
+ discountCategory: 'CREDITS',
157
+ oneTimeUsage: false,
158
+ entityId: 'user-uuid-here',
159
+ type: 'LOCAL',
160
+ usage: 'ALL'
161
+ });
162
+
163
+ console.log('Credits added:', credits);
164
+
165
+ // Check user credits
166
+ const userCredits = await getUserCreditsByEntityId(client, 'user-uuid-here');
167
+ console.log('User credits:', userCredits);
168
+
169
+ // Charge a product
170
+ const charge = await chargeProduct(client, {
171
+ entityId: 'user-uuid-here',
172
+ productId: 'product-id-here',
173
+ amount: 25
174
+ });
175
+
176
+ console.log('Product charged:', charge);
177
+
178
+ } catch (error) {
179
+ console.error('Billing error:', error);
180
+ }
181
+ }
182
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vulog/aima-billing",
3
- "version": "1.1.89",
3
+ "version": "1.1.92",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.mjs",
6
6
  "types": "dist/index.d.ts",
@@ -19,8 +19,8 @@
19
19
  "author": "Vulog",
20
20
  "license": "MIT",
21
21
  "dependencies": {
22
- "@vulog/aima-client": "1.1.89",
23
- "@vulog/aima-core": "1.1.89"
22
+ "@vulog/aima-client": "1.1.92",
23
+ "@vulog/aima-core": "1.1.92"
24
24
  },
25
25
  "peerDependencies": {
26
26
  "zod": "^3.25.76"