@shophost/rest-api 2.0.34 → 2.0.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +17 -13
- package/README.md +76 -66
- package/package.json +2 -2
- package/scripts/minify-dist.mjs +45 -0
- package/src/app.js +1 -53
- package/src/app.js.map +1 -1
- package/src/core/auth/auth.schema.js +1 -41
- package/src/core/auth/auth.util.js +1 -44
- package/src/core/auth/better-auth.lib.js +1 -100
- package/src/core/auth/generate-password-hash.util.js +1 -30
- package/src/core/auth/headers.schema.js +1 -22
- package/src/core/auth/user.schema.js +1 -30
- package/src/core/db/__generated__/client/browser.js +1 -18
- package/src/core/db/__generated__/client/client.js +1 -35
- package/src/core/db/__generated__/client/commonInputTypes.js +1 -11
- package/src/core/db/__generated__/client/enums.js +1 -200
- package/src/core/db/__generated__/client/internal/class.js +769 -55
- package/src/core/db/__generated__/client/internal/prismaNamespace.d.ts +2 -2
- package/src/core/db/__generated__/client/internal/prismaNamespace.js +1 -541
- package/src/core/db/__generated__/client/internal/prismaNamespaceBrowser.js +1 -512
- package/src/core/db/__generated__/client/models/Account.d.ts +0 -5
- package/src/core/db/__generated__/client/models/Account.js +1 -2
- package/src/core/db/__generated__/client/models/Address.d.ts +0 -5
- package/src/core/db/__generated__/client/models/Address.js +1 -2
- package/src/core/db/__generated__/client/models/Campaign.d.ts +0 -5
- package/src/core/db/__generated__/client/models/Campaign.js +1 -2
- package/src/core/db/__generated__/client/models/ClosingTimes.d.ts +0 -5
- package/src/core/db/__generated__/client/models/ClosingTimes.js +1 -2
- package/src/core/db/__generated__/client/models/File.d.ts +0 -5
- package/src/core/db/__generated__/client/models/File.js +1 -2
- package/src/core/db/__generated__/client/models/Invitation.d.ts +0 -5
- package/src/core/db/__generated__/client/models/Invitation.js +1 -2
- package/src/core/db/__generated__/client/models/LegalEntity.d.ts +0 -5
- package/src/core/db/__generated__/client/models/LegalEntity.js +1 -2
- package/src/core/db/__generated__/client/models/Manufacturer.d.ts +0 -5
- package/src/core/db/__generated__/client/models/Manufacturer.js +1 -2
- package/src/core/db/__generated__/client/models/ManufacturerTranslation.d.ts +0 -5
- package/src/core/db/__generated__/client/models/ManufacturerTranslation.js +1 -2
- package/src/core/db/__generated__/client/models/Member.d.ts +0 -5
- package/src/core/db/__generated__/client/models/Member.js +1 -2
- package/src/core/db/__generated__/client/models/Modifier.d.ts +0 -5
- package/src/core/db/__generated__/client/models/Modifier.js +1 -2
- package/src/core/db/__generated__/client/models/ModifierGroup.d.ts +0 -5
- package/src/core/db/__generated__/client/models/ModifierGroup.js +1 -2
- package/src/core/db/__generated__/client/models/ModifierGroupTranslation.d.ts +0 -5
- package/src/core/db/__generated__/client/models/ModifierGroupTranslation.js +1 -2
- package/src/core/db/__generated__/client/models/OpeningTimes.d.ts +0 -5
- package/src/core/db/__generated__/client/models/OpeningTimes.js +1 -2
- package/src/core/db/__generated__/client/models/Order.d.ts +0 -5
- package/src/core/db/__generated__/client/models/Order.js +1 -2
- package/src/core/db/__generated__/client/models/OrderItem.d.ts +0 -5
- package/src/core/db/__generated__/client/models/OrderItem.js +1 -2
- package/src/core/db/__generated__/client/models/OrderItemTranslation.d.ts +0 -5
- package/src/core/db/__generated__/client/models/OrderItemTranslation.js +1 -2
- package/src/core/db/__generated__/client/models/Organization.d.ts +0 -5
- package/src/core/db/__generated__/client/models/Organization.js +1 -2
- package/src/core/db/__generated__/client/models/OrganizationConfiguration.d.ts +0 -5
- package/src/core/db/__generated__/client/models/OrganizationConfiguration.js +1 -2
- package/src/core/db/__generated__/client/models/Payment.d.ts +0 -5
- package/src/core/db/__generated__/client/models/Payment.js +1 -2
- package/src/core/db/__generated__/client/models/PaymentSession.d.ts +0 -5
- package/src/core/db/__generated__/client/models/PaymentSession.js +1 -2
- package/src/core/db/__generated__/client/models/Product.d.ts +0 -5
- package/src/core/db/__generated__/client/models/Product.js +1 -2
- package/src/core/db/__generated__/client/models/ProductCategory.d.ts +0 -5
- package/src/core/db/__generated__/client/models/ProductCategory.js +1 -2
- package/src/core/db/__generated__/client/models/ProductCategoryTranslation.d.ts +0 -5
- package/src/core/db/__generated__/client/models/ProductCategoryTranslation.js +1 -2
- package/src/core/db/__generated__/client/models/ProductSnapshot.d.ts +0 -5
- package/src/core/db/__generated__/client/models/ProductSnapshot.js +1 -2
- package/src/core/db/__generated__/client/models/ProductTranslation.d.ts +0 -5
- package/src/core/db/__generated__/client/models/ProductTranslation.js +1 -2
- package/src/core/db/__generated__/client/models/Reservation.d.ts +0 -5
- package/src/core/db/__generated__/client/models/Reservation.js +1 -2
- package/src/core/db/__generated__/client/models/Session.d.ts +0 -5
- package/src/core/db/__generated__/client/models/Session.js +1 -2
- package/src/core/db/__generated__/client/models/ShippingMethod.d.ts +0 -5
- package/src/core/db/__generated__/client/models/ShippingMethod.js +1 -2
- package/src/core/db/__generated__/client/models/ShippingZone.d.ts +0 -5
- package/src/core/db/__generated__/client/models/ShippingZone.js +1 -2
- package/src/core/db/__generated__/client/models/User.d.ts +0 -5
- package/src/core/db/__generated__/client/models/User.js +1 -2
- package/src/core/db/__generated__/client/models/Verification.d.ts +0 -5
- package/src/core/db/__generated__/client/models/Verification.js +1 -2
- package/src/core/db/__generated__/client/models.js +1 -2
- package/src/core/db/index.js +1 -2
- package/src/core/email/components.d.ts +16 -0
- package/src/core/email/components.js +1 -0
- package/src/core/email/components.js.map +1 -0
- package/src/core/exceptions/http-exception.js +1 -9
- package/src/core/hono/hono.js +1 -123
- package/src/core/lib/prisma.d.ts +8 -8
- package/src/core/lib/prisma.js +1 -11
- package/src/core/logging/pino.js +1 -5
- package/src/core/notifications/email.service.js +1 -116
- package/src/core/openapi/openapi.lib.js +1 -26
- package/src/core/types/google-maps.types.js +1 -2
- package/src/core/utils/currency.util.js +1 -11
- package/src/core/utils/env.util.js +1 -8
- package/src/core/utils/object.util.js +1 -39
- package/src/core/utils/translations.util.js +0 -1
- package/src/core/utils/zod.util.js +1 -85
- package/src/db.js +1 -3
- package/src/features/access/access.handler.js +1 -91
- package/src/features/access/access.route.js +1 -220
- package/src/features/access/access.schema.js +1 -108
- package/src/features/access/access.service.js +1 -294
- package/src/features/analytics/analytics.handler.d.ts +2 -0
- package/src/features/analytics/analytics.handler.js +1 -0
- package/src/features/analytics/analytics.handler.js.map +1 -0
- package/src/features/analytics/analytics.route.d.ts +3 -0
- package/src/features/analytics/analytics.route.js +1 -0
- package/src/features/analytics/analytics.route.js.map +1 -0
- package/src/features/analytics/analytics.schema.d.ts +86 -0
- package/src/features/analytics/analytics.schema.js +1 -0
- package/src/features/analytics/analytics.schema.js.map +1 -0
- package/src/features/analytics/analytics.service.d.ts +45 -0
- package/src/features/analytics/analytics.service.js +1 -0
- package/src/features/analytics/analytics.service.js.map +1 -0
- package/src/features/cart/cart.handler.js +1 -17
- package/src/features/cart/cart.route.js +1 -32
- package/src/features/cart/cart.schema.d.ts +1 -1
- package/src/features/cart/cart.schema.js +1 -39
- package/src/features/cart/cart.service.d.ts +1 -1
- package/src/features/cart/cart.service.js +1 -97
- package/src/features/cart/cart.util.js +1 -76
- package/src/features/file/file.handler.js +1 -23
- package/src/features/file/file.route.js +1 -34
- package/src/features/file/file.schema.js +1 -77
- package/src/features/file/file.service.js +1 -66
- package/src/features/health/health.handler.js +1 -10
- package/src/features/health/health.route.js +1 -25
- package/src/features/index.d.ts +1 -0
- package/src/features/index.js +1 -16
- package/src/features/index.js.map +1 -1
- package/src/features/location/location.handler.js +1 -25
- package/src/features/location/location.route.js +1 -56
- package/src/features/location/location.schema.js +1 -50
- package/src/features/location/location.service.js +1 -141
- package/src/features/manufacturer/manufacturer.handler.js +1 -53
- package/src/features/manufacturer/manufacturer.route.js +1 -97
- package/src/features/manufacturer/manufacturer.schema.js +1 -125
- package/src/features/manufacturer/manufacturer.service.js +1 -190
- package/src/features/order/emails/order-confirmation.email.js +1 -229
- package/src/features/order/emails/order-confirmation.email.js.map +1 -1
- package/src/features/order/emails/order-notification.email.js +1 -229
- package/src/features/order/emails/order-notification.email.js.map +1 -1
- package/src/features/order/fulfilment.schema.js +1 -3
- package/src/features/order/order.handler.js +1 -54
- package/src/features/order/order.route.js +1 -111
- package/src/features/order/order.schema.d.ts +4 -4
- package/src/features/order/order.schema.js +1 -158
- package/src/features/order/order.service.d.ts +4 -4
- package/src/features/order/order.service.js +1 -306
- package/src/features/order/recipient.schema.js +1 -38
- package/src/features/organization/legal-entity.schema.js +1 -83
- package/src/features/organization/organization-configuration.schema.js +1 -115
- package/src/features/organization/organization.handler.js +1 -48
- package/src/features/organization/organization.route.js +1 -84
- package/src/features/organization/organization.schema.js +1 -64
- package/src/features/organization/organization.service.js +1 -334
- package/src/features/payment/payment.handler.js +1 -16
- package/src/features/payment/payment.route.js +1 -22
- package/src/features/payment/payment.schema.d.ts +3 -3
- package/src/features/payment/payment.schema.js +1 -46
- package/src/features/payment/payment.service.d.ts +1 -1
- package/src/features/payment/payment.service.js +1 -100
- package/src/features/payment/stripe.service.js +1 -164
- package/src/features/product/product-modifier.schema.js +1 -84
- package/src/features/product/product.handler.js +1 -87
- package/src/features/product/product.route.js +1 -179
- package/src/features/product/product.schema.d.ts +3 -3
- package/src/features/product/product.schema.js +1 -143
- package/src/features/product/product.service.d.ts +2 -2
- package/src/features/product/product.service.js +1 -440
- package/src/features/product-category/product-category.handler.js +1 -59
- package/src/features/product-category/product-category.route.js +1 -139
- package/src/features/product-category/product-category.schema.js +1 -86
- package/src/features/product-category/product-category.service.js +1 -220
- package/src/features/reservation/emails/reservation-cancellation.email.js +1 -82
- package/src/features/reservation/emails/reservation-cancellation.email.js.map +1 -1
- package/src/features/reservation/emails/reservation-confirmation.email.js +1 -82
- package/src/features/reservation/emails/reservation-confirmation.email.js.map +1 -1
- package/src/features/reservation/emails/reservation-notification.email.js +1 -93
- package/src/features/reservation/emails/reservation-notification.email.js.map +1 -1
- package/src/features/reservation/reservation.handler.js +1 -65
- package/src/features/reservation/reservation.route.js +1 -167
- package/src/features/reservation/reservation.schema.d.ts +1 -1
- package/src/features/reservation/reservation.schema.js +1 -51
- package/src/features/reservation/reservation.service.js +1 -231
- package/src/features/shipping/shipping.handler.js +1 -32
- package/src/features/shipping/shipping.route.js +1 -51
- package/src/features/shipping/shipping.service.js +1 -96
- package/src/features/shipping-method/shipping-method.handler.js +1 -60
- package/src/features/shipping-method/shipping-method.route.js +1 -144
- package/src/features/shipping-method/shipping-method.schema.js +1 -48
- package/src/features/shipping-method/shipping-method.service.js +1 -229
- package/src/features/shipping-method/shipping-zone.schema.js +1 -31
- package/src/features/webhook/webhook.handler.js +1 -50
- package/src/features/webhook/webhook.route.js +1 -33
- package/src/index.js +1 -6
- package/src/integrations/next.js +1 -82
- package/src/schemas/address.schema.js +1 -112
- package/src/schemas/currency.schema.js +1 -118
- package/src/schemas/error.schema.js +1 -12
- package/src/schemas/index.d.ts +1 -0
- package/src/schemas/index.js +1 -29
- package/src/schemas/index.js.map +1 -1
- package/src/schemas/locales.schema.js +1 -238
- package/src/schemas/number.schema.js +1 -29
- package/src/schemas/pagination.schema.js +1 -54
- package/src/schemas/params.schema.js +1 -20
- package/src/schemas/queries.schema.js +1 -6
- package/src/test/global-setup.js +1 -37
- package/src/test/integration/api-fixtures.js +1 -160
- package/src/test/integration/seed.js +1 -368
- package/src/test/integration/test-helpers.d.ts +2 -0
- package/src/test/integration/test-helpers.js +1 -154
- package/src/test/integration/test-helpers.js.map +1 -1
- package/src/test/setup-test-env.js +1 -7
|
@@ -1,334 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { z } from "@hono/zod-openapi";
|
|
3
|
-
import { HttpException } from "../../core/exceptions/http-exception";
|
|
4
|
-
import { OrganizationSchema, PaginationMetaSchema, } from "../../schemas";
|
|
5
|
-
import { LocationService } from "../location/location.service";
|
|
6
|
-
class OrganizationService {
|
|
7
|
-
constructor(prisma, googleMapsApiKey) {
|
|
8
|
-
this.prisma = prisma;
|
|
9
|
-
this.convertToTimeString = (date) => {
|
|
10
|
-
if (!date)
|
|
11
|
-
return "";
|
|
12
|
-
return date.toLocaleTimeString("en-US", {
|
|
13
|
-
hour: "2-digit",
|
|
14
|
-
minute: "2-digit",
|
|
15
|
-
hour12: false,
|
|
16
|
-
timeZone: "UTC",
|
|
17
|
-
});
|
|
18
|
-
};
|
|
19
|
-
this.locationService = new LocationService(googleMapsApiKey);
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Get a paginated list of organizations
|
|
23
|
-
*/
|
|
24
|
-
getOrganizations(userId, query) {
|
|
25
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
-
const { page, limit } = query;
|
|
27
|
-
// Fetch organizations with pagination
|
|
28
|
-
const [list, meta] = yield this.prisma.organization
|
|
29
|
-
.paginate({
|
|
30
|
-
orderBy: {
|
|
31
|
-
createdAt: "desc",
|
|
32
|
-
},
|
|
33
|
-
where: {
|
|
34
|
-
members: {
|
|
35
|
-
some: {
|
|
36
|
-
userId: userId,
|
|
37
|
-
},
|
|
38
|
-
},
|
|
39
|
-
},
|
|
40
|
-
include: {
|
|
41
|
-
address: true,
|
|
42
|
-
configuration: true,
|
|
43
|
-
logoFile: true,
|
|
44
|
-
},
|
|
45
|
-
})
|
|
46
|
-
.withPages({
|
|
47
|
-
page,
|
|
48
|
-
limit,
|
|
49
|
-
});
|
|
50
|
-
return {
|
|
51
|
-
meta: PaginationMetaSchema.parse(meta),
|
|
52
|
-
list: z.array(OrganizationSchema).parse(list),
|
|
53
|
-
};
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
formatDateScheduleToTimeString(times) {
|
|
57
|
-
if (!times)
|
|
58
|
-
return null;
|
|
59
|
-
const weekdays = [
|
|
60
|
-
"monday",
|
|
61
|
-
"tuesday",
|
|
62
|
-
"wednesday",
|
|
63
|
-
"thursday",
|
|
64
|
-
"friday",
|
|
65
|
-
"saturday",
|
|
66
|
-
"sunday",
|
|
67
|
-
];
|
|
68
|
-
return weekdays.reduce((acc, day) => {
|
|
69
|
-
acc[day] = this.convertToTimeString(times[day]);
|
|
70
|
-
return acc;
|
|
71
|
-
}, {});
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Get a specific organization by ID
|
|
75
|
-
*/
|
|
76
|
-
getOrganization(organizationId) {
|
|
77
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
78
|
-
// Check if the organization exists in the database
|
|
79
|
-
const organization = yield this.prisma.organization.findUnique({
|
|
80
|
-
where: { id: organizationId, deletedAt: null },
|
|
81
|
-
include: {
|
|
82
|
-
address: true,
|
|
83
|
-
configuration: {
|
|
84
|
-
include: {
|
|
85
|
-
openingTimes: true,
|
|
86
|
-
closingTimes: true,
|
|
87
|
-
},
|
|
88
|
-
},
|
|
89
|
-
logoFile: true,
|
|
90
|
-
},
|
|
91
|
-
});
|
|
92
|
-
if (!organization) {
|
|
93
|
-
throw new HttpException(404, "Organization not found");
|
|
94
|
-
}
|
|
95
|
-
const isOpen = (() => {
|
|
96
|
-
if (!organization.configuration.isAcceptingOrders)
|
|
97
|
-
return false;
|
|
98
|
-
if (!organization.configuration.openingTimes ||
|
|
99
|
-
!organization.configuration.closingTimes)
|
|
100
|
-
return false;
|
|
101
|
-
const warsawDate = new Date(new Date().toLocaleString("en-US", { timeZone: "Europe/Warsaw" }));
|
|
102
|
-
const currentDay = warsawDate
|
|
103
|
-
.toLocaleDateString("en-US", {
|
|
104
|
-
weekday: "long",
|
|
105
|
-
})
|
|
106
|
-
.toLowerCase();
|
|
107
|
-
const currentTime = warsawDate.toLocaleTimeString("en-US", {
|
|
108
|
-
hour: "2-digit",
|
|
109
|
-
minute: "2-digit",
|
|
110
|
-
hour12: false,
|
|
111
|
-
timeZone: "Europe/Warsaw",
|
|
112
|
-
});
|
|
113
|
-
const openingTime = organization.configuration.openingTimes[currentDay];
|
|
114
|
-
const closingTime = organization.configuration.closingTimes[currentDay];
|
|
115
|
-
if (!openingTime || !closingTime)
|
|
116
|
-
return false;
|
|
117
|
-
const openingTimeStr = this.convertToTimeString(openingTime);
|
|
118
|
-
const closingTimeStr = this.convertToTimeString(closingTime);
|
|
119
|
-
return currentTime >= openingTimeStr && currentTime <= closingTimeStr;
|
|
120
|
-
})();
|
|
121
|
-
return OrganizationSchema.parse(Object.assign(Object.assign({}, organization), { configuration: Object.assign(Object.assign({}, organization.configuration), { isOpen, openingTimes: this.formatDateScheduleToTimeString(organization.configuration.openingTimes), closingTimes: this.formatDateScheduleToTimeString(organization.configuration.closingTimes) }) }));
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Create a new organization
|
|
126
|
-
*/
|
|
127
|
-
createOrganization(userId, body) {
|
|
128
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
129
|
-
const placeDetails = yield this.locationService.getPlaceDetails(body.address.placeId);
|
|
130
|
-
// Create organization
|
|
131
|
-
const organization = yield this.prisma.organization.create({
|
|
132
|
-
data: Object.assign({ name: body.name, phone: body.phone, email: body.email, address: {
|
|
133
|
-
create: Object.assign(Object.assign({}, body.address), { latitude: placeDetails.latitude, longitude: placeDetails.longitude, createdBy: userId }),
|
|
134
|
-
}, configuration: {
|
|
135
|
-
create: {
|
|
136
|
-
countriesShipping: ["us"],
|
|
137
|
-
createdBy: userId,
|
|
138
|
-
enableHostCheckout: false,
|
|
139
|
-
enableHostTracking: false,
|
|
140
|
-
openingTimes: {
|
|
141
|
-
create: {
|
|
142
|
-
monday: null,
|
|
143
|
-
tuesday: null,
|
|
144
|
-
wednesday: null,
|
|
145
|
-
thursday: null,
|
|
146
|
-
friday: null,
|
|
147
|
-
saturday: null,
|
|
148
|
-
sunday: null,
|
|
149
|
-
},
|
|
150
|
-
},
|
|
151
|
-
closingTimes: {
|
|
152
|
-
create: {
|
|
153
|
-
monday: null,
|
|
154
|
-
tuesday: null,
|
|
155
|
-
wednesday: null,
|
|
156
|
-
thursday: null,
|
|
157
|
-
friday: null,
|
|
158
|
-
saturday: null,
|
|
159
|
-
},
|
|
160
|
-
},
|
|
161
|
-
},
|
|
162
|
-
}, members: {
|
|
163
|
-
create: {
|
|
164
|
-
user: {
|
|
165
|
-
connect: {
|
|
166
|
-
id: userId,
|
|
167
|
-
},
|
|
168
|
-
},
|
|
169
|
-
role: "owner",
|
|
170
|
-
},
|
|
171
|
-
}, createdBy: userId }, (body.logoId ? { logoFile: { connect: { id: body.logoId } } } : {})),
|
|
172
|
-
include: {
|
|
173
|
-
address: true,
|
|
174
|
-
configuration: {
|
|
175
|
-
include: {
|
|
176
|
-
openingTimes: true,
|
|
177
|
-
closingTimes: true,
|
|
178
|
-
},
|
|
179
|
-
},
|
|
180
|
-
logoFile: true,
|
|
181
|
-
},
|
|
182
|
-
});
|
|
183
|
-
return OrganizationSchema.parse(organization);
|
|
184
|
-
});
|
|
185
|
-
}
|
|
186
|
-
/**
|
|
187
|
-
* Update an existing organization
|
|
188
|
-
*/
|
|
189
|
-
updateOrganization(organizationId, userId, body) {
|
|
190
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
191
|
-
// Check if the organization exists
|
|
192
|
-
const organization = yield this.prisma.organization.findUnique({
|
|
193
|
-
where: { id: organizationId, deletedAt: null },
|
|
194
|
-
});
|
|
195
|
-
if (!organization) {
|
|
196
|
-
// Throw 404 error if organization not found
|
|
197
|
-
throw new HttpException(404, "Organization not found");
|
|
198
|
-
}
|
|
199
|
-
const placeDetails = body.address
|
|
200
|
-
? yield this.locationService.getPlaceDetails(body.address.placeId)
|
|
201
|
-
: undefined;
|
|
202
|
-
const convertToDate = (timeString) => {
|
|
203
|
-
if (!timeString)
|
|
204
|
-
return null;
|
|
205
|
-
const [hours, minutes] = timeString.split(":").map(Number);
|
|
206
|
-
// Create date in UTC
|
|
207
|
-
const date = new Date();
|
|
208
|
-
date.setUTCHours(hours);
|
|
209
|
-
date.setUTCMinutes(minutes);
|
|
210
|
-
date.setUTCSeconds(0);
|
|
211
|
-
date.setUTCMilliseconds(0);
|
|
212
|
-
return date;
|
|
213
|
-
};
|
|
214
|
-
const updatedOrganization = yield this.prisma.organization.update({
|
|
215
|
-
where: { id: organizationId },
|
|
216
|
-
data: Object.assign(Object.assign(Object.assign(Object.assign({ name: body.name, phone: body.phone, email: body.email }, (body.logoId ? { logoFile: { connect: { id: body.logoId } } } : {})), { address: body.address
|
|
217
|
-
? {
|
|
218
|
-
update: Object.assign(Object.assign({}, body.address), { latitude: placeDetails.latitude, longitude: placeDetails.longitude, updatedBy: userId }),
|
|
219
|
-
}
|
|
220
|
-
: undefined }), (body.configuration
|
|
221
|
-
? {
|
|
222
|
-
configuration: {
|
|
223
|
-
update: {
|
|
224
|
-
countriesShipping: body.configuration.countriesShipping,
|
|
225
|
-
enableHostCheckout: body.configuration.enableHostCheckout,
|
|
226
|
-
enableHostTracking: body.configuration.enableHostTracking,
|
|
227
|
-
defaultLocale: body.configuration.defaultLocale,
|
|
228
|
-
supportedLocales: body.configuration.supportedLocales,
|
|
229
|
-
defaultCurrency: body.configuration.defaultCurrency,
|
|
230
|
-
updatedBy: userId,
|
|
231
|
-
isAcceptingOrders: body.configuration.isAcceptingOrders,
|
|
232
|
-
openingTimes: body.configuration.openingTimes
|
|
233
|
-
? {
|
|
234
|
-
update: {
|
|
235
|
-
data: {
|
|
236
|
-
monday: body.configuration.openingTimes.monday
|
|
237
|
-
? convertToDate(body.configuration.openingTimes.monday)
|
|
238
|
-
: null,
|
|
239
|
-
tuesday: body.configuration.openingTimes.tuesday
|
|
240
|
-
? convertToDate(body.configuration.openingTimes.tuesday)
|
|
241
|
-
: null,
|
|
242
|
-
wednesday: body.configuration.openingTimes.wednesday
|
|
243
|
-
? convertToDate(body.configuration.openingTimes.wednesday)
|
|
244
|
-
: null,
|
|
245
|
-
thursday: body.configuration.openingTimes.thursday
|
|
246
|
-
? convertToDate(body.configuration.openingTimes.thursday)
|
|
247
|
-
: null,
|
|
248
|
-
friday: body.configuration.openingTimes.friday
|
|
249
|
-
? convertToDate(body.configuration.openingTimes.friday)
|
|
250
|
-
: null,
|
|
251
|
-
saturday: body.configuration.openingTimes.saturday
|
|
252
|
-
? convertToDate(body.configuration.openingTimes.saturday)
|
|
253
|
-
: null,
|
|
254
|
-
sunday: body.configuration.openingTimes.sunday
|
|
255
|
-
? convertToDate(body.configuration.openingTimes.sunday)
|
|
256
|
-
: null,
|
|
257
|
-
},
|
|
258
|
-
},
|
|
259
|
-
}
|
|
260
|
-
: undefined,
|
|
261
|
-
closingTimes: body.configuration.closingTimes
|
|
262
|
-
? {
|
|
263
|
-
update: {
|
|
264
|
-
data: {
|
|
265
|
-
monday: body.configuration.closingTimes.monday
|
|
266
|
-
? convertToDate(body.configuration.closingTimes.monday)
|
|
267
|
-
: null,
|
|
268
|
-
tuesday: body.configuration.closingTimes.tuesday
|
|
269
|
-
? convertToDate(body.configuration.closingTimes.tuesday)
|
|
270
|
-
: null,
|
|
271
|
-
wednesday: body.configuration.closingTimes.wednesday
|
|
272
|
-
? convertToDate(body.configuration.closingTimes.wednesday)
|
|
273
|
-
: null,
|
|
274
|
-
thursday: body.configuration.closingTimes.thursday
|
|
275
|
-
? convertToDate(body.configuration.closingTimes.thursday)
|
|
276
|
-
: null,
|
|
277
|
-
friday: body.configuration.closingTimes.friday
|
|
278
|
-
? convertToDate(body.configuration.closingTimes.friday)
|
|
279
|
-
: null,
|
|
280
|
-
saturday: body.configuration.closingTimes.saturday
|
|
281
|
-
? convertToDate(body.configuration.closingTimes.saturday)
|
|
282
|
-
: null,
|
|
283
|
-
sunday: body.configuration.closingTimes.sunday
|
|
284
|
-
? convertToDate(body.configuration.closingTimes.sunday)
|
|
285
|
-
: null,
|
|
286
|
-
},
|
|
287
|
-
},
|
|
288
|
-
}
|
|
289
|
-
: undefined,
|
|
290
|
-
},
|
|
291
|
-
},
|
|
292
|
-
}
|
|
293
|
-
: undefined)), { updatedBy: userId }),
|
|
294
|
-
include: {
|
|
295
|
-
address: true,
|
|
296
|
-
logoFile: true,
|
|
297
|
-
configuration: {
|
|
298
|
-
include: {
|
|
299
|
-
openingTimes: true,
|
|
300
|
-
closingTimes: true,
|
|
301
|
-
},
|
|
302
|
-
},
|
|
303
|
-
},
|
|
304
|
-
});
|
|
305
|
-
return OrganizationSchema.parse(Object.assign(Object.assign({}, updatedOrganization), { configuration: Object.assign(Object.assign({}, updatedOrganization.configuration), { openingTimes: this.formatDateScheduleToTimeString(updatedOrganization.configuration.openingTimes), closingTimes: this.formatDateScheduleToTimeString(updatedOrganization.configuration.closingTimes) }) }));
|
|
306
|
-
});
|
|
307
|
-
}
|
|
308
|
-
/**
|
|
309
|
-
* Delete an organization (soft delete)
|
|
310
|
-
*/
|
|
311
|
-
deleteOrganization(organizationId, userId) {
|
|
312
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
313
|
-
// Check if the organization exists
|
|
314
|
-
const organization = yield this.prisma.organization.findUnique({
|
|
315
|
-
where: { id: organizationId },
|
|
316
|
-
});
|
|
317
|
-
// Throw 404 error if organization not found
|
|
318
|
-
if (!organization) {
|
|
319
|
-
throw new HttpException(404, "Organization not found");
|
|
320
|
-
}
|
|
321
|
-
// Soft delete the organization
|
|
322
|
-
yield this.prisma.organization.update({
|
|
323
|
-
where: { id: organizationId },
|
|
324
|
-
data: {
|
|
325
|
-
deletedAt: new Date(),
|
|
326
|
-
deletedBy: userId,
|
|
327
|
-
},
|
|
328
|
-
});
|
|
329
|
-
return;
|
|
330
|
-
});
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
export { OrganizationService };
|
|
334
|
-
//# sourceMappingURL=organization.service.js.map
|
|
1
|
+
import{__awaiter as c}from"tslib";import{z as f}from"@hono/zod-openapi";import{HttpException as m}from"../../core/exceptions/http-exception";import{OrganizationSchema as g,PaginationMetaSchema as p}from"../../schemas";import{LocationService as T}from"../location/location.service";class h{constructor(e,n){this.prisma=e,this.convertToTimeString=i=>i?i.toLocaleTimeString("en-US",{hour:"2-digit",minute:"2-digit",hour12:!1,timeZone:"UTC"}):"",this.locationService=new T(n)}getOrganizations(e,n){return c(this,void 0,void 0,function*(){const{page:i,limit:a}=n,[o,t]=yield this.prisma.organization.paginate({orderBy:{createdAt:"desc"},where:{members:{some:{userId:e}}},include:{address:!0,configuration:!0,logoFile:!0}}).withPages({page:i,limit:a});return{meta:p.parse(t),list:f.array(g).parse(o)}})}formatDateScheduleToTimeString(e){return e?["monday","tuesday","wednesday","thursday","friday","saturday","sunday"].reduce((i,a)=>(i[a]=this.convertToTimeString(e[a]),i),{}):null}getOrganization(e){return c(this,void 0,void 0,function*(){const n=yield this.prisma.organization.findUnique({where:{id:e,deletedAt:null},include:{address:!0,configuration:{include:{openingTimes:!0,closingTimes:!0}},logoFile:!0}});if(!n)throw new m(404,"Organization not found");const i=(()=>{if(!n.configuration.isAcceptingOrders||!n.configuration.openingTimes||!n.configuration.closingTimes)return!1;const a=new Date(new Date().toLocaleString("en-US",{timeZone:"Europe/Warsaw"})),o=a.toLocaleDateString("en-US",{weekday:"long"}).toLowerCase(),t=a.toLocaleTimeString("en-US",{hour:"2-digit",minute:"2-digit",hour12:!1,timeZone:"Europe/Warsaw"}),s=n.configuration.openingTimes[o],r=n.configuration.closingTimes[o];if(!s||!r)return!1;const l=this.convertToTimeString(s),d=this.convertToTimeString(r);return t>=l&&t<=d})();return g.parse(Object.assign(Object.assign({},n),{configuration:Object.assign(Object.assign({},n.configuration),{isOpen:i,openingTimes:this.formatDateScheduleToTimeString(n.configuration.openingTimes),closingTimes:this.formatDateScheduleToTimeString(n.configuration.closingTimes)})}))})}createOrganization(e,n){return c(this,void 0,void 0,function*(){const i=yield this.locationService.getPlaceDetails(n.address.placeId),a=yield this.prisma.organization.create({data:Object.assign({name:n.name,phone:n.phone,email:n.email,address:{create:Object.assign(Object.assign({},n.address),{latitude:i.latitude,longitude:i.longitude,createdBy:e})},configuration:{create:{countriesShipping:["us"],createdBy:e,enableHostCheckout:!1,enableHostTracking:!1,openingTimes:{create:{monday:null,tuesday:null,wednesday:null,thursday:null,friday:null,saturday:null,sunday:null}},closingTimes:{create:{monday:null,tuesday:null,wednesday:null,thursday:null,friday:null,saturday:null}}}},members:{create:{user:{connect:{id:e}},role:"owner"}},createdBy:e},n.logoId?{logoFile:{connect:{id:n.logoId}}}:{}),include:{address:!0,configuration:{include:{openingTimes:!0,closingTimes:!0}},logoFile:!0}});return g.parse(a)})}updateOrganization(e,n,i){return c(this,void 0,void 0,function*(){if(!(yield this.prisma.organization.findUnique({where:{id:e,deletedAt:null}})))throw new m(404,"Organization not found");const o=i.address?yield this.locationService.getPlaceDetails(i.address.placeId):void 0,t=r=>{if(!r)return null;const[l,d]=r.split(":").map(Number),u=new Date;return u.setUTCHours(l),u.setUTCMinutes(d),u.setUTCSeconds(0),u.setUTCMilliseconds(0),u},s=yield this.prisma.organization.update({where:{id:e},data:Object.assign(Object.assign(Object.assign(Object.assign({name:i.name,phone:i.phone,email:i.email},i.logoId?{logoFile:{connect:{id:i.logoId}}}:{}),{address:i.address?{update:Object.assign(Object.assign({},i.address),{latitude:o.latitude,longitude:o.longitude,updatedBy:n})}:void 0}),i.configuration?{configuration:{update:{countriesShipping:i.configuration.countriesShipping,enableHostCheckout:i.configuration.enableHostCheckout,enableHostTracking:i.configuration.enableHostTracking,defaultLocale:i.configuration.defaultLocale,supportedLocales:i.configuration.supportedLocales,defaultCurrency:i.configuration.defaultCurrency,updatedBy:n,isAcceptingOrders:i.configuration.isAcceptingOrders,openingTimes:i.configuration.openingTimes?{update:{data:{monday:i.configuration.openingTimes.monday?t(i.configuration.openingTimes.monday):null,tuesday:i.configuration.openingTimes.tuesday?t(i.configuration.openingTimes.tuesday):null,wednesday:i.configuration.openingTimes.wednesday?t(i.configuration.openingTimes.wednesday):null,thursday:i.configuration.openingTimes.thursday?t(i.configuration.openingTimes.thursday):null,friday:i.configuration.openingTimes.friday?t(i.configuration.openingTimes.friday):null,saturday:i.configuration.openingTimes.saturday?t(i.configuration.openingTimes.saturday):null,sunday:i.configuration.openingTimes.sunday?t(i.configuration.openingTimes.sunday):null}}}:void 0,closingTimes:i.configuration.closingTimes?{update:{data:{monday:i.configuration.closingTimes.monday?t(i.configuration.closingTimes.monday):null,tuesday:i.configuration.closingTimes.tuesday?t(i.configuration.closingTimes.tuesday):null,wednesday:i.configuration.closingTimes.wednesday?t(i.configuration.closingTimes.wednesday):null,thursday:i.configuration.closingTimes.thursday?t(i.configuration.closingTimes.thursday):null,friday:i.configuration.closingTimes.friday?t(i.configuration.closingTimes.friday):null,saturday:i.configuration.closingTimes.saturday?t(i.configuration.closingTimes.saturday):null,sunday:i.configuration.closingTimes.sunday?t(i.configuration.closingTimes.sunday):null}}}:void 0}}}:void 0),{updatedBy:n}),include:{address:!0,logoFile:!0,configuration:{include:{openingTimes:!0,closingTimes:!0}}}});return g.parse(Object.assign(Object.assign({},s),{configuration:Object.assign(Object.assign({},s.configuration),{openingTimes:this.formatDateScheduleToTimeString(s.configuration.openingTimes),closingTimes:this.formatDateScheduleToTimeString(s.configuration.closingTimes)})}))})}deleteOrganization(e,n){return c(this,void 0,void 0,function*(){if(!(yield this.prisma.organization.findUnique({where:{id:e}})))throw new m(404,"Organization not found");yield this.prisma.organization.update({where:{id:e},data:{deletedAt:new Date,deletedBy:n}})})}}export{h as OrganizationService};
|
|
@@ -1,16 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { createApiRouter } from "../../core/hono/hono";
|
|
3
|
-
import { paymentRoute } from "./payment.route";
|
|
4
|
-
import { PaymentService } from "./payment.service";
|
|
5
|
-
export const buildPaymentHandler = (prisma, options) => {
|
|
6
|
-
const app = createApiRouter();
|
|
7
|
-
app.openapi(paymentRoute.getAvailablePaymentMethods, (c) => __awaiter(void 0, void 0, void 0, function* () {
|
|
8
|
-
const auth = c.get("auth");
|
|
9
|
-
yield auth.getCurrentUser();
|
|
10
|
-
const service = new PaymentService(prisma, options);
|
|
11
|
-
const paymentMethods = yield service.getPaymentMethods();
|
|
12
|
-
return c.json(paymentMethods, 200);
|
|
13
|
-
}));
|
|
14
|
-
return app;
|
|
15
|
-
};
|
|
16
|
-
//# sourceMappingURL=payment.handler.js.map
|
|
1
|
+
import{__awaiter as i}from"tslib";import{createApiRouter as a}from"../../core/hono/hono";import{paymentRoute as m}from"./payment.route";import{PaymentService as p}from"./payment.service";export const buildPaymentHandler=(o,r)=>{const e=a();return e.openapi(m.getAvailablePaymentMethods,t=>i(void 0,void 0,void 0,function*(){yield t.get("auth").getCurrentUser();const n=yield new p(o,r).getPaymentMethods();return t.json(n,200)})),e};
|
|
@@ -1,22 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { ErrorSchema, HeaderSchema, OrganizationParams } from "../../schemas";
|
|
3
|
-
import { PaymentMethodDetailsSchema } from "./payment.schema";
|
|
4
|
-
const getAvailablePaymentMethodsRoute = createApiRoute({
|
|
5
|
-
description: "Returns a list of available payment methods for the organization.",
|
|
6
|
-
headers: HeaderSchema,
|
|
7
|
-
method: "GET",
|
|
8
|
-
operationId: "getAvailablePaymentMethods",
|
|
9
|
-
path: "/:organizationId/payment/methods",
|
|
10
|
-
pathParams: OrganizationParams,
|
|
11
|
-
responses: {
|
|
12
|
-
200: PaymentMethodDetailsSchema.array(),
|
|
13
|
-
400: ErrorSchema,
|
|
14
|
-
401: ErrorSchema,
|
|
15
|
-
},
|
|
16
|
-
summary: "Get Available Payment Methods",
|
|
17
|
-
tags: ["Payment"],
|
|
18
|
-
});
|
|
19
|
-
export const paymentRoute = {
|
|
20
|
-
getAvailablePaymentMethods: getAvailablePaymentMethodsRoute,
|
|
21
|
-
};
|
|
22
|
-
//# sourceMappingURL=payment.route.js.map
|
|
1
|
+
import{createApiRoute as a}from"../../core/hono/hono";import{ErrorSchema as e,HeaderSchema as t,OrganizationParams as o}from"../../schemas";import{PaymentMethodDetailsSchema as r}from"./payment.schema";const m=a({description:"Returns a list of available payment methods for the organization.",headers:t,method:"GET",operationId:"getAvailablePaymentMethods",path:"/:organizationId/payment/methods",pathParams:o,responses:{200:r.array(),400:e,401:e},summary:"Get Available Payment Methods",tags:["Payment"]});export const paymentRoute={getAvailablePaymentMethods:m};
|
|
@@ -2,8 +2,8 @@ import { z } from "@hono/zod-openapi";
|
|
|
2
2
|
export declare const PaymentMethodSchema: z.ZodEnum<{
|
|
3
3
|
card: "card";
|
|
4
4
|
blik: "blik";
|
|
5
|
-
cash_on_delivery: "cash_on_delivery";
|
|
6
5
|
paypal: "paypal";
|
|
6
|
+
cash_on_delivery: "cash_on_delivery";
|
|
7
7
|
}>;
|
|
8
8
|
export declare const PaymentProviderSchema: z.ZodEnum<{
|
|
9
9
|
stripe: "stripe";
|
|
@@ -29,8 +29,8 @@ export declare const PaymentMethodDetailsSchema: z.ZodObject<{
|
|
|
29
29
|
method: z.ZodEnum<{
|
|
30
30
|
card: "card";
|
|
31
31
|
blik: "blik";
|
|
32
|
-
cash_on_delivery: "cash_on_delivery";
|
|
33
32
|
paypal: "paypal";
|
|
33
|
+
cash_on_delivery: "cash_on_delivery";
|
|
34
34
|
}>;
|
|
35
35
|
description: z.ZodString;
|
|
36
36
|
}, z.core.$strip>;
|
|
@@ -39,8 +39,8 @@ export declare const PaymentSchema: z.ZodObject<{
|
|
|
39
39
|
method: z.ZodEnum<{
|
|
40
40
|
card: "card";
|
|
41
41
|
blik: "blik";
|
|
42
|
-
cash_on_delivery: "cash_on_delivery";
|
|
43
42
|
paypal: "paypal";
|
|
43
|
+
cash_on_delivery: "cash_on_delivery";
|
|
44
44
|
}>;
|
|
45
45
|
provider: z.ZodEnum<{
|
|
46
46
|
stripe: "stripe";
|
|
@@ -1,46 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { currency } from "../../schemas/currency.schema";
|
|
3
|
-
export const PaymentMethodSchema = z
|
|
4
|
-
.enum(["card", "blik", "cash_on_delivery", "paypal"])
|
|
5
|
-
.openapi({
|
|
6
|
-
description: "The payment method",
|
|
7
|
-
example: "card",
|
|
8
|
-
});
|
|
9
|
-
export const PaymentProviderSchema = z
|
|
10
|
-
.enum(["stripe", "revolut", "payu", "not_applicable"])
|
|
11
|
-
.openapi({
|
|
12
|
-
description: "The payment method",
|
|
13
|
-
example: "card",
|
|
14
|
-
});
|
|
15
|
-
export const PaymentStatusSchema = z
|
|
16
|
-
.enum(["pending", "succeeded", "refunded", "failed", "canceled"])
|
|
17
|
-
.openapi({
|
|
18
|
-
description: "The payment status",
|
|
19
|
-
example: "pending",
|
|
20
|
-
});
|
|
21
|
-
export const PaymentMethodDetailsSchema = z
|
|
22
|
-
.object({
|
|
23
|
-
id: z.string().min(1),
|
|
24
|
-
provider: PaymentProviderSchema,
|
|
25
|
-
method: PaymentMethodSchema,
|
|
26
|
-
description: z.string().min(1),
|
|
27
|
-
})
|
|
28
|
-
.openapi({
|
|
29
|
-
description: "The payment method",
|
|
30
|
-
example: {
|
|
31
|
-
provider: "stripe",
|
|
32
|
-
type: "card",
|
|
33
|
-
},
|
|
34
|
-
});
|
|
35
|
-
export const PaymentSchema = z.object({
|
|
36
|
-
id: z.string().cuid().min(1),
|
|
37
|
-
method: PaymentMethodSchema,
|
|
38
|
-
provider: PaymentProviderSchema,
|
|
39
|
-
status: PaymentStatusSchema,
|
|
40
|
-
shipping: z.number().min(0).default(0),
|
|
41
|
-
subtotal: z.number().min(0),
|
|
42
|
-
total: z.number().min(0),
|
|
43
|
-
discount: z.number().min(0).default(0),
|
|
44
|
-
currency,
|
|
45
|
-
});
|
|
46
|
-
//# sourceMappingURL=payment.schema.js.map
|
|
1
|
+
import{z as e}from"@hono/zod-openapi";import{currency as t}from"../../schemas/currency.schema";export const PaymentMethodSchema=e.enum(["card","blik","cash_on_delivery","paypal"]).openapi({description:"The payment method",example:"card"}),PaymentProviderSchema=e.enum(["stripe","revolut","payu","not_applicable"]).openapi({description:"The payment method",example:"card"}),PaymentStatusSchema=e.enum(["pending","succeeded","refunded","failed","canceled"]).openapi({description:"The payment status",example:"pending"}),PaymentMethodDetailsSchema=e.object({id:e.string().min(1),provider:PaymentProviderSchema,method:PaymentMethodSchema,description:e.string().min(1)}).openapi({description:"The payment method",example:{provider:"stripe",type:"card"}}),PaymentSchema=e.object({id:e.string().cuid().min(1),method:PaymentMethodSchema,provider:PaymentProviderSchema,status:PaymentStatusSchema,shipping:e.number().min(0).default(0),subtotal:e.number().min(0),total:e.number().min(0),discount:e.number().min(0).default(0),currency:t});
|
|
@@ -22,7 +22,7 @@ declare class PaymentService {
|
|
|
22
22
|
getPaymentMethods(): Promise<{
|
|
23
23
|
id: string;
|
|
24
24
|
provider: "stripe" | "revolut" | "payu" | "not_applicable";
|
|
25
|
-
method: "card" | "blik" | "
|
|
25
|
+
method: "card" | "blik" | "paypal" | "cash_on_delivery";
|
|
26
26
|
description: string;
|
|
27
27
|
}[]>;
|
|
28
28
|
private handleCheckoutSessionByProvider;
|
|
@@ -1,100 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { HttpException } from "../../core/exceptions/http-exception";
|
|
3
|
-
import { StripeService } from "./stripe.service";
|
|
4
|
-
class PaymentService {
|
|
5
|
-
constructor(prisma, options) {
|
|
6
|
-
this.prisma = prisma;
|
|
7
|
-
this.options = options;
|
|
8
|
-
if (!(options === null || options === void 0 ? void 0 : options.stripe)) {
|
|
9
|
-
throw new Error("Stripe options must be provided");
|
|
10
|
-
}
|
|
11
|
-
this.stripeService = new StripeService(prisma, options.stripe);
|
|
12
|
-
}
|
|
13
|
-
getPaymentMethods() {
|
|
14
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
15
|
-
const methods = [];
|
|
16
|
-
if (this.options.stripe &&
|
|
17
|
-
this.options.stripe.paymentMethods.includes("card")) {
|
|
18
|
-
methods.push({
|
|
19
|
-
id: "stripe:card",
|
|
20
|
-
provider: "stripe",
|
|
21
|
-
description: "Visa, Mastercard, American Express etc..",
|
|
22
|
-
method: "card",
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
if (this.options.stripe &&
|
|
26
|
-
this.options.stripe.paymentMethods.includes("blik")) {
|
|
27
|
-
methods.push({
|
|
28
|
-
id: "stripe:blik",
|
|
29
|
-
provider: "stripe",
|
|
30
|
-
description: "Popular payment method in Poland",
|
|
31
|
-
method: "blik",
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
if (this.options.revolut &&
|
|
35
|
-
this.options.revolut.paymentMethods.includes("card")) {
|
|
36
|
-
methods.push({
|
|
37
|
-
id: "revolut:card",
|
|
38
|
-
provider: "revolut",
|
|
39
|
-
description: "Visa, Mastercard, American Express etc..",
|
|
40
|
-
method: "card",
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
if (this.options.revolut &&
|
|
44
|
-
this.options.revolut.paymentMethods.includes("blik")) {
|
|
45
|
-
methods.push({
|
|
46
|
-
id: "revolut:blik",
|
|
47
|
-
provider: "revolut",
|
|
48
|
-
description: "Popular payment method in Poland",
|
|
49
|
-
method: "blik",
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
return methods;
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
handleCheckoutSessionByProvider(user, order, options) {
|
|
56
|
-
switch (order.payment.provider) {
|
|
57
|
-
case "stripe":
|
|
58
|
-
return this.stripeService.createCheckoutSession(user, order, options);
|
|
59
|
-
default:
|
|
60
|
-
throw new HttpException(400, "Payment provider not supported");
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
createCheckoutSession(user, order, options) {
|
|
64
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
65
|
-
const session = yield this.handleCheckoutSessionByProvider(user, order, options);
|
|
66
|
-
yield this.prisma.paymentSession.create({
|
|
67
|
-
data: {
|
|
68
|
-
payment: {
|
|
69
|
-
connect: {
|
|
70
|
-
id: order.payment.id,
|
|
71
|
-
},
|
|
72
|
-
},
|
|
73
|
-
referenceId: session.id,
|
|
74
|
-
amount: order.payment.total,
|
|
75
|
-
currency: order.payment.currency,
|
|
76
|
-
rawData: JSON.stringify(session),
|
|
77
|
-
},
|
|
78
|
-
});
|
|
79
|
-
return {
|
|
80
|
-
sessionId: session.id,
|
|
81
|
-
redirectUrl: session.url,
|
|
82
|
-
};
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
processWebhookEvent(provider, signature, body) {
|
|
86
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
87
|
-
if (!signature) {
|
|
88
|
-
throw new HttpException(401, "Signature is required");
|
|
89
|
-
}
|
|
90
|
-
switch (provider) {
|
|
91
|
-
case "stripe":
|
|
92
|
-
return this.stripeService.handleWebhookEvent(signature, body);
|
|
93
|
-
default:
|
|
94
|
-
throw new HttpException(400, "Payment provider not supported");
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
export { PaymentService };
|
|
100
|
-
//# sourceMappingURL=payment.service.js.map
|
|
1
|
+
import{__awaiter as o}from"tslib";import{HttpException as s}from"../../core/exceptions/http-exception";import{StripeService as n}from"./stripe.service";class d{constructor(t,e){if(this.prisma=t,this.options=e,!e?.stripe)throw new Error("Stripe options must be provided");this.stripeService=new n(t,e.stripe)}getPaymentMethods(){return o(this,void 0,void 0,function*(){const t=[];return this.options.stripe&&this.options.stripe.paymentMethods.includes("card")&&t.push({id:"stripe:card",provider:"stripe",description:"Visa, Mastercard, American Express etc..",method:"card"}),this.options.stripe&&this.options.stripe.paymentMethods.includes("blik")&&t.push({id:"stripe:blik",provider:"stripe",description:"Popular payment method in Poland",method:"blik"}),this.options.revolut&&this.options.revolut.paymentMethods.includes("card")&&t.push({id:"revolut:card",provider:"revolut",description:"Visa, Mastercard, American Express etc..",method:"card"}),this.options.revolut&&this.options.revolut.paymentMethods.includes("blik")&&t.push({id:"revolut:blik",provider:"revolut",description:"Popular payment method in Poland",method:"blik"}),t})}handleCheckoutSessionByProvider(t,e,i){if(e.payment.provider==="stripe")return this.stripeService.createCheckoutSession(t,e,i);throw new s(400,"Payment provider not supported")}createCheckoutSession(t,e,i){return o(this,void 0,void 0,function*(){const r=yield this.handleCheckoutSessionByProvider(t,e,i);return yield this.prisma.paymentSession.create({data:{payment:{connect:{id:e.payment.id}},referenceId:r.id,amount:e.payment.total,currency:e.payment.currency,rawData:JSON.stringify(r)}}),{sessionId:r.id,redirectUrl:r.url}})}processWebhookEvent(t,e,i){return o(this,void 0,void 0,function*(){if(!e)throw new s(401,"Signature is required");if(t==="stripe")return this.stripeService.handleWebhookEvent(e,i);throw new s(400,"Payment provider not supported")})}}export{d as PaymentService};
|