@payloadcms/plugin-ecommerce 4.0.0-internal.cc18726 → 4.0.0-internal.cd47d20
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/addresses/createAddressesCollection.d.ts.map +1 -1
- package/dist/collections/addresses/createAddressesCollection.js +1 -0
- package/dist/collections/addresses/createAddressesCollection.js.map +1 -1
- package/dist/collections/carts/beforeChange.d.ts.map +1 -1
- package/dist/collections/carts/beforeChange.js +2 -0
- package/dist/collections/carts/beforeChange.js.map +1 -1
- package/dist/collections/carts/createCartsCollection.d.ts.map +1 -1
- package/dist/collections/carts/createCartsCollection.js +1 -0
- package/dist/collections/carts/createCartsCollection.js.map +1 -1
- package/dist/collections/orders/createOrdersCollection.d.ts.map +1 -1
- package/dist/collections/orders/createOrdersCollection.js +1 -0
- package/dist/collections/orders/createOrdersCollection.js.map +1 -1
- package/dist/collections/products/createProductsCollection.d.ts.map +1 -1
- package/dist/collections/products/createProductsCollection.js +1 -0
- package/dist/collections/products/createProductsCollection.js.map +1 -1
- package/dist/collections/transactions/createTransactionsCollection.d.ts.map +1 -1
- package/dist/collections/transactions/createTransactionsCollection.js +1 -0
- package/dist/collections/transactions/createTransactionsCollection.js.map +1 -1
- package/dist/collections/variants/createVariantOptionsCollection.d.ts.map +1 -1
- package/dist/collections/variants/createVariantOptionsCollection.js +1 -0
- package/dist/collections/variants/createVariantOptionsCollection.js.map +1 -1
- package/dist/collections/variants/createVariantTypesCollection.d.ts.map +1 -1
- package/dist/collections/variants/createVariantTypesCollection.js +1 -0
- package/dist/collections/variants/createVariantTypesCollection.js.map +1 -1
- package/dist/collections/variants/createVariantsCollection/hooks/beforeChange.d.ts.map +1 -1
- package/dist/collections/variants/createVariantsCollection/hooks/beforeChange.js +2 -0
- package/dist/collections/variants/createVariantsCollection/hooks/beforeChange.js.map +1 -1
- package/dist/collections/variants/createVariantsCollection/hooks/validateOptions.d.ts.map +1 -1
- package/dist/collections/variants/createVariantsCollection/hooks/validateOptions.js +1 -0
- package/dist/collections/variants/createVariantsCollection/hooks/validateOptions.js.map +1 -1
- package/dist/collections/variants/createVariantsCollection/index.d.ts.map +1 -1
- package/dist/collections/variants/createVariantsCollection/index.js +1 -0
- package/dist/collections/variants/createVariantsCollection/index.js.map +1 -1
- package/dist/endpoints/confirmOrder.d.ts.map +1 -1
- package/dist/endpoints/confirmOrder.js +306 -44
- package/dist/endpoints/confirmOrder.js.map +1 -1
- package/dist/endpoints/initiatePayment.d.ts.map +1 -1
- package/dist/endpoints/initiatePayment.js +2 -0
- package/dist/endpoints/initiatePayment.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 +108 -75
- package/dist/payments/adapters/stripe/confirmOrder.js.map +1 -1
- package/dist/payments/adapters/stripe/initiatePayment.d.ts.map +1 -1
- package/dist/payments/adapters/stripe/initiatePayment.js +1 -0
- package/dist/payments/adapters/stripe/initiatePayment.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/types/index.d.ts +24 -5
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js.map +1 -1
- package/dist/ui/VariantOptionsSelector/index.d.ts.map +1 -1
- package/dist/ui/VariantOptionsSelector/index.js +3 -1
- package/dist/ui/VariantOptionsSelector/index.js.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,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,EAA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,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;A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9BC,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,65 @@ 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
|
+
overrideAccess: true,
|
|
102
|
+
pagination: false,
|
|
103
|
+
req,
|
|
104
|
+
where: {
|
|
105
|
+
'stripe.paymentIntentID': {
|
|
106
|
+
equals: paymentIntentID
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
if (result.totalDocs !== 1 || result.docs.length !== 1 || !result.docs[0]) {
|
|
111
|
+
throw new Error('Expected exactly one transaction for the provided PaymentIntent ID');
|
|
112
|
+
}
|
|
113
|
+
return result.docs[0];
|
|
114
|
+
};
|
|
115
|
+
const parseOptionalMetadata = ({ fieldName, value })=>{
|
|
116
|
+
if (value === undefined) {
|
|
117
|
+
return undefined;
|
|
118
|
+
}
|
|
119
|
+
const parsedValue = parseRequiredMetadata({
|
|
120
|
+
fieldName,
|
|
121
|
+
value
|
|
122
|
+
});
|
|
123
|
+
if (!isRecord(parsedValue)) {
|
|
124
|
+
throw new Error(`${fieldName} metadata is invalid`);
|
|
125
|
+
}
|
|
126
|
+
return parsedValue;
|
|
127
|
+
};
|
|
128
|
+
const parseRequiredMetadata = ({ fieldName, value })=>{
|
|
129
|
+
if (typeof value !== 'string' || !value) {
|
|
130
|
+
throw new Error(`${fieldName} metadata is missing or invalid`);
|
|
131
|
+
}
|
|
132
|
+
try {
|
|
133
|
+
return JSON.parse(value);
|
|
134
|
+
} catch {
|
|
135
|
+
throw new Error(`${fieldName} metadata is missing or invalid`);
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
const requireDocumentID = ({ fieldName, value })=>{
|
|
139
|
+
if ((typeof value !== 'number' || !Number.isFinite(value)) && (typeof value !== 'string' || !value.trim())) {
|
|
140
|
+
throw new Error(`${fieldName} is missing or invalid`);
|
|
141
|
+
}
|
|
142
|
+
return value;
|
|
143
|
+
};
|
|
144
|
+
const isRecord = (value)=>typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
112
145
|
|
|
113
146
|
//# 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 overrideAccess: true,\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","overrideAccess","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;YACzGF,YAAYA,cAAc;YAC1BC,SAASA,WAAW;gBAClBK,MAAM;gBACNC,KAAK;YACP;QACF;QAEA,IAAI;YACF,MAAMC,cAAc,MAAMC,gBAAgB;gBAAEN;gBAAiBN;gBAAKC;YAAiB;YACnF,MAAMY,gBAAgBC,kBAAkB;gBACtCC,WAAW;gBACXC,OAAOL,YAAYM,EAAE;YACvB;YACA,MAAMC,gBAAgB,MAAMV,OAAOW,cAAc,CAACC,QAAQ,CAACd;YAC3D,MAAMe,oBAAoBC,sBAAsB;gBAC9CP,WAAW;gBACXC,OAAOE,cAAcK,QAAQ,CAACF,iBAAiB;YACjD;Y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A,OAAOC;AACT;AAEA,MAAM4C,WAAW,CAAC5C,QAChB,OAAOA,UAAU,YAAYA,UAAU,QAAQ,CAACkD,MAAMC,OAAO,CAACnD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initiatePayment.d.ts","sourceRoot":"","sources":["../../../../src/payments/adapters/stripe/initiatePayment.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAA;AAE3B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AAC7D,OAAO,KAAK,EAA6B,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAE9E,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;AAED,eAAO,MAAM,eAAe,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,WAAW,CAAC,cAAc,CAAC,CAAC,iBAAiB,
|
|
1
|
+
{"version":3,"file":"initiatePayment.d.ts","sourceRoot":"","sources":["../../../../src/payments/adapters/stripe/initiatePayment.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAA;AAE3B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AAC7D,OAAO,KAAK,EAA6B,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAE9E,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;AAED,eAAO,MAAM,eAAe,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,WAAW,CAAC,cAAc,CAAC,CAAC,iBAAiB,CA8H1F,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/payments/adapters/stripe/initiatePayment.ts"],"sourcesContent":["import Stripe from 'stripe'\n\nimport type { PaymentAdapter } from '../../../types/index.js'\nimport type { InitiatePaymentReturnType, 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 initiatePayment: (props: Props) => NonNullable<PaymentAdapter>['initiatePayment'] =\n (props) =>\n async ({ data, req, transactionsSlug }) => {\n const payload = req.payload\n const { apiVersion, appInfo, secretKey } = props || {}\n\n const customerEmail = data.customerEmail\n const currency = data.currency\n const cart = data.cart\n const amount = cart.subtotal\n const billingAddressFromData = data.billingAddress\n const shippingAddressFromData = data.shippingAddress\n\n if (!secretKey) {\n throw new Error('Stripe secret key is required.')\n }\n\n if (!currency) {\n throw new Error('Currency is required.')\n }\n\n if (!cart || !cart.items || cart.items.length === 0) {\n throw new Error('Cart is empty or not provided.')\n }\n\n if (!customerEmail || typeof customerEmail !== 'string') {\n throw new Error('A valid customer email is required to make a purchase.')\n }\n\n if (!amount || typeof amount !== 'number' || amount <= 0) {\n throw new Error('A valid amount is required to initiate a payment.')\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-06-30.preview',\n appInfo: appInfo || {\n name: 'Stripe Payload Plugin',\n url: 'https://payloadcms.com',\n },\n })\n\n try {\n let customer = (\n await stripe.customers.list({\n email: customerEmail,\n })\n ).data[0]\n\n if (!customer?.id) {\n customer = await stripe.customers.create({\n email: customerEmail,\n })\n }\n\n const flattenedCart = cart.items.map((item) => {\n const productID = typeof item.product === 'object' ? item.product.id : item.product\n const variantID = item.variant\n ? typeof item.variant === 'object'\n ? item.variant.id\n : item.variant\n : undefined\n\n // Preserve any additional custom properties (e.g., deliveryOption, customizations)\n // that may have been added via cartItemMatcher\n const { product: _product, variant: _variant, ...customProperties } = item\n\n return {\n ...customProperties,\n product: productID,\n quantity: item.quantity,\n ...(variantID ? { variant: variantID } : {}),\n }\n })\n\n const shippingAddressAsString = JSON.stringify(shippingAddressFromData)\n\n const paymentIntent = await stripe.paymentIntents.create({\n amount,\n automatic_payment_methods: {\n enabled: true,\n },\n currency,\n customer: customer.id,\n metadata: {\n cartID: cart.id,\n cartItemsSnapshot: JSON.stringify(flattenedCart),\n shippingAddress: shippingAddressAsString,\n },\n })\n\n // Create a transaction for the payment intent in the database\n const transaction = await payload.create({\n collection: transactionsSlug,\n data: {\n ...(req.user ? { customer: req.user.id } : { customerEmail }),\n amount: paymentIntent.amount,\n billingAddress: billingAddressFromData,\n cart: cart.id,\n currency: paymentIntent.currency.toUpperCase(),\n items: flattenedCart,\n paymentMethod: 'stripe',\n status: 'pending',\n stripe: {\n customerID: customer.id,\n paymentIntentID: paymentIntent.id,\n },\n },\n req,\n })\n\n const returnData: InitiatePaymentReturnType = {\n clientSecret: paymentIntent.client_secret || '',\n message: 'Payment initiated successfully',\n paymentIntentID: paymentIntent.id,\n }\n\n return returnData\n } catch (error) {\n payload.logger.error({ err: error, msg: 'Error initiating payment with Stripe' })\n\n throw new Error(error instanceof Error ? error.message : 'Unknown error initiating payment')\n }\n }\n"],"names":["Stripe","initiatePayment","props","data","req","transactionsSlug","payload","apiVersion","appInfo","secretKey","customerEmail","currency","cart","amount","subtotal","billingAddressFromData","billingAddress","shippingAddressFromData","shippingAddress","Error","items","length","stripe","name","url","customer","customers","list","email","id","create","flattenedCart","map","item","productID","product","variantID","variant","undefined","_product","_variant","customProperties","quantity","shippingAddressAsString","JSON","stringify","paymentIntent","paymentIntents","automatic_payment_methods","enabled","metadata","cartID","cartItemsSnapshot","transaction","collection","user","toUpperCase","paymentMethod","status","customerID","paymentIntentID","returnData","clientSecret","client_secret","message","error","logger","err","msg"],"mappings":"AAAA,OAAOA,YAAY,SAAQ;AAW3B,OAAO,MAAMC,kBACX,CAACC,QACD,OAAO,EAAEC,IAAI,EAAEC,GAAG,EAAEC,gBAAgB,EAAE;QACpC,MAAMC,UAAUF,IAAIE,OAAO;QAC3B,MAAM,EAAEC,UAAU,EAAEC,OAAO,EAAEC,SAAS,EAAE,GAAGP,SAAS,CAAC;QAErD,MAAMQ,gBAAgBP,KAAKO,aAAa;QACxC,MAAMC,WAAWR,KAAKQ,QAAQ;QAC9B,MAAMC,OAAOT,KAAKS,IAAI;QACtB,MAAMC,SAASD,KAAKE,QAAQ;QAC5B,MAAMC,yBAAyBZ,KAAKa,cAAc;QAClD,MAAMC,0BAA0Bd,KAAKe,eAAe;QAEpD,IAAI,CAACT,WAAW;YACd,MAAM,IAAIU,MAAM;QAClB;QAEA,IAAI,CAACR,UAAU;YACb,MAAM,IAAIQ,MAAM;QAClB;QAEA,IAAI,CAACP,QAAQ,CAACA,KAAKQ,KAAK,IAAIR,KAAKQ,KAAK,CAACC,MAAM,KAAK,GAAG;YACnD,MAAM,IAAIF,MAAM;QAClB;QAEA,IAAI,CAACT,iBAAiB,OAAOA,kBAAkB,UAAU;YACvD,MAAM,IAAIS,MAAM;QAClB;QAEA,IAAI,CAACN,UAAU,OAAOA,WAAW,YAAYA,UAAU,GAAG;YACxD,MAAM,IAAIM,MAAM;QAClB;QAEA,MAAMG,SAAS,IAAItB,OAAOS,WAAW;YACnC,uEAAuE;YACvE,6DAA6D;YAC7D,yGAAyG;YACzGF,YAAYA,cAAc;YAC1BC,SAASA,WAAW;gBAClBe,MAAM;gBACNC,KAAK;YACP;QACF;QAEA,IAAI;YACF,IAAIC,WAAW,AACb,CAAA,MAAMH,OAAOI,SAAS,CAACC,IAAI,CAAC;gBAC1BC,OAAOlB;YACT,EAAC,EACDP,IAAI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,MAAM;oBAC5BG,gBAAgBD;oBAChBH,MAAMA,KAAKiB,EAAE;oBACblB,UAAUmC,cAAcnC,QAAQ,CAAC6C,WAAW;oBAC5CpC,OAAOW;oBACP0B,eAAe;oBACfC,QAAQ;oBACRpC,QAAQ;wBACNqC,YAAYlC,SAASI,EAAE;wBACvB+B,iBAAiBd,cAAcjB,EAAE;oBACnC;gBACF;
|
|
1
|
+
{"version":3,"sources":["../../../../src/payments/adapters/stripe/initiatePayment.ts"],"sourcesContent":["import Stripe from 'stripe'\n\nimport type { PaymentAdapter } from '../../../types/index.js'\nimport type { InitiatePaymentReturnType, 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 initiatePayment: (props: Props) => NonNullable<PaymentAdapter>['initiatePayment'] =\n (props) =>\n async ({ data, req, transactionsSlug }) => {\n const payload = req.payload\n const { apiVersion, appInfo, secretKey } = props || {}\n\n const customerEmail = data.customerEmail\n const currency = data.currency\n const cart = data.cart\n const amount = cart.subtotal\n const billingAddressFromData = data.billingAddress\n const shippingAddressFromData = data.shippingAddress\n\n if (!secretKey) {\n throw new Error('Stripe secret key is required.')\n }\n\n if (!currency) {\n throw new Error('Currency is required.')\n }\n\n if (!cart || !cart.items || cart.items.length === 0) {\n throw new Error('Cart is empty or not provided.')\n }\n\n if (!customerEmail || typeof customerEmail !== 'string') {\n throw new Error('A valid customer email is required to make a purchase.')\n }\n\n if (!amount || typeof amount !== 'number' || amount <= 0) {\n throw new Error('A valid amount is required to initiate a payment.')\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-06-30.preview',\n appInfo: appInfo || {\n name: 'Stripe Payload Plugin',\n url: 'https://payloadcms.com',\n },\n })\n\n try {\n let customer = (\n await stripe.customers.list({\n email: customerEmail,\n })\n ).data[0]\n\n if (!customer?.id) {\n customer = await stripe.customers.create({\n email: customerEmail,\n })\n }\n\n const flattenedCart = cart.items.map((item) => {\n const productID = typeof item.product === 'object' ? item.product.id : item.product\n const variantID = item.variant\n ? typeof item.variant === 'object'\n ? item.variant.id\n : item.variant\n : undefined\n\n // Preserve any additional custom properties (e.g., deliveryOption, customizations)\n // that may have been added via cartItemMatcher\n const { product: _product, variant: _variant, ...customProperties } = item\n\n return {\n ...customProperties,\n product: productID,\n quantity: item.quantity,\n ...(variantID ? { variant: variantID } : {}),\n }\n })\n\n const shippingAddressAsString = JSON.stringify(shippingAddressFromData)\n\n const paymentIntent = await stripe.paymentIntents.create({\n amount,\n automatic_payment_methods: {\n enabled: true,\n },\n currency,\n customer: customer.id,\n metadata: {\n cartID: cart.id,\n cartItemsSnapshot: JSON.stringify(flattenedCart),\n shippingAddress: shippingAddressAsString,\n },\n })\n\n // Create a transaction for the payment intent in the database\n const transaction = await payload.create({\n collection: transactionsSlug,\n data: {\n ...(req.user ? { customer: req.user.id } : { customerEmail }),\n amount: paymentIntent.amount,\n billingAddress: billingAddressFromData,\n cart: cart.id,\n currency: paymentIntent.currency.toUpperCase(),\n items: flattenedCart,\n paymentMethod: 'stripe',\n status: 'pending',\n stripe: {\n customerID: customer.id,\n paymentIntentID: paymentIntent.id,\n },\n },\n overrideAccess: true,\n req,\n })\n\n const returnData: InitiatePaymentReturnType = {\n clientSecret: paymentIntent.client_secret || '',\n message: 'Payment initiated successfully',\n paymentIntentID: paymentIntent.id,\n }\n\n return returnData\n } catch (error) {\n payload.logger.error({ err: error, msg: 'Error initiating payment with Stripe' })\n\n throw new Error(error instanceof Error ? error.message : 'Unknown error initiating payment')\n }\n }\n"],"names":["Stripe","initiatePayment","props","data","req","transactionsSlug","payload","apiVersion","appInfo","secretKey","customerEmail","currency","cart","amount","subtotal","billingAddressFromData","billingAddress","shippingAddressFromData","shippingAddress","Error","items","length","stripe","name","url","customer","customers","list","email","id","create","flattenedCart","map","item","productID","product","variantID","variant","undefined","_product","_variant","customProperties","quantity","shippingAddressAsString","JSON","stringify","paymentIntent","paymentIntents","automatic_payment_methods","enabled","metadata","cartID","cartItemsSnapshot","transaction","collection","user","toUpperCase","paymentMethod","status","customerID","paymentIntentID","overrideAccess","returnData","clientSecret","client_secret","message","error","logger","err","msg"],"mappings":"AAAA,OAAOA,YAAY,SAAQ;AAW3B,OAAO,MAAMC,kBACX,CAACC,QACD,OAAO,EAAEC,IAAI,EAAEC,GAAG,EAAEC,gBAAgB,EAAE;QACpC,MAAMC,UAAUF,IAAIE,OAAO;QAC3B,MAAM,EAAEC,UAAU,EAAEC,OAAO,EAAEC,SAAS,EAAE,GAAGP,SAAS,CAAC;QAErD,MAAMQ,gBAAgBP,KAAKO,aAAa;QACxC,MAAMC,WAAWR,KAAKQ,QAAQ;QAC9B,MAAMC,OAAOT,KAAKS,IAAI;QACtB,MAAMC,SAASD,KAAKE,QAAQ;QAC5B,MAAMC,yBAAyBZ,KAAKa,cAAc;QAClD,MAAMC,0BAA0Bd,KAAKe,eAAe;QAEpD,IAAI,CAACT,WAAW;YACd,MAAM,IAAIU,MAAM;QAClB;QAEA,IAAI,CAACR,UAAU;YACb,MAAM,IAAIQ,MAAM;QAClB;QAEA,IAAI,CAACP,QAAQ,CAACA,KAAKQ,KAAK,IAAIR,KAAKQ,KAAK,CAACC,MAAM,KAAK,GAAG;YACnD,MAAM,IAAIF,MAAM;QAClB;QAEA,IAAI,CAACT,iBAAiB,OAAOA,kBAAkB,UAAU;YACvD,MAAM,IAAIS,MAAM;QAClB;QAEA,IAAI,CAACN,UAAU,OAAOA,WAAW,YAAYA,UAAU,GAAG;YACxD,MAAM,IAAIM,MAAM;QAClB;QAEA,MAAMG,SAAS,IAAItB,OAAOS,WAAW;YACnC,uEAAuE;YACvE,6DAA6D;YAC7D,yGAAyG;YACzGF,YAAYA,cAAc;YAC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;gBACvCwB,YAAYjD;gBACZF,MAAM;oBACJ,GAAIC,IAAImD,IAAI,GAAG;wBAAE9B,UAAUrB,IAAImD,IAAI,CAAC1B,EAAE;oBAAC,IAAI;wBAAEnB;oBAAc,CAAC;oBAC5DG,QAAQiC,cAAcjC,MAAM;oBAC5BG,gBAAgBD;oBAChBH,MAAMA,KAAKiB,EAAE;oBACblB,UAAUmC,cAAcnC,QAAQ,CAAC6C,WAAW;oBAC5CpC,OAAOW;oBACP0B,eAAe;oBACfC,QAAQ;oBACRpC,QAAQ;wBACNqC,YAAYlC,SAASI,EAAE;wBACvB+B,iBAAiBd,cAAcjB,EAAE;oBACnC;gBACF;gBACAgC,gBAAgB;gBAChBzD;YACF;YAEA,MAAM0D,aAAwC;gBAC5CC,cAAcjB,cAAckB,aAAa,IAAI;gBAC7CC,SAAS;gBACTL,iBAAiBd,cAAcjB,EAAE;YACnC;YAEA,OAAOiC;QACT,EAAE,OAAOI,OAAO;YACd5D,QAAQ6D,MAAM,CAACD,KAAK,CAAC;gBAAEE,KAAKF;gBAAOG,KAAK;YAAuC;YAE/E,MAAM,IAAIlD,MAAM+C,iBAAiB/C,QAAQ+C,MAAMD,OAAO,GAAG;QAC3D;IACF,EAAC"}
|
|
@@ -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,EAA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