@vulog/aima-payment 1.2.30 → 1.2.32
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/dist/index.cjs +85 -0
- package/dist/index.d.cts +198 -0
- package/dist/index.d.mts +165 -164
- package/dist/index.mjs +73 -99
- package/package.json +20 -7
- package/src/getPaymentMethodDetailsForUser.test.ts +8 -14
- package/{tsup.config.ts → tsdown.config.ts} +1 -1
- package/dist/index.d.ts +0 -197
- package/dist/index.js +0 -137
- /package/{.eslintrc.js → .eslintrc.cjs} +0 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let zod = require("zod");
|
|
3
|
+
//#region src/getPaymentMethodDetailsForUser.ts
|
|
4
|
+
const getPaymentMethodDetailsForUser = async (client, id) => {
|
|
5
|
+
const result = zod.z.string().trim().min(1).uuid().safeParse(id);
|
|
6
|
+
if (!result.success) throw new TypeError("Invalid id", { cause: result.error.issues });
|
|
7
|
+
return client.get(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/users/${id}/paymentMethodDetails`).then(({ data }) => data.find((paymentDetail) => paymentDetail.profileType === "Single"));
|
|
8
|
+
};
|
|
9
|
+
//#endregion
|
|
10
|
+
//#region src/getSetupIntent.ts
|
|
11
|
+
const browserInfosSchema = zod.z.object({
|
|
12
|
+
origin: zod.z.string().url(),
|
|
13
|
+
userAgent: zod.z.string(),
|
|
14
|
+
screenHeight: zod.z.number(),
|
|
15
|
+
screenWidth: zod.z.number(),
|
|
16
|
+
colorDepth: zod.z.number()
|
|
17
|
+
});
|
|
18
|
+
const getSetupIntent = async (client, userId, entityId, returnURL, browserInfos) => {
|
|
19
|
+
const resultUserId = zod.z.string().trim().min(1).safeParse(userId);
|
|
20
|
+
if (!resultUserId.success) throw new TypeError("Invalid userId", { cause: resultUserId.error.issues });
|
|
21
|
+
const resultEntityId = zod.z.string().trim().min(1).safeParse(entityId);
|
|
22
|
+
if (!resultEntityId.success) throw new TypeError("Invalid entityId", { cause: resultEntityId.error.issues });
|
|
23
|
+
const resultBrowserInfos = browserInfosSchema.safeParse(browserInfos);
|
|
24
|
+
if (!resultBrowserInfos.success) throw new TypeError("Invalid browser infos", { cause: resultBrowserInfos.error.issues });
|
|
25
|
+
return client.post(`boapi/proxy/user/fleets/${client.clientOptions.fleetId}/users/${userId}/entities/${entityId}/setup_intents`, {
|
|
26
|
+
paymentMethodType: "CREDIT_CARD",
|
|
27
|
+
returnURL,
|
|
28
|
+
paymentMethod: { browserInfo: { ...resultBrowserInfos.data } }
|
|
29
|
+
}).then(({ data }) => data);
|
|
30
|
+
};
|
|
31
|
+
//#endregion
|
|
32
|
+
//#region src/getSynchronize.ts
|
|
33
|
+
const schema$1 = zod.z.object({
|
|
34
|
+
userId: zod.z.string().trim().uuid(),
|
|
35
|
+
entityId: zod.z.string().trim().uuid(),
|
|
36
|
+
setupIntent: zod.z.string().trim().min(1)
|
|
37
|
+
});
|
|
38
|
+
const getSynchronize = async (client, userId, entityId, setupIntent) => {
|
|
39
|
+
const result = schema$1.safeParse({
|
|
40
|
+
userId,
|
|
41
|
+
entityId,
|
|
42
|
+
setupIntent
|
|
43
|
+
});
|
|
44
|
+
if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
|
|
45
|
+
return client.post(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/users/${userId}/entities/${entityId}/setup_intents/${setupIntent}/synchronize`, {}).then(({ data }) => data);
|
|
46
|
+
};
|
|
47
|
+
//#endregion
|
|
48
|
+
//#region src/payATrip.ts
|
|
49
|
+
/**
|
|
50
|
+
* Pay for a trip by its ID.
|
|
51
|
+
*
|
|
52
|
+
* @param client - The Aima client instance.
|
|
53
|
+
* @param tripId - The ID of the trip to pay for.
|
|
54
|
+
* @returns A promise that resolves when the payment is successful.
|
|
55
|
+
* @throws TypeError if the parameters are invalid.
|
|
56
|
+
*/
|
|
57
|
+
const schema = zod.z.object({
|
|
58
|
+
tripId: zod.z.string().nonempty(),
|
|
59
|
+
body: zod.z.object({
|
|
60
|
+
online: zod.z.boolean().optional(),
|
|
61
|
+
scope: zod.z.enum(["RENTAL", "DEPOSIT"]).optional(),
|
|
62
|
+
amountType: zod.z.enum(["FIXED", "PERCENTAGE"]).optional(),
|
|
63
|
+
amountValue: zod.z.number().nonnegative(),
|
|
64
|
+
useSystemCredit: zod.z.boolean().optional()
|
|
65
|
+
})
|
|
66
|
+
});
|
|
67
|
+
const payATrip = async (client, tripId, body) => {
|
|
68
|
+
const validated = schema.safeParse({
|
|
69
|
+
tripId,
|
|
70
|
+
body
|
|
71
|
+
});
|
|
72
|
+
if (!validated.success) throw new TypeError("Invalid parameters", { cause: validated.error.issues });
|
|
73
|
+
return client.post(`/boapi/proxy/trip/fleets/${client.clientOptions.fleetId}/trips/${tripId}/pay`, {
|
|
74
|
+
online: body.online ?? false,
|
|
75
|
+
scope: body.scope ?? "RENTAL",
|
|
76
|
+
amountType: body.amountType ?? "FIXED",
|
|
77
|
+
amountValue: body.amountValue,
|
|
78
|
+
useSystemCredit: body.useSystemCredit ?? true
|
|
79
|
+
}).then(({ data }) => data);
|
|
80
|
+
};
|
|
81
|
+
//#endregion
|
|
82
|
+
exports.getPaymentMethodDetailsForUser = getPaymentMethodDetailsForUser;
|
|
83
|
+
exports.getSetupIntent = getSetupIntent;
|
|
84
|
+
exports.getSynchronize = getSynchronize;
|
|
85
|
+
exports.payATrip = payATrip;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { Client } from "@vulog/aima-client";
|
|
2
|
+
import { UUID } from "crypto";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
|
|
5
|
+
//#region src/types.d.ts
|
|
6
|
+
type SetupIntent = {
|
|
7
|
+
id: string;
|
|
8
|
+
pspPublishableKey: string;
|
|
9
|
+
pspCustomerReference: string;
|
|
10
|
+
pspName: string;
|
|
11
|
+
pspReference: string;
|
|
12
|
+
pspClientSecret: string;
|
|
13
|
+
date: string;
|
|
14
|
+
[key: string]: any;
|
|
15
|
+
};
|
|
16
|
+
type BrowserInfos = {
|
|
17
|
+
origin: string;
|
|
18
|
+
userAgent: string;
|
|
19
|
+
screenHeight: number;
|
|
20
|
+
screenWidth: number;
|
|
21
|
+
colorDepth: number;
|
|
22
|
+
};
|
|
23
|
+
type PaymentDetail = {
|
|
24
|
+
token: string;
|
|
25
|
+
holderName: string;
|
|
26
|
+
fleetId: string;
|
|
27
|
+
entityId: string;
|
|
28
|
+
pspName: string;
|
|
29
|
+
customerPspReference: string;
|
|
30
|
+
entityStatus: string;
|
|
31
|
+
profileId: string;
|
|
32
|
+
profileName: string;
|
|
33
|
+
profileType: 'Single' | 'Business';
|
|
34
|
+
paymentMethod: 'SEPA' | 'IDEAL' | 'PAYPAL' | 'CREDIT_CARD' | 'WIRE_TRANSFER' | 'EXTERNAL';
|
|
35
|
+
mopStatus: 'MOP_VALID' | 'MOP_MISSING' | 'MOP_EXPIRED' | 'MOP_INVALID' | 'MOP_UPDATING' | 'MOP_UPDATE_FAILED' | 'MOP_UNKNOWN';
|
|
36
|
+
paymentCurrency: string;
|
|
37
|
+
cardFunding: 'credit' | 'debit' | 'prepaid' | 'unknown';
|
|
38
|
+
} & ({
|
|
39
|
+
paymentType: 'CARD';
|
|
40
|
+
cardSummary?: string;
|
|
41
|
+
cardType?: string;
|
|
42
|
+
expiryDate?: number;
|
|
43
|
+
expiryMonth?: string;
|
|
44
|
+
expiryYear?: string;
|
|
45
|
+
} | {
|
|
46
|
+
paymentType: 'SEPA';
|
|
47
|
+
bankCode: string;
|
|
48
|
+
branchCode: string;
|
|
49
|
+
country: string;
|
|
50
|
+
fingerprint: string;
|
|
51
|
+
last4: string;
|
|
52
|
+
} | {
|
|
53
|
+
paymentType: 'BANK';
|
|
54
|
+
bankName: string;
|
|
55
|
+
bankAccountNumber: string;
|
|
56
|
+
iban: string;
|
|
57
|
+
bic: string;
|
|
58
|
+
} | {
|
|
59
|
+
paymentType: 'PAYPAL';
|
|
60
|
+
} | {
|
|
61
|
+
paymentType: 'EXTERNAL';
|
|
62
|
+
});
|
|
63
|
+
type SynchronizeResponse = {
|
|
64
|
+
status: 'SUCCEEDED' | 'REQUIRES_CAPTURE' | 'FAILED';
|
|
65
|
+
};
|
|
66
|
+
type TripPayment = {
|
|
67
|
+
paymentIntents: [{
|
|
68
|
+
id: string;
|
|
69
|
+
pspName: 'STRIPE' | 'ADYEN';
|
|
70
|
+
pspReference: string;
|
|
71
|
+
pspPublishableKey: string;
|
|
72
|
+
amount: number;
|
|
73
|
+
currency: string;
|
|
74
|
+
date: string;
|
|
75
|
+
status: string;
|
|
76
|
+
paymentMethodType: string;
|
|
77
|
+
paymentMethodPspReference: string;
|
|
78
|
+
paymentIntentPspReference: string;
|
|
79
|
+
number: number;
|
|
80
|
+
code: string;
|
|
81
|
+
declineCode: string;
|
|
82
|
+
pspClientSecret: string;
|
|
83
|
+
reason: string;
|
|
84
|
+
note: string;
|
|
85
|
+
nextAction: {
|
|
86
|
+
nextActionRedirectUrl: {
|
|
87
|
+
url: string;
|
|
88
|
+
method: string;
|
|
89
|
+
data: {
|
|
90
|
+
[key: string]: any;
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
type: string;
|
|
94
|
+
};
|
|
95
|
+
metadatas: {
|
|
96
|
+
[key: string]: any;
|
|
97
|
+
};
|
|
98
|
+
}];
|
|
99
|
+
paymentReceipts: [{
|
|
100
|
+
id: string;
|
|
101
|
+
pspName: string;
|
|
102
|
+
pspReference: string;
|
|
103
|
+
pspPublishableKey: string;
|
|
104
|
+
amount: number;
|
|
105
|
+
currency: string;
|
|
106
|
+
date: string;
|
|
107
|
+
status: string;
|
|
108
|
+
paymentMethodType: string;
|
|
109
|
+
paymentMethodPspReference: string;
|
|
110
|
+
paymentIntentPspReference: string;
|
|
111
|
+
number: number;
|
|
112
|
+
code: string;
|
|
113
|
+
declineCode: string;
|
|
114
|
+
pspClientSecret: string;
|
|
115
|
+
reason: string;
|
|
116
|
+
note: string;
|
|
117
|
+
nextAction: {
|
|
118
|
+
nextActionRedirectUrl: {
|
|
119
|
+
url: string;
|
|
120
|
+
method: string;
|
|
121
|
+
data: {
|
|
122
|
+
[key: string]: any;
|
|
123
|
+
};
|
|
124
|
+
};
|
|
125
|
+
type: string;
|
|
126
|
+
};
|
|
127
|
+
metadatas: {
|
|
128
|
+
[key: string]: any;
|
|
129
|
+
};
|
|
130
|
+
}];
|
|
131
|
+
id: string;
|
|
132
|
+
fleetId: string;
|
|
133
|
+
profileId: string;
|
|
134
|
+
vehicleId: string;
|
|
135
|
+
serviceId: string;
|
|
136
|
+
};
|
|
137
|
+
//#endregion
|
|
138
|
+
//#region src/getPaymentMethodDetailsForUser.d.ts
|
|
139
|
+
declare const getPaymentMethodDetailsForUser: (client: Client, id: string) => Promise<PaymentDetail | undefined>;
|
|
140
|
+
//#endregion
|
|
141
|
+
//#region src/getSetupIntent.d.ts
|
|
142
|
+
declare const getSetupIntent: (client: Client, userId: UUID, entityId: UUID, returnURL: string, browserInfos: BrowserInfos) => Promise<SetupIntent>;
|
|
143
|
+
//#endregion
|
|
144
|
+
//#region src/getSynchronize.d.ts
|
|
145
|
+
declare const getSynchronize: (client: Client, userId: string, entityId: string, setupIntent: string) => Promise<SynchronizeResponse | undefined>;
|
|
146
|
+
//#endregion
|
|
147
|
+
//#region src/payATrip.d.ts
|
|
148
|
+
/**
|
|
149
|
+
* Pay for a trip by its ID.
|
|
150
|
+
*
|
|
151
|
+
* @param client - The Aima client instance.
|
|
152
|
+
* @param tripId - The ID of the trip to pay for.
|
|
153
|
+
* @returns A promise that resolves when the payment is successful.
|
|
154
|
+
* @throws TypeError if the parameters are invalid.
|
|
155
|
+
*/
|
|
156
|
+
declare const schema: z.ZodObject<{
|
|
157
|
+
tripId: z.ZodString;
|
|
158
|
+
body: z.ZodObject<{
|
|
159
|
+
online: z.ZodOptional<z.ZodBoolean>;
|
|
160
|
+
scope: z.ZodOptional<z.ZodEnum<["RENTAL", "DEPOSIT"]>>;
|
|
161
|
+
amountType: z.ZodOptional<z.ZodEnum<["FIXED", "PERCENTAGE"]>>;
|
|
162
|
+
amountValue: z.ZodNumber;
|
|
163
|
+
useSystemCredit: z.ZodOptional<z.ZodBoolean>;
|
|
164
|
+
}, "strip", z.ZodTypeAny, {
|
|
165
|
+
amountValue: number;
|
|
166
|
+
online?: boolean | undefined;
|
|
167
|
+
scope?: "RENTAL" | "DEPOSIT" | undefined;
|
|
168
|
+
amountType?: "FIXED" | "PERCENTAGE" | undefined;
|
|
169
|
+
useSystemCredit?: boolean | undefined;
|
|
170
|
+
}, {
|
|
171
|
+
amountValue: number;
|
|
172
|
+
online?: boolean | undefined;
|
|
173
|
+
scope?: "RENTAL" | "DEPOSIT" | undefined;
|
|
174
|
+
amountType?: "FIXED" | "PERCENTAGE" | undefined;
|
|
175
|
+
useSystemCredit?: boolean | undefined;
|
|
176
|
+
}>;
|
|
177
|
+
}, "strip", z.ZodTypeAny, {
|
|
178
|
+
tripId: string;
|
|
179
|
+
body: {
|
|
180
|
+
amountValue: number;
|
|
181
|
+
online?: boolean | undefined;
|
|
182
|
+
scope?: "RENTAL" | "DEPOSIT" | undefined;
|
|
183
|
+
amountType?: "FIXED" | "PERCENTAGE" | undefined;
|
|
184
|
+
useSystemCredit?: boolean | undefined;
|
|
185
|
+
};
|
|
186
|
+
}, {
|
|
187
|
+
tripId: string;
|
|
188
|
+
body: {
|
|
189
|
+
amountValue: number;
|
|
190
|
+
online?: boolean | undefined;
|
|
191
|
+
scope?: "RENTAL" | "DEPOSIT" | undefined;
|
|
192
|
+
amountType?: "FIXED" | "PERCENTAGE" | undefined;
|
|
193
|
+
useSystemCredit?: boolean | undefined;
|
|
194
|
+
};
|
|
195
|
+
}>;
|
|
196
|
+
declare const payATrip: (client: Client, tripId: string, body: z.infer<typeof schema>["body"]) => Promise<TripPayment>;
|
|
197
|
+
//#endregion
|
|
198
|
+
export { BrowserInfos, PaymentDetail, SetupIntent, SynchronizeResponse, TripPayment, getPaymentMethodDetailsForUser, getSetupIntent, getSynchronize, payATrip };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,149 +1,150 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { Client } from "@vulog/aima-client";
|
|
3
|
+
import { UUID } from "crypto";
|
|
4
4
|
|
|
5
|
+
//#region src/types.d.ts
|
|
5
6
|
type SetupIntent = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
id: string;
|
|
8
|
+
pspPublishableKey: string;
|
|
9
|
+
pspCustomerReference: string;
|
|
10
|
+
pspName: string;
|
|
11
|
+
pspReference: string;
|
|
12
|
+
pspClientSecret: string;
|
|
13
|
+
date: string;
|
|
14
|
+
[key: string]: any;
|
|
14
15
|
};
|
|
15
16
|
type BrowserInfos = {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
origin: string;
|
|
18
|
+
userAgent: string;
|
|
19
|
+
screenHeight: number;
|
|
20
|
+
screenWidth: number;
|
|
21
|
+
colorDepth: number;
|
|
21
22
|
};
|
|
22
23
|
type PaymentDetail = {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
24
|
+
token: string;
|
|
25
|
+
holderName: string;
|
|
26
|
+
fleetId: string;
|
|
27
|
+
entityId: string;
|
|
28
|
+
pspName: string;
|
|
29
|
+
customerPspReference: string;
|
|
30
|
+
entityStatus: string;
|
|
31
|
+
profileId: string;
|
|
32
|
+
profileName: string;
|
|
33
|
+
profileType: 'Single' | 'Business';
|
|
34
|
+
paymentMethod: 'SEPA' | 'IDEAL' | 'PAYPAL' | 'CREDIT_CARD' | 'WIRE_TRANSFER' | 'EXTERNAL';
|
|
35
|
+
mopStatus: 'MOP_VALID' | 'MOP_MISSING' | 'MOP_EXPIRED' | 'MOP_INVALID' | 'MOP_UPDATING' | 'MOP_UPDATE_FAILED' | 'MOP_UNKNOWN';
|
|
36
|
+
paymentCurrency: string;
|
|
37
|
+
cardFunding: 'credit' | 'debit' | 'prepaid' | 'unknown';
|
|
37
38
|
} & ({
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
paymentType: 'CARD';
|
|
40
|
+
cardSummary?: string;
|
|
41
|
+
cardType?: string;
|
|
42
|
+
expiryDate?: number;
|
|
43
|
+
expiryMonth?: string;
|
|
44
|
+
expiryYear?: string;
|
|
44
45
|
} | {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
46
|
+
paymentType: 'SEPA';
|
|
47
|
+
bankCode: string;
|
|
48
|
+
branchCode: string;
|
|
49
|
+
country: string;
|
|
50
|
+
fingerprint: string;
|
|
51
|
+
last4: string;
|
|
51
52
|
} | {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
53
|
+
paymentType: 'BANK';
|
|
54
|
+
bankName: string;
|
|
55
|
+
bankAccountNumber: string;
|
|
56
|
+
iban: string;
|
|
57
|
+
bic: string;
|
|
57
58
|
} | {
|
|
58
|
-
|
|
59
|
+
paymentType: 'PAYPAL';
|
|
59
60
|
} | {
|
|
60
|
-
|
|
61
|
+
paymentType: 'EXTERNAL';
|
|
61
62
|
});
|
|
62
63
|
type SynchronizeResponse = {
|
|
63
|
-
|
|
64
|
+
status: 'SUCCEEDED' | 'REQUIRES_CAPTURE' | 'FAILED';
|
|
64
65
|
};
|
|
65
66
|
type TripPayment = {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
];
|
|
100
|
-
paymentReceipts: [
|
|
101
|
-
{
|
|
102
|
-
id: string;
|
|
103
|
-
pspName: string;
|
|
104
|
-
pspReference: string;
|
|
105
|
-
pspPublishableKey: string;
|
|
106
|
-
amount: number;
|
|
107
|
-
currency: string;
|
|
108
|
-
date: string;
|
|
109
|
-
status: string;
|
|
110
|
-
paymentMethodType: string;
|
|
111
|
-
paymentMethodPspReference: string;
|
|
112
|
-
paymentIntentPspReference: string;
|
|
113
|
-
number: number;
|
|
114
|
-
code: string;
|
|
115
|
-
declineCode: string;
|
|
116
|
-
pspClientSecret: string;
|
|
117
|
-
reason: string;
|
|
118
|
-
note: string;
|
|
119
|
-
nextAction: {
|
|
120
|
-
nextActionRedirectUrl: {
|
|
121
|
-
url: string;
|
|
122
|
-
method: string;
|
|
123
|
-
data: {
|
|
124
|
-
[key: string]: any;
|
|
125
|
-
};
|
|
126
|
-
};
|
|
127
|
-
type: string;
|
|
128
|
-
};
|
|
129
|
-
metadatas: {
|
|
130
|
-
[key: string]: any;
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
];
|
|
67
|
+
paymentIntents: [{
|
|
68
|
+
id: string;
|
|
69
|
+
pspName: 'STRIPE' | 'ADYEN';
|
|
70
|
+
pspReference: string;
|
|
71
|
+
pspPublishableKey: string;
|
|
72
|
+
amount: number;
|
|
73
|
+
currency: string;
|
|
74
|
+
date: string;
|
|
75
|
+
status: string;
|
|
76
|
+
paymentMethodType: string;
|
|
77
|
+
paymentMethodPspReference: string;
|
|
78
|
+
paymentIntentPspReference: string;
|
|
79
|
+
number: number;
|
|
80
|
+
code: string;
|
|
81
|
+
declineCode: string;
|
|
82
|
+
pspClientSecret: string;
|
|
83
|
+
reason: string;
|
|
84
|
+
note: string;
|
|
85
|
+
nextAction: {
|
|
86
|
+
nextActionRedirectUrl: {
|
|
87
|
+
url: string;
|
|
88
|
+
method: string;
|
|
89
|
+
data: {
|
|
90
|
+
[key: string]: any;
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
type: string;
|
|
94
|
+
};
|
|
95
|
+
metadatas: {
|
|
96
|
+
[key: string]: any;
|
|
97
|
+
};
|
|
98
|
+
}];
|
|
99
|
+
paymentReceipts: [{
|
|
134
100
|
id: string;
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
101
|
+
pspName: string;
|
|
102
|
+
pspReference: string;
|
|
103
|
+
pspPublishableKey: string;
|
|
104
|
+
amount: number;
|
|
105
|
+
currency: string;
|
|
106
|
+
date: string;
|
|
107
|
+
status: string;
|
|
108
|
+
paymentMethodType: string;
|
|
109
|
+
paymentMethodPspReference: string;
|
|
110
|
+
paymentIntentPspReference: string;
|
|
111
|
+
number: number;
|
|
112
|
+
code: string;
|
|
113
|
+
declineCode: string;
|
|
114
|
+
pspClientSecret: string;
|
|
115
|
+
reason: string;
|
|
116
|
+
note: string;
|
|
117
|
+
nextAction: {
|
|
118
|
+
nextActionRedirectUrl: {
|
|
119
|
+
url: string;
|
|
120
|
+
method: string;
|
|
121
|
+
data: {
|
|
122
|
+
[key: string]: any;
|
|
123
|
+
};
|
|
124
|
+
};
|
|
125
|
+
type: string;
|
|
126
|
+
};
|
|
127
|
+
metadatas: {
|
|
128
|
+
[key: string]: any;
|
|
129
|
+
};
|
|
130
|
+
}];
|
|
131
|
+
id: string;
|
|
132
|
+
fleetId: string;
|
|
133
|
+
profileId: string;
|
|
134
|
+
vehicleId: string;
|
|
135
|
+
serviceId: string;
|
|
139
136
|
};
|
|
140
|
-
|
|
137
|
+
//#endregion
|
|
138
|
+
//#region src/getPaymentMethodDetailsForUser.d.ts
|
|
141
139
|
declare const getPaymentMethodDetailsForUser: (client: Client, id: string) => Promise<PaymentDetail | undefined>;
|
|
142
|
-
|
|
140
|
+
//#endregion
|
|
141
|
+
//#region src/getSetupIntent.d.ts
|
|
143
142
|
declare const getSetupIntent: (client: Client, userId: UUID, entityId: UUID, returnURL: string, browserInfos: BrowserInfos) => Promise<SetupIntent>;
|
|
144
|
-
|
|
143
|
+
//#endregion
|
|
144
|
+
//#region src/getSynchronize.d.ts
|
|
145
145
|
declare const getSynchronize: (client: Client, userId: string, entityId: string, setupIntent: string) => Promise<SynchronizeResponse | undefined>;
|
|
146
|
-
|
|
146
|
+
//#endregion
|
|
147
|
+
//#region src/payATrip.d.ts
|
|
147
148
|
/**
|
|
148
149
|
* Pay for a trip by its ID.
|
|
149
150
|
*
|
|
@@ -153,45 +154,45 @@ declare const getSynchronize: (client: Client, userId: string, entityId: string,
|
|
|
153
154
|
* @throws TypeError if the parameters are invalid.
|
|
154
155
|
*/
|
|
155
156
|
declare const schema: z.ZodObject<{
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
157
|
+
tripId: z.ZodString;
|
|
158
|
+
body: z.ZodObject<{
|
|
159
|
+
online: z.ZodOptional<z.ZodBoolean>;
|
|
160
|
+
scope: z.ZodOptional<z.ZodEnum<["RENTAL", "DEPOSIT"]>>;
|
|
161
|
+
amountType: z.ZodOptional<z.ZodEnum<["FIXED", "PERCENTAGE"]>>;
|
|
162
|
+
amountValue: z.ZodNumber;
|
|
163
|
+
useSystemCredit: z.ZodOptional<z.ZodBoolean>;
|
|
164
|
+
}, "strip", z.ZodTypeAny, {
|
|
165
|
+
amountValue: number;
|
|
166
|
+
online?: boolean | undefined;
|
|
167
|
+
scope?: "RENTAL" | "DEPOSIT" | undefined;
|
|
168
|
+
amountType?: "FIXED" | "PERCENTAGE" | undefined;
|
|
169
|
+
useSystemCredit?: boolean | undefined;
|
|
170
|
+
}, {
|
|
171
|
+
amountValue: number;
|
|
172
|
+
online?: boolean | undefined;
|
|
173
|
+
scope?: "RENTAL" | "DEPOSIT" | undefined;
|
|
174
|
+
amountType?: "FIXED" | "PERCENTAGE" | undefined;
|
|
175
|
+
useSystemCredit?: boolean | undefined;
|
|
176
|
+
}>;
|
|
176
177
|
}, "strip", z.ZodTypeAny, {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
178
|
+
tripId: string;
|
|
179
|
+
body: {
|
|
180
|
+
amountValue: number;
|
|
181
|
+
online?: boolean | undefined;
|
|
182
|
+
scope?: "RENTAL" | "DEPOSIT" | undefined;
|
|
183
|
+
amountType?: "FIXED" | "PERCENTAGE" | undefined;
|
|
184
|
+
useSystemCredit?: boolean | undefined;
|
|
185
|
+
};
|
|
185
186
|
}, {
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
187
|
+
tripId: string;
|
|
188
|
+
body: {
|
|
189
|
+
amountValue: number;
|
|
190
|
+
online?: boolean | undefined;
|
|
191
|
+
scope?: "RENTAL" | "DEPOSIT" | undefined;
|
|
192
|
+
amountType?: "FIXED" | "PERCENTAGE" | undefined;
|
|
193
|
+
useSystemCredit?: boolean | undefined;
|
|
194
|
+
};
|
|
194
195
|
}>;
|
|
195
196
|
declare const payATrip: (client: Client, tripId: string, body: z.infer<typeof schema>["body"]) => Promise<TripPayment>;
|
|
196
|
-
|
|
197
|
-
export {
|
|
197
|
+
//#endregion
|
|
198
|
+
export { BrowserInfos, PaymentDetail, SetupIntent, SynchronizeResponse, TripPayment, getPaymentMethodDetailsForUser, getSetupIntent, getSynchronize, payATrip };
|
package/dist/index.mjs
CHANGED
|
@@ -1,107 +1,81 @@
|
|
|
1
|
-
// src/getPaymentMethodDetailsForUser.ts
|
|
2
1
|
import { z } from "zod";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
});
|
|
9
|
-
}
|
|
10
|
-
return client.get(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/users/${id}/paymentMethodDetails`).then(({ data }) => data.find((paymentDetail) => paymentDetail.profileType === "Single"));
|
|
2
|
+
//#region src/getPaymentMethodDetailsForUser.ts
|
|
3
|
+
const getPaymentMethodDetailsForUser = async (client, id) => {
|
|
4
|
+
const result = z.string().trim().min(1).uuid().safeParse(id);
|
|
5
|
+
if (!result.success) throw new TypeError("Invalid id", { cause: result.error.issues });
|
|
6
|
+
return client.get(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/users/${id}/paymentMethodDetails`).then(({ data }) => data.find((paymentDetail) => paymentDetail.profileType === "Single"));
|
|
11
7
|
};
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
colorDepth: z2.number()
|
|
8
|
+
//#endregion
|
|
9
|
+
//#region src/getSetupIntent.ts
|
|
10
|
+
const browserInfosSchema = z.object({
|
|
11
|
+
origin: z.string().url(),
|
|
12
|
+
userAgent: z.string(),
|
|
13
|
+
screenHeight: z.number(),
|
|
14
|
+
screenWidth: z.number(),
|
|
15
|
+
colorDepth: z.number()
|
|
21
16
|
});
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
const resultBrowserInfos = browserInfosSchema.safeParse(browserInfos);
|
|
36
|
-
if (!resultBrowserInfos.success) {
|
|
37
|
-
throw new TypeError("Invalid browser infos", {
|
|
38
|
-
cause: resultBrowserInfos.error.issues
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
return client.post(
|
|
42
|
-
`boapi/proxy/user/fleets/${client.clientOptions.fleetId}/users/${userId}/entities/${entityId}/setup_intents`,
|
|
43
|
-
{
|
|
44
|
-
paymentMethodType: "CREDIT_CARD",
|
|
45
|
-
returnURL,
|
|
46
|
-
paymentMethod: {
|
|
47
|
-
browserInfo: {
|
|
48
|
-
...resultBrowserInfos.data
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
).then(({ data }) => data);
|
|
17
|
+
const getSetupIntent = async (client, userId, entityId, returnURL, browserInfos) => {
|
|
18
|
+
const resultUserId = z.string().trim().min(1).safeParse(userId);
|
|
19
|
+
if (!resultUserId.success) throw new TypeError("Invalid userId", { cause: resultUserId.error.issues });
|
|
20
|
+
const resultEntityId = z.string().trim().min(1).safeParse(entityId);
|
|
21
|
+
if (!resultEntityId.success) throw new TypeError("Invalid entityId", { cause: resultEntityId.error.issues });
|
|
22
|
+
const resultBrowserInfos = browserInfosSchema.safeParse(browserInfos);
|
|
23
|
+
if (!resultBrowserInfos.success) throw new TypeError("Invalid browser infos", { cause: resultBrowserInfos.error.issues });
|
|
24
|
+
return client.post(`boapi/proxy/user/fleets/${client.clientOptions.fleetId}/users/${userId}/entities/${entityId}/setup_intents`, {
|
|
25
|
+
paymentMethodType: "CREDIT_CARD",
|
|
26
|
+
returnURL,
|
|
27
|
+
paymentMethod: { browserInfo: { ...resultBrowserInfos.data } }
|
|
28
|
+
}).then(({ data }) => data);
|
|
53
29
|
};
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
setupIntent: z3.string().trim().min(1)
|
|
30
|
+
//#endregion
|
|
31
|
+
//#region src/getSynchronize.ts
|
|
32
|
+
const schema$1 = z.object({
|
|
33
|
+
userId: z.string().trim().uuid(),
|
|
34
|
+
entityId: z.string().trim().uuid(),
|
|
35
|
+
setupIntent: z.string().trim().min(1)
|
|
61
36
|
});
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/users/${userId}/entities/${entityId}/setup_intents/${setupIntent}/synchronize`,
|
|
71
|
-
{}
|
|
72
|
-
).then(({ data }) => data);
|
|
37
|
+
const getSynchronize = async (client, userId, entityId, setupIntent) => {
|
|
38
|
+
const result = schema$1.safeParse({
|
|
39
|
+
userId,
|
|
40
|
+
entityId,
|
|
41
|
+
setupIntent
|
|
42
|
+
});
|
|
43
|
+
if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
|
|
44
|
+
return client.post(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/users/${userId}/entities/${entityId}/setup_intents/${setupIntent}/synchronize`, {}).then(({ data }) => data);
|
|
73
45
|
};
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
46
|
+
//#endregion
|
|
47
|
+
//#region src/payATrip.ts
|
|
48
|
+
/**
|
|
49
|
+
* Pay for a trip by its ID.
|
|
50
|
+
*
|
|
51
|
+
* @param client - The Aima client instance.
|
|
52
|
+
* @param tripId - The ID of the trip to pay for.
|
|
53
|
+
* @returns A promise that resolves when the payment is successful.
|
|
54
|
+
* @throws TypeError if the parameters are invalid.
|
|
55
|
+
*/
|
|
56
|
+
const schema = z.object({
|
|
57
|
+
tripId: z.string().nonempty(),
|
|
58
|
+
body: z.object({
|
|
59
|
+
online: z.boolean().optional(),
|
|
60
|
+
scope: z.enum(["RENTAL", "DEPOSIT"]).optional(),
|
|
61
|
+
amountType: z.enum(["FIXED", "PERCENTAGE"]).optional(),
|
|
62
|
+
amountValue: z.number().nonnegative(),
|
|
63
|
+
useSystemCredit: z.boolean().optional()
|
|
64
|
+
})
|
|
86
65
|
});
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}).then(({ data }) => data);
|
|
101
|
-
};
|
|
102
|
-
export {
|
|
103
|
-
getPaymentMethodDetailsForUser,
|
|
104
|
-
getSetupIntent,
|
|
105
|
-
getSynchronize,
|
|
106
|
-
payATrip
|
|
66
|
+
const payATrip = async (client, tripId, body) => {
|
|
67
|
+
const validated = schema.safeParse({
|
|
68
|
+
tripId,
|
|
69
|
+
body
|
|
70
|
+
});
|
|
71
|
+
if (!validated.success) throw new TypeError("Invalid parameters", { cause: validated.error.issues });
|
|
72
|
+
return client.post(`/boapi/proxy/trip/fleets/${client.clientOptions.fleetId}/trips/${tripId}/pay`, {
|
|
73
|
+
online: body.online ?? false,
|
|
74
|
+
scope: body.scope ?? "RENTAL",
|
|
75
|
+
amountType: body.amountType ?? "FIXED",
|
|
76
|
+
amountValue: body.amountValue,
|
|
77
|
+
useSystemCredit: body.useSystemCredit ?? true
|
|
78
|
+
}).then(({ data }) => data);
|
|
107
79
|
};
|
|
80
|
+
//#endregion
|
|
81
|
+
export { getPaymentMethodDetailsForUser, getSetupIntent, getSynchronize, payATrip };
|
package/package.json
CHANGED
|
@@ -1,12 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vulog/aima-payment",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "1.2.32",
|
|
5
|
+
"main": "dist/index.cjs",
|
|
5
6
|
"module": "dist/index.mjs",
|
|
6
|
-
"types": "dist/index.d.
|
|
7
|
+
"types": "dist/index.d.cts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": {
|
|
11
|
+
"types": "./dist/index.d.mts",
|
|
12
|
+
"default": "./dist/index.mjs"
|
|
13
|
+
},
|
|
14
|
+
"require": {
|
|
15
|
+
"types": "./dist/index.d.cts",
|
|
16
|
+
"default": "./dist/index.cjs"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
},
|
|
7
20
|
"scripts": {
|
|
8
|
-
"build": "
|
|
9
|
-
"dev": "
|
|
21
|
+
"build": "tsdown",
|
|
22
|
+
"dev": "tsdown --watch",
|
|
10
23
|
"test": "vitest run",
|
|
11
24
|
"test:watch": "vitest",
|
|
12
25
|
"lint": "eslint src/**/* --ext .ts"
|
|
@@ -19,8 +32,8 @@
|
|
|
19
32
|
"author": "Vulog",
|
|
20
33
|
"license": "MIT",
|
|
21
34
|
"dependencies": {
|
|
22
|
-
"@vulog/aima-client": "1.2.
|
|
23
|
-
"@vulog/aima-core": "1.2.
|
|
35
|
+
"@vulog/aima-client": "1.2.32",
|
|
36
|
+
"@vulog/aima-core": "1.2.32"
|
|
24
37
|
},
|
|
25
38
|
"peerDependencies": {
|
|
26
39
|
"zod": "^3.25.76"
|
|
@@ -43,12 +43,10 @@ describe('getPaymentMethodDetailsForUser', () => {
|
|
|
43
43
|
expiryYear: '2028',
|
|
44
44
|
paymentType: 'CARD',
|
|
45
45
|
};
|
|
46
|
-
getMock.mockResolvedValueOnce({ data: [
|
|
47
|
-
mockData,
|
|
48
|
-
]});
|
|
46
|
+
getMock.mockResolvedValueOnce({ data: [mockData] });
|
|
49
47
|
|
|
50
48
|
const result = await getPaymentMethodDetailsForUser(client, userId);
|
|
51
|
-
|
|
49
|
+
|
|
52
50
|
expect(getMock).toBeCalled();
|
|
53
51
|
expect(getMock).toBeCalledWith(`/boapi/proxy/user/fleets/FLEET_ID/users/${userId}/paymentMethodDetails`);
|
|
54
52
|
expect(result).toBeTruthy();
|
|
@@ -98,12 +96,10 @@ describe('getPaymentMethodDetailsForUser', () => {
|
|
|
98
96
|
last4: '2606',
|
|
99
97
|
paymentType: 'SEPA',
|
|
100
98
|
};
|
|
101
|
-
getMock.mockResolvedValueOnce({ data: [
|
|
102
|
-
mockData,
|
|
103
|
-
]});
|
|
99
|
+
getMock.mockResolvedValueOnce({ data: [mockData] });
|
|
104
100
|
|
|
105
101
|
const result = await getPaymentMethodDetailsForUser(client, userId);
|
|
106
|
-
|
|
102
|
+
|
|
107
103
|
expect(getMock).toBeCalled();
|
|
108
104
|
expect(getMock).toBeCalledWith(`/boapi/proxy/user/fleets/FLEET_ID/users/${userId}/paymentMethodDetails`);
|
|
109
105
|
expect(result).toBeTruthy();
|
|
@@ -153,12 +149,10 @@ describe('getPaymentMethodDetailsForUser', () => {
|
|
|
153
149
|
bic: 'TESTNL01',
|
|
154
150
|
paymentType: 'BANK',
|
|
155
151
|
};
|
|
156
|
-
getMock.mockResolvedValueOnce({ data: [
|
|
157
|
-
mockData,
|
|
158
|
-
]});
|
|
152
|
+
getMock.mockResolvedValueOnce({ data: [mockData] });
|
|
159
153
|
|
|
160
154
|
const result = await getPaymentMethodDetailsForUser(client, userId);
|
|
161
|
-
|
|
155
|
+
|
|
162
156
|
expect(getMock).toBeCalled();
|
|
163
157
|
expect(getMock).toBeCalledWith(`/boapi/proxy/user/fleets/FLEET_ID/users/${userId}/paymentMethodDetails`);
|
|
164
158
|
expect(result).toBeTruthy();
|
|
@@ -216,12 +210,12 @@ describe('getPaymentMethodDetailsForUser', () => {
|
|
|
216
210
|
paymentMethod: 'CREDIT_CARD',
|
|
217
211
|
mopStatus: 'MOP_MISSING',
|
|
218
212
|
paymentType: 'CARD',
|
|
219
|
-
}
|
|
213
|
+
},
|
|
220
214
|
];
|
|
221
215
|
getMock.mockResolvedValueOnce({ data: mockData });
|
|
222
216
|
|
|
223
217
|
const result = await getPaymentMethodDetailsForUser(client, userId);
|
|
224
|
-
|
|
218
|
+
|
|
225
219
|
expect(getMock).toBeCalled();
|
|
226
220
|
expect(getMock).toBeCalledWith(`/boapi/proxy/user/fleets/FLEET_ID/users/${userId}/paymentMethodDetails`);
|
|
227
221
|
expect(result).toBeTruthy();
|
package/dist/index.d.ts
DELETED
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
import { Client } from '@vulog/aima-client';
|
|
2
|
-
import { UUID } from 'crypto';
|
|
3
|
-
import { z } from 'zod';
|
|
4
|
-
|
|
5
|
-
type SetupIntent = {
|
|
6
|
-
id: string;
|
|
7
|
-
pspPublishableKey: string;
|
|
8
|
-
pspCustomerReference: string;
|
|
9
|
-
pspName: string;
|
|
10
|
-
pspReference: string;
|
|
11
|
-
pspClientSecret: string;
|
|
12
|
-
date: string;
|
|
13
|
-
[key: string]: any;
|
|
14
|
-
};
|
|
15
|
-
type BrowserInfos = {
|
|
16
|
-
origin: string;
|
|
17
|
-
userAgent: string;
|
|
18
|
-
screenHeight: number;
|
|
19
|
-
screenWidth: number;
|
|
20
|
-
colorDepth: number;
|
|
21
|
-
};
|
|
22
|
-
type PaymentDetail = {
|
|
23
|
-
token: string;
|
|
24
|
-
holderName: string;
|
|
25
|
-
fleetId: string;
|
|
26
|
-
entityId: string;
|
|
27
|
-
pspName: string;
|
|
28
|
-
customerPspReference: string;
|
|
29
|
-
entityStatus: string;
|
|
30
|
-
profileId: string;
|
|
31
|
-
profileName: string;
|
|
32
|
-
profileType: 'Single' | 'Business';
|
|
33
|
-
paymentMethod: 'SEPA' | 'IDEAL' | 'PAYPAL' | 'CREDIT_CARD' | 'WIRE_TRANSFER' | 'EXTERNAL';
|
|
34
|
-
mopStatus: 'MOP_VALID' | 'MOP_MISSING' | 'MOP_EXPIRED' | 'MOP_INVALID' | 'MOP_UPDATING' | 'MOP_UPDATE_FAILED' | 'MOP_UNKNOWN';
|
|
35
|
-
paymentCurrency: string;
|
|
36
|
-
cardFunding: 'credit' | 'debit' | 'prepaid' | 'unknown';
|
|
37
|
-
} & ({
|
|
38
|
-
paymentType: 'CARD';
|
|
39
|
-
cardSummary?: string;
|
|
40
|
-
cardType?: string;
|
|
41
|
-
expiryDate?: number;
|
|
42
|
-
expiryMonth?: string;
|
|
43
|
-
expiryYear?: string;
|
|
44
|
-
} | {
|
|
45
|
-
paymentType: 'SEPA';
|
|
46
|
-
bankCode: string;
|
|
47
|
-
branchCode: string;
|
|
48
|
-
country: string;
|
|
49
|
-
fingerprint: string;
|
|
50
|
-
last4: string;
|
|
51
|
-
} | {
|
|
52
|
-
paymentType: 'BANK';
|
|
53
|
-
bankName: string;
|
|
54
|
-
bankAccountNumber: string;
|
|
55
|
-
iban: string;
|
|
56
|
-
bic: string;
|
|
57
|
-
} | {
|
|
58
|
-
paymentType: 'PAYPAL';
|
|
59
|
-
} | {
|
|
60
|
-
paymentType: 'EXTERNAL';
|
|
61
|
-
});
|
|
62
|
-
type SynchronizeResponse = {
|
|
63
|
-
status: 'SUCCEEDED' | 'REQUIRES_CAPTURE' | 'FAILED';
|
|
64
|
-
};
|
|
65
|
-
type TripPayment = {
|
|
66
|
-
paymentIntents: [
|
|
67
|
-
{
|
|
68
|
-
id: string;
|
|
69
|
-
pspName: 'STRIPE' | 'ADYEN';
|
|
70
|
-
pspReference: string;
|
|
71
|
-
pspPublishableKey: string;
|
|
72
|
-
amount: number;
|
|
73
|
-
currency: string;
|
|
74
|
-
date: string;
|
|
75
|
-
status: string;
|
|
76
|
-
paymentMethodType: string;
|
|
77
|
-
paymentMethodPspReference: string;
|
|
78
|
-
paymentIntentPspReference: string;
|
|
79
|
-
number: number;
|
|
80
|
-
code: string;
|
|
81
|
-
declineCode: string;
|
|
82
|
-
pspClientSecret: string;
|
|
83
|
-
reason: string;
|
|
84
|
-
note: string;
|
|
85
|
-
nextAction: {
|
|
86
|
-
nextActionRedirectUrl: {
|
|
87
|
-
url: string;
|
|
88
|
-
method: string;
|
|
89
|
-
data: {
|
|
90
|
-
[key: string]: any;
|
|
91
|
-
};
|
|
92
|
-
};
|
|
93
|
-
type: string;
|
|
94
|
-
};
|
|
95
|
-
metadatas: {
|
|
96
|
-
[key: string]: any;
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
];
|
|
100
|
-
paymentReceipts: [
|
|
101
|
-
{
|
|
102
|
-
id: string;
|
|
103
|
-
pspName: string;
|
|
104
|
-
pspReference: string;
|
|
105
|
-
pspPublishableKey: string;
|
|
106
|
-
amount: number;
|
|
107
|
-
currency: string;
|
|
108
|
-
date: string;
|
|
109
|
-
status: string;
|
|
110
|
-
paymentMethodType: string;
|
|
111
|
-
paymentMethodPspReference: string;
|
|
112
|
-
paymentIntentPspReference: string;
|
|
113
|
-
number: number;
|
|
114
|
-
code: string;
|
|
115
|
-
declineCode: string;
|
|
116
|
-
pspClientSecret: string;
|
|
117
|
-
reason: string;
|
|
118
|
-
note: string;
|
|
119
|
-
nextAction: {
|
|
120
|
-
nextActionRedirectUrl: {
|
|
121
|
-
url: string;
|
|
122
|
-
method: string;
|
|
123
|
-
data: {
|
|
124
|
-
[key: string]: any;
|
|
125
|
-
};
|
|
126
|
-
};
|
|
127
|
-
type: string;
|
|
128
|
-
};
|
|
129
|
-
metadatas: {
|
|
130
|
-
[key: string]: any;
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
];
|
|
134
|
-
id: string;
|
|
135
|
-
fleetId: string;
|
|
136
|
-
profileId: string;
|
|
137
|
-
vehicleId: string;
|
|
138
|
-
serviceId: string;
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
declare const getPaymentMethodDetailsForUser: (client: Client, id: string) => Promise<PaymentDetail | undefined>;
|
|
142
|
-
|
|
143
|
-
declare const getSetupIntent: (client: Client, userId: UUID, entityId: UUID, returnURL: string, browserInfos: BrowserInfos) => Promise<SetupIntent>;
|
|
144
|
-
|
|
145
|
-
declare const getSynchronize: (client: Client, userId: string, entityId: string, setupIntent: string) => Promise<SynchronizeResponse | undefined>;
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* Pay for a trip by its ID.
|
|
149
|
-
*
|
|
150
|
-
* @param client - The Aima client instance.
|
|
151
|
-
* @param tripId - The ID of the trip to pay for.
|
|
152
|
-
* @returns A promise that resolves when the payment is successful.
|
|
153
|
-
* @throws TypeError if the parameters are invalid.
|
|
154
|
-
*/
|
|
155
|
-
declare const schema: z.ZodObject<{
|
|
156
|
-
tripId: z.ZodString;
|
|
157
|
-
body: z.ZodObject<{
|
|
158
|
-
online: z.ZodOptional<z.ZodBoolean>;
|
|
159
|
-
scope: z.ZodOptional<z.ZodEnum<["RENTAL", "DEPOSIT"]>>;
|
|
160
|
-
amountType: z.ZodOptional<z.ZodEnum<["FIXED", "PERCENTAGE"]>>;
|
|
161
|
-
amountValue: z.ZodNumber;
|
|
162
|
-
useSystemCredit: z.ZodOptional<z.ZodBoolean>;
|
|
163
|
-
}, "strip", z.ZodTypeAny, {
|
|
164
|
-
amountValue: number;
|
|
165
|
-
online?: boolean | undefined;
|
|
166
|
-
scope?: "RENTAL" | "DEPOSIT" | undefined;
|
|
167
|
-
amountType?: "FIXED" | "PERCENTAGE" | undefined;
|
|
168
|
-
useSystemCredit?: boolean | undefined;
|
|
169
|
-
}, {
|
|
170
|
-
amountValue: number;
|
|
171
|
-
online?: boolean | undefined;
|
|
172
|
-
scope?: "RENTAL" | "DEPOSIT" | undefined;
|
|
173
|
-
amountType?: "FIXED" | "PERCENTAGE" | undefined;
|
|
174
|
-
useSystemCredit?: boolean | undefined;
|
|
175
|
-
}>;
|
|
176
|
-
}, "strip", z.ZodTypeAny, {
|
|
177
|
-
tripId: string;
|
|
178
|
-
body: {
|
|
179
|
-
amountValue: number;
|
|
180
|
-
online?: boolean | undefined;
|
|
181
|
-
scope?: "RENTAL" | "DEPOSIT" | undefined;
|
|
182
|
-
amountType?: "FIXED" | "PERCENTAGE" | undefined;
|
|
183
|
-
useSystemCredit?: boolean | undefined;
|
|
184
|
-
};
|
|
185
|
-
}, {
|
|
186
|
-
tripId: string;
|
|
187
|
-
body: {
|
|
188
|
-
amountValue: number;
|
|
189
|
-
online?: boolean | undefined;
|
|
190
|
-
scope?: "RENTAL" | "DEPOSIT" | undefined;
|
|
191
|
-
amountType?: "FIXED" | "PERCENTAGE" | undefined;
|
|
192
|
-
useSystemCredit?: boolean | undefined;
|
|
193
|
-
};
|
|
194
|
-
}>;
|
|
195
|
-
declare const payATrip: (client: Client, tripId: string, body: z.infer<typeof schema>["body"]) => Promise<TripPayment>;
|
|
196
|
-
|
|
197
|
-
export { type BrowserInfos, type PaymentDetail, type SetupIntent, type SynchronizeResponse, type TripPayment, getPaymentMethodDetailsForUser, getSetupIntent, getSynchronize, payATrip };
|
package/dist/index.js
DELETED
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/index.ts
|
|
21
|
-
var index_exports = {};
|
|
22
|
-
__export(index_exports, {
|
|
23
|
-
getPaymentMethodDetailsForUser: () => getPaymentMethodDetailsForUser,
|
|
24
|
-
getSetupIntent: () => getSetupIntent,
|
|
25
|
-
getSynchronize: () => getSynchronize,
|
|
26
|
-
payATrip: () => payATrip
|
|
27
|
-
});
|
|
28
|
-
module.exports = __toCommonJS(index_exports);
|
|
29
|
-
|
|
30
|
-
// src/getPaymentMethodDetailsForUser.ts
|
|
31
|
-
var import_zod = require("zod");
|
|
32
|
-
var getPaymentMethodDetailsForUser = async (client, id) => {
|
|
33
|
-
const result = import_zod.z.string().trim().min(1).uuid().safeParse(id);
|
|
34
|
-
if (!result.success) {
|
|
35
|
-
throw new TypeError("Invalid id", {
|
|
36
|
-
cause: result.error.issues
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
return client.get(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/users/${id}/paymentMethodDetails`).then(({ data }) => data.find((paymentDetail) => paymentDetail.profileType === "Single"));
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
// src/getSetupIntent.ts
|
|
43
|
-
var import_zod2 = require("zod");
|
|
44
|
-
var browserInfosSchema = import_zod2.z.object({
|
|
45
|
-
origin: import_zod2.z.string().url(),
|
|
46
|
-
userAgent: import_zod2.z.string(),
|
|
47
|
-
screenHeight: import_zod2.z.number(),
|
|
48
|
-
screenWidth: import_zod2.z.number(),
|
|
49
|
-
colorDepth: import_zod2.z.number()
|
|
50
|
-
});
|
|
51
|
-
var getSetupIntent = async (client, userId, entityId, returnURL, browserInfos) => {
|
|
52
|
-
const resultUserId = import_zod2.z.string().trim().min(1).safeParse(userId);
|
|
53
|
-
if (!resultUserId.success) {
|
|
54
|
-
throw new TypeError("Invalid userId", {
|
|
55
|
-
cause: resultUserId.error.issues
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
const resultEntityId = import_zod2.z.string().trim().min(1).safeParse(entityId);
|
|
59
|
-
if (!resultEntityId.success) {
|
|
60
|
-
throw new TypeError("Invalid entityId", {
|
|
61
|
-
cause: resultEntityId.error.issues
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
const resultBrowserInfos = browserInfosSchema.safeParse(browserInfos);
|
|
65
|
-
if (!resultBrowserInfos.success) {
|
|
66
|
-
throw new TypeError("Invalid browser infos", {
|
|
67
|
-
cause: resultBrowserInfos.error.issues
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
return client.post(
|
|
71
|
-
`boapi/proxy/user/fleets/${client.clientOptions.fleetId}/users/${userId}/entities/${entityId}/setup_intents`,
|
|
72
|
-
{
|
|
73
|
-
paymentMethodType: "CREDIT_CARD",
|
|
74
|
-
returnURL,
|
|
75
|
-
paymentMethod: {
|
|
76
|
-
browserInfo: {
|
|
77
|
-
...resultBrowserInfos.data
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
).then(({ data }) => data);
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
// src/getSynchronize.ts
|
|
85
|
-
var import_zod3 = require("zod");
|
|
86
|
-
var schema = import_zod3.z.object({
|
|
87
|
-
userId: import_zod3.z.string().trim().uuid(),
|
|
88
|
-
entityId: import_zod3.z.string().trim().uuid(),
|
|
89
|
-
setupIntent: import_zod3.z.string().trim().min(1)
|
|
90
|
-
});
|
|
91
|
-
var getSynchronize = async (client, userId, entityId, setupIntent) => {
|
|
92
|
-
const result = schema.safeParse({ userId, entityId, setupIntent });
|
|
93
|
-
if (!result.success) {
|
|
94
|
-
throw new TypeError("Invalid args", {
|
|
95
|
-
cause: result.error.issues
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
return client.post(
|
|
99
|
-
`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/users/${userId}/entities/${entityId}/setup_intents/${setupIntent}/synchronize`,
|
|
100
|
-
{}
|
|
101
|
-
).then(({ data }) => data);
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
// src/payATrip.ts
|
|
105
|
-
var import_zod4 = require("zod");
|
|
106
|
-
var schema2 = import_zod4.z.object({
|
|
107
|
-
tripId: import_zod4.z.string().nonempty(),
|
|
108
|
-
body: import_zod4.z.object({
|
|
109
|
-
online: import_zod4.z.boolean().optional(),
|
|
110
|
-
scope: import_zod4.z.enum(["RENTAL", "DEPOSIT"]).optional(),
|
|
111
|
-
amountType: import_zod4.z.enum(["FIXED", "PERCENTAGE"]).optional(),
|
|
112
|
-
amountValue: import_zod4.z.number().nonnegative(),
|
|
113
|
-
useSystemCredit: import_zod4.z.boolean().optional()
|
|
114
|
-
})
|
|
115
|
-
});
|
|
116
|
-
var payATrip = async (client, tripId, body) => {
|
|
117
|
-
const validated = schema2.safeParse({ tripId, body });
|
|
118
|
-
if (!validated.success) {
|
|
119
|
-
throw new TypeError("Invalid parameters", {
|
|
120
|
-
cause: validated.error.issues
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
return client.post(`/boapi/proxy/trip/fleets/${client.clientOptions.fleetId}/trips/${tripId}/pay`, {
|
|
124
|
-
online: body.online ?? false,
|
|
125
|
-
scope: body.scope ?? "RENTAL",
|
|
126
|
-
amountType: body.amountType ?? "FIXED",
|
|
127
|
-
amountValue: body.amountValue,
|
|
128
|
-
useSystemCredit: body.useSystemCredit ?? true
|
|
129
|
-
}).then(({ data }) => data);
|
|
130
|
-
};
|
|
131
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
132
|
-
0 && (module.exports = {
|
|
133
|
-
getPaymentMethodDetailsForUser,
|
|
134
|
-
getSetupIntent,
|
|
135
|
-
getSynchronize,
|
|
136
|
-
payATrip
|
|
137
|
-
});
|
|
File without changes
|