@payloadcms/storage-r2 0.0.1-beta.0 → 3.50.0-internal.ca62628
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/handleDelete.d.ts +8 -0
- package/dist/handleDelete.d.ts.map +1 -0
- package/dist/handleDelete.js +8 -0
- package/dist/handleDelete.js.map +1 -0
- package/dist/handleUpload.d.ts +11 -0
- package/dist/handleUpload.d.ts.map +1 -0
- package/dist/handleUpload.js +13 -0
- package/dist/handleUpload.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +59 -0
- package/dist/index.js.map +1 -0
- package/dist/staticHandler.d.ts +11 -0
- package/dist/staticHandler.d.ts.map +1 -0
- package/dist/staticHandler.js +29 -0
- package/dist/staticHandler.js.map +1 -0
- package/dist/types.d.ts +16 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/package.json +57 -1
- package/.prettierignore +0 -12
- package/.swcrc +0 -24
- package/README.md +0 -3
- package/eslint.config.js +0 -18
- package/src/addresses/addressesCollection.ts +0 -76
- package/src/addresses/defaultAddressFields.ts +0 -83
- package/src/addresses/defaultCountries.ts +0 -50
- package/src/carts/beforeChange.ts +0 -51
- package/src/carts/cartsCollection.ts +0 -146
- package/src/currencies/index.ts +0 -29
- package/src/endpoints/confirmOrder.ts +0 -312
- package/src/endpoints/initiatePayment.ts +0 -322
- package/src/exports/addresses.ts +0 -2
- package/src/exports/currencies.ts +0 -1
- package/src/exports/fields.ts +0 -5
- package/src/exports/orders.ts +0 -1
- package/src/exports/payments/stripe.ts +0 -1
- package/src/exports/plugin.ts +0 -1
- package/src/exports/products.ts +0 -1
- package/src/exports/react.ts +0 -8
- package/src/exports/transactions.ts +0 -1
- package/src/exports/translations.ts +0 -1
- package/src/exports/types.ts +0 -7
- package/src/exports/ui.ts +0 -3
- package/src/exports/variants.ts +0 -5
- package/src/fields/amountField.ts +0 -43
- package/src/fields/cartItemsField.ts +0 -84
- package/src/fields/currencyField.ts +0 -39
- package/src/fields/inventoryField.ts +0 -22
- package/src/fields/pricesField.ts +0 -65
- package/src/fields/statusField.ts +0 -57
- package/src/fields/variantsFields.ts +0 -56
- package/src/index.ts +0 -275
- package/src/orders/ordersCollection.ts +0 -157
- package/src/payments/adapters/stripe/confirmOrder.ts +0 -123
- package/src/payments/adapters/stripe/endpoints/webhooks.ts +0 -69
- package/src/payments/adapters/stripe/index.ts +0 -135
- package/src/payments/adapters/stripe/initiatePayment.ts +0 -131
- package/src/products/productsCollection.ts +0 -78
- package/src/react/provider/index.tsx +0 -893
- package/src/react/provider/types.ts +0 -184
- package/src/react/provider/utilities.ts +0 -22
- package/src/transactions/transactionsCollection.ts +0 -166
- package/src/translations/en.ts +0 -64
- package/src/translations/index.ts +0 -11
- package/src/translations/translation-schema.json +0 -35
- package/src/types.ts +0 -403
- package/src/ui/PriceInput/FormattedInput.tsx +0 -134
- package/src/ui/PriceInput/index.scss +0 -28
- package/src/ui/PriceInput/index.tsx +0 -43
- package/src/ui/PriceInput/utilities.ts +0 -46
- package/src/ui/PriceRowLabel/index.css +0 -13
- package/src/ui/PriceRowLabel/index.tsx +0 -56
- package/src/ui/VariantOptionsSelector/ErrorBox.tsx +0 -27
- package/src/ui/VariantOptionsSelector/OptionsSelect.tsx +0 -78
- package/src/ui/VariantOptionsSelector/index.css +0 -37
- package/src/ui/VariantOptionsSelector/index.tsx +0 -83
- package/src/utilities/defaultProductsValidation.ts +0 -42
- package/src/utilities/errorCodes.ts +0 -14
- package/src/utilities/getCollectionSlugMap.ts +0 -84
- package/src/utilities/sanitizePluginConfig.ts +0 -80
- package/src/variants/variantOptionsCollection.ts +0 -59
- package/src/variants/variantTypesCollection.ts +0 -55
- package/src/variants/variantsCollection/hooks/beforeChange.ts +0 -47
- package/src/variants/variantsCollection/hooks/validateOptions.ts +0 -72
- package/src/variants/variantsCollection/index.ts +0 -119
- package/tsconfig.json +0 -7
- package/tsconfig.tsbuildinfo +0 -1
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
import type { Field, GroupField, PayloadRequest } from 'payload'
|
|
2
|
-
import type { Stripe } from 'stripe'
|
|
3
|
-
|
|
4
|
-
import type {
|
|
5
|
-
BasePaymentAdapterArgs,
|
|
6
|
-
BasePaymentAdapterClientArgs,
|
|
7
|
-
PaymentAdapter,
|
|
8
|
-
PaymentAdapterClient,
|
|
9
|
-
} from '../../../types.js'
|
|
10
|
-
|
|
11
|
-
import { confirmOrder } from './confirmOrder.js'
|
|
12
|
-
import { webhooksEndpoint } from './endpoints/webhooks.js'
|
|
13
|
-
import { initiatePayment } from './initiatePayment.js'
|
|
14
|
-
|
|
15
|
-
type StripeWebhookHandler = (args: {
|
|
16
|
-
event: Stripe.Event
|
|
17
|
-
req: PayloadRequest
|
|
18
|
-
stripe: Stripe
|
|
19
|
-
}) => Promise<void> | void
|
|
20
|
-
|
|
21
|
-
type StripeWebhookHandlers = {
|
|
22
|
-
/**
|
|
23
|
-
* Description of the event (e.g., invoice.created or charge.refunded).
|
|
24
|
-
*/
|
|
25
|
-
[webhookName: string]: StripeWebhookHandler
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export type StripeAdapterArgs = {
|
|
29
|
-
/**
|
|
30
|
-
* This library's types only reflect the latest API version.
|
|
31
|
-
*
|
|
32
|
-
* We recommend upgrading your account's API Version to the latest version
|
|
33
|
-
* if you wish to use TypeScript with this library.
|
|
34
|
-
*
|
|
35
|
-
* If you wish to remain on your account's default API version,
|
|
36
|
-
* you may pass `null` or another version instead of the latest version,
|
|
37
|
-
* and add a `@ts-ignore` comment here and anywhere the types differ between API versions.
|
|
38
|
-
*
|
|
39
|
-
* @docs https://stripe.com/docs/api/versioning
|
|
40
|
-
*/
|
|
41
|
-
apiVersion?: Stripe.StripeConfig['apiVersion']
|
|
42
|
-
appInfo?: Stripe.StripeConfig['appInfo']
|
|
43
|
-
publishableKey: string
|
|
44
|
-
secretKey: string
|
|
45
|
-
webhooks?: StripeWebhookHandlers
|
|
46
|
-
webhookSecret: string
|
|
47
|
-
} & BasePaymentAdapterArgs
|
|
48
|
-
|
|
49
|
-
export const stripeAdapter: (props: StripeAdapterArgs) => PaymentAdapter = (props) => {
|
|
50
|
-
const { apiVersion, appInfo, groupOverrides, secretKey, webhooks, webhookSecret } = props
|
|
51
|
-
const label = props?.label || 'Stripe'
|
|
52
|
-
|
|
53
|
-
const baseFields: Field[] = [
|
|
54
|
-
{
|
|
55
|
-
name: 'customerID',
|
|
56
|
-
type: 'text',
|
|
57
|
-
label: 'Stripe Customer ID',
|
|
58
|
-
},
|
|
59
|
-
{
|
|
60
|
-
name: 'paymentIntentID',
|
|
61
|
-
type: 'text',
|
|
62
|
-
label: 'Stripe PaymentIntent ID',
|
|
63
|
-
},
|
|
64
|
-
]
|
|
65
|
-
|
|
66
|
-
const groupField: GroupField = {
|
|
67
|
-
name: 'stripe',
|
|
68
|
-
type: 'group',
|
|
69
|
-
...groupOverrides,
|
|
70
|
-
admin: {
|
|
71
|
-
condition: (data) => {
|
|
72
|
-
const path = 'paymentMethod'
|
|
73
|
-
|
|
74
|
-
return data?.[path] === 'stripe'
|
|
75
|
-
},
|
|
76
|
-
...groupOverrides?.admin,
|
|
77
|
-
},
|
|
78
|
-
fields:
|
|
79
|
-
groupOverrides?.fields && typeof groupOverrides?.fields === 'function'
|
|
80
|
-
? groupOverrides.fields({ defaultFields: baseFields })
|
|
81
|
-
: baseFields,
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
return {
|
|
85
|
-
name: 'stripe',
|
|
86
|
-
confirmOrder: confirmOrder({
|
|
87
|
-
apiVersion,
|
|
88
|
-
appInfo,
|
|
89
|
-
secretKey,
|
|
90
|
-
}),
|
|
91
|
-
endpoints: [webhooksEndpoint({ apiVersion, appInfo, secretKey, webhooks, webhookSecret })],
|
|
92
|
-
group: groupField,
|
|
93
|
-
initiatePayment: initiatePayment({
|
|
94
|
-
apiVersion,
|
|
95
|
-
appInfo,
|
|
96
|
-
secretKey,
|
|
97
|
-
}),
|
|
98
|
-
label,
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
export type StripeAdapterClientArgs = {
|
|
103
|
-
/**
|
|
104
|
-
* This library's types only reflect the latest API version.
|
|
105
|
-
*
|
|
106
|
-
* We recommend upgrading your account's API Version to the latest version
|
|
107
|
-
* if you wish to use TypeScript with this library.
|
|
108
|
-
*
|
|
109
|
-
* If you wish to remain on your account's default API version,
|
|
110
|
-
* you may pass `null` or another version instead of the latest version,
|
|
111
|
-
* and add a `@ts-ignore` comment here and anywhere the types differ between API versions.
|
|
112
|
-
*
|
|
113
|
-
* @docs https://stripe.com/docs/api/versioning
|
|
114
|
-
*/
|
|
115
|
-
apiVersion?: Stripe.StripeConfig['apiVersion']
|
|
116
|
-
appInfo?: Stripe.StripeConfig['appInfo']
|
|
117
|
-
publishableKey: string
|
|
118
|
-
} & BasePaymentAdapterClientArgs
|
|
119
|
-
|
|
120
|
-
export const stripeAdapterClient: (props: StripeAdapterClientArgs) => PaymentAdapterClient = (
|
|
121
|
-
props,
|
|
122
|
-
) => {
|
|
123
|
-
return {
|
|
124
|
-
name: 'stripe',
|
|
125
|
-
confirmOrder: true,
|
|
126
|
-
initiatePayment: true,
|
|
127
|
-
label: 'Card',
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
export type InitiatePaymentReturnType = {
|
|
132
|
-
clientSecret: string
|
|
133
|
-
message: string
|
|
134
|
-
paymentIntentID: string
|
|
135
|
-
}
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
import Stripe from 'stripe'
|
|
2
|
-
|
|
3
|
-
import type { PaymentAdapter } from '../../../types.js'
|
|
4
|
-
import type { InitiatePaymentReturnType, StripeAdapterArgs } from './index.js'
|
|
5
|
-
|
|
6
|
-
type Props = {
|
|
7
|
-
apiVersion?: Stripe.StripeConfig['apiVersion']
|
|
8
|
-
appInfo?: Stripe.StripeConfig['appInfo']
|
|
9
|
-
secretKey: StripeAdapterArgs['secretKey']
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export const initiatePayment: (props: Props) => NonNullable<PaymentAdapter>['initiatePayment'] =
|
|
13
|
-
(props) =>
|
|
14
|
-
async ({ data, req, transactionsSlug }) => {
|
|
15
|
-
const payload = req.payload
|
|
16
|
-
const { apiVersion, appInfo, secretKey } = props || {}
|
|
17
|
-
|
|
18
|
-
const customerEmail = data.customerEmail
|
|
19
|
-
const currency = data.currency
|
|
20
|
-
const cart = data.cart
|
|
21
|
-
const amount = cart.subtotal
|
|
22
|
-
const billingAddressFromData = data.billingAddress
|
|
23
|
-
const shippingAddressFromData = data.shippingAddress
|
|
24
|
-
|
|
25
|
-
if (!secretKey) {
|
|
26
|
-
throw new Error('Stripe secret key is required.')
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
if (!currency) {
|
|
30
|
-
throw new Error('Currency is required.')
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
if (!cart || !cart.items || cart.items.length === 0) {
|
|
34
|
-
throw new Error('Cart is empty or not provided.')
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
if (!customerEmail || typeof customerEmail !== 'string') {
|
|
38
|
-
throw new Error('A valid customer email is required to make a purchase.')
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
if (!amount || typeof amount !== 'number' || amount <= 0) {
|
|
42
|
-
throw new Error('A valid amount is required to initiate a payment.')
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const stripe = new Stripe(secretKey, {
|
|
46
|
-
// API version can only be the latest, stripe recommends ts ignoring it
|
|
47
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
48
|
-
// @ts-ignore - ignoring since possible versions are not type safe, only the latest version is recognised
|
|
49
|
-
apiVersion: apiVersion || '2025-06-30.preview',
|
|
50
|
-
appInfo: appInfo || {
|
|
51
|
-
name: 'Stripe Payload Plugin',
|
|
52
|
-
url: 'https://payloadcms.com',
|
|
53
|
-
},
|
|
54
|
-
})
|
|
55
|
-
|
|
56
|
-
try {
|
|
57
|
-
let customer = (
|
|
58
|
-
await stripe.customers.list({
|
|
59
|
-
email: customerEmail,
|
|
60
|
-
})
|
|
61
|
-
).data[0]
|
|
62
|
-
|
|
63
|
-
if (!customer?.id) {
|
|
64
|
-
customer = await stripe.customers.create({
|
|
65
|
-
email: customerEmail,
|
|
66
|
-
})
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const flattenedCart = cart.items.map((item) => {
|
|
70
|
-
const productID = typeof item.product === 'object' ? item.product.id : item.product
|
|
71
|
-
const variantID = item.variant
|
|
72
|
-
? typeof item.variant === 'object'
|
|
73
|
-
? item.variant.id
|
|
74
|
-
: item.variant
|
|
75
|
-
: undefined
|
|
76
|
-
|
|
77
|
-
return {
|
|
78
|
-
product: productID,
|
|
79
|
-
quantity: item.quantity,
|
|
80
|
-
variant: variantID,
|
|
81
|
-
}
|
|
82
|
-
})
|
|
83
|
-
|
|
84
|
-
const shippingAddressAsString = JSON.stringify(shippingAddressFromData)
|
|
85
|
-
|
|
86
|
-
const paymentIntent = await stripe.paymentIntents.create({
|
|
87
|
-
amount,
|
|
88
|
-
automatic_payment_methods: {
|
|
89
|
-
enabled: true,
|
|
90
|
-
},
|
|
91
|
-
currency,
|
|
92
|
-
customer: customer.id,
|
|
93
|
-
metadata: {
|
|
94
|
-
cartID: cart.id,
|
|
95
|
-
cartItemsSnapshot: JSON.stringify(flattenedCart),
|
|
96
|
-
shippingAddress: shippingAddressAsString,
|
|
97
|
-
},
|
|
98
|
-
})
|
|
99
|
-
|
|
100
|
-
// Create a transaction for the payment intent in the database
|
|
101
|
-
const transaction = await payload.create({
|
|
102
|
-
collection: transactionsSlug,
|
|
103
|
-
data: {
|
|
104
|
-
...(req.user ? { customer: req.user.id } : { customerEmail }),
|
|
105
|
-
amount: paymentIntent.amount,
|
|
106
|
-
billingAddress: billingAddressFromData,
|
|
107
|
-
cart: cart.id,
|
|
108
|
-
currency: paymentIntent.currency.toUpperCase(),
|
|
109
|
-
items: flattenedCart,
|
|
110
|
-
paymentMethod: 'stripe',
|
|
111
|
-
status: 'pending',
|
|
112
|
-
stripe: {
|
|
113
|
-
customerID: customer.id,
|
|
114
|
-
paymentIntentID: paymentIntent.id,
|
|
115
|
-
},
|
|
116
|
-
},
|
|
117
|
-
})
|
|
118
|
-
|
|
119
|
-
const returnData: InitiatePaymentReturnType = {
|
|
120
|
-
clientSecret: paymentIntent.client_secret || '',
|
|
121
|
-
message: 'Payment initiated successfully',
|
|
122
|
-
paymentIntentID: paymentIntent.id,
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
return returnData
|
|
126
|
-
} catch (error) {
|
|
127
|
-
payload.logger.error(error, 'Error initiating payment with Stripe')
|
|
128
|
-
|
|
129
|
-
throw new Error(error instanceof Error ? error.message : 'Unknown error initiating payment')
|
|
130
|
-
}
|
|
131
|
-
}
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import type { CollectionConfig, Field } from 'payload'
|
|
2
|
-
|
|
3
|
-
import type { CurrenciesConfig, FieldsOverride, InventoryConfig } from '../types.js'
|
|
4
|
-
|
|
5
|
-
import { inventoryField } from '../fields/inventoryField.js'
|
|
6
|
-
import { pricesField } from '../fields/pricesField.js'
|
|
7
|
-
import { variantsFields } from '../fields/variantsFields.js'
|
|
8
|
-
|
|
9
|
-
type Props = {
|
|
10
|
-
currenciesConfig: CurrenciesConfig
|
|
11
|
-
enableVariants?: boolean
|
|
12
|
-
/**
|
|
13
|
-
* Adds in an inventory field to the product and its variants. This is useful for tracking inventory levels.
|
|
14
|
-
* Defaults to true.
|
|
15
|
-
*/
|
|
16
|
-
inventory?: boolean | InventoryConfig
|
|
17
|
-
overrides?: { fields?: FieldsOverride } & Partial<Omit<CollectionConfig, 'fields'>>
|
|
18
|
-
/**
|
|
19
|
-
* Slug of the variants collection, defaults to 'variants'.
|
|
20
|
-
*/
|
|
21
|
-
variantsSlug?: string
|
|
22
|
-
/**
|
|
23
|
-
* Slug of the variant types collection, defaults to 'variantTypes'.
|
|
24
|
-
*/
|
|
25
|
-
variantTypesSlug?: string
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export const productsCollection: (props: Props) => CollectionConfig = (props) => {
|
|
29
|
-
const {
|
|
30
|
-
currenciesConfig,
|
|
31
|
-
enableVariants = false,
|
|
32
|
-
inventory = true,
|
|
33
|
-
overrides,
|
|
34
|
-
variantsSlug = 'variants',
|
|
35
|
-
variantTypesSlug = 'variantTypes',
|
|
36
|
-
} = props || {}
|
|
37
|
-
const fieldsOverride = overrides?.fields
|
|
38
|
-
|
|
39
|
-
const defaultFields: Field[] = [
|
|
40
|
-
...(inventory
|
|
41
|
-
? [
|
|
42
|
-
inventoryField({
|
|
43
|
-
overrides: {
|
|
44
|
-
admin: {
|
|
45
|
-
condition: ({ enableVariants }) => !enableVariants,
|
|
46
|
-
},
|
|
47
|
-
},
|
|
48
|
-
}),
|
|
49
|
-
]
|
|
50
|
-
: []),
|
|
51
|
-
]
|
|
52
|
-
|
|
53
|
-
const baseFields = [
|
|
54
|
-
...defaultFields,
|
|
55
|
-
...(enableVariants ? variantsFields({ variantsSlug, variantTypesSlug }) : []),
|
|
56
|
-
...(currenciesConfig ? [...pricesField({ currenciesConfig })] : []),
|
|
57
|
-
]
|
|
58
|
-
|
|
59
|
-
const fields =
|
|
60
|
-
fieldsOverride && typeof fieldsOverride === 'function'
|
|
61
|
-
? fieldsOverride({ defaultFields: baseFields })
|
|
62
|
-
: baseFields
|
|
63
|
-
|
|
64
|
-
const baseConfig: CollectionConfig = {
|
|
65
|
-
slug: 'products',
|
|
66
|
-
...overrides,
|
|
67
|
-
admin: {
|
|
68
|
-
defaultColumns: [
|
|
69
|
-
...(currenciesConfig ? ['prices'] : []),
|
|
70
|
-
...(enableVariants ? ['variants'] : []),
|
|
71
|
-
],
|
|
72
|
-
...overrides?.admin,
|
|
73
|
-
},
|
|
74
|
-
fields,
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return { ...baseConfig }
|
|
78
|
-
}
|