@payloadcms/storage-r2 0.0.1-beta.0 → 3.58.0-canary.4
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/handleDelete.d.ts +8 -0
- package/dist/handleDelete.d.ts.map +1 -0
- package/dist/handleDelete.js +8 -0
- package/dist/handleDelete.js.map +1 -0
- package/dist/handleUpload.d.ts +11 -0
- package/dist/handleUpload.d.ts.map +1 -0
- package/dist/handleUpload.js +13 -0
- package/dist/handleUpload.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +59 -0
- package/dist/index.js.map +1 -0
- package/dist/staticHandler.d.ts +11 -0
- package/dist/staticHandler.d.ts.map +1 -0
- package/dist/staticHandler.js +29 -0
- package/dist/staticHandler.js.map +1 -0
- package/dist/types.d.ts +16 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/package.json +57 -1
- package/.prettierignore +0 -12
- package/.swcrc +0 -24
- package/README.md +0 -3
- package/eslint.config.js +0 -18
- package/src/addresses/addressesCollection.ts +0 -76
- package/src/addresses/defaultAddressFields.ts +0 -83
- package/src/addresses/defaultCountries.ts +0 -50
- package/src/carts/beforeChange.ts +0 -51
- package/src/carts/cartsCollection.ts +0 -146
- package/src/currencies/index.ts +0 -29
- package/src/endpoints/confirmOrder.ts +0 -312
- package/src/endpoints/initiatePayment.ts +0 -322
- package/src/exports/addresses.ts +0 -2
- package/src/exports/currencies.ts +0 -1
- package/src/exports/fields.ts +0 -5
- package/src/exports/orders.ts +0 -1
- package/src/exports/payments/stripe.ts +0 -1
- package/src/exports/plugin.ts +0 -1
- package/src/exports/products.ts +0 -1
- package/src/exports/react.ts +0 -8
- package/src/exports/transactions.ts +0 -1
- package/src/exports/translations.ts +0 -1
- package/src/exports/types.ts +0 -7
- package/src/exports/ui.ts +0 -3
- package/src/exports/variants.ts +0 -5
- package/src/fields/amountField.ts +0 -43
- package/src/fields/cartItemsField.ts +0 -84
- package/src/fields/currencyField.ts +0 -39
- package/src/fields/inventoryField.ts +0 -22
- package/src/fields/pricesField.ts +0 -65
- package/src/fields/statusField.ts +0 -57
- package/src/fields/variantsFields.ts +0 -56
- package/src/index.ts +0 -275
- package/src/orders/ordersCollection.ts +0 -157
- package/src/payments/adapters/stripe/confirmOrder.ts +0 -123
- package/src/payments/adapters/stripe/endpoints/webhooks.ts +0 -69
- package/src/payments/adapters/stripe/index.ts +0 -135
- package/src/payments/adapters/stripe/initiatePayment.ts +0 -131
- package/src/products/productsCollection.ts +0 -78
- package/src/react/provider/index.tsx +0 -893
- package/src/react/provider/types.ts +0 -184
- package/src/react/provider/utilities.ts +0 -22
- package/src/transactions/transactionsCollection.ts +0 -166
- package/src/translations/en.ts +0 -64
- package/src/translations/index.ts +0 -11
- package/src/translations/translation-schema.json +0 -35
- package/src/types.ts +0 -403
- package/src/ui/PriceInput/FormattedInput.tsx +0 -134
- package/src/ui/PriceInput/index.scss +0 -28
- package/src/ui/PriceInput/index.tsx +0 -43
- package/src/ui/PriceInput/utilities.ts +0 -46
- package/src/ui/PriceRowLabel/index.css +0 -13
- package/src/ui/PriceRowLabel/index.tsx +0 -56
- package/src/ui/VariantOptionsSelector/ErrorBox.tsx +0 -27
- package/src/ui/VariantOptionsSelector/OptionsSelect.tsx +0 -78
- package/src/ui/VariantOptionsSelector/index.css +0 -37
- package/src/ui/VariantOptionsSelector/index.tsx +0 -83
- package/src/utilities/defaultProductsValidation.ts +0 -42
- package/src/utilities/errorCodes.ts +0 -14
- package/src/utilities/getCollectionSlugMap.ts +0 -84
- package/src/utilities/sanitizePluginConfig.ts +0 -80
- package/src/variants/variantOptionsCollection.ts +0 -59
- package/src/variants/variantTypesCollection.ts +0 -55
- package/src/variants/variantsCollection/hooks/beforeChange.ts +0 -47
- package/src/variants/variantsCollection/hooks/validateOptions.ts +0 -72
- package/src/variants/variantsCollection/index.ts +0 -119
- package/tsconfig.json +0 -7
- package/tsconfig.tsbuildinfo +0 -1
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
import type { CollectionConfig, Field } from 'payload'
|
|
2
|
-
|
|
3
|
-
import type { CurrenciesConfig, FieldsOverride } from '../types.js'
|
|
4
|
-
|
|
5
|
-
import { amountField } from '../fields/amountField.js'
|
|
6
|
-
import { cartItemsField } from '../fields/cartItemsField.js'
|
|
7
|
-
import { currencyField } from '../fields/currencyField.js'
|
|
8
|
-
import { beforeChangeCart } from './beforeChange.js'
|
|
9
|
-
|
|
10
|
-
type Props = {
|
|
11
|
-
currenciesConfig?: CurrenciesConfig
|
|
12
|
-
/**
|
|
13
|
-
* Slug of the customers collection, defaults to 'users'.
|
|
14
|
-
*/
|
|
15
|
-
customersSlug?: string
|
|
16
|
-
/**
|
|
17
|
-
* Enables support for variants in the cart.
|
|
18
|
-
* Defaults to false.
|
|
19
|
-
*/
|
|
20
|
-
enableVariants?: boolean
|
|
21
|
-
overrides?: { fields?: FieldsOverride } & Partial<Omit<CollectionConfig, 'fields'>>
|
|
22
|
-
/**
|
|
23
|
-
* Slug of the products collection, defaults to 'products'.
|
|
24
|
-
*/
|
|
25
|
-
productsSlug?: string
|
|
26
|
-
/**
|
|
27
|
-
* Slug of the variants collection, defaults to 'variants'.
|
|
28
|
-
*/
|
|
29
|
-
variantsSlug?: string
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export const cartsCollection: (props?: Props) => CollectionConfig = (props) => {
|
|
33
|
-
const {
|
|
34
|
-
currenciesConfig,
|
|
35
|
-
customersSlug = 'users',
|
|
36
|
-
enableVariants = false,
|
|
37
|
-
overrides,
|
|
38
|
-
productsSlug = 'products',
|
|
39
|
-
variantsSlug = 'variants',
|
|
40
|
-
} = props || {}
|
|
41
|
-
const fieldsOverride = overrides?.fields
|
|
42
|
-
|
|
43
|
-
const defaultFields: Field[] = [
|
|
44
|
-
{
|
|
45
|
-
name: 'customer',
|
|
46
|
-
type: 'relationship',
|
|
47
|
-
label: ({ t }) =>
|
|
48
|
-
// @ts-expect-error - translations are not typed in plugins yet
|
|
49
|
-
t('plugin-ecommerce:customer'),
|
|
50
|
-
relationTo: customersSlug,
|
|
51
|
-
},
|
|
52
|
-
{
|
|
53
|
-
name: 'purchasedAt',
|
|
54
|
-
type: 'date',
|
|
55
|
-
label: ({ t }) =>
|
|
56
|
-
// @ts-expect-error - translations are not typed in plugins yet
|
|
57
|
-
t('plugin-ecommerce:purchasedAt'),
|
|
58
|
-
},
|
|
59
|
-
{
|
|
60
|
-
name: 'status',
|
|
61
|
-
type: 'select',
|
|
62
|
-
defaultValue: 'open',
|
|
63
|
-
interfaceName: 'CartStatus',
|
|
64
|
-
label: ({ t }) =>
|
|
65
|
-
// @ts-expect-error - translations are not typed in plugins yet
|
|
66
|
-
t('plugin-ecommerce:status'),
|
|
67
|
-
options: [
|
|
68
|
-
{
|
|
69
|
-
// @ts-expect-error - translations are not typed in plugins yet
|
|
70
|
-
label: ({ t }) => t('plugin-ecommerce:open'),
|
|
71
|
-
value: 'open',
|
|
72
|
-
},
|
|
73
|
-
{
|
|
74
|
-
// @ts-expect-error - translations are not typed in plugins yet
|
|
75
|
-
label: ({ t }) => t('plugin-ecommerce:abandoned'),
|
|
76
|
-
value: 'abandoned',
|
|
77
|
-
},
|
|
78
|
-
{
|
|
79
|
-
// @ts-expect-error - translations are not typed in plugins yet
|
|
80
|
-
label: ({ t }) => t('plugin-ecommerce:completed'),
|
|
81
|
-
value: 'completed',
|
|
82
|
-
},
|
|
83
|
-
],
|
|
84
|
-
},
|
|
85
|
-
...(currenciesConfig
|
|
86
|
-
? [
|
|
87
|
-
currencyField({
|
|
88
|
-
currenciesConfig,
|
|
89
|
-
}),
|
|
90
|
-
amountField({
|
|
91
|
-
currenciesConfig,
|
|
92
|
-
overrides: {
|
|
93
|
-
name: 'subtotal',
|
|
94
|
-
label: ({ t }) =>
|
|
95
|
-
// @ts-expect-error - translations are not typed in plugins yet
|
|
96
|
-
t('plugin-ecommerce:subtotal'),
|
|
97
|
-
},
|
|
98
|
-
}),
|
|
99
|
-
]
|
|
100
|
-
: []),
|
|
101
|
-
cartItemsField({
|
|
102
|
-
enableVariants,
|
|
103
|
-
overrides: {
|
|
104
|
-
label: ({ t }) =>
|
|
105
|
-
// @ts-expect-error - translations are not typed in plugins yet
|
|
106
|
-
t('plugin-ecommerce:items'),
|
|
107
|
-
labels: {
|
|
108
|
-
plural: ({ t }) =>
|
|
109
|
-
// @ts-expect-error - translations are not typed in plugins yet
|
|
110
|
-
t('plugin-ecommerce:items'),
|
|
111
|
-
singular: ({ t }) =>
|
|
112
|
-
// @ts-expect-error - translations are not typed in plugins yet
|
|
113
|
-
t('plugin-ecommerce:item'),
|
|
114
|
-
},
|
|
115
|
-
},
|
|
116
|
-
productsSlug,
|
|
117
|
-
variantsSlug,
|
|
118
|
-
}),
|
|
119
|
-
]
|
|
120
|
-
|
|
121
|
-
const fields =
|
|
122
|
-
fieldsOverride && typeof fieldsOverride === 'function'
|
|
123
|
-
? fieldsOverride({ defaultFields })
|
|
124
|
-
: defaultFields
|
|
125
|
-
|
|
126
|
-
const baseConfig: CollectionConfig = {
|
|
127
|
-
slug: 'carts',
|
|
128
|
-
timestamps: true,
|
|
129
|
-
...overrides,
|
|
130
|
-
admin: {
|
|
131
|
-
useAsTitle: 'createdAt',
|
|
132
|
-
...overrides?.admin,
|
|
133
|
-
},
|
|
134
|
-
fields,
|
|
135
|
-
hooks: {
|
|
136
|
-
beforeChange: [
|
|
137
|
-
// This hook can be used to update the subtotal before saving the cart
|
|
138
|
-
beforeChangeCart({ productsSlug, variantsSlug }),
|
|
139
|
-
...(overrides?.hooks?.beforeChange || []),
|
|
140
|
-
],
|
|
141
|
-
...overrides?.hooks,
|
|
142
|
-
},
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
return { ...baseConfig }
|
|
146
|
-
}
|
package/src/currencies/index.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import type { Currency } from '../types.js'
|
|
2
|
-
|
|
3
|
-
export const EUR: Currency = {
|
|
4
|
-
code: 'EUR',
|
|
5
|
-
decimals: 2,
|
|
6
|
-
label: 'Euro',
|
|
7
|
-
symbol: '€',
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export const USD: Currency = {
|
|
11
|
-
code: 'USD',
|
|
12
|
-
decimals: 2,
|
|
13
|
-
label: 'US Dollar',
|
|
14
|
-
symbol: '$',
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export const GBP: Currency = {
|
|
18
|
-
code: 'GBP',
|
|
19
|
-
decimals: 2,
|
|
20
|
-
label: 'British Pound',
|
|
21
|
-
symbol: '£',
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export const JPY: Currency = {
|
|
25
|
-
code: 'JPY',
|
|
26
|
-
decimals: 0,
|
|
27
|
-
label: 'Japanese Yen',
|
|
28
|
-
symbol: '¥',
|
|
29
|
-
}
|
|
@@ -1,312 +0,0 @@
|
|
|
1
|
-
import { addDataAndFileToRequest, type DefaultDocumentIDType, type Endpoint } from 'payload'
|
|
2
|
-
|
|
3
|
-
import type { CurrenciesConfig, PaymentAdapter, ProductsValidation } from '../types.js'
|
|
4
|
-
|
|
5
|
-
import { defaultProductsValidation } from '../utilities/defaultProductsValidation.js'
|
|
6
|
-
|
|
7
|
-
type Args = {
|
|
8
|
-
/**
|
|
9
|
-
* The slug of the carts collection, defaults to 'carts'.
|
|
10
|
-
*/
|
|
11
|
-
cartsSlug?: string
|
|
12
|
-
currenciesConfig: CurrenciesConfig
|
|
13
|
-
/**
|
|
14
|
-
* The slug of the customers collection, defaults to 'users'.
|
|
15
|
-
*/
|
|
16
|
-
customersSlug?: string
|
|
17
|
-
/**
|
|
18
|
-
* The slug of the orders collection, defaults to 'orders'.
|
|
19
|
-
*/
|
|
20
|
-
ordersSlug?: string
|
|
21
|
-
paymentMethod: PaymentAdapter
|
|
22
|
-
/**
|
|
23
|
-
* The slug of the products collection, defaults to 'products'.
|
|
24
|
-
*/
|
|
25
|
-
productsSlug?: string
|
|
26
|
-
/**
|
|
27
|
-
* Customise the validation used for checking products or variants before a transaction is created.
|
|
28
|
-
*/
|
|
29
|
-
productsValidation?: ProductsValidation
|
|
30
|
-
/**
|
|
31
|
-
* The slug of the transactions collection, defaults to 'transactions'.
|
|
32
|
-
*/
|
|
33
|
-
transactionsSlug?: string
|
|
34
|
-
/**
|
|
35
|
-
* The slug of the variants collection, defaults to 'variants'.
|
|
36
|
-
*/
|
|
37
|
-
variantsSlug?: string
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
type ConfirmOrderHandler = (args: Args) => Endpoint['handler']
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Handles the endpoint for initiating payments. We will handle checking the amount and product and variant prices here before it is sent to the payment provider.
|
|
44
|
-
* This is the first step in the payment process.
|
|
45
|
-
*/
|
|
46
|
-
export const confirmOrderHandler: ConfirmOrderHandler =
|
|
47
|
-
({
|
|
48
|
-
cartsSlug = 'carts',
|
|
49
|
-
currenciesConfig,
|
|
50
|
-
customersSlug = 'users',
|
|
51
|
-
ordersSlug = 'orders',
|
|
52
|
-
paymentMethod,
|
|
53
|
-
productsSlug = 'products',
|
|
54
|
-
productsValidation,
|
|
55
|
-
transactionsSlug = 'transactions',
|
|
56
|
-
variantsSlug = 'variants',
|
|
57
|
-
}) =>
|
|
58
|
-
async (req) => {
|
|
59
|
-
await addDataAndFileToRequest(req)
|
|
60
|
-
|
|
61
|
-
const data = req.data
|
|
62
|
-
const payload = req.payload
|
|
63
|
-
const user = req.user
|
|
64
|
-
|
|
65
|
-
let currency: string = currenciesConfig.defaultCurrency
|
|
66
|
-
let cartID: DefaultDocumentIDType = data?.cartID
|
|
67
|
-
let cart = undefined
|
|
68
|
-
let customerEmail: string = user?.email ?? ''
|
|
69
|
-
|
|
70
|
-
if (user) {
|
|
71
|
-
if (user.cart?.docs && Array.isArray(user.cart.docs) && user.cart.docs.length > 0) {
|
|
72
|
-
if (!cartID && user.cart.docs[0]) {
|
|
73
|
-
// Use the user's cart instead
|
|
74
|
-
if (typeof user.cart.docs[0] === 'object') {
|
|
75
|
-
cartID = user.cart.docs[0].id
|
|
76
|
-
cart = user.cart.docs[0]
|
|
77
|
-
} else {
|
|
78
|
-
cartID = user.cart.docs[0]
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
} else {
|
|
83
|
-
// Get the email from the data if user is not available
|
|
84
|
-
if (data?.customerEmail && typeof data.customerEmail === 'string') {
|
|
85
|
-
customerEmail = data.customerEmail
|
|
86
|
-
} else {
|
|
87
|
-
return Response.json(
|
|
88
|
-
{
|
|
89
|
-
message: 'A customer email is required to make a purchase.',
|
|
90
|
-
},
|
|
91
|
-
{
|
|
92
|
-
status: 400,
|
|
93
|
-
},
|
|
94
|
-
)
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
if (!cart) {
|
|
99
|
-
if (cartID) {
|
|
100
|
-
cart = await payload.findByID({
|
|
101
|
-
id: cartID,
|
|
102
|
-
collection: cartsSlug,
|
|
103
|
-
depth: 2,
|
|
104
|
-
overrideAccess: false,
|
|
105
|
-
select: {
|
|
106
|
-
id: true,
|
|
107
|
-
currency: true,
|
|
108
|
-
customerEmail: true,
|
|
109
|
-
items: true,
|
|
110
|
-
subtotal: true,
|
|
111
|
-
},
|
|
112
|
-
user,
|
|
113
|
-
})
|
|
114
|
-
|
|
115
|
-
if (!cart) {
|
|
116
|
-
return Response.json(
|
|
117
|
-
{
|
|
118
|
-
message: `Cart with ID ${cartID} not found.`,
|
|
119
|
-
},
|
|
120
|
-
{
|
|
121
|
-
status: 404,
|
|
122
|
-
},
|
|
123
|
-
)
|
|
124
|
-
}
|
|
125
|
-
} else {
|
|
126
|
-
return Response.json(
|
|
127
|
-
{
|
|
128
|
-
message: 'Cart ID is required.',
|
|
129
|
-
},
|
|
130
|
-
{
|
|
131
|
-
status: 400,
|
|
132
|
-
},
|
|
133
|
-
)
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
if (cart.currency && typeof cart.currency === 'string') {
|
|
138
|
-
currency = cart.currency
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
// Ensure the currency is provided or inferred in some way
|
|
142
|
-
if (!currency) {
|
|
143
|
-
return Response.json(
|
|
144
|
-
{
|
|
145
|
-
message: 'Currency is required.',
|
|
146
|
-
},
|
|
147
|
-
{
|
|
148
|
-
status: 400,
|
|
149
|
-
},
|
|
150
|
-
)
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
try {
|
|
154
|
-
if (Array.isArray(cart.items) && cart.items.length > 0) {
|
|
155
|
-
for (const item of cart.items) {
|
|
156
|
-
// Target field to check the price based on the currency so we can validate the total
|
|
157
|
-
const priceField = `priceIn${currency.toUpperCase()}`
|
|
158
|
-
const quantity = item.quantity || 1
|
|
159
|
-
|
|
160
|
-
// If the item has a product but no variant, we assume the product has a price in the specified currency
|
|
161
|
-
if (item.product) {
|
|
162
|
-
const id = typeof item.product === 'object' ? item.product.id : item.product
|
|
163
|
-
|
|
164
|
-
const product = await payload.findByID({
|
|
165
|
-
id,
|
|
166
|
-
collection: productsSlug,
|
|
167
|
-
depth: 0,
|
|
168
|
-
select: {
|
|
169
|
-
[priceField]: true,
|
|
170
|
-
},
|
|
171
|
-
})
|
|
172
|
-
|
|
173
|
-
if (!product) {
|
|
174
|
-
payload.logger.error(
|
|
175
|
-
`Product with ID ${item.product} not found.`,
|
|
176
|
-
'Error validating product',
|
|
177
|
-
)
|
|
178
|
-
|
|
179
|
-
return Response.json(
|
|
180
|
-
{
|
|
181
|
-
message: `Product with ID ${item.product} not found.`,
|
|
182
|
-
},
|
|
183
|
-
{
|
|
184
|
-
status: 404,
|
|
185
|
-
},
|
|
186
|
-
)
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
// Run product validation only if the item does not have a variant, each variant will have its own inventory and price
|
|
190
|
-
if (!item.variant) {
|
|
191
|
-
try {
|
|
192
|
-
if (productsValidation) {
|
|
193
|
-
await productsValidation({
|
|
194
|
-
currenciesConfig,
|
|
195
|
-
currency,
|
|
196
|
-
product,
|
|
197
|
-
quantity,
|
|
198
|
-
})
|
|
199
|
-
} else {
|
|
200
|
-
await defaultProductsValidation({
|
|
201
|
-
currenciesConfig,
|
|
202
|
-
currency,
|
|
203
|
-
product,
|
|
204
|
-
quantity,
|
|
205
|
-
})
|
|
206
|
-
}
|
|
207
|
-
} catch (error) {
|
|
208
|
-
payload.logger.error(error, 'Error validating product.')
|
|
209
|
-
return Response.json(
|
|
210
|
-
{
|
|
211
|
-
message: error,
|
|
212
|
-
},
|
|
213
|
-
{
|
|
214
|
-
status: 400,
|
|
215
|
-
},
|
|
216
|
-
)
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
if (item.variant) {
|
|
221
|
-
const id = typeof item.variant === 'object' ? item.variant.id : item.variant
|
|
222
|
-
|
|
223
|
-
const variant = await payload.findByID({
|
|
224
|
-
id,
|
|
225
|
-
collection: variantsSlug,
|
|
226
|
-
depth: 0,
|
|
227
|
-
select: {
|
|
228
|
-
inventory: true,
|
|
229
|
-
[priceField]: true,
|
|
230
|
-
},
|
|
231
|
-
})
|
|
232
|
-
|
|
233
|
-
if (!variant) {
|
|
234
|
-
payload.logger.error(
|
|
235
|
-
`Variant with ID ${item.variant} not found.`,
|
|
236
|
-
'Error validating variant',
|
|
237
|
-
)
|
|
238
|
-
|
|
239
|
-
return Response.json(
|
|
240
|
-
{
|
|
241
|
-
message: `Variant with ID ${item.variant} not found.`,
|
|
242
|
-
},
|
|
243
|
-
{
|
|
244
|
-
status: 404,
|
|
245
|
-
},
|
|
246
|
-
)
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
try {
|
|
250
|
-
if (productsValidation) {
|
|
251
|
-
await productsValidation({
|
|
252
|
-
currenciesConfig,
|
|
253
|
-
currency,
|
|
254
|
-
product,
|
|
255
|
-
quantity,
|
|
256
|
-
variant,
|
|
257
|
-
})
|
|
258
|
-
} else {
|
|
259
|
-
await defaultProductsValidation({
|
|
260
|
-
currenciesConfig,
|
|
261
|
-
currency,
|
|
262
|
-
product,
|
|
263
|
-
quantity,
|
|
264
|
-
variant,
|
|
265
|
-
})
|
|
266
|
-
}
|
|
267
|
-
} catch (error) {
|
|
268
|
-
payload.logger.error(error, 'Error validating product or variant.')
|
|
269
|
-
|
|
270
|
-
return Response.json(
|
|
271
|
-
{
|
|
272
|
-
message: error,
|
|
273
|
-
},
|
|
274
|
-
{
|
|
275
|
-
status: 400,
|
|
276
|
-
},
|
|
277
|
-
)
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
const paymentResponse = await paymentMethod.confirmOrder({
|
|
285
|
-
customersSlug,
|
|
286
|
-
data: {
|
|
287
|
-
...data,
|
|
288
|
-
customerEmail,
|
|
289
|
-
},
|
|
290
|
-
ordersSlug,
|
|
291
|
-
req,
|
|
292
|
-
transactionsSlug,
|
|
293
|
-
})
|
|
294
|
-
|
|
295
|
-
if (paymentResponse) {
|
|
296
|
-
// Start decrementing the inventory for each product and variant in the cart
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
return Response.json(paymentResponse)
|
|
300
|
-
} catch (error) {
|
|
301
|
-
payload.logger.error(error, 'Error initiating payment')
|
|
302
|
-
|
|
303
|
-
return Response.json(
|
|
304
|
-
{
|
|
305
|
-
message: 'Error confirming order.',
|
|
306
|
-
},
|
|
307
|
-
{
|
|
308
|
-
status: 500,
|
|
309
|
-
},
|
|
310
|
-
)
|
|
311
|
-
}
|
|
312
|
-
}
|