@vulog/aima-payment 1.1.89 → 1.1.91
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/README.md +310 -9
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,20 +1,321 @@
|
|
|
1
|
-
# @vulog/aima-
|
|
1
|
+
# @vulog/aima-payment
|
|
2
|
+
|
|
3
|
+
Payment management module for the AIMA platform. This module provides functionality to handle payments, setup intents, payment methods, and trip payments.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
2
6
|
|
|
3
7
|
```bash
|
|
4
|
-
npm
|
|
8
|
+
npm install @vulog/aima-client @vulog/aima-core @vulog/aima-payment
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
### Initialize Client
|
|
14
|
+
|
|
15
|
+
```javascript
|
|
16
|
+
import { getClient } from '@vulog/aima-client';
|
|
17
|
+
import {
|
|
18
|
+
getSetupIntent,
|
|
19
|
+
getPaymentMethodDetailsForUser,
|
|
20
|
+
getSynchronize,
|
|
21
|
+
payATrip
|
|
22
|
+
} from '@vulog/aima-payment';
|
|
23
|
+
|
|
24
|
+
const client = getClient({
|
|
25
|
+
apiKey: 'your-api-key',
|
|
26
|
+
baseUrl: 'https://your-api-base-url',
|
|
27
|
+
clientId: 'your-client-id',
|
|
28
|
+
clientSecret: 'your-client-secret',
|
|
29
|
+
fleetId: 'your-fleet-id',
|
|
30
|
+
});
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## API Reference
|
|
34
|
+
|
|
35
|
+
### Payment Setup
|
|
36
|
+
|
|
37
|
+
#### getSetupIntent
|
|
38
|
+
|
|
39
|
+
Create a setup intent for payment method configuration.
|
|
40
|
+
|
|
41
|
+
```javascript
|
|
42
|
+
const setupIntent = await getSetupIntent(client, 'user-uuid-here');
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
**Parameters:**
|
|
46
|
+
- `client`: AIMA client instance
|
|
47
|
+
- `entityId`: User UUID
|
|
48
|
+
|
|
49
|
+
**Returns:** Setup intent object for payment method configuration
|
|
50
|
+
|
|
51
|
+
#### getPaymentMethodDetailsForUser
|
|
52
|
+
|
|
53
|
+
Retrieve payment method details for a specific user.
|
|
54
|
+
|
|
55
|
+
```javascript
|
|
56
|
+
const paymentMethods = await getPaymentMethodDetailsForUser(client, 'user-uuid-here');
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
**Parameters:**
|
|
60
|
+
- `client`: AIMA client instance
|
|
61
|
+
- `entityId`: User UUID
|
|
62
|
+
|
|
63
|
+
**Returns:** Array of user's payment methods
|
|
64
|
+
|
|
65
|
+
### Payment Processing
|
|
66
|
+
|
|
67
|
+
#### payATrip
|
|
68
|
+
|
|
69
|
+
Process payment for a trip.
|
|
70
|
+
|
|
71
|
+
```javascript
|
|
72
|
+
const paymentResult = await payATrip(client, {
|
|
73
|
+
tripId: 'trip-uuid-here',
|
|
74
|
+
paymentMethodId: 'payment-method-id-here',
|
|
75
|
+
amount: 25.50,
|
|
76
|
+
currency: 'EUR'
|
|
77
|
+
});
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
**Parameters:**
|
|
81
|
+
- `client`: AIMA client instance
|
|
82
|
+
- `paymentData`: Payment configuration object
|
|
83
|
+
- `tripId`: Trip identifier
|
|
84
|
+
- `paymentMethodId`: Payment method identifier
|
|
85
|
+
- `amount`: Payment amount
|
|
86
|
+
- `currency`: Currency code
|
|
87
|
+
|
|
88
|
+
**Returns:** Payment processing result
|
|
89
|
+
|
|
90
|
+
#### getSynchronize
|
|
91
|
+
|
|
92
|
+
Synchronize payment data.
|
|
93
|
+
|
|
94
|
+
```javascript
|
|
95
|
+
const syncResult = await getSynchronize(client, {
|
|
96
|
+
entityId: 'user-uuid-here',
|
|
97
|
+
lastSyncDate: '2024-01-01T00:00:00Z'
|
|
98
|
+
});
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
**Parameters:**
|
|
102
|
+
- `client`: AIMA client instance
|
|
103
|
+
- `syncData`: Synchronization configuration
|
|
104
|
+
- `entityId`: User UUID
|
|
105
|
+
- `lastSyncDate`: Last synchronization date
|
|
106
|
+
|
|
107
|
+
**Returns:** Synchronization result
|
|
108
|
+
|
|
109
|
+
## Types
|
|
110
|
+
|
|
111
|
+
### SetupIntent
|
|
112
|
+
|
|
113
|
+
```typescript
|
|
114
|
+
interface SetupIntent {
|
|
115
|
+
id: string;
|
|
116
|
+
clientSecret: string;
|
|
117
|
+
status: 'requires_payment_method' | 'requires_confirmation' | 'requires_action' | 'processing' | 'succeeded' | 'canceled';
|
|
118
|
+
paymentMethodTypes: string[];
|
|
119
|
+
createdAt: string;
|
|
120
|
+
updatedAt: string;
|
|
121
|
+
}
|
|
5
122
|
```
|
|
6
123
|
|
|
124
|
+
### PaymentMethod
|
|
125
|
+
|
|
126
|
+
```typescript
|
|
127
|
+
interface PaymentMethod {
|
|
128
|
+
id: string;
|
|
129
|
+
type: 'card' | 'bank_account' | 'sepa_debit';
|
|
130
|
+
card?: {
|
|
131
|
+
brand: string;
|
|
132
|
+
last4: string;
|
|
133
|
+
expMonth: number;
|
|
134
|
+
expYear: number;
|
|
135
|
+
};
|
|
136
|
+
bankAccount?: {
|
|
137
|
+
bankName: string;
|
|
138
|
+
last4: string;
|
|
139
|
+
routingNumber: string;
|
|
140
|
+
};
|
|
141
|
+
isDefault: boolean;
|
|
142
|
+
createdAt: string;
|
|
143
|
+
updatedAt: string;
|
|
144
|
+
}
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### PaymentResult
|
|
148
|
+
|
|
149
|
+
```typescript
|
|
150
|
+
interface PaymentResult {
|
|
151
|
+
id: string;
|
|
152
|
+
status: 'succeeded' | 'failed' | 'pending' | 'canceled';
|
|
153
|
+
amount: number;
|
|
154
|
+
currency: string;
|
|
155
|
+
paymentMethodId: string;
|
|
156
|
+
tripId: string;
|
|
157
|
+
errorMessage?: string;
|
|
158
|
+
createdAt: string;
|
|
159
|
+
}
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
## Error Handling
|
|
163
|
+
|
|
164
|
+
All functions include validation and will throw appropriate errors if:
|
|
165
|
+
- Required parameters are missing
|
|
166
|
+
- Invalid user or trip IDs are provided
|
|
167
|
+
- Payment processing fails
|
|
168
|
+
- Network errors occur
|
|
169
|
+
|
|
170
|
+
## Examples
|
|
171
|
+
|
|
172
|
+
### Complete Payment Workflow
|
|
173
|
+
|
|
7
174
|
```javascript
|
|
8
175
|
import { getClient } from '@vulog/aima-client';
|
|
9
|
-
import {
|
|
176
|
+
import {
|
|
177
|
+
getSetupIntent,
|
|
178
|
+
getPaymentMethodDetailsForUser,
|
|
179
|
+
payATrip
|
|
180
|
+
} from '@vulog/aima-payment';
|
|
10
181
|
|
|
11
182
|
const client = getClient({
|
|
12
|
-
apiKey: '
|
|
13
|
-
baseUrl: '
|
|
14
|
-
clientId: '
|
|
15
|
-
clientSecret: '
|
|
16
|
-
fleetId: '
|
|
183
|
+
apiKey: 'your-api-key',
|
|
184
|
+
baseUrl: 'https://your-api-base-url',
|
|
185
|
+
clientId: 'your-client-id',
|
|
186
|
+
clientSecret: 'your-client-secret',
|
|
187
|
+
fleetId: 'your-fleet-id',
|
|
17
188
|
});
|
|
18
189
|
|
|
19
|
-
|
|
190
|
+
async function paymentWorkflow() {
|
|
191
|
+
try {
|
|
192
|
+
const userId = 'user-uuid-here';
|
|
193
|
+
|
|
194
|
+
// Create setup intent for new payment method
|
|
195
|
+
const setupIntent = await getSetupIntent(client, userId);
|
|
196
|
+
console.log('Setup intent created:', setupIntent);
|
|
197
|
+
|
|
198
|
+
// Get user's existing payment methods
|
|
199
|
+
const paymentMethods = await getPaymentMethodDetailsForUser(client, userId);
|
|
200
|
+
console.log(`User has ${paymentMethods.length} payment methods`);
|
|
201
|
+
|
|
202
|
+
// Process trip payment
|
|
203
|
+
const paymentResult = await payATrip(client, {
|
|
204
|
+
tripId: 'trip-uuid-here',
|
|
205
|
+
paymentMethodId: paymentMethods[0].id,
|
|
206
|
+
amount: 25.50,
|
|
207
|
+
currency: 'EUR'
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
console.log('Payment processed:', paymentResult);
|
|
211
|
+
|
|
212
|
+
return { setupIntent, paymentMethods, paymentResult };
|
|
213
|
+
} catch (error) {
|
|
214
|
+
console.error('Payment workflow error:', error);
|
|
215
|
+
throw error;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
### Payment Method Management
|
|
221
|
+
|
|
222
|
+
```javascript
|
|
223
|
+
async function managePaymentMethods(client, userId) {
|
|
224
|
+
try {
|
|
225
|
+
const paymentMethods = await getPaymentMethodDetailsForUser(client, userId);
|
|
226
|
+
|
|
227
|
+
const analysis = {
|
|
228
|
+
totalMethods: paymentMethods.length,
|
|
229
|
+
defaultMethod: paymentMethods.find(pm => pm.isDefault),
|
|
230
|
+
cardMethods: paymentMethods.filter(pm => pm.type === 'card'),
|
|
231
|
+
bankMethods: paymentMethods.filter(pm => pm.type === 'bank_account'),
|
|
232
|
+
sepaMethods: paymentMethods.filter(pm => pm.type === 'sepa_debit')
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
console.log('Payment Method Analysis:');
|
|
236
|
+
console.log(`Total Methods: ${analysis.totalMethods}`);
|
|
237
|
+
console.log(`Default Method: ${analysis.defaultMethod?.id || 'None'}`);
|
|
238
|
+
console.log(`Card Methods: ${analysis.cardMethods.length}`);
|
|
239
|
+
console.log(`Bank Methods: ${analysis.bankMethods.length}`);
|
|
240
|
+
console.log(`SEPA Methods: ${analysis.sepaMethods.length}`);
|
|
241
|
+
|
|
242
|
+
return analysis;
|
|
243
|
+
} catch (error) {
|
|
244
|
+
console.error('Payment method management error:', error);
|
|
245
|
+
throw error;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
### Trip Payment Processing
|
|
251
|
+
|
|
252
|
+
```javascript
|
|
253
|
+
async function processTripPayment(client, tripId, userId, amount, currency = 'EUR') {
|
|
254
|
+
try {
|
|
255
|
+
// Get user's payment methods
|
|
256
|
+
const paymentMethods = await getPaymentMethodDetailsForUser(client, userId);
|
|
257
|
+
|
|
258
|
+
if (paymentMethods.length === 0) {
|
|
259
|
+
throw new Error('No payment methods found for user');
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// Use default payment method or first available
|
|
263
|
+
const paymentMethod = paymentMethods.find(pm => pm.isDefault) || paymentMethods[0];
|
|
264
|
+
|
|
265
|
+
// Process payment
|
|
266
|
+
const paymentResult = await payATrip(client, {
|
|
267
|
+
tripId,
|
|
268
|
+
paymentMethodId: paymentMethod.id,
|
|
269
|
+
amount,
|
|
270
|
+
currency
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
if (paymentResult.status === 'succeeded') {
|
|
274
|
+
console.log(`Payment successful: ${amount} ${currency} for trip ${tripId}`);
|
|
275
|
+
} else {
|
|
276
|
+
console.log(`Payment failed: ${paymentResult.errorMessage}`);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
return paymentResult;
|
|
280
|
+
} catch (error) {
|
|
281
|
+
console.error('Trip payment processing error:', error);
|
|
282
|
+
throw error;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
### Payment History and Analytics
|
|
288
|
+
|
|
289
|
+
```javascript
|
|
290
|
+
async function analyzePayments(client, userId) {
|
|
291
|
+
try {
|
|
292
|
+
// This would require additional API endpoints for payment history
|
|
293
|
+
// For now, we'll demonstrate with payment methods
|
|
294
|
+
const paymentMethods = await getPaymentMethodDetailsForUser(client, userId);
|
|
295
|
+
|
|
296
|
+
const analysis = {
|
|
297
|
+
userPaymentMethods: paymentMethods.length,
|
|
298
|
+
hasDefaultMethod: paymentMethods.some(pm => pm.isDefault),
|
|
299
|
+
supportedTypes: [...new Set(paymentMethods.map(pm => pm.type))],
|
|
300
|
+
cardBrands: paymentMethods
|
|
301
|
+
.filter(pm => pm.card)
|
|
302
|
+
.map(pm => pm.card.brand),
|
|
303
|
+
recentMethods: paymentMethods
|
|
304
|
+
.sort((a, b) => new Date(b.createdAt) - new Date(a.createdAt))
|
|
305
|
+
.slice(0, 3)
|
|
306
|
+
};
|
|
307
|
+
|
|
308
|
+
console.log('Payment Analysis:');
|
|
309
|
+
console.log(`Payment Methods: ${analysis.userPaymentMethods}`);
|
|
310
|
+
console.log(`Has Default: ${analysis.hasDefaultMethod}`);
|
|
311
|
+
console.log(`Supported Types: ${analysis.supportedTypes.join(', ')}`);
|
|
312
|
+
console.log(`Card Brands: ${analysis.cardBrands.join(', ')}`);
|
|
313
|
+
console.log('Recent Methods:', analysis.recentMethods);
|
|
314
|
+
|
|
315
|
+
return analysis;
|
|
316
|
+
} catch (error) {
|
|
317
|
+
console.error('Payment analysis error:', error);
|
|
318
|
+
throw error;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
20
321
|
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vulog/aima-payment",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.91",
|
|
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.
|
|
23
|
-
"@vulog/aima-core": "1.1.
|
|
22
|
+
"@vulog/aima-client": "1.1.91",
|
|
23
|
+
"@vulog/aima-core": "1.1.91"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
26
|
"zod": "^3.25.76"
|