@payloadcms/plugin-ecommerce 4.0.0-internal.697830c → 4.0.0-internal.77191e5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -0
- package/dist/collections/carts/endpoints/addItem.d.ts.map +1 -1
- package/dist/collections/carts/endpoints/clearCart.d.ts.map +1 -1
- package/dist/collections/carts/endpoints/mergeCart.d.ts.map +1 -1
- package/dist/collections/carts/endpoints/removeItem.d.ts.map +1 -1
- package/dist/collections/carts/endpoints/updateItem.d.ts.map +1 -1
- package/dist/collections/carts/hasCartSecretAccess.d.ts.map +1 -1
- package/dist/collections/carts/operations/addItem.d.ts.map +1 -1
- package/dist/collections/carts/operations/clearCart.d.ts.map +1 -1
- package/dist/collections/carts/operations/createRequestWithSecret.d.ts.map +1 -1
- package/dist/collections/carts/operations/mergeCart.d.ts.map +1 -1
- package/dist/collections/carts/operations/removeItem.d.ts.map +1 -1
- package/dist/collections/carts/operations/updateItem.d.ts.map +1 -1
- package/dist/endpoints/confirmOrder.d.ts.map +1 -1
- package/dist/endpoints/confirmOrder.js +299 -44
- package/dist/endpoints/confirmOrder.js.map +1 -1
- package/dist/exports/types.d.ts +1 -1
- package/dist/exports/types.d.ts.map +1 -1
- package/dist/exports/types.js.map +1 -1
- package/dist/fields/statusField.d.ts.map +1 -1
- package/dist/fields/statusField.js +5 -0
- package/dist/fields/statusField.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/payments/adapters/stripe/confirmOrder.d.ts.map +1 -1
- package/dist/payments/adapters/stripe/confirmOrder.js +107 -75
- package/dist/payments/adapters/stripe/confirmOrder.js.map +1 -1
- package/dist/payments/adapters/stripe/validateSettlement.d.ts +37 -0
- package/dist/payments/adapters/stripe/validateSettlement.d.ts.map +1 -0
- package/dist/payments/adapters/stripe/validateSettlement.js +157 -0
- package/dist/payments/adapters/stripe/validateSettlement.js.map +1 -0
- package/dist/react/provider/index.d.ts.map +1 -1
- package/dist/react/provider/index.js +75 -34
- package/dist/react/provider/index.js.map +1 -1
- package/dist/react/provider/utilities.d.ts.map +1 -1
- package/dist/translations/languages/ar.d.ts.map +1 -1
- package/dist/translations/languages/az.d.ts.map +1 -1
- package/dist/translations/languages/bg.d.ts.map +1 -1
- package/dist/translations/languages/ca.d.ts.map +1 -1
- package/dist/translations/languages/cs.d.ts.map +1 -1
- package/dist/translations/languages/da.d.ts.map +1 -1
- package/dist/translations/languages/de.d.ts.map +1 -1
- package/dist/translations/languages/en.d.ts.map +1 -1
- package/dist/translations/languages/es.d.ts.map +1 -1
- package/dist/translations/languages/et.d.ts.map +1 -1
- package/dist/translations/languages/fa.d.ts.map +1 -1
- package/dist/translations/languages/fr.d.ts.map +1 -1
- package/dist/translations/languages/he.d.ts.map +1 -1
- package/dist/translations/languages/hr.d.ts.map +1 -1
- package/dist/translations/languages/hu.d.ts.map +1 -1
- package/dist/translations/languages/hy.d.ts.map +1 -1
- package/dist/translations/languages/is.d.ts.map +1 -1
- package/dist/translations/languages/it.d.ts.map +1 -1
- package/dist/translations/languages/ja.d.ts.map +1 -1
- package/dist/translations/languages/ko.d.ts.map +1 -1
- package/dist/translations/languages/lt.d.ts.map +1 -1
- package/dist/translations/languages/my.d.ts.map +1 -1
- package/dist/translations/languages/nb.d.ts.map +1 -1
- package/dist/translations/languages/nl.d.ts.map +1 -1
- package/dist/translations/languages/pl.d.ts.map +1 -1
- package/dist/translations/languages/pt.d.ts.map +1 -1
- package/dist/translations/languages/ro.d.ts.map +1 -1
- package/dist/translations/languages/rs.d.ts.map +1 -1
- package/dist/translations/languages/rsLatin.d.ts.map +1 -1
- package/dist/translations/languages/ru.d.ts.map +1 -1
- package/dist/translations/languages/sk.d.ts.map +1 -1
- package/dist/translations/languages/sl.d.ts.map +1 -1
- package/dist/translations/languages/sv.d.ts.map +1 -1
- package/dist/translations/languages/ta.d.ts.map +1 -1
- package/dist/translations/languages/th.d.ts.map +1 -1
- package/dist/translations/languages/tr.d.ts.map +1 -1
- package/dist/translations/languages/uk.d.ts.map +1 -1
- package/dist/translations/languages/vi.d.ts.map +1 -1
- package/dist/translations/languages/zh.d.ts.map +1 -1
- package/dist/translations/languages/zhTw.d.ts.map +1 -1
- package/dist/types/index.d.ts +26 -9
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js.map +1 -1
- package/dist/ui/utilities.d.ts.map +1 -1
- package/dist/utilities/accessComposition.d.ts.map +1 -1
- package/dist/utilities/getCollectionSlugMap.d.ts.map +1 -1
- package/dist/utilities/pushTypeScriptProperties.d.ts.map +1 -1
- package/dist/utilities/sanitizePluginConfig.d.ts.map +1 -1
- package/package.json +8 -8
- package/dist/collections/carts/operations/defaultCartItemMatcher.spec.js +0 -358
- package/dist/collections/carts/operations/defaultCartItemMatcher.spec.js.map +0 -1
- package/dist/payments/adapters/stripe/confirmOrder.spec.js +0 -166
- package/dist/payments/adapters/stripe/confirmOrder.spec.js.map +0 -1
- package/dist/utilities/accessComposition.spec.js +0 -765
- package/dist/utilities/accessComposition.spec.js.map +0 -1
- package/dist/utilities/defaultProductsValidation.spec.js +0 -384
- package/dist/utilities/defaultProductsValidation.spec.js.map +0 -1
- package/dist/utilities/getCollectionSlugMap.spec.js +0 -254
- package/dist/utilities/getCollectionSlugMap.spec.js.map +0 -1
- package/dist/utilities/sanitizePluginConfig.spec.js +0 -516
- package/dist/utilities/sanitizePluginConfig.spec.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -123,6 +123,7 @@ export const ecommercePlugin = definePlugin({
|
|
|
123
123
|
customersSlug: collectionSlugMap.customers,
|
|
124
124
|
enableVariants,
|
|
125
125
|
productsSlug: collectionSlugMap.products,
|
|
126
|
+
transactionsSlug: collectionSlugMap.transactions,
|
|
126
127
|
variantsSlug: collectionSlugMap.variants ?? 'variants'
|
|
127
128
|
});
|
|
128
129
|
const ordersCollection = sanitizedPluginConfig.orders && typeof sanitizedPluginConfig.orders === 'object' && 'ordersCollectionOverride' in sanitizedPluginConfig.orders && sanitizedPluginConfig.orders.ordersCollectionOverride ? await sanitizedPluginConfig.orders.ordersCollectionOverride({
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { AcceptedLanguages } from '@payloadcms/translations'\nimport type { Endpoint } from 'payload'\n\nimport { definePlugin } from 'payload'\n\nimport type { PluginDefaultTranslationsObject } from './translations/types.js'\nimport type { EcommercePluginConfig, SanitizedEcommercePluginConfig } from './types/index.js'\n\nimport { createAddressesCollection } from './collections/addresses/createAddressesCollection.js'\nimport { createCartsCollection } from './collections/carts/createCartsCollection.js'\nimport { createOrdersCollection } from './collections/orders/createOrdersCollection.js'\nimport { createProductsCollection } from './collections/products/createProductsCollection.js'\nimport { createTransactionsCollection } from './collections/transactions/createTransactionsCollection.js'\nimport { createVariantOptionsCollection } from './collections/variants/createVariantOptionsCollection.js'\nimport { createVariantsCollection } from './collections/variants/createVariantsCollection/index.js'\nimport { createVariantTypesCollection } from './collections/variants/createVariantTypesCollection.js'\nimport { confirmOrderHandler } from './endpoints/confirmOrder.js'\nimport { initiatePaymentHandler } from './endpoints/initiatePayment.js'\nimport { translations } from './translations/index.js'\nimport { getCollectionSlugMap } from './utilities/getCollectionSlugMap.js'\nimport { pushTypeScriptProperties } from './utilities/pushTypeScriptProperties.js'\nimport { sanitizePluginConfig } from './utilities/sanitizePluginConfig.js'\n\nexport const ecommercePlugin = definePlugin<EcommercePluginConfig | undefined>({\n slug: '@payloadcms/plugin-ecommerce',\n plugin: async ({ config: incomingConfig, options: pluginConfig }) => {\n if (!pluginConfig) {\n return incomingConfig\n }\n\n const sanitizedPluginConfig = sanitizePluginConfig({ pluginConfig })\n\n const accessConfig = sanitizedPluginConfig.access\n\n // Ensure collections exists\n if (!incomingConfig.collections) {\n incomingConfig.collections = []\n }\n\n // Determine if variants are enabled based on products config\n const productsConfig =\n typeof sanitizedPluginConfig.products === 'boolean'\n ? sanitizedPluginConfig.products\n ? { variants: true }\n : undefined\n : sanitizedPluginConfig.products\n\n const enableVariants = Boolean(productsConfig?.variants)\n\n /**\n * Used to keep track of the slugs of collections in case they are overridden by the user.\n * Variant-related slugs are only included when variants are enabled.\n */\n const collectionSlugMap = getCollectionSlugMap({ enableVariants, sanitizedPluginConfig })\n\n const currenciesConfig: Required<SanitizedEcommercePluginConfig['currencies']> =\n sanitizedPluginConfig.currencies\n\n let addressFields\n\n if (sanitizedPluginConfig.addresses) {\n addressFields = sanitizedPluginConfig.addresses.addressFields\n\n const supportedCountries = sanitizedPluginConfig.addresses.supportedCountries\n\n const defaultAddressesCollection = createAddressesCollection({\n access: accessConfig,\n addressFields,\n customersSlug: collectionSlugMap.customers,\n supportedCountries,\n })\n\n const addressesCollection =\n sanitizedPluginConfig.addresses &&\n typeof sanitizedPluginConfig.addresses === 'object' &&\n 'addressesCollectionOverride' in sanitizedPluginConfig.addresses &&\n sanitizedPluginConfig.addresses.addressesCollectionOverride\n ? await sanitizedPluginConfig.addresses.addressesCollectionOverride({\n defaultCollection: defaultAddressesCollection,\n })\n : defaultAddressesCollection\n\n incomingConfig.collections.push(addressesCollection)\n }\n\n if (productsConfig) {\n if (productsConfig.variants) {\n const variantsConfig =\n typeof productsConfig.variants === 'boolean' ? undefined : productsConfig.variants\n\n const defaultVariantsCollection = createVariantsCollection({\n access: accessConfig,\n currenciesConfig,\n inventory: sanitizedPluginConfig.inventory,\n productsSlug: collectionSlugMap.products,\n variantOptionsSlug: collectionSlugMap.variantOptions ?? 'variantOptions',\n variantTypesSlug: collectionSlugMap.variantTypes ?? 'variantTypes',\n })\n\n const variants =\n variantsConfig &&\n typeof variantsConfig === 'object' &&\n 'variantsCollectionOverride' in variantsConfig &&\n variantsConfig.variantsCollectionOverride\n ? await variantsConfig.variantsCollectionOverride({\n defaultCollection: defaultVariantsCollection,\n })\n : defaultVariantsCollection\n\n const defaultVariantTypesCollection = createVariantTypesCollection({\n access: accessConfig,\n variantOptionsSlug: collectionSlugMap.variantOptions ?? 'variantOptions',\n })\n\n const variantTypes =\n variantsConfig &&\n typeof variantsConfig === 'object' &&\n 'variantTypesCollectionOverride' in variantsConfig &&\n variantsConfig.variantTypesCollectionOverride\n ? await variantsConfig.variantTypesCollectionOverride({\n defaultCollection: defaultVariantTypesCollection,\n })\n : defaultVariantTypesCollection\n\n const defaultVariantOptionsCollection = createVariantOptionsCollection({\n access: accessConfig,\n variantTypesSlug: collectionSlugMap.variantTypes ?? 'variantTypes',\n })\n\n const variantOptions =\n variantsConfig &&\n typeof variantsConfig === 'object' &&\n 'variantOptionsCollectionOverride' in variantsConfig &&\n variantsConfig.variantOptionsCollectionOverride\n ? await variantsConfig.variantOptionsCollectionOverride({\n defaultCollection: defaultVariantOptionsCollection,\n })\n : defaultVariantOptionsCollection\n\n incomingConfig.collections.push(variants, variantTypes, variantOptions)\n }\n\n const defaultProductsCollection = createProductsCollection({\n access: accessConfig,\n currenciesConfig,\n enableVariants,\n inventory: sanitizedPluginConfig.inventory,\n variantsSlug: collectionSlugMap.variants ?? 'variants',\n variantTypesSlug: collectionSlugMap.variantTypes ?? 'variantTypes',\n })\n\n const productsCollection =\n productsConfig &&\n 'productsCollectionOverride' in productsConfig &&\n productsConfig.productsCollectionOverride\n ? await productsConfig.productsCollectionOverride({\n defaultCollection: defaultProductsCollection,\n })\n : defaultProductsCollection\n\n incomingConfig.collections.push(productsCollection)\n\n if (sanitizedPluginConfig.carts) {\n const cartsConfig =\n typeof sanitizedPluginConfig.carts === 'object' ? sanitizedPluginConfig.carts : {}\n\n const defaultCartsCollection = createCartsCollection({\n access: accessConfig,\n allowGuestCarts: cartsConfig.allowGuestCarts,\n cartItemMatcher: cartsConfig.cartItemMatcher,\n currenciesConfig,\n customersSlug: collectionSlugMap.customers,\n enableVariants: Boolean(productsConfig.variants),\n productsSlug: collectionSlugMap.products,\n variantsSlug: collectionSlugMap.variants ?? 'variants',\n })\n\n const cartsCollection =\n sanitizedPluginConfig.carts &&\n typeof sanitizedPluginConfig.carts === 'object' &&\n 'cartsCollectionOverride' in sanitizedPluginConfig.carts &&\n sanitizedPluginConfig.carts.cartsCollectionOverride\n ? await sanitizedPluginConfig.carts.cartsCollectionOverride({\n defaultCollection: defaultCartsCollection,\n })\n : defaultCartsCollection\n\n incomingConfig.collections.push(cartsCollection)\n }\n }\n\n if (sanitizedPluginConfig.orders) {\n const defaultOrdersCollection = createOrdersCollection({\n access: accessConfig,\n addressFields,\n currenciesConfig,\n customersSlug: collectionSlugMap.customers,\n enableVariants,\n productsSlug: collectionSlugMap.products,\n variantsSlug: collectionSlugMap.variants ?? 'variants',\n })\n\n const ordersCollection =\n sanitizedPluginConfig.orders &&\n typeof sanitizedPluginConfig.orders === 'object' &&\n 'ordersCollectionOverride' in sanitizedPluginConfig.orders &&\n sanitizedPluginConfig.orders.ordersCollectionOverride\n ? await sanitizedPluginConfig.orders.ordersCollectionOverride({\n defaultCollection: defaultOrdersCollection,\n })\n : defaultOrdersCollection\n\n incomingConfig.collections.push(ordersCollection)\n }\n\n const paymentMethods = sanitizedPluginConfig.payments.paymentMethods\n\n if (sanitizedPluginConfig.payments) {\n if (paymentMethods.length) {\n if (!Array.isArray(incomingConfig.endpoints)) {\n incomingConfig.endpoints = []\n }\n\n const productsValidation =\n (typeof sanitizedPluginConfig.products === 'object' &&\n sanitizedPluginConfig.products.validation) ||\n undefined\n\n paymentMethods.forEach((paymentMethod) => {\n const methodPath = `/payments/${paymentMethod.name}`\n const endpoints: Endpoint[] = []\n\n const initiatePayment: Endpoint = {\n handler: initiatePaymentHandler({\n currenciesConfig,\n inventory: sanitizedPluginConfig.inventory,\n paymentMethod,\n productsSlug: collectionSlugMap.products,\n productsValidation,\n transactionsSlug: collectionSlugMap.transactions,\n variantsSlug: collectionSlugMap.variants ?? 'variants',\n }),\n method: 'post',\n path: `${methodPath}/initiate`,\n }\n\n const confirmOrder: Endpoint = {\n handler: confirmOrderHandler({\n cartsSlug: collectionSlugMap.carts,\n currenciesConfig,\n ordersSlug: collectionSlugMap.orders,\n paymentMethod,\n productsSlug: collectionSlugMap.products,\n productsValidation,\n transactionsSlug: collectionSlugMap.transactions,\n variantsSlug: collectionSlugMap.variants ?? 'variants',\n }),\n method: 'post',\n path: `${methodPath}/confirm-order`,\n }\n\n endpoints.push(initiatePayment, confirmOrder)\n\n // Attach any additional endpoints defined in the payment method\n if (paymentMethod.endpoints && paymentMethod.endpoints.length > 0) {\n const methodEndpoints = paymentMethod.endpoints.map((endpoint) => {\n const path = endpoint.path.startsWith('/') ? endpoint.path : `/${endpoint.path}`\n\n return {\n ...endpoint,\n path: `${methodPath}${path}`,\n }\n })\n\n endpoints.push(...methodEndpoints)\n }\n\n incomingConfig.endpoints!.push(...endpoints)\n })\n }\n }\n\n if (sanitizedPluginConfig.transactions) {\n const defaultTransactionsCollection = createTransactionsCollection({\n access: accessConfig,\n addressFields,\n cartsSlug: collectionSlugMap.carts,\n currenciesConfig,\n customersSlug: collectionSlugMap.customers,\n enableVariants,\n ordersSlug: collectionSlugMap.orders,\n paymentMethods,\n productsSlug: collectionSlugMap.products,\n variantsSlug: collectionSlugMap.variants ?? 'variants',\n })\n\n const transactionsCollection =\n sanitizedPluginConfig.transactions &&\n typeof sanitizedPluginConfig.transactions === 'object' &&\n 'transactionsCollectionOverride' in sanitizedPluginConfig.transactions &&\n sanitizedPluginConfig.transactions.transactionsCollectionOverride\n ? await sanitizedPluginConfig.transactions.transactionsCollectionOverride({\n defaultCollection: defaultTransactionsCollection,\n })\n : defaultTransactionsCollection\n\n incomingConfig.collections.push(transactionsCollection)\n }\n\n if (!incomingConfig.i18n) {\n incomingConfig.i18n = {}\n }\n\n if (!incomingConfig.i18n.translations) {\n incomingConfig.i18n.translations = {}\n }\n\n /**\n * Merge plugin translations — only for languages the user has enabled.\n * Plugins run before sanitize, so `supportedLanguages` may be undefined; sanitize will\n * default it to `{ en }`, so we mirror that here. Plugin-ecommerce translations always\n * win over user-provided ones for the `plugin-ecommerce` namespace.\n */\n const supportedLanguageKeys = incomingConfig.i18n?.supportedLanguages\n ? Object.keys(incomingConfig.i18n.supportedLanguages)\n : ['en']\n\n for (const lang of supportedLanguageKeys) {\n const pluginEntry = translations[lang as keyof typeof translations]\n if (!pluginEntry) {\n continue\n }\n const typedLocale = lang as AcceptedLanguages\n const existing = (incomingConfig.i18n.translations[typedLocale] ?? {}) as Record<\n string,\n unknown\n >\n incomingConfig.i18n.translations[typedLocale] = {\n ...existing,\n 'plugin-ecommerce': pluginEntry.translations['plugin-ecommerce'],\n } as PluginDefaultTranslationsObject\n }\n\n if (!incomingConfig.typescript) {\n incomingConfig.typescript = {}\n }\n\n if (!incomingConfig.typescript.schema) {\n incomingConfig.typescript.schema = []\n }\n\n incomingConfig.typescript.schema.push((args) =>\n pushTypeScriptProperties({\n ...args,\n collectionSlugMap,\n sanitizedPluginConfig,\n }),\n )\n\n return incomingConfig\n },\n})\n\nexport {\n createAddressesCollection,\n createCartsCollection,\n createOrdersCollection,\n createProductsCollection,\n createTransactionsCollection,\n createVariantOptionsCollection,\n createVariantsCollection,\n createVariantTypesCollection,\n}\n\nexport { addItem } from './collections/carts/operations/addItem.js'\nexport { clearCart } from './collections/carts/operations/clearCart.js'\nexport { defaultCartItemMatcher } from './collections/carts/operations/defaultCartItemMatcher.js'\nexport { removeItem } from './collections/carts/operations/removeItem.js'\nexport { isNumericOperator } from './collections/carts/operations/types.js'\nexport type {\n AddItemArgs,\n CartItemData,\n CartItemMatcher,\n CartItemMatcherArgs,\n CartOperationResult,\n ClearCartArgs,\n FieldWithOperator,\n NewCartItem,\n NumericOperator,\n RemoveItemArgs,\n UpdateItemArgs,\n} from './collections/carts/operations/types.js'\nexport { updateItem } from './collections/carts/operations/updateItem.js'\nexport { EUR, GBP, USD } from './currencies/index.js'\nexport { amountField } from './fields/amountField.js'\nexport { currencyField } from './fields/currencyField.js'\nexport { pricesField } from './fields/pricesField.js'\nexport { statusField } from './fields/statusField.js'\nexport { variantsFields } from './fields/variantsFields.js'\n"],"names":["definePlugin","createAddressesCollection","createCartsCollection","createOrdersCollection","createProductsCollection","createTransactionsCollection","createVariantOptionsCollection","createVariantsCollection","createVariantTypesCollection","confirmOrderHandler","initiatePaymentHandler","translations","getCollectionSlugMap","pushTypeScriptProperties","sanitizePluginConfig","ecommercePlugin","slug","plugin","config","incomingConfig","options","pluginConfig","sanitizedPluginConfig","accessConfig","access","collections","productsConfig","products","variants","undefined","enableVariants","Boolean","collectionSlugMap","currenciesConfig","currencies","addressFields","addresses","supportedCountries","defaultAddressesCollection","customersSlug","customers","addressesCollection","addressesCollectionOverride","defaultCollection","push","variantsConfig","defaultVariantsCollection","inventory","productsSlug","variantOptionsSlug","variantOptions","variantTypesSlug","variantTypes","variantsCollectionOverride","defaultVariantTypesCollection","variantTypesCollectionOverride","defaultVariantOptionsCollection","variantOptionsCollectionOverride","defaultProductsCollection","variantsSlug","productsCollection","productsCollectionOverride","carts","cartsConfig","defaultCartsCollection","allowGuestCarts","cartItemMatcher","cartsCollection","cartsCollectionOverride","orders","defaultOrdersCollection","ordersCollection","ordersCollectionOverride","paymentMethods","payments","length","Array","isArray","endpoints","productsValidation","validation","forEach","paymentMethod","methodPath","name","initiatePayment","handler","transactionsSlug","transactions","method","path","confirmOrder","cartsSlug","ordersSlug","methodEndpoints","map","endpoint","startsWith","defaultTransactionsCollection","transactionsCollection","transactionsCollectionOverride","i18n","supportedLanguageKeys","supportedLanguages","Object","keys","lang","pluginEntry","typedLocale","existing","typescript","schema","args","addItem","clearCart","defaultCartItemMatcher","removeItem","isNumericOperator","updateItem","EUR","GBP","USD","amountField","currencyField","pricesField","statusField","variantsFields"],"mappings":"AAGA,SAASA,YAAY,QAAQ,UAAS;AAKtC,SAASC,yBAAyB,QAAQ,uDAAsD;AAChG,SAASC,qBAAqB,QAAQ,+CAA8C;AACpF,SAASC,sBAAsB,QAAQ,iDAAgD;AACvF,SAASC,wBAAwB,QAAQ,qDAAoD;AAC7F,SAASC,4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AA4B,EAC5BC,8BAA8B,EAC9BC,wBAAwB,EACxBC,4BAA4B,KAC7B;AAED,SAASyG,OAAO,QAAQ,4CAA2C;AACnE,SAASC,SAAS,QAAQ,8CAA6C;AACvE,SAASC,sBAAsB,QAAQ,2DAA0D;AACjG,SAASC,UAAU,QAAQ,+CAA8C;AACzE,SAASC,iBAAiB,QAAQ,0CAAyC;AAc3E,SAASC,UAAU,QAAQ,+CAA8C;AACzE,SAASC,GAAG,EAAEC,GAAG,EAAEC,GAAG,QAAQ,wBAAuB;AACrD,SAASC,WAAW,QAAQ,0BAAyB;AACrD,SAASC,aAAa,QAAQ,4BAA2B;AACzD,SAASC,WAAW,QAAQ,0BAAyB;AACrD,SAASC,WAAW,QAAQ,0BAAyB;AACrD,SAASC,cAAc,QAAQ,6BAA4B"}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { AcceptedLanguages } from '@payloadcms/translations'\nimport type { Endpoint } from 'payload'\n\nimport { definePlugin } from 'payload'\n\nimport type { PluginDefaultTranslationsObject } from './translations/types.js'\nimport type { EcommercePluginConfig, SanitizedEcommercePluginConfig } from './types/index.js'\n\nimport { createAddressesCollection } from './collections/addresses/createAddressesCollection.js'\nimport { createCartsCollection } from './collections/carts/createCartsCollection.js'\nimport { createOrdersCollection } from './collections/orders/createOrdersCollection.js'\nimport { createProductsCollection } from './collections/products/createProductsCollection.js'\nimport { createTransactionsCollection } from './collections/transactions/createTransactionsCollection.js'\nimport { createVariantOptionsCollection } from './collections/variants/createVariantOptionsCollection.js'\nimport { createVariantsCollection } from './collections/variants/createVariantsCollection/index.js'\nimport { createVariantTypesCollection } from './collections/variants/createVariantTypesCollection.js'\nimport { confirmOrderHandler } from './endpoints/confirmOrder.js'\nimport { initiatePaymentHandler } from './endpoints/initiatePayment.js'\nimport { translations } from './translations/index.js'\nimport { getCollectionSlugMap } from './utilities/getCollectionSlugMap.js'\nimport { pushTypeScriptProperties } from './utilities/pushTypeScriptProperties.js'\nimport { sanitizePluginConfig } from './utilities/sanitizePluginConfig.js'\n\nexport const ecommercePlugin = definePlugin<EcommercePluginConfig | undefined>({\n slug: '@payloadcms/plugin-ecommerce',\n plugin: async ({ config: incomingConfig, options: pluginConfig }) => {\n if (!pluginConfig) {\n return incomingConfig\n }\n\n const sanitizedPluginConfig = sanitizePluginConfig({ pluginConfig })\n\n const accessConfig = sanitizedPluginConfig.access\n\n // Ensure collections exists\n if (!incomingConfig.collections) {\n incomingConfig.collections = []\n }\n\n // Determine if variants are enabled based on products config\n const productsConfig =\n typeof sanitizedPluginConfig.products === 'boolean'\n ? sanitizedPluginConfig.products\n ? { variants: true }\n : undefined\n : sanitizedPluginConfig.products\n\n const enableVariants = Boolean(productsConfig?.variants)\n\n /**\n * Used to keep track of the slugs of collections in case they are overridden by the user.\n * Variant-related slugs are only included when variants are enabled.\n */\n const collectionSlugMap = getCollectionSlugMap({ enableVariants, sanitizedPluginConfig })\n\n const currenciesConfig: Required<SanitizedEcommercePluginConfig['currencies']> =\n sanitizedPluginConfig.currencies\n\n let addressFields\n\n if (sanitizedPluginConfig.addresses) {\n addressFields = sanitizedPluginConfig.addresses.addressFields\n\n const supportedCountries = sanitizedPluginConfig.addresses.supportedCountries\n\n const defaultAddressesCollection = createAddressesCollection({\n access: accessConfig,\n addressFields,\n customersSlug: collectionSlugMap.customers,\n supportedCountries,\n })\n\n const addressesCollection =\n sanitizedPluginConfig.addresses &&\n typeof sanitizedPluginConfig.addresses === 'object' &&\n 'addressesCollectionOverride' in sanitizedPluginConfig.addresses &&\n sanitizedPluginConfig.addresses.addressesCollectionOverride\n ? await sanitizedPluginConfig.addresses.addressesCollectionOverride({\n defaultCollection: defaultAddressesCollection,\n })\n : defaultAddressesCollection\n\n incomingConfig.collections.push(addressesCollection)\n }\n\n if (productsConfig) {\n if (productsConfig.variants) {\n const variantsConfig =\n typeof productsConfig.variants === 'boolean' ? undefined : productsConfig.variants\n\n const defaultVariantsCollection = createVariantsCollection({\n access: accessConfig,\n currenciesConfig,\n inventory: sanitizedPluginConfig.inventory,\n productsSlug: collectionSlugMap.products,\n variantOptionsSlug: collectionSlugMap.variantOptions ?? 'variantOptions',\n variantTypesSlug: collectionSlugMap.variantTypes ?? 'variantTypes',\n })\n\n const variants =\n variantsConfig &&\n typeof variantsConfig === 'object' &&\n 'variantsCollectionOverride' in variantsConfig &&\n variantsConfig.variantsCollectionOverride\n ? await variantsConfig.variantsCollectionOverride({\n defaultCollection: defaultVariantsCollection,\n })\n : defaultVariantsCollection\n\n const defaultVariantTypesCollection = createVariantTypesCollection({\n access: accessConfig,\n variantOptionsSlug: collectionSlugMap.variantOptions ?? 'variantOptions',\n })\n\n const variantTypes =\n variantsConfig &&\n typeof variantsConfig === 'object' &&\n 'variantTypesCollectionOverride' in variantsConfig &&\n variantsConfig.variantTypesCollectionOverride\n ? await variantsConfig.variantTypesCollectionOverride({\n defaultCollection: defaultVariantTypesCollection,\n })\n : defaultVariantTypesCollection\n\n const defaultVariantOptionsCollection = createVariantOptionsCollection({\n access: accessConfig,\n variantTypesSlug: collectionSlugMap.variantTypes ?? 'variantTypes',\n })\n\n const variantOptions =\n variantsConfig &&\n typeof variantsConfig === 'object' &&\n 'variantOptionsCollectionOverride' in variantsConfig &&\n variantsConfig.variantOptionsCollectionOverride\n ? await variantsConfig.variantOptionsCollectionOverride({\n defaultCollection: defaultVariantOptionsCollection,\n })\n : defaultVariantOptionsCollection\n\n incomingConfig.collections.push(variants, variantTypes, variantOptions)\n }\n\n const defaultProductsCollection = createProductsCollection({\n access: accessConfig,\n currenciesConfig,\n enableVariants,\n inventory: sanitizedPluginConfig.inventory,\n variantsSlug: collectionSlugMap.variants ?? 'variants',\n variantTypesSlug: collectionSlugMap.variantTypes ?? 'variantTypes',\n })\n\n const productsCollection =\n productsConfig &&\n 'productsCollectionOverride' in productsConfig &&\n productsConfig.productsCollectionOverride\n ? await productsConfig.productsCollectionOverride({\n defaultCollection: defaultProductsCollection,\n })\n : defaultProductsCollection\n\n incomingConfig.collections.push(productsCollection)\n\n if (sanitizedPluginConfig.carts) {\n const cartsConfig =\n typeof sanitizedPluginConfig.carts === 'object' ? sanitizedPluginConfig.carts : {}\n\n const defaultCartsCollection = createCartsCollection({\n access: accessConfig,\n allowGuestCarts: cartsConfig.allowGuestCarts,\n cartItemMatcher: cartsConfig.cartItemMatcher,\n currenciesConfig,\n customersSlug: collectionSlugMap.customers,\n enableVariants: Boolean(productsConfig.variants),\n productsSlug: collectionSlugMap.products,\n variantsSlug: collectionSlugMap.variants ?? 'variants',\n })\n\n const cartsCollection =\n sanitizedPluginConfig.carts &&\n typeof sanitizedPluginConfig.carts === 'object' &&\n 'cartsCollectionOverride' in sanitizedPluginConfig.carts &&\n sanitizedPluginConfig.carts.cartsCollectionOverride\n ? await sanitizedPluginConfig.carts.cartsCollectionOverride({\n defaultCollection: defaultCartsCollection,\n })\n : defaultCartsCollection\n\n incomingConfig.collections.push(cartsCollection)\n }\n }\n\n if (sanitizedPluginConfig.orders) {\n const defaultOrdersCollection = createOrdersCollection({\n access: accessConfig,\n addressFields,\n currenciesConfig,\n customersSlug: collectionSlugMap.customers,\n enableVariants,\n productsSlug: collectionSlugMap.products,\n transactionsSlug: collectionSlugMap.transactions,\n variantsSlug: collectionSlugMap.variants ?? 'variants',\n })\n\n const ordersCollection =\n sanitizedPluginConfig.orders &&\n typeof sanitizedPluginConfig.orders === 'object' &&\n 'ordersCollectionOverride' in sanitizedPluginConfig.orders &&\n sanitizedPluginConfig.orders.ordersCollectionOverride\n ? await sanitizedPluginConfig.orders.ordersCollectionOverride({\n defaultCollection: defaultOrdersCollection,\n })\n : defaultOrdersCollection\n\n incomingConfig.collections.push(ordersCollection)\n }\n\n const paymentMethods = sanitizedPluginConfig.payments.paymentMethods\n\n if (sanitizedPluginConfig.payments) {\n if (paymentMethods.length) {\n if (!Array.isArray(incomingConfig.endpoints)) {\n incomingConfig.endpoints = []\n }\n\n const productsValidation =\n (typeof sanitizedPluginConfig.products === 'object' &&\n sanitizedPluginConfig.products.validation) ||\n undefined\n\n paymentMethods.forEach((paymentMethod) => {\n const methodPath = `/payments/${paymentMethod.name}`\n const endpoints: Endpoint[] = []\n\n const initiatePayment: Endpoint = {\n handler: initiatePaymentHandler({\n currenciesConfig,\n inventory: sanitizedPluginConfig.inventory,\n paymentMethod,\n productsSlug: collectionSlugMap.products,\n productsValidation,\n transactionsSlug: collectionSlugMap.transactions,\n variantsSlug: collectionSlugMap.variants ?? 'variants',\n }),\n method: 'post',\n path: `${methodPath}/initiate`,\n }\n\n const confirmOrder: Endpoint = {\n handler: confirmOrderHandler({\n cartsSlug: collectionSlugMap.carts,\n currenciesConfig,\n ordersSlug: collectionSlugMap.orders,\n paymentMethod,\n productsSlug: collectionSlugMap.products,\n productsValidation,\n transactionsSlug: collectionSlugMap.transactions,\n variantsSlug: collectionSlugMap.variants ?? 'variants',\n }),\n method: 'post',\n path: `${methodPath}/confirm-order`,\n }\n\n endpoints.push(initiatePayment, confirmOrder)\n\n // Attach any additional endpoints defined in the payment method\n if (paymentMethod.endpoints && paymentMethod.endpoints.length > 0) {\n const methodEndpoints = paymentMethod.endpoints.map((endpoint) => {\n const path = endpoint.path.startsWith('/') ? endpoint.path : `/${endpoint.path}`\n\n return {\n ...endpoint,\n path: `${methodPath}${path}`,\n }\n })\n\n endpoints.push(...methodEndpoints)\n }\n\n incomingConfig.endpoints!.push(...endpoints)\n })\n }\n }\n\n if (sanitizedPluginConfig.transactions) {\n const defaultTransactionsCollection = createTransactionsCollection({\n access: accessConfig,\n addressFields,\n cartsSlug: collectionSlugMap.carts,\n currenciesConfig,\n customersSlug: collectionSlugMap.customers,\n enableVariants,\n ordersSlug: collectionSlugMap.orders,\n paymentMethods,\n productsSlug: collectionSlugMap.products,\n variantsSlug: collectionSlugMap.variants ?? 'variants',\n })\n\n const transactionsCollection =\n sanitizedPluginConfig.transactions &&\n typeof sanitizedPluginConfig.transactions === 'object' &&\n 'transactionsCollectionOverride' in sanitizedPluginConfig.transactions &&\n sanitizedPluginConfig.transactions.transactionsCollectionOverride\n ? await sanitizedPluginConfig.transactions.transactionsCollectionOverride({\n defaultCollection: defaultTransactionsCollection,\n })\n : defaultTransactionsCollection\n\n incomingConfig.collections.push(transactionsCollection)\n }\n\n if (!incomingConfig.i18n) {\n incomingConfig.i18n = {}\n }\n\n if (!incomingConfig.i18n.translations) {\n incomingConfig.i18n.translations = {}\n }\n\n /**\n * Merge plugin translations — only for languages the user has enabled.\n * Plugins run before sanitize, so `supportedLanguages` may be undefined; sanitize will\n * default it to `{ en }`, so we mirror that here. Plugin-ecommerce translations always\n * win over user-provided ones for the `plugin-ecommerce` namespace.\n */\n const supportedLanguageKeys = incomingConfig.i18n?.supportedLanguages\n ? Object.keys(incomingConfig.i18n.supportedLanguages)\n : ['en']\n\n for (const lang of supportedLanguageKeys) {\n const pluginEntry = translations[lang as keyof typeof translations]\n if (!pluginEntry) {\n continue\n }\n const typedLocale = lang as AcceptedLanguages\n const existing = (incomingConfig.i18n.translations[typedLocale] ?? {}) as Record<\n string,\n unknown\n >\n incomingConfig.i18n.translations[typedLocale] = {\n ...existing,\n 'plugin-ecommerce': pluginEntry.translations['plugin-ecommerce'],\n } as PluginDefaultTranslationsObject\n }\n\n if (!incomingConfig.typescript) {\n incomingConfig.typescript = {}\n }\n\n if (!incomingConfig.typescript.schema) {\n incomingConfig.typescript.schema = []\n }\n\n incomingConfig.typescript.schema.push((args) =>\n pushTypeScriptProperties({\n ...args,\n collectionSlugMap,\n sanitizedPluginConfig,\n }),\n )\n\n return incomingConfig\n },\n})\n\nexport {\n createAddressesCollection,\n createCartsCollection,\n createOrdersCollection,\n createProductsCollection,\n createTransactionsCollection,\n createVariantOptionsCollection,\n createVariantsCollection,\n createVariantTypesCollection,\n}\n\nexport { addItem } from './collections/carts/operations/addItem.js'\nexport { clearCart } from './collections/carts/operations/clearCart.js'\nexport { defaultCartItemMatcher } from './collections/carts/operations/defaultCartItemMatcher.js'\nexport { removeItem } from './collections/carts/operations/removeItem.js'\nexport { isNumericOperator } from './collections/carts/operations/types.js'\nexport type {\n AddItemArgs,\n CartItemData,\n CartItemMatcher,\n CartItemMatcherArgs,\n CartOperationResult,\n ClearCartArgs,\n FieldWithOperator,\n NewCartItem,\n NumericOperator,\n RemoveItemArgs,\n UpdateItemArgs,\n} from './collections/carts/operations/types.js'\nexport { updateItem } from './collections/carts/operations/updateItem.js'\nexport { EUR, GBP, USD } from './currencies/index.js'\nexport { amountField } from './fields/amountField.js'\nexport { currencyField } from './fields/currencyField.js'\nexport { pricesField } from './fields/pricesField.js'\nexport { statusField } from './fields/statusField.js'\nexport { variantsFields } from './fields/variantsFields.js'\n"],"names":["definePlugin","createAddressesCollection","createCartsCollection","createOrdersCollection","createProductsCollection","createTransactionsCollection","createVariantOptionsCollection","createVariantsCollection","createVariantTypesCollection","confirmOrderHandler","initiatePaymentHandler","translations","getCollectionSlugMap","pushTypeScriptProperties","sanitizePluginConfig","ecommercePlugin","slug","plugin","config","incomingConfig","options","pluginConfig","sanitizedPluginConfig","accessConfig","access","collections","productsConfig","products","variants","undefined","enableVariants","Boolean","collectionSlugMap","currenciesConfig","currencies","addressFields","addresses","supportedCountries","defaultAddressesCollection","customersSlug","customers","addressesCollection","addressesCollectionOverride","defaultCollection","push","variantsConfig","defaultVariantsCollection","inventory","productsSlug","variantOptionsSlug","variantOptions","variantTypesSlug","variantTypes","variantsCollectionOverride","defaultVariantTypesCollection","variantTypesCollectionOverride","defaultVariantOptionsCollection","variantOptionsCollectionOverride","defaultProductsCollection","variantsSlug","productsCollection","productsCollectionOverride","carts","cartsConfig","defaultCartsCollection","allowGuestCarts","cartItemMatcher","cartsCollection","cartsCollectionOverride","orders","defaultOrdersCollection","transactionsSlug","transactions","ordersCollection","ordersCollectionOverride","paymentMethods","payments","length","Array","isArray","endpoints","productsValidation","validation","forEach","paymentMethod","methodPath","name","initiatePayment","handler","method","path","confirmOrder","cartsSlug","ordersSlug","methodEndpoints","map","endpoint","startsWith","defaultTransactionsCollection","transactionsCollection","transactionsCollectionOverride","i18n","supportedLanguageKeys","supportedLanguages","Object","keys","lang","pluginEntry","typedLocale","existing","typescript","schema","args","addItem","clearCart","defaultCartItemMatcher","removeItem","isNumericOperator","updateItem","EUR","GBP","USD","amountField","currencyField","pricesField","statusField","variantsFields"],"mappings":"AAGA,SAASA,YAAY,QAAQ,UAAS;AAKtC,SAASC,yBAAyB,QAAQ,uDAAsD;AAChG,SAASC,qBAAqB,QAAQ,+CAA8C;AACpF,SAASC,sBAAsB,QAAQ,iDAAgD;AACvF,SAASC,wBAAwB,QAAQ,qDAAoD;AAC7F,SAASC,4BAA4B,QAAQ,6DAA4D;AACzG,SAASC,8BAA8B,QAAQ,2DAA0D;AACzG,SAASC,wBAAwB,QAAQ,2DAA0D;AACnG,SAASC,4BAA4B,QAAQ,yDAAwD;AACrG,SAASC,mBAAmB,QAAQ,8BAA6B;AACjE,SAASC,sBAAsB,QAAQ,iCAAgC;AACvE,SAASC,YAAY,QAAQ,0BAAyB;AACtD,SAASC,oBAAoB,QAAQ,sCAAqC;AAC1E,SAASC,wBAAwB,QAAQ,0CAAyC;AAClF,SAASC,oBAAoB,QAAQ,sCAAqC;AAE1E,OAAO,MAAMC,kBAAkBf,aAAgD;IAC7EgB,MAAM;IACNC,QAAQ,OAAO,EAAEC,QAAQC,cAAc,EAAEC,SAASC,YAAY,EAAE;QAC9D,IAAI,CAACA,cAAc;YACjB,OAAOF;QACT;QAEA,MAAMG,wBAAwBR,qBAAqB;YAAEO;QAAa;QAElE,MAAME,eAAeD,sBAAsBE,MAAM;QAEjD,4BAA4B;QAC5B,IAAI,CAACL,eAAeM,WAAW,EAAE;YAC/BN,eAAeM,WAAW,GAAG,EAAE;QACjC;QAEA,6DAA6D;QAC7D,MAAMC,iBACJ,OAAOJ,sBAAsBK,QAAQ,KAAK,YACtCL,sBAAsBK,QAAQ,GAC5B;YAAEC,UAAU;QAAK,IACjBC,YACFP,sBAAsBK,QAAQ;QAEpC,MAAMG,iBAAi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;QAEA,IAAI,CAACQ,eAAe2F,UAAU,EAAE;YAC9B3F,eAAe2F,UAAU,GAAG,CAAC;QAC/B;QAEA,IAAI,CAAC3F,eAAe2F,UAAU,CAACC,MAAM,EAAE;YACrC5F,eAAe2F,UAAU,CAACC,MAAM,GAAG,EAAE;QACvC;QAEA5F,eAAe2F,UAAU,CAACC,MAAM,CAACnE,IAAI,CAAC,CAACoE,OACrCnG,yBAAyB;gBACvB,GAAGmG,IAAI;gBACPhF;gBACAV;YACF;QAGF,OAAOH;IACT;AACF,GAAE;AAEF,SACElB,yBAAyB,EACzBC,qBAAqB,EACrBC,sBAAsB,EACtBC,wBAAwB,EACxBC,4BAA4B,EAC5BC,8BAA8B,EAC9BC,wBAAwB,EACxBC,4BAA4B,KAC7B;AAED,SAASyG,OAAO,QAAQ,4CAA2C;AACnE,SAASC,SAAS,QAAQ,8CAA6C;AACvE,SAASC,sBAAsB,QAAQ,2DAA0D;AACjG,SAASC,UAAU,QAAQ,+CAA8C;AACzE,SAASC,iBAAiB,QAAQ,0CAAyC;AAc3E,SAASC,UAAU,QAAQ,+CAA8C;AACzE,SAASC,GAAG,EAAEC,GAAG,EAAEC,GAAG,QAAQ,wBAAuB;AACrD,SAASC,WAAW,QAAQ,0BAAyB;AACrD,SAASC,aAAa,QAAQ,4BAA2B;AACzD,SAASC,WAAW,QAAQ,0BAAyB;AACrD,SAASC,WAAW,QAAQ,0BAAyB;AACrD,SAASC,cAAc,QAAQ,6BAA4B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"confirmOrder.d.ts","sourceRoot":"","sources":["../../../../src/payments/adapters/stripe/confirmOrder.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"confirmOrder.d.ts","sourceRoot":"","sources":["../../../../src/payments/adapters/stripe/confirmOrder.ts"],"names":[],"mappings":"AAEA,OAAO,MAAM,MAAM,QAAQ,CAAA;AAE3B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AAC7D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAInD,KAAK,KAAK,GAAG;IACX,UAAU,CAAC,EAAE,MAAM,CAAC,YAAY,CAAC,YAAY,CAAC,CAAA;IAC9C,OAAO,CAAC,EAAE,MAAM,CAAC,YAAY,CAAC,SAAS,CAAC,CAAA;IACxC,SAAS,EAAE,iBAAiB,CAAC,WAAW,CAAC,CAAA;CAC1C,CAAA;AAID,eAAO,MAAM,YAAY,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,WAAW,CAAC,cAAc,CAAC,CAAC,cAAc,CAmFpF,CAAA"}
|
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
import Stripe from 'stripe';
|
|
2
|
-
|
|
2
|
+
import { normalizeEmail, validateSettlement } from './validateSettlement.js';
|
|
3
|
+
export const confirmOrder = (props)=>async ({ data, finalizeOrder, req, transactionsSlug = 'transactions' })=>{
|
|
3
4
|
const payload = req.payload;
|
|
4
5
|
const { apiVersion, appInfo, secretKey } = props || {};
|
|
5
|
-
const customerEmail = data.customerEmail;
|
|
6
6
|
const paymentIntentID = data.paymentIntentID;
|
|
7
7
|
if (!secretKey) {
|
|
8
8
|
throw new Error('Stripe secret key is required');
|
|
9
9
|
}
|
|
10
|
-
if (!paymentIntentID) {
|
|
10
|
+
if (typeof paymentIntentID !== 'string' || !paymentIntentID) {
|
|
11
11
|
throw new Error('PaymentIntent ID is required');
|
|
12
12
|
}
|
|
13
|
+
if (typeof finalizeOrder !== 'function') {
|
|
14
|
+
throw new Error('Core order finalizer is required');
|
|
15
|
+
}
|
|
13
16
|
const stripe = new Stripe(secretKey, {
|
|
14
17
|
// API version can only be the latest, stripe recommends ts ignoring it
|
|
15
18
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
@@ -21,86 +24,56 @@ export const confirmOrder = (props)=>async ({ cartsSlug = 'carts', data, ordersS
|
|
|
21
24
|
}
|
|
22
25
|
});
|
|
23
26
|
try {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
})).data[0];
|
|
27
|
-
if (!customer?.id) {
|
|
28
|
-
customer = await stripe.customers.create({
|
|
29
|
-
email: customerEmail
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
// Find our existing transaction by the payment intent ID
|
|
33
|
-
const transactionsResults = await payload.find({
|
|
34
|
-
collection: transactionsSlug,
|
|
27
|
+
const transaction = await findTransaction({
|
|
28
|
+
paymentIntentID,
|
|
35
29
|
req,
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
30
|
+
transactionsSlug
|
|
31
|
+
});
|
|
32
|
+
const transactionID = requireDocumentID({
|
|
33
|
+
fieldName: 'transaction ID',
|
|
34
|
+
value: transaction.id
|
|
41
35
|
});
|
|
42
|
-
const transaction = transactionsResults.docs[0];
|
|
43
|
-
if (!transactionsResults.totalDocs || !transaction) {
|
|
44
|
-
throw new Error('No transaction found for the provided PaymentIntent ID');
|
|
45
|
-
}
|
|
46
36
|
const paymentIntent = await stripe.paymentIntents.retrieve(paymentIntentID);
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
37
|
+
const cartItemsSnapshot = parseRequiredMetadata({
|
|
38
|
+
fieldName: 'cartItemsSnapshot',
|
|
39
|
+
value: paymentIntent.metadata.cartItemsSnapshot
|
|
40
|
+
});
|
|
41
|
+
const shippingAddress = parseOptionalMetadata({
|
|
42
|
+
fieldName: 'shippingAddress',
|
|
43
|
+
value: paymentIntent.metadata.shippingAddress
|
|
44
|
+
});
|
|
45
|
+
const purchaser = req.user === null || req.user === undefined ? {
|
|
46
|
+
customerEmail: normalizeEmail(data.customerEmail)
|
|
47
|
+
} : {
|
|
48
|
+
customer: requireDocumentID({
|
|
49
|
+
fieldName: 'authenticated customer ID',
|
|
50
|
+
value: req.user.id
|
|
51
|
+
})
|
|
52
|
+
};
|
|
53
|
+
validateSettlement({
|
|
54
|
+
canonicalCartID: data.cartID,
|
|
55
|
+
cartItemsSnapshot,
|
|
56
|
+
customerEmail: data.customerEmail,
|
|
57
|
+
paymentIntent,
|
|
58
|
+
paymentIntentID,
|
|
59
|
+
transaction,
|
|
60
|
+
user: req.user
|
|
61
|
+
});
|
|
62
|
+
const order = await finalizeOrder({
|
|
63
|
+
orderData: {
|
|
64
|
+
amount: transaction.amount,
|
|
65
|
+
currency: transaction.currency,
|
|
66
|
+
...purchaser,
|
|
69
67
|
items: cartItemsSnapshot,
|
|
70
68
|
shippingAddress,
|
|
71
|
-
status: 'processing'
|
|
72
|
-
transactions: [
|
|
73
|
-
transaction.id
|
|
74
|
-
]
|
|
75
|
-
},
|
|
76
|
-
req
|
|
77
|
-
});
|
|
78
|
-
const timestamp = new Date().toISOString();
|
|
79
|
-
await payload.update({
|
|
80
|
-
id: cartID,
|
|
81
|
-
collection: cartsSlug,
|
|
82
|
-
data: {
|
|
83
|
-
purchasedAt: timestamp
|
|
69
|
+
status: 'processing'
|
|
84
70
|
},
|
|
85
|
-
|
|
71
|
+
transactionID
|
|
86
72
|
});
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
data: {
|
|
91
|
-
order: order.id,
|
|
92
|
-
status: 'succeeded'
|
|
93
|
-
},
|
|
94
|
-
req
|
|
73
|
+
return createConfirmationResult({
|
|
74
|
+
order,
|
|
75
|
+
transactionID
|
|
95
76
|
});
|
|
96
|
-
return {
|
|
97
|
-
message: 'Payment initiated successfully',
|
|
98
|
-
orderID: order.id,
|
|
99
|
-
transactionID: transaction.id,
|
|
100
|
-
...order.accessToken ? {
|
|
101
|
-
accessToken: order.accessToken
|
|
102
|
-
} : {}
|
|
103
|
-
};
|
|
104
77
|
} catch (error) {
|
|
105
78
|
payload.logger.error({
|
|
106
79
|
err: error,
|
|
@@ -109,5 +82,64 @@ export const confirmOrder = (props)=>async ({ cartsSlug = 'carts', data, ordersS
|
|
|
109
82
|
throw new Error(error instanceof Error ? error.message : 'Unknown error initiating payment');
|
|
110
83
|
}
|
|
111
84
|
};
|
|
85
|
+
const createConfirmationResult = ({ order, transactionID })=>({
|
|
86
|
+
message: 'Payment initiated successfully',
|
|
87
|
+
orderID: requireDocumentID({
|
|
88
|
+
fieldName: 'order ID',
|
|
89
|
+
value: order.id
|
|
90
|
+
}),
|
|
91
|
+
transactionID,
|
|
92
|
+
...typeof order.accessToken === 'string' ? {
|
|
93
|
+
accessToken: order.accessToken
|
|
94
|
+
} : {}
|
|
95
|
+
});
|
|
96
|
+
const findTransaction = async ({ paymentIntentID, req, transactionsSlug })=>{
|
|
97
|
+
const result = await req.payload.find({
|
|
98
|
+
collection: transactionsSlug,
|
|
99
|
+
depth: 0,
|
|
100
|
+
limit: 2,
|
|
101
|
+
pagination: false,
|
|
102
|
+
req,
|
|
103
|
+
where: {
|
|
104
|
+
'stripe.paymentIntentID': {
|
|
105
|
+
equals: paymentIntentID
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
if (result.totalDocs !== 1 || result.docs.length !== 1 || !result.docs[0]) {
|
|
110
|
+
throw new Error('Expected exactly one transaction for the provided PaymentIntent ID');
|
|
111
|
+
}
|
|
112
|
+
return result.docs[0];
|
|
113
|
+
};
|
|
114
|
+
const parseOptionalMetadata = ({ fieldName, value })=>{
|
|
115
|
+
if (value === undefined) {
|
|
116
|
+
return undefined;
|
|
117
|
+
}
|
|
118
|
+
const parsedValue = parseRequiredMetadata({
|
|
119
|
+
fieldName,
|
|
120
|
+
value
|
|
121
|
+
});
|
|
122
|
+
if (!isRecord(parsedValue)) {
|
|
123
|
+
throw new Error(`${fieldName} metadata is invalid`);
|
|
124
|
+
}
|
|
125
|
+
return parsedValue;
|
|
126
|
+
};
|
|
127
|
+
const parseRequiredMetadata = ({ fieldName, value })=>{
|
|
128
|
+
if (typeof value !== 'string' || !value) {
|
|
129
|
+
throw new Error(`${fieldName} metadata is missing or invalid`);
|
|
130
|
+
}
|
|
131
|
+
try {
|
|
132
|
+
return JSON.parse(value);
|
|
133
|
+
} catch {
|
|
134
|
+
throw new Error(`${fieldName} metadata is missing or invalid`);
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
const requireDocumentID = ({ fieldName, value })=>{
|
|
138
|
+
if ((typeof value !== 'number' || !Number.isFinite(value)) && (typeof value !== 'string' || !value.trim())) {
|
|
139
|
+
throw new Error(`${fieldName} is missing or invalid`);
|
|
140
|
+
}
|
|
141
|
+
return value;
|
|
142
|
+
};
|
|
143
|
+
const isRecord = (value)=>typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
112
144
|
|
|
113
145
|
//# sourceMappingURL=confirmOrder.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/payments/adapters/stripe/confirmOrder.ts"],"sourcesContent":["import Stripe from 'stripe'\n\nimport type { PaymentAdapter } from '../../../types/index.js'\nimport type { StripeAdapterArgs } from './index.js'\n\ntype Props = {\n apiVersion?: Stripe.StripeConfig['apiVersion']\n appInfo?: Stripe.StripeConfig['appInfo']\n secretKey: StripeAdapterArgs['secretKey']\n}\n\nexport const confirmOrder: (props: Props) => NonNullable<PaymentAdapter>['confirmOrder'] =\n (props) =>\n async ({
|
|
1
|
+
{"version":3,"sources":["../../../../src/payments/adapters/stripe/confirmOrder.ts"],"sourcesContent":["import type { DefaultDocumentIDType } from 'payload'\n\nimport Stripe from 'stripe'\n\nimport type { PaymentAdapter } from '../../../types/index.js'\nimport type { StripeAdapterArgs } from './index.js'\n\nimport { normalizeEmail, validateSettlement } from './validateSettlement.js'\n\ntype Props = {\n apiVersion?: Stripe.StripeConfig['apiVersion']\n appInfo?: Stripe.StripeConfig['appInfo']\n secretKey: StripeAdapterArgs['secretKey']\n}\n\ntype RecordValue = Record<string, unknown>\n\nexport const confirmOrder: (props: Props) => NonNullable<PaymentAdapter>['confirmOrder'] =\n (props) =>\n async ({ data, finalizeOrder, req, transactionsSlug = 'transactions' }) => {\n const payload = req.payload\n const { apiVersion, appInfo, secretKey } = props || {}\n const paymentIntentID = data.paymentIntentID\n\n if (!secretKey) {\n throw new Error('Stripe secret key is required')\n }\n\n if (typeof paymentIntentID !== 'string' || !paymentIntentID) {\n throw new Error('PaymentIntent ID is required')\n }\n\n if (typeof finalizeOrder !== 'function') {\n throw new Error('Core order finalizer is required')\n }\n\n const stripe = new Stripe(secretKey, {\n // API version can only be the latest, stripe recommends ts ignoring it\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore - ignoring since possible versions are not type safe, only the latest version is recognised\n apiVersion: apiVersion || '2025-03-31.basil',\n appInfo: appInfo || {\n name: 'Stripe Payload Plugin',\n url: 'https://payloadcms.com',\n },\n })\n\n try {\n const transaction = await findTransaction({ paymentIntentID, req, transactionsSlug })\n const transactionID = requireDocumentID({\n fieldName: 'transaction ID',\n value: transaction.id,\n })\n const paymentIntent = await stripe.paymentIntents.retrieve(paymentIntentID)\n const cartItemsSnapshot = parseRequiredMetadata({\n fieldName: 'cartItemsSnapshot',\n value: paymentIntent.metadata.cartItemsSnapshot,\n })\n const shippingAddress = parseOptionalMetadata({\n fieldName: 'shippingAddress',\n value: paymentIntent.metadata.shippingAddress,\n })\n const purchaser =\n req.user === null || req.user === undefined\n ? { customerEmail: normalizeEmail(data.customerEmail) }\n : {\n customer: requireDocumentID({\n fieldName: 'authenticated customer ID',\n value: req.user.id,\n }),\n }\n\n validateSettlement({\n canonicalCartID: data.cartID,\n cartItemsSnapshot,\n customerEmail: data.customerEmail,\n paymentIntent,\n paymentIntentID,\n transaction,\n user: req.user,\n })\n\n const order = await finalizeOrder({\n orderData: {\n amount: transaction.amount,\n currency: transaction.currency,\n ...purchaser,\n items: cartItemsSnapshot,\n shippingAddress,\n status: 'processing',\n },\n transactionID,\n })\n\n return createConfirmationResult({ order, transactionID })\n } catch (error) {\n payload.logger.error({ err: error, msg: 'Error confirming order with Stripe' })\n\n throw new Error(error instanceof Error ? error.message : 'Unknown error initiating payment')\n }\n }\n\nconst createConfirmationResult = ({\n order,\n transactionID,\n}: {\n order: RecordValue\n transactionID: DefaultDocumentIDType\n}) => ({\n message: 'Payment initiated successfully',\n orderID: requireDocumentID({ fieldName: 'order ID', value: order.id }),\n transactionID,\n ...(typeof order.accessToken === 'string' ? { accessToken: order.accessToken } : {}),\n})\n\nconst findTransaction = async ({\n paymentIntentID,\n req,\n transactionsSlug,\n}: {\n paymentIntentID: string\n req: Parameters<NonNullable<PaymentAdapter>['confirmOrder']>[0]['req']\n transactionsSlug: string\n}): Promise<RecordValue> => {\n const result = await req.payload.find({\n collection: transactionsSlug,\n depth: 0,\n limit: 2,\n pagination: false,\n req,\n where: {\n 'stripe.paymentIntentID': {\n equals: paymentIntentID,\n },\n },\n })\n\n if (result.totalDocs !== 1 || result.docs.length !== 1 || !result.docs[0]) {\n throw new Error('Expected exactly one transaction for the provided PaymentIntent ID')\n }\n\n return result.docs[0] as RecordValue\n}\n\nconst parseOptionalMetadata = ({\n fieldName,\n value,\n}: {\n fieldName: string\n value?: string\n}): RecordValue | undefined => {\n if (value === undefined) {\n return undefined\n }\n\n const parsedValue = parseRequiredMetadata({ fieldName, value })\n\n if (!isRecord(parsedValue)) {\n throw new Error(`${fieldName} metadata is invalid`)\n }\n\n return parsedValue\n}\n\nconst parseRequiredMetadata = ({\n fieldName,\n value,\n}: {\n fieldName: string\n value?: string\n}): unknown => {\n if (typeof value !== 'string' || !value) {\n throw new Error(`${fieldName} metadata is missing or invalid`)\n }\n\n try {\n return JSON.parse(value)\n } catch {\n throw new Error(`${fieldName} metadata is missing or invalid`)\n }\n}\n\nconst requireDocumentID = ({\n fieldName,\n value,\n}: {\n fieldName: string\n value: unknown\n}): DefaultDocumentIDType => {\n if (\n (typeof value !== 'number' || !Number.isFinite(value)) &&\n (typeof value !== 'string' || !value.trim())\n ) {\n throw new Error(`${fieldName} is missing or invalid`)\n }\n\n return value\n}\n\nconst isRecord = (value: unknown): value is RecordValue =>\n typeof value === 'object' && value !== null && !Array.isArray(value)\n"],"names":["Stripe","normalizeEmail","validateSettlement","confirmOrder","props","data","finalizeOrder","req","transactionsSlug","payload","apiVersion","appInfo","secretKey","paymentIntentID","Error","stripe","name","url","transaction","findTransaction","transactionID","requireDocumentID","fieldName","value","id","paymentIntent","paymentIntents","retrieve","cartItemsSnapshot","parseRequiredMetadata","metadata","shippingAddress","parseOptionalMetadata","purchaser","user","undefined","customerEmail","customer","canonicalCartID","cartID","order","orderData","amount","currency","items","status","createConfirmationResult","error","logger","err","msg","message","orderID","accessToken","result","find","collection","depth","limit","pagination","where","equals","totalDocs","docs","length","parsedValue","isRecord","JSON","parse","Number","isFinite","trim","Array","isArray"],"mappings":"AAEA,OAAOA,YAAY,SAAQ;AAK3B,SAASC,cAAc,EAAEC,kBAAkB,QAAQ,0BAAyB;AAU5E,OAAO,MAAMC,eACX,CAACC,QACD,OAAO,EAAEC,IAAI,EAAEC,aAAa,EAAEC,GAAG,EAAEC,mBAAmB,cAAc,EAAE;QACpE,MAAMC,UAAUF,IAAIE,OAAO;QAC3B,MAAM,EAAEC,UAAU,EAAEC,OAAO,EAAEC,SAAS,EAAE,GAAGR,SAAS,CAAC;QACrD,MAAMS,kBAAkBR,KAAKQ,eAAe;QAE5C,IAAI,CAACD,WAAW;YACd,MAAM,IAAIE,MAAM;QAClB;QAEA,IAAI,OAAOD,oBAAoB,YAAY,CAACA,iBAAiB;YAC3D,MAAM,IAAIC,MAAM;QAClB;QAEA,IAAI,OAAOR,kBAAkB,YAAY;YACvC,MAAM,IAAIQ,MAAM;QAClB;QAEA,MAAMC,SAAS,IAAIf,OAAOY,WAAW;YACnC,uEAAuE;YACvE,6DAA6D;YAC7D,yGAAyG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ACF,OAAO6C,KAAKC,KAAK,CAAC7C;IACpB,EAAE,OAAM;QACN,MAAM,IAAIT,MAAM,GAAGQ,UAAU,+BAA+B,CAAC;IAC/D;AACF;AAEA,MAAMD,oBAAoB,CAAC,EACzBC,SAAS,EACTC,KAAK,EAIN;IACC,IACE,AAAC,CAAA,OAAOA,UAAU,YAAY,CAAC8C,OAAOC,QAAQ,CAAC/C,MAAK,KACnD,CAAA,OAAOA,UAAU,YAAY,CAACA,MAAMgD,IAAI,EAAC,GAC1C;QACA,MAAM,IAAIzD,MAAM,GAAGQ,UAAU,sBAAsB,CAAC;IACtD;IAEA,OAAOC;AACT;AAEA,MAAM2C,WAAW,CAAC3C,QAChB,OAAOA,UAAU,YAAYA,UAAU,QAAQ,CAACiD,MAAMC,OAAO,CAAClD"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
type SettlementPaymentIntent = {
|
|
2
|
+
amount?: unknown;
|
|
3
|
+
currency?: unknown;
|
|
4
|
+
customer?: unknown;
|
|
5
|
+
id?: unknown;
|
|
6
|
+
metadata?: unknown;
|
|
7
|
+
status?: unknown;
|
|
8
|
+
};
|
|
9
|
+
type SettlementTransaction = {
|
|
10
|
+
amount?: unknown;
|
|
11
|
+
cart?: unknown;
|
|
12
|
+
currency?: unknown;
|
|
13
|
+
customer?: unknown;
|
|
14
|
+
customerEmail?: unknown;
|
|
15
|
+
id?: unknown;
|
|
16
|
+
items?: unknown;
|
|
17
|
+
order?: unknown;
|
|
18
|
+
status?: unknown;
|
|
19
|
+
stripe?: unknown;
|
|
20
|
+
};
|
|
21
|
+
type SettlementValidationArgs = {
|
|
22
|
+
canonicalCartID: unknown;
|
|
23
|
+
cartItemsSnapshot: unknown;
|
|
24
|
+
customerEmail: unknown;
|
|
25
|
+
paymentIntent: SettlementPaymentIntent;
|
|
26
|
+
paymentIntentID: string;
|
|
27
|
+
transaction: SettlementTransaction;
|
|
28
|
+
user?: {
|
|
29
|
+
id?: unknown;
|
|
30
|
+
} | null;
|
|
31
|
+
};
|
|
32
|
+
export declare const getRelationshipID: (value: unknown) => string | undefined;
|
|
33
|
+
export declare const normalizeEmail: (value: unknown) => string | undefined;
|
|
34
|
+
export declare const normalizeCartItems: (items: unknown) => unknown[];
|
|
35
|
+
export declare const validateSettlement: ({ canonicalCartID, cartItemsSnapshot, customerEmail, paymentIntent, paymentIntentID, transaction, user, }: SettlementValidationArgs) => void;
|
|
36
|
+
export {};
|
|
37
|
+
//# sourceMappingURL=validateSettlement.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateSettlement.d.ts","sourceRoot":"","sources":["../../../../src/payments/adapters/stripe/validateSettlement.ts"],"names":[],"mappings":"AAEA,KAAK,uBAAuB,GAAG;IAC7B,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,EAAE,CAAC,EAAE,OAAO,CAAA;IACZ,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB,CAAA;AAED,KAAK,qBAAqB,GAAG;IAC3B,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,EAAE,CAAC,EAAE,OAAO,CAAA;IACZ,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB,CAAA;AAED,KAAK,wBAAwB,GAAG;IAC9B,eAAe,EAAE,OAAO,CAAA;IACxB,iBAAiB,EAAE,OAAO,CAAA;IAC1B,aAAa,EAAE,OAAO,CAAA;IACtB,aAAa,EAAE,uBAAuB,CAAA;IACtC,eAAe,EAAE,MAAM,CAAA;IACvB,WAAW,EAAE,qBAAqB,CAAA;IAClC,IAAI,CAAC,EAAE;QAAE,EAAE,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI,CAAA;CAC/B,CAAA;AAED,eAAO,MAAM,iBAAiB,UAAW,OAAO,KAAG,MAAM,GAAG,SAY3D,CAAA;AAED,eAAO,MAAM,cAAc,UAAW,OAAO,KAAG,MAAM,GAAG,SAQxD,CAAA;AAED,eAAO,MAAM,kBAAkB,UAAW,OAAO,KAAG,OAAO,EA0C1D,CAAA;AAED,eAAO,MAAM,kBAAkB,8GAQ5B,wBAAwB,KAAG,IA2E7B,CAAA"}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
export const getRelationshipID = (value)=>{
|
|
2
|
+
const relationshipID = isRecord(value) ? value.id : value;
|
|
3
|
+
if (typeof relationshipID === 'number' && Number.isFinite(relationshipID)) {
|
|
4
|
+
return String(relationshipID);
|
|
5
|
+
}
|
|
6
|
+
if (typeof relationshipID === 'string' && relationshipID.trim()) {
|
|
7
|
+
return relationshipID;
|
|
8
|
+
}
|
|
9
|
+
return undefined;
|
|
10
|
+
};
|
|
11
|
+
export const normalizeEmail = (value)=>{
|
|
12
|
+
if (typeof value !== 'string') {
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
const normalizedEmail = value.trim().toLowerCase();
|
|
16
|
+
return normalizedEmail || undefined;
|
|
17
|
+
};
|
|
18
|
+
export const normalizeCartItems = (items)=>{
|
|
19
|
+
if (!Array.isArray(items) || items.length === 0) {
|
|
20
|
+
throw new Error('Cart items are missing or invalid');
|
|
21
|
+
}
|
|
22
|
+
return items.map((item)=>{
|
|
23
|
+
if (!isRecord(item)) {
|
|
24
|
+
throw new Error('Cart items are missing or invalid');
|
|
25
|
+
}
|
|
26
|
+
const productID = getRelationshipID(item.product);
|
|
27
|
+
if (!productID || typeof item.quantity !== 'number' || !Number.isFinite(item.quantity)) {
|
|
28
|
+
throw new Error('Cart items are missing or invalid');
|
|
29
|
+
}
|
|
30
|
+
return Object.fromEntries(Object.entries(item).flatMap(([key, value])=>{
|
|
31
|
+
if (key === 'product') {
|
|
32
|
+
return [
|
|
33
|
+
[
|
|
34
|
+
key,
|
|
35
|
+
productID
|
|
36
|
+
]
|
|
37
|
+
];
|
|
38
|
+
}
|
|
39
|
+
if (key === 'variant') {
|
|
40
|
+
if (value === null || value === undefined) {
|
|
41
|
+
return [];
|
|
42
|
+
}
|
|
43
|
+
const variantID = getRelationshipID(value);
|
|
44
|
+
if (!variantID) {
|
|
45
|
+
throw new Error('Cart item variant relationship is invalid');
|
|
46
|
+
}
|
|
47
|
+
return [
|
|
48
|
+
[
|
|
49
|
+
key,
|
|
50
|
+
variantID
|
|
51
|
+
]
|
|
52
|
+
];
|
|
53
|
+
}
|
|
54
|
+
const normalizedValue = normalizeValue(value);
|
|
55
|
+
return normalizedValue === undefined ? [] : [
|
|
56
|
+
[
|
|
57
|
+
key,
|
|
58
|
+
normalizedValue
|
|
59
|
+
]
|
|
60
|
+
];
|
|
61
|
+
}));
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
export const validateSettlement = ({ canonicalCartID, cartItemsSnapshot, customerEmail, paymentIntent, paymentIntentID, transaction, user })=>{
|
|
65
|
+
if (paymentIntentID !== getNestedString(transaction, 'stripe', 'paymentIntentID') || paymentIntentID !== paymentIntent.id) {
|
|
66
|
+
throw new Error('PaymentIntent does not match the transaction');
|
|
67
|
+
}
|
|
68
|
+
const normalizedCartID = getRelationshipID(canonicalCartID);
|
|
69
|
+
if (!normalizedCartID || normalizedCartID !== getRelationshipID(transaction.cart)) {
|
|
70
|
+
throw new Error('Canonical cart does not match the transaction cart');
|
|
71
|
+
}
|
|
72
|
+
const metadata = isRecord(paymentIntent.metadata) ? paymentIntent.metadata : undefined;
|
|
73
|
+
if (normalizedCartID !== getRelationshipID(metadata?.cartID)) {
|
|
74
|
+
throw new Error('Canonical cart does not match the PaymentIntent cart');
|
|
75
|
+
}
|
|
76
|
+
const transactionCustomerID = getRelationshipID(transaction.customer);
|
|
77
|
+
if (user !== null && user !== undefined) {
|
|
78
|
+
const authenticatedUserID = getRelationshipID(user.id);
|
|
79
|
+
if (!authenticatedUserID) {
|
|
80
|
+
throw new Error('Authenticated customer ID is missing or invalid');
|
|
81
|
+
}
|
|
82
|
+
if (transactionCustomerID !== authenticatedUserID) {
|
|
83
|
+
throw new Error('Authenticated customer does not match the transaction customer');
|
|
84
|
+
}
|
|
85
|
+
} else {
|
|
86
|
+
if (transactionCustomerID) {
|
|
87
|
+
throw new Error('Guest transaction belongs to an authenticated customer');
|
|
88
|
+
}
|
|
89
|
+
const normalizedCustomerEmail = normalizeEmail(customerEmail);
|
|
90
|
+
if (!normalizedCustomerEmail || normalizedCustomerEmail !== normalizeEmail(transaction.customerEmail)) {
|
|
91
|
+
throw new Error('Guest email does not match the transaction email');
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
const stripeCustomerID = getNestedString(transaction, 'stripe', 'customerID');
|
|
95
|
+
if (!stripeCustomerID || stripeCustomerID !== getRelationshipID(paymentIntent.customer)) {
|
|
96
|
+
throw new Error('Stripe customer does not match the transaction');
|
|
97
|
+
}
|
|
98
|
+
if (paymentIntent.amount !== transaction.amount) {
|
|
99
|
+
throw new Error('Stripe amount does not match the transaction amount');
|
|
100
|
+
}
|
|
101
|
+
if (typeof paymentIntent.currency !== 'string' || typeof transaction.currency !== 'string' || paymentIntent.currency.toUpperCase() !== transaction.currency) {
|
|
102
|
+
throw new Error('Stripe currency does not match the transaction currency');
|
|
103
|
+
}
|
|
104
|
+
const normalizedSnapshot = normalizeCartItems(cartItemsSnapshot);
|
|
105
|
+
const normalizedTransactionItems = normalizeCartItems(transaction.items);
|
|
106
|
+
if (stableSerialize(normalizedSnapshot) !== stableSerialize(normalizedTransactionItems)) {
|
|
107
|
+
throw new Error('Stripe cart items do not match the transaction items');
|
|
108
|
+
}
|
|
109
|
+
if (paymentIntent.status !== 'succeeded') {
|
|
110
|
+
throw new Error('Payment not completed.');
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
const getNestedString = (value, groupName, fieldName)=>{
|
|
114
|
+
if (!isRecord(value)) {
|
|
115
|
+
return undefined;
|
|
116
|
+
}
|
|
117
|
+
const group = value[groupName];
|
|
118
|
+
if (!isRecord(group) || typeof group[fieldName] !== 'string') {
|
|
119
|
+
return undefined;
|
|
120
|
+
}
|
|
121
|
+
return group[fieldName];
|
|
122
|
+
};
|
|
123
|
+
const isRecord = (value)=>typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
124
|
+
const normalizeValue = (value)=>{
|
|
125
|
+
if (Array.isArray(value)) {
|
|
126
|
+
return value.map((entry)=>normalizeValue(entry));
|
|
127
|
+
}
|
|
128
|
+
if (isRecord(value)) {
|
|
129
|
+
return Object.fromEntries(Object.entries(value).flatMap(([entryKey, entryValue])=>{
|
|
130
|
+
const normalizedValue = normalizeValue(entryValue);
|
|
131
|
+
return normalizedValue === undefined ? [] : [
|
|
132
|
+
[
|
|
133
|
+
entryKey,
|
|
134
|
+
normalizedValue
|
|
135
|
+
]
|
|
136
|
+
];
|
|
137
|
+
}));
|
|
138
|
+
}
|
|
139
|
+
if (value === null || typeof value === 'boolean' || typeof value === 'number' || typeof value === 'string') {
|
|
140
|
+
return value;
|
|
141
|
+
}
|
|
142
|
+
if (value === undefined) {
|
|
143
|
+
return undefined;
|
|
144
|
+
}
|
|
145
|
+
throw new Error('Cart items contain unsupported data');
|
|
146
|
+
};
|
|
147
|
+
const stableSerialize = (value)=>{
|
|
148
|
+
if (Array.isArray(value)) {
|
|
149
|
+
return `[${value.map((entry)=>stableSerialize(entry)).join(',')}]`;
|
|
150
|
+
}
|
|
151
|
+
if (isRecord(value)) {
|
|
152
|
+
return `{${Object.keys(value).sort().map((key)=>`${JSON.stringify(key)}:${stableSerialize(value[key])}`).join(',')}}`;
|
|
153
|
+
}
|
|
154
|
+
return JSON.stringify(value);
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
//# sourceMappingURL=validateSettlement.js.map
|