Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/plugin-ecommerce/src/endpoints/confirmOrder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const confirmOrderHandler: ConfirmOrderHandler =

const data = req.data
const payload = req.payload
const user = req.user
const user = req.user?.collection === customersSlug ? req.user : undefined

let currency: string = currenciesConfig.defaultCurrency
let cartID: DefaultDocumentIDType = data?.cartID
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-ecommerce/src/endpoints/initiatePayment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export const initiatePaymentHandler: InitiatePayment =
await addDataAndFileToRequest(req)
const data = req.data
const payload = req.payload
const user = req.user
const user = req.user?.collection === customersSlug ? req.user : undefined

let currency: string = currenciesConfig.defaultCurrency
let cartID: DefaultDocumentIDType = data?.cartID
Expand Down
2 changes: 2 additions & 0 deletions packages/plugin-ecommerce/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,9 @@ export const ecommercePlugin =

const initiatePayment: Endpoint = {
handler: initiatePaymentHandler({
cartsSlug: collectionSlugMap.carts,
currenciesConfig,
customersSlug: collectionSlugMap.customers,
inventory: sanitizedPluginConfig.inventory,
paymentMethod,
productsSlug: collectionSlugMap.products,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const confirmOrder: (props: Props) => NonNullable<PaymentAdapter>['confir
(props) =>
async ({
cartsSlug = 'carts',
customersSlug = 'users',
data,
ordersSlug = 'orders',
req,
Expand Down Expand Up @@ -102,7 +103,9 @@ export const confirmOrder: (props: Props) => NonNullable<PaymentAdapter>['confir
data: {
amount: paymentIntent.amount,
currency: paymentIntent.currency.toUpperCase(),
...(req.user ? { customer: req.user.id } : { customerEmail }),
...(req.user?.collection === customersSlug
? { customer: req.user.id }
: { customerEmail }),
items: cartItemsSnapshot,
shippingAddress,
status: 'processing',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type Props = {

export const initiatePayment: (props: Props) => NonNullable<PaymentAdapter>['initiatePayment'] =
(props) =>
async ({ data, req, transactionsSlug }) => {
async ({ customersSlug = 'users', data, req, transactionsSlug }) => {
const payload = req.payload
const { apiVersion, appInfo, secretKey } = props || {}

Expand Down Expand Up @@ -106,7 +106,9 @@ export const initiatePayment: (props: Props) => NonNullable<PaymentAdapter>['ini
const transaction = await payload.create({
collection: transactionsSlug,
data: {
...(req.user ? { customer: req.user.id } : { customerEmail }),
...(req.user?.collection === customersSlug
? { customer: req.user.id }
: { customerEmail }),
amount: paymentIntent.amount,
billingAddress: billingAddressFromData,
cart: cart.id,
Expand Down
Loading