@driveflux/api-functions 1.0.103 → 1.0.105
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/auth/otp.d.ts +1 -1
- package/dist/auth/register.d.ts +1 -1
- package/dist/auth/register.d.ts.map +1 -1
- package/dist/auth/register.js +46 -43
- package/dist/auth/register.js.map +1 -1
- package/dist/auth/tokens.d.ts +12 -12
- package/dist/reservation/display-vehicle.d.ts +9 -5
- package/dist/reservation/invoice.js +88 -77
- package/dist/reservation/payment-intent-sync.js +6 -4
- package/package.json +2 -2
package/dist/auth/otp.d.ts
CHANGED
|
@@ -21,8 +21,8 @@ declare const SendVerificationSMSBody: z.ZodObject<{
|
|
|
21
21
|
}, z.core.$strip>;
|
|
22
22
|
declare const VerifyOtpBody: z.ZodObject<{
|
|
23
23
|
scope: z.ZodEnum<{
|
|
24
|
-
"verify-email": "verify-email";
|
|
25
24
|
"verify-phone": "verify-phone";
|
|
25
|
+
"verify-email": "verify-email";
|
|
26
26
|
}>;
|
|
27
27
|
email: z.ZodPipe<z.ZodOptional<z.ZodEmail>, z.ZodTransform<string | undefined, string | undefined>>;
|
|
28
28
|
phoneNumber: z.ZodOptional<z.ZodString>;
|
package/dist/auth/register.d.ts
CHANGED
|
@@ -11,8 +11,8 @@ export declare const RegistrationValidation: z.ZodObject<{
|
|
|
11
11
|
lastName: z.ZodString;
|
|
12
12
|
phoneNumber: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
|
|
13
13
|
authMethod: z.ZodEnum<{
|
|
14
|
-
email: "email";
|
|
15
14
|
mobile: "mobile";
|
|
15
|
+
email: "email";
|
|
16
16
|
facebook: "facebook";
|
|
17
17
|
google: "google";
|
|
18
18
|
apple: "apple";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../../src/auth/register.ts"],"names":[],"mappings":"AAGA,OAAO,EAAuB,KAAK,KAAK,EAAE,KAAK,IAAI,EAAE,MAAM,eAAe,CAAA;AAG1E,OAAO,EAAW,KAAK,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAMhE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAOvB,MAAM,MAAM,mBAAmB,GAAG;IACjC,KAAK,EAAE,KAAK,CAAA;IACZ,IAAI,EAAE,IAAI,CAAA;CACV,CAAA;AAED,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAA;AAElE,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;iBA6BjC,CAAA;AAEF,eAAO,MAAM,cAAc,GAAU,iLAgBlC,aAAa,KAAG,cAAc,CAAC,mBAAmB,
|
|
1
|
+
{"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../../src/auth/register.ts"],"names":[],"mappings":"AAGA,OAAO,EAAuB,KAAK,KAAK,EAAE,KAAK,IAAI,EAAE,MAAM,eAAe,CAAA;AAG1E,OAAO,EAAW,KAAK,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAMhE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAOvB,MAAM,MAAM,mBAAmB,GAAG;IACjC,KAAK,EAAE,KAAK,CAAA;IACZ,IAAI,EAAE,IAAI,CAAA;CACV,CAAA;AAED,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAA;AAElE,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;iBA6BjC,CAAA;AAEF,eAAO,MAAM,cAAc,GAAU,iLAgBlC,aAAa,KAAG,cAAc,CAAC,mBAAmB,CAmIpD,CAAA"}
|
package/dist/auth/register.js
CHANGED
|
@@ -19,25 +19,19 @@ import { sendVerificationEmail } from './verifications.js';
|
|
|
19
19
|
export const RegistrationValidation = z.object({
|
|
20
20
|
firstName: z.string(),
|
|
21
21
|
lastName: z.string(),
|
|
22
|
-
phoneNumber: z.string().transform((s)=>s.replace(/[\s-]/g, '')),
|
|
23
|
-
authMethod: z.enum([
|
|
24
|
-
'mobile',
|
|
25
|
-
'email',
|
|
26
|
-
'facebook',
|
|
27
|
-
'google',
|
|
28
|
-
'apple'
|
|
29
|
-
]),
|
|
22
|
+
phoneNumber: z.string().transform((s) => s.replace(/[\s-]/g, '')),
|
|
23
|
+
authMethod: z.enum(['mobile', 'email', 'facebook', 'google', 'apple']),
|
|
30
24
|
code: z.string().optional().nullable(),
|
|
31
25
|
keepCode: z.boolean().optional().default(false),
|
|
32
|
-
email: z.email().transform((s)=>s.toLowerCase().trim()),
|
|
33
|
-
dateOfBirth: dateValidation
|
|
26
|
+
email: z.email().transform((s) => s.toLowerCase().trim()),
|
|
27
|
+
dateOfBirth: dateValidation
|
|
28
|
+
.refine((d) => {
|
|
34
29
|
return isAfter(d, subYears(new Date(), 25));
|
|
35
30
|
}, {
|
|
36
|
-
path: [
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}).optional(),
|
|
31
|
+
path: ['dateOfBirth'],
|
|
32
|
+
message: 'You must be at least 25 years old to signup for the service.',
|
|
33
|
+
})
|
|
34
|
+
.optional(),
|
|
41
35
|
password: z.string().min(6).optional(),
|
|
42
36
|
noMarketing: z.boolean().optional(),
|
|
43
37
|
pageSource: z.string().optional().nullable(),
|
|
@@ -47,14 +41,12 @@ export const RegistrationValidation = z.object({
|
|
|
47
41
|
userAgent: z.string().optional(),
|
|
48
42
|
ipAddress: z.ipv4().or(z.ipv6()),
|
|
49
43
|
sessionToken: z.string().optional(),
|
|
50
|
-
sessionId: z.string().optional()
|
|
44
|
+
sessionId: z.string().optional(),
|
|
51
45
|
});
|
|
52
|
-
export const handleRegister = async ({ noMarketing, password, authMethod, phoneNumber, code, keepCode, pageSource, skipPassword, fingerprint, termsVersion, userAgent, ipAddress, sessionToken, sessionId, ...body })=>{
|
|
46
|
+
export const handleRegister = async ({ noMarketing, password, authMethod, phoneNumber, code, keepCode, pageSource, skipPassword, fingerprint, termsVersion, userAgent, ipAddress, sessionToken, sessionId, ...body }) => {
|
|
53
47
|
let phoneNumberVerified = false;
|
|
54
48
|
if (code) {
|
|
55
|
-
const tokenResult = await verifyToken(code, {
|
|
56
|
-
scope: 'verify-phone'
|
|
57
|
-
});
|
|
49
|
+
const tokenResult = await verifyToken(code, { scope: 'verify-phone' });
|
|
58
50
|
if (tokenResult.err) {
|
|
59
51
|
return new Err(makeProblem(PROBLEM_CONFLICT, 'Invalid OTP token'));
|
|
60
52
|
}
|
|
@@ -68,9 +60,7 @@ export const handleRegister = async ({ noMarketing, password, authMethod, phoneN
|
|
|
68
60
|
}
|
|
69
61
|
// Check if the user exists
|
|
70
62
|
const foundUser = await prisma.user.findFirst({
|
|
71
|
-
where: {
|
|
72
|
-
email: body.email
|
|
73
|
-
}
|
|
63
|
+
where: { email: body.email },
|
|
74
64
|
});
|
|
75
65
|
if (foundUser) {
|
|
76
66
|
return new Err(makeProblem(PROBLEM_CONFLICT, 'A user with this email address already exists. Did you mean to login?'));
|
|
@@ -87,12 +77,10 @@ export const handleRegister = async ({ noMarketing, password, authMethod, phoneN
|
|
|
87
77
|
preferredCurrency: 'MYR',
|
|
88
78
|
preferredLocale: 'en',
|
|
89
79
|
phoneNumberVerified,
|
|
90
|
-
groups: [
|
|
91
|
-
'member'
|
|
92
|
-
],
|
|
80
|
+
groups: ['member'],
|
|
93
81
|
signupParams: {
|
|
94
82
|
method: authMethod,
|
|
95
|
-
source: pageSource
|
|
83
|
+
source: pageSource,
|
|
96
84
|
},
|
|
97
85
|
registrationComplete: true,
|
|
98
86
|
accounts: {
|
|
@@ -101,16 +89,16 @@ export const handleRegister = async ({ noMarketing, password, authMethod, phoneN
|
|
|
101
89
|
object: 'account',
|
|
102
90
|
type: 'default',
|
|
103
91
|
provider: 'credentials',
|
|
104
|
-
providerAccountId: id
|
|
105
|
-
}
|
|
92
|
+
providerAccountId: id,
|
|
93
|
+
},
|
|
106
94
|
},
|
|
107
95
|
tokens: {
|
|
108
96
|
create: {
|
|
109
97
|
id: tokenId,
|
|
110
98
|
expiresAt: addDays(new Date(), 365),
|
|
111
|
-
scope: 'all'
|
|
112
|
-
}
|
|
113
|
-
}
|
|
99
|
+
scope: 'all',
|
|
100
|
+
},
|
|
101
|
+
},
|
|
114
102
|
};
|
|
115
103
|
const { user: _removeDueToNestedCreate, ...consentCreate } = getConsentCreateData({
|
|
116
104
|
user: userCreateData,
|
|
@@ -119,34 +107,49 @@ export const handleRegister = async ({ noMarketing, password, authMethod, phoneN
|
|
|
119
107
|
ipAddress: ipAddress,
|
|
120
108
|
userAgent: userAgent,
|
|
121
109
|
sessionToken: tokenId,
|
|
122
|
-
consentType: 'terms'
|
|
110
|
+
consentType: 'terms',
|
|
123
111
|
});
|
|
124
112
|
const finalCreateData = {
|
|
125
113
|
...userCreateData,
|
|
126
114
|
consents: {
|
|
127
|
-
create: consentCreate
|
|
128
|
-
}
|
|
115
|
+
create: consentCreate,
|
|
116
|
+
},
|
|
129
117
|
};
|
|
118
|
+
// Find a host with the same email
|
|
119
|
+
const host = await prisma.host.findFirst({
|
|
120
|
+
where: {
|
|
121
|
+
email: finalCreateData.email,
|
|
122
|
+
},
|
|
123
|
+
select: {
|
|
124
|
+
id: true,
|
|
125
|
+
},
|
|
126
|
+
});
|
|
127
|
+
if (host?.id) {
|
|
128
|
+
finalCreateData.host = {
|
|
129
|
+
connect: {
|
|
130
|
+
id: host.id,
|
|
131
|
+
},
|
|
132
|
+
};
|
|
133
|
+
}
|
|
130
134
|
const user = await prisma.user.create({
|
|
131
135
|
data: finalCreateData,
|
|
132
136
|
include: {
|
|
133
137
|
tokens: {
|
|
134
138
|
where: {
|
|
135
|
-
id: tokenId
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
+
id: tokenId,
|
|
140
|
+
},
|
|
141
|
+
},
|
|
142
|
+
},
|
|
139
143
|
});
|
|
140
144
|
// We don't want this to be a task. It should be instant
|
|
141
145
|
await sendVerificationEmail(user.id);
|
|
142
146
|
if (!noMarketing) {
|
|
143
|
-
await setContactInList(user.id, {
|
|
144
|
-
generalMarketing: true
|
|
145
|
-
});
|
|
147
|
+
await setContactInList(user.id, { generalMarketing: true });
|
|
146
148
|
}
|
|
147
149
|
await refreshEmailPreferences(user.id);
|
|
148
150
|
return new Ok({
|
|
149
151
|
token: user.tokens[0],
|
|
150
|
-
user
|
|
152
|
+
user,
|
|
151
153
|
});
|
|
152
154
|
};
|
|
155
|
+
//# sourceMappingURL=register.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"register.js","sourceRoot":"","sources":["../../src/auth/register.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,yCAAyC,CAAA;AAC5E,OAAO,EAAE,uBAAuB,EAAE,MAAM,4DAA4D,CAAA;AACpG,OAAO,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAA;AACpE,OAAO,EAAe,MAAM,EAAyB,MAAM,eAAe,CAAA;AAC1E,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAClE,OAAO,EAAE,GAAG,EAAE,EAAE,EAAuB,MAAM,mBAAmB,CAAA;AAChE,OAAO,MAAM,MAAM,UAAU,CAAA;AAC7B,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC/B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAA;AAC5D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CAAC,CAAA"}
|
package/dist/auth/tokens.d.ts
CHANGED
|
@@ -10,50 +10,50 @@ type VerifyTokenOptions = {
|
|
|
10
10
|
export declare const createToken: (userId: string | null, type: "email" | "phoneNumber", value: string, providedExpiresAt?: Date) => Promise<{
|
|
11
11
|
object: import("@driveflux/db").TokenObject;
|
|
12
12
|
id: string;
|
|
13
|
-
metadata: PrismaJson.AnyMetadata | null;
|
|
14
|
-
createdAt: Date;
|
|
15
|
-
updatedAt: Date;
|
|
16
13
|
value: string | null;
|
|
17
|
-
userId: string | null;
|
|
18
14
|
client: string | null;
|
|
15
|
+
userId: string | null;
|
|
19
16
|
identifier: string | null;
|
|
20
17
|
expiresAt: Date | null;
|
|
21
18
|
redirectUrl: string | null;
|
|
22
19
|
scope: string | null;
|
|
23
20
|
invalid: boolean;
|
|
24
21
|
lastUsed: Date | null;
|
|
22
|
+
createdAt: Date;
|
|
23
|
+
updatedAt: Date;
|
|
24
|
+
metadata: PrismaJson.AnyMetadata | null;
|
|
25
25
|
} | undefined>;
|
|
26
26
|
export declare const createEmailToken: (userId: string, email: string) => Promise<{
|
|
27
27
|
object: import("@driveflux/db").TokenObject;
|
|
28
28
|
id: string;
|
|
29
|
-
metadata: PrismaJson.AnyMetadata | null;
|
|
30
|
-
createdAt: Date;
|
|
31
|
-
updatedAt: Date;
|
|
32
29
|
value: string | null;
|
|
33
|
-
userId: string | null;
|
|
34
30
|
client: string | null;
|
|
31
|
+
userId: string | null;
|
|
35
32
|
identifier: string | null;
|
|
36
33
|
expiresAt: Date | null;
|
|
37
34
|
redirectUrl: string | null;
|
|
38
35
|
scope: string | null;
|
|
39
36
|
invalid: boolean;
|
|
40
37
|
lastUsed: Date | null;
|
|
38
|
+
createdAt: Date;
|
|
39
|
+
updatedAt: Date;
|
|
40
|
+
metadata: PrismaJson.AnyMetadata | null;
|
|
41
41
|
} | undefined>;
|
|
42
42
|
export declare const createSMSToken: (userId: string | null, phoneNumber: string) => Promise<{
|
|
43
43
|
object: import("@driveflux/db").TokenObject;
|
|
44
44
|
id: string;
|
|
45
|
-
metadata: PrismaJson.AnyMetadata | null;
|
|
46
|
-
createdAt: Date;
|
|
47
|
-
updatedAt: Date;
|
|
48
45
|
value: string | null;
|
|
49
|
-
userId: string | null;
|
|
50
46
|
client: string | null;
|
|
47
|
+
userId: string | null;
|
|
51
48
|
identifier: string | null;
|
|
52
49
|
expiresAt: Date | null;
|
|
53
50
|
redirectUrl: string | null;
|
|
54
51
|
scope: string | null;
|
|
55
52
|
invalid: boolean;
|
|
56
53
|
lastUsed: Date | null;
|
|
54
|
+
createdAt: Date;
|
|
55
|
+
updatedAt: Date;
|
|
56
|
+
metadata: PrismaJson.AnyMetadata | null;
|
|
57
57
|
} | undefined>;
|
|
58
58
|
export declare const verifyToken: (tokenIdOrValue: string | TokenWithMaybeUser, verifications?: Verifications, option?: VerifyTokenOptions) => PromisedResult<TokenWithMaybeUser>;
|
|
59
59
|
export declare const clearToken: (tokenId: string) => Promise<void>;
|
|
@@ -199,21 +199,23 @@ export declare const createVehicleFromDisplayVehicle: (displayVehicle: DisplayVe
|
|
|
199
199
|
host: {
|
|
200
200
|
object: import("@driveflux/db").HostObject;
|
|
201
201
|
phoneNumber: string | null;
|
|
202
|
+
email: string | null;
|
|
202
203
|
type: import("@driveflux/db").HostType | null;
|
|
203
|
-
id: string;
|
|
204
|
-
metadata: PrismaJson.AnyMetadata | null;
|
|
205
204
|
name: string;
|
|
205
|
+
id: string;
|
|
206
206
|
createdAt: Date;
|
|
207
207
|
updatedAt: Date;
|
|
208
|
-
|
|
208
|
+
metadata: PrismaJson.AnyMetadata | null;
|
|
209
209
|
race: import("@driveflux/db").Race | null;
|
|
210
210
|
emergencyContactName: string | null;
|
|
211
211
|
emergencyPhoneNumber: string | null;
|
|
212
|
+
companyName: string | null;
|
|
212
213
|
active: boolean;
|
|
213
214
|
sstNumber: string | null;
|
|
214
215
|
tinNumber: string | null;
|
|
215
216
|
commencementDate: Date | null;
|
|
216
217
|
registrationNumber: string | null;
|
|
218
|
+
faxNumber: string | null;
|
|
217
219
|
stripeAccountId: string | null;
|
|
218
220
|
isStripeConnected: boolean;
|
|
219
221
|
serviceCenterIds: string[];
|
|
@@ -243,6 +245,8 @@ export declare const createVehicleFromDisplayVehicle: (displayVehicle: DisplayVe
|
|
|
243
245
|
email: string | null;
|
|
244
246
|
phoneNumber: string | null;
|
|
245
247
|
remarks: string | null;
|
|
248
|
+
identificationNumber: string | null;
|
|
249
|
+
isDefault: boolean;
|
|
246
250
|
}[];
|
|
247
251
|
stripeConnectToken: {
|
|
248
252
|
access_token: string | null;
|
|
@@ -273,9 +277,9 @@ export declare const createVehicleFromDisplayVehicle: (displayVehicle: DisplayVe
|
|
|
273
277
|
object: import("@driveflux/db").VehicleObject;
|
|
274
278
|
type: VehicleType;
|
|
275
279
|
id: string;
|
|
276
|
-
metadata: PrismaJson.AnyMetadata | null;
|
|
277
280
|
createdAt: Date;
|
|
278
281
|
updatedAt: Date;
|
|
282
|
+
metadata: PrismaJson.AnyMetadata | null;
|
|
279
283
|
hostId: string;
|
|
280
284
|
status: import("@driveflux/db").VehicleStatus;
|
|
281
285
|
temporary: boolean;
|
|
@@ -700,9 +704,9 @@ export declare const transfromVehicleDisplayToVehicle: (displayVehicle: DisplayV
|
|
|
700
704
|
object: import("@driveflux/db").VehicleObject;
|
|
701
705
|
type: VehicleType;
|
|
702
706
|
id: string;
|
|
703
|
-
metadata: PrismaJson.AnyMetadata | null;
|
|
704
707
|
createdAt: Date;
|
|
705
708
|
updatedAt: Date;
|
|
709
|
+
metadata: PrismaJson.AnyMetadata | null;
|
|
706
710
|
hostId: string;
|
|
707
711
|
status: import("@driveflux/db").VehicleStatus;
|
|
708
712
|
temporary: boolean;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { config } from '@driveflux/config/backend';
|
|
2
2
|
import { loadCoupon, PROBLEM_APPLICABLE_NOT_FOUND } from '@driveflux/coupon';
|
|
3
|
-
import { prisma } from '@driveflux/db';
|
|
3
|
+
import { prisma, } from '@driveflux/db';
|
|
4
4
|
import { generateId } from '@driveflux/db/id';
|
|
5
5
|
import { EMPTY_BILLING_ADDRESS } from '@driveflux/db/models/other';
|
|
6
|
-
import { INVOICE_LINE_CYCLE, INVOICE_LINE_DEPOSIT, INVOICE_LINE_OTHER, INVOICE_LINE_RESERVATION_FEE, PURPOSE_FULL_BOOKING, PURPOSE_RESERVATION } from '@driveflux/db/models/subscription';
|
|
6
|
+
import { INVOICE_LINE_CYCLE, INVOICE_LINE_DEPOSIT, INVOICE_LINE_OTHER, INVOICE_LINE_RESERVATION_FEE, PURPOSE_FULL_BOOKING, PURPOSE_RESERVATION, } from '@driveflux/db/models/subscription';
|
|
7
7
|
import { userName } from '@driveflux/db/models/user';
|
|
8
8
|
import { vehicleName } from '@driveflux/db/models/vehicle';
|
|
9
9
|
import { biller, coupons } from '@driveflux/engine';
|
|
@@ -16,15 +16,16 @@ import { isAfter } from 'date-fns/isAfter';
|
|
|
16
16
|
import { subMinutes } from 'date-fns/subMinutes';
|
|
17
17
|
import { createScopedLogger } from '../create-logger.js';
|
|
18
18
|
const log = createScopedLogger('reservation:invoice');
|
|
19
|
-
export const updateReservationInvoiceIfNeeded = async (oldReservationInvoice, newParams)=>{
|
|
19
|
+
export const updateReservationInvoiceIfNeeded = async (oldReservationInvoice, newParams) => {
|
|
20
20
|
const couponIsDifferent = oldReservationInvoice.couponCode !== newParams.couponCode;
|
|
21
|
-
if (!couponIsDifferent &&
|
|
21
|
+
if (!couponIsDifferent &&
|
|
22
|
+
oldReservationInvoice.stripePaymentIntentId === newParams.paymentIntentId) {
|
|
22
23
|
return new Ok(oldReservationInvoice);
|
|
23
24
|
}
|
|
24
25
|
// If the coupon or payment intent are differnt we should update the invoice
|
|
25
26
|
let update = {
|
|
26
27
|
stripePaymentIntentId: newParams.paymentIntentId,
|
|
27
|
-
couponCode: newParams.couponCode
|
|
28
|
+
couponCode: newParams.couponCode,
|
|
28
29
|
};
|
|
29
30
|
// If the coupon is different, we need to apply the coupon to the invoice
|
|
30
31
|
if (couponIsDifferent) {
|
|
@@ -32,56 +33,63 @@ export const updateReservationInvoiceIfNeeded = async (oldReservationInvoice, ne
|
|
|
32
33
|
const result = await coupons.applyCouponToUnsavedInvoice(newParams.couponCode, oldReservationInvoice);
|
|
33
34
|
if (result.ok) {
|
|
34
35
|
const { discounts, ...rest } = result.val;
|
|
35
|
-
const toDisconnect = discounts
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
36
|
+
const toDisconnect = discounts
|
|
37
|
+
? oldReservationInvoice.discountIds?.filter((id) => !discounts.connect?.some((d) => d.id === id))
|
|
38
|
+
: undefined;
|
|
39
|
+
const disconnectClauses = toDisconnect?.length
|
|
40
|
+
? {
|
|
41
|
+
disconnect: toDisconnect.map((id) => ({ id })),
|
|
42
|
+
}
|
|
43
|
+
: undefined;
|
|
41
44
|
update = {
|
|
42
45
|
...update,
|
|
43
46
|
...rest,
|
|
44
|
-
...discounts || disconnectClauses
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
47
|
+
...(discounts || disconnectClauses
|
|
48
|
+
? {
|
|
49
|
+
discounts: {
|
|
50
|
+
...(discounts || {}),
|
|
51
|
+
...(disconnectClauses || {}),
|
|
52
|
+
},
|
|
48
53
|
}
|
|
49
|
-
|
|
54
|
+
: {}),
|
|
50
55
|
metadata: {
|
|
51
56
|
...update.metadata,
|
|
52
|
-
couponCode: newParams.couponCode
|
|
57
|
+
couponCode: newParams.couponCode,
|
|
53
58
|
},
|
|
54
59
|
providerMetadata: {
|
|
55
60
|
...update.providerMetadata,
|
|
56
|
-
couponCode: newParams.couponCode
|
|
57
|
-
}
|
|
61
|
+
couponCode: newParams.couponCode,
|
|
62
|
+
},
|
|
58
63
|
};
|
|
59
64
|
}
|
|
60
65
|
if (result.err && result.val.code !== PROBLEM_APPLICABLE_NOT_FOUND) {
|
|
61
66
|
return result;
|
|
62
67
|
}
|
|
63
|
-
}
|
|
68
|
+
}
|
|
69
|
+
else if (oldReservationInvoice.discountIds.length) {
|
|
64
70
|
// No discounts, so we disconnect all of them
|
|
65
71
|
update = {
|
|
66
72
|
discounts: {
|
|
67
|
-
disconnect: oldReservationInvoice.discountIds.map((id)=>({
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
73
|
+
disconnect: oldReservationInvoice.discountIds.map((id) => ({
|
|
74
|
+
id,
|
|
75
|
+
})),
|
|
76
|
+
},
|
|
71
77
|
};
|
|
72
78
|
}
|
|
73
79
|
}
|
|
74
80
|
let updated = await wrapInResult(biller.updateInvoice(oldReservationInvoice.id, update));
|
|
75
81
|
// If the invoice was locked due to pending status and we're more than 1 minute old, we unlock it
|
|
76
82
|
if (updated.err && updated.val.code === 'invoice_pending') {
|
|
77
|
-
if (oldReservationInvoice.lockedAt &&
|
|
83
|
+
if ((oldReservationInvoice.lockedAt &&
|
|
84
|
+
isAfter(oldReservationInvoice.lockedAt, subMinutes(new Date(), 1))) ||
|
|
85
|
+
!oldReservationInvoice.lockedAt) {
|
|
78
86
|
updated = await wrapInResult(biller.updateInvoice(oldReservationInvoice.id, {
|
|
79
87
|
...update,
|
|
80
88
|
locked: false,
|
|
81
89
|
lockedAt: null,
|
|
82
90
|
lockReason: null,
|
|
83
91
|
unlockAt: null,
|
|
84
|
-
status: 'draft'
|
|
92
|
+
status: 'draft',
|
|
85
93
|
}));
|
|
86
94
|
}
|
|
87
95
|
}
|
|
@@ -90,7 +98,7 @@ export const updateReservationInvoiceIfNeeded = async (oldReservationInvoice, ne
|
|
|
90
98
|
}
|
|
91
99
|
return new Ok(updated.val);
|
|
92
100
|
};
|
|
93
|
-
export const createReservationInvoice = async ({ invoiceId, couponCode, plan, mileagePackage, referralCode, reservationId, paymentIntentId, freeReservation, freeReservationReason, analytics, vehicle, payer, subscribingUser, fullBooking })=>{
|
|
101
|
+
export const createReservationInvoice = async ({ invoiceId, couponCode, plan, mileagePackage, referralCode, reservationId, paymentIntentId, freeReservation, freeReservationReason, analytics, vehicle, payer, subscribingUser, fullBooking, }) => {
|
|
94
102
|
if (freeReservation && !fullBooking) {
|
|
95
103
|
// It's a free reservation, so we don't need to add a coupon code
|
|
96
104
|
return await wrapInResult(biller.createInvoice(getInvoiceCreateDetails({
|
|
@@ -102,17 +110,21 @@ export const createReservationInvoice = async ({ invoiceId, couponCode, plan, mi
|
|
|
102
110
|
freeReservation,
|
|
103
111
|
freeReservationReason,
|
|
104
112
|
analytics,
|
|
105
|
-
reservationId
|
|
113
|
+
reservationId,
|
|
106
114
|
})));
|
|
107
115
|
}
|
|
108
116
|
let finalCouponCode = couponCode;
|
|
109
117
|
// If we don't have a reservation coupon ID, we apply the referral discount if any
|
|
110
|
-
const referral = referralCode &&
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
118
|
+
const referral = referralCode &&
|
|
119
|
+
(await prisma.referral.findUnique({
|
|
120
|
+
where: {
|
|
121
|
+
id: referralCode,
|
|
122
|
+
},
|
|
123
|
+
}));
|
|
124
|
+
if (!finalCouponCode &&
|
|
125
|
+
referral &&
|
|
126
|
+
referral.discountToReceiverCouponId &&
|
|
127
|
+
referral.discountToReceiverCouponApplicationName === 'reservationFee') {
|
|
116
128
|
const referralCoupon = await loadCoupon(referral.discountToReceiverCouponId);
|
|
117
129
|
if (referralCoupon) {
|
|
118
130
|
finalCouponCode = referralCoupon.code;
|
|
@@ -131,8 +143,8 @@ export const createReservationInvoice = async ({ invoiceId, couponCode, plan, mi
|
|
|
131
143
|
freeReservation,
|
|
132
144
|
freeReservationReason,
|
|
133
145
|
analytics,
|
|
134
|
-
reservationId
|
|
135
|
-
})
|
|
146
|
+
reservationId,
|
|
147
|
+
}),
|
|
136
148
|
};
|
|
137
149
|
if (fullBooking) {
|
|
138
150
|
invoiceCreateDetails.subscriptionPurpose = PURPOSE_FULL_BOOKING;
|
|
@@ -144,32 +156,31 @@ export const createReservationInvoice = async ({ invoiceId, couponCode, plan, mi
|
|
|
144
156
|
{
|
|
145
157
|
amount: vehiclePrice,
|
|
146
158
|
chargingFor: INVOICE_LINE_CYCLE,
|
|
147
|
-
description: `First payment for ${vehicleName(vehicle)}
|
|
159
|
+
description: `First payment for ${vehicleName(vehicle)}`,
|
|
148
160
|
},
|
|
149
161
|
{
|
|
150
162
|
amount: vehiclePrice * config.taxRate,
|
|
151
163
|
chargingFor: INVOICE_LINE_OTHER,
|
|
152
|
-
description: `Processing fee for ${vehicleName(vehicle)}
|
|
164
|
+
description: `Processing fee for ${vehicleName(vehicle)}`,
|
|
153
165
|
},
|
|
154
166
|
{
|
|
155
167
|
amount: vehiclePrice,
|
|
156
168
|
description: `Deposit for ${vehicleName(vehicle)}`,
|
|
157
|
-
chargingFor: INVOICE_LINE_DEPOSIT
|
|
158
|
-
}
|
|
169
|
+
chargingFor: INVOICE_LINE_DEPOSIT,
|
|
170
|
+
},
|
|
159
171
|
];
|
|
160
|
-
}
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
161
174
|
invoiceCreateDetails.lines = [
|
|
162
175
|
{
|
|
163
176
|
amount: reservationAmount,
|
|
164
177
|
description: `Reservation fee for ${vehicleName(vehicle)}`,
|
|
165
|
-
chargingFor: INVOICE_LINE_RESERVATION_FEE
|
|
166
|
-
}
|
|
178
|
+
chargingFor: INVOICE_LINE_RESERVATION_FEE,
|
|
179
|
+
},
|
|
167
180
|
];
|
|
168
181
|
}
|
|
169
182
|
if (finalCouponCode) {
|
|
170
|
-
log.debug({
|
|
171
|
-
finalCouponCode
|
|
172
|
-
}, 'Applying coupon code to invoice');
|
|
183
|
+
log.debug({ finalCouponCode }, 'Applying coupon code to invoice');
|
|
173
184
|
const withCoupon = await coupons.applyCouponToUnsavedInvoice(finalCouponCode, invoiceCreateDetails, 'reservationFee', {
|
|
174
185
|
subscriptionPlans: plan,
|
|
175
186
|
subscriptionMileagePackages: mileagePackage,
|
|
@@ -177,25 +188,24 @@ export const createReservationInvoice = async ({ invoiceId, couponCode, plan, mi
|
|
|
177
188
|
vehicleMake: vehicle.make,
|
|
178
189
|
userId: subscribingUser.id,
|
|
179
190
|
businessId: payer.object === 'business' ? payer.id : undefined,
|
|
180
|
-
vehicleType: vehicle.type
|
|
191
|
+
vehicleType: vehicle.type,
|
|
181
192
|
});
|
|
182
|
-
if (withCoupon.err &&
|
|
193
|
+
if (withCoupon.err &&
|
|
194
|
+
withCoupon.val.code !== PROBLEM_APPLICABLE_NOT_FOUND) {
|
|
183
195
|
return withCoupon;
|
|
184
196
|
}
|
|
185
|
-
log.debug({
|
|
186
|
-
couponUpdates: withCoupon.val
|
|
187
|
-
}, 'Coupon applied to invoice');
|
|
197
|
+
log.debug({ couponUpdates: withCoupon.val }, 'Coupon applied to invoice');
|
|
188
198
|
if (withCoupon.ok) {
|
|
189
199
|
invoiceCreateDetails = {
|
|
190
200
|
...withCoupon.val,
|
|
191
201
|
metadata: {
|
|
192
202
|
...withCoupon.val.metadata,
|
|
193
|
-
couponCode: finalCouponCode
|
|
203
|
+
couponCode: finalCouponCode,
|
|
194
204
|
},
|
|
195
205
|
providerMetadata: {
|
|
196
206
|
...withCoupon.val.providerMetadata,
|
|
197
|
-
couponCode: finalCouponCode
|
|
198
|
-
}
|
|
207
|
+
couponCode: finalCouponCode,
|
|
208
|
+
},
|
|
199
209
|
};
|
|
200
210
|
}
|
|
201
211
|
}
|
|
@@ -207,7 +217,9 @@ export const createReservationInvoice = async ({ invoiceId, couponCode, plan, mi
|
|
|
207
217
|
if (paymentIntentResult.err) {
|
|
208
218
|
return new Err(makeProblem(PROBLEM_EXTERNAL, 'Payment intent not found'));
|
|
209
219
|
}
|
|
210
|
-
if (paymentIntentResult.val.amount !==
|
|
220
|
+
if (paymentIntentResult.val.amount !==
|
|
221
|
+
currency(biller.getCorrectedInvoiceData(invoiceCreateDetails).total)
|
|
222
|
+
.intValue) {
|
|
211
223
|
return new Err(makeProblem(PROBLEM_EXTERNAL, 'Payment intent amount does not match invoice amount'));
|
|
212
224
|
}
|
|
213
225
|
}
|
|
@@ -215,15 +227,15 @@ export const createReservationInvoice = async ({ invoiceId, couponCode, plan, mi
|
|
|
215
227
|
...invoiceCreateDetails,
|
|
216
228
|
providerMetadata: {
|
|
217
229
|
...invoiceCreateDetails.providerMetadata,
|
|
218
|
-
invoiceId: invoiceCreateDetails.id
|
|
219
|
-
}
|
|
230
|
+
invoiceId: invoiceCreateDetails.id,
|
|
231
|
+
},
|
|
220
232
|
}));
|
|
221
233
|
if (result.err) {
|
|
222
234
|
return result;
|
|
223
235
|
}
|
|
224
236
|
return new Ok(result.val);
|
|
225
237
|
};
|
|
226
|
-
const getInvoiceCreateDetails = ({ invoiceId, payer, date, reservationDiscountId, vehicle, plan, mileagePackage, couponCode, paymentIntentId, freeReservation, freeReservationReason, analytics, reservationId })=>{
|
|
238
|
+
const getInvoiceCreateDetails = ({ invoiceId, payer, date, reservationDiscountId, vehicle, plan, mileagePackage, couponCode, paymentIntentId, freeReservation, freeReservationReason, analytics, reservationId, }) => {
|
|
227
239
|
return {
|
|
228
240
|
id: invoiceId || generateId('Invoice'),
|
|
229
241
|
taxPercentage: 0,
|
|
@@ -239,13 +251,15 @@ const getInvoiceCreateDetails = ({ invoiceId, payer, date, reservationDiscountId
|
|
|
239
251
|
description: 'Reservation fee for a FLUX subscription',
|
|
240
252
|
footer: `Invoice for a FLUX subscription reservation. Due by ${format(date ?? new Date())}`,
|
|
241
253
|
invoiceUrl: `${config.appUrl}/invoice-preview/${invoiceId}`,
|
|
242
|
-
...reservationDiscountId
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
254
|
+
...(reservationDiscountId
|
|
255
|
+
? {
|
|
256
|
+
discounts: {
|
|
257
|
+
connect: {
|
|
258
|
+
id: reservationDiscountId,
|
|
259
|
+
},
|
|
260
|
+
},
|
|
247
261
|
}
|
|
248
|
-
|
|
262
|
+
: {}),
|
|
249
263
|
lines: [],
|
|
250
264
|
subscriptionDetails: {
|
|
251
265
|
vehicleId: vehicle.id,
|
|
@@ -254,7 +268,7 @@ const getInvoiceCreateDetails = ({ invoiceId, payer, date, reservationDiscountId
|
|
|
254
268
|
variant: vehicle.variant,
|
|
255
269
|
year: vehicle.year,
|
|
256
270
|
plan: plan,
|
|
257
|
-
mileagePackage: mileagePackage
|
|
271
|
+
mileagePackage: mileagePackage,
|
|
258
272
|
},
|
|
259
273
|
// Legacy field:
|
|
260
274
|
stripePaymentIntentId: paymentIntentId,
|
|
@@ -264,18 +278,14 @@ const getInvoiceCreateDetails = ({ invoiceId, payer, date, reservationDiscountId
|
|
|
264
278
|
mileagePackage,
|
|
265
279
|
vehicleId: vehicle.id,
|
|
266
280
|
vehicleName: vehicleName(vehicle),
|
|
267
|
-
...reservationId ? {
|
|
268
|
-
|
|
269
|
-
} : {},
|
|
270
|
-
...couponCode ? {
|
|
271
|
-
couponCode
|
|
272
|
-
} : {}
|
|
281
|
+
...(reservationId ? { reservationId } : {}),
|
|
282
|
+
...(couponCode ? { couponCode } : {}),
|
|
273
283
|
},
|
|
274
284
|
autoRetry: {
|
|
275
285
|
enabled: false,
|
|
276
286
|
interval: 0,
|
|
277
287
|
maxAttempts: 0,
|
|
278
|
-
attempts: 0
|
|
288
|
+
attempts: 0,
|
|
279
289
|
},
|
|
280
290
|
metadata: {
|
|
281
291
|
purpose: PURPOSE_RESERVATION,
|
|
@@ -284,10 +294,11 @@ const getInvoiceCreateDetails = ({ invoiceId, payer, date, reservationDiscountId
|
|
|
284
294
|
plan,
|
|
285
295
|
mileagePackage,
|
|
286
296
|
couponCode,
|
|
287
|
-
...freeReservation && freeReservationReason
|
|
288
|
-
freeReservationReason
|
|
289
|
-
|
|
290
|
-
analytics
|
|
291
|
-
}
|
|
297
|
+
...(freeReservation && freeReservationReason
|
|
298
|
+
? { freeReservationReason }
|
|
299
|
+
: {}),
|
|
300
|
+
analytics,
|
|
301
|
+
},
|
|
292
302
|
};
|
|
293
303
|
};
|
|
304
|
+
//# sourceMappingURL=invoice.js.map
|
|
@@ -3,18 +3,20 @@ import { makeProblem, PROBLEM_EXTERNAL } from '@driveflux/problem';
|
|
|
3
3
|
import { Err, Ok } from '@driveflux/result';
|
|
4
4
|
import { createScopedLogger } from '../create-logger.js';
|
|
5
5
|
const log = createScopedLogger('reservation:payment-intent-sync');
|
|
6
|
-
export const ensurePaymentIntentIdIsSynced = async (invoice, paymentIntentId)=>{
|
|
6
|
+
export const ensurePaymentIntentIdIsSynced = async (invoice, paymentIntentId) => {
|
|
7
7
|
const stripe = biller.getPaymentProvider('stripe').getStripe();
|
|
8
8
|
try {
|
|
9
9
|
await stripe.paymentIntents.update(paymentIntentId, {
|
|
10
10
|
metadata: {
|
|
11
11
|
...invoice.providerMetadata,
|
|
12
|
-
invoiceId: invoice.id
|
|
13
|
-
}
|
|
12
|
+
invoiceId: invoice.id,
|
|
13
|
+
},
|
|
14
14
|
});
|
|
15
15
|
return new Ok(true);
|
|
16
|
-
}
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
17
18
|
log.error(error, 'Error updating payment intent metadata');
|
|
18
19
|
return new Err(makeProblem(PROBLEM_EXTERNAL, 'Error updating payment intent metadata'));
|
|
19
20
|
}
|
|
20
21
|
};
|
|
22
|
+
//# sourceMappingURL=payment-intent-sync.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@driveflux/api-functions",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.105",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
"./notion": {
|
|
@@ -80,7 +80,7 @@
|
|
|
80
80
|
"@driveflux/db": "4.0.32",
|
|
81
81
|
"@driveflux/email": "7.0.33",
|
|
82
82
|
"@driveflux/email-templates": "1.1.3",
|
|
83
|
-
"@driveflux/engine": "1.0.
|
|
83
|
+
"@driveflux/engine": "1.0.89",
|
|
84
84
|
"@driveflux/fetch": "8.0.0",
|
|
85
85
|
"@driveflux/format-money": "7.0.0",
|
|
86
86
|
"@driveflux/logger": "1.0.1",
|