Skip to content

Commit 74799ea

Browse files
authored
fix(plugin-ecommerce): pass req to Payload API calls in Stripe adapter (#15839)
### What? Adds the missing `req` parameter to all `payload.find()`, `payload.create()`, and `payload.update()` calls in the Stripe adapter's `confirmOrder.ts` and `initiatePayment.ts`. ### Why? Without `req`, hooks on transactions/orders/carts receive an empty request context, and each database call runs in an isolated session — breaking transactional consistency (e.g. order created but cart not marked as purchased on failure). ### How? Pass the existing `req` (already available in scope) to each Payload API call. Also fixes `payload.logger.error` calls to use the correct object form per project conventions. Fixes #15836
1 parent ee083f0 commit 74799ea

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

packages/plugin-ecommerce/src/payments/adapters/stripe/confirmOrder.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export const confirmOrder: (props: Props) => NonNullable<PaymentAdapter>['confir
6060
// Find our existing transaction by the payment intent ID
6161
const transactionsResults = await payload.find({
6262
collection: transactionsSlug,
63+
req,
6364
where: {
6465
'stripe.paymentIntentID': {
6566
equals: paymentIntentID,
@@ -104,6 +105,7 @@ export const confirmOrder: (props: Props) => NonNullable<PaymentAdapter>['confir
104105
status: 'processing',
105106
transactions: [transaction.id],
106107
},
108+
req,
107109
})
108110

109111
const timestamp = new Date().toISOString()
@@ -114,6 +116,7 @@ export const confirmOrder: (props: Props) => NonNullable<PaymentAdapter>['confir
114116
data: {
115117
purchasedAt: timestamp,
116118
},
119+
req,
117120
})
118121

119122
await payload.update({
@@ -123,6 +126,7 @@ export const confirmOrder: (props: Props) => NonNullable<PaymentAdapter>['confir
123126
order: order.id,
124127
status: 'succeeded',
125128
},
129+
req,
126130
})
127131

128132
return {
@@ -132,7 +136,7 @@ export const confirmOrder: (props: Props) => NonNullable<PaymentAdapter>['confir
132136
...(order.accessToken ? { accessToken: order.accessToken } : {}),
133137
}
134138
} catch (error) {
135-
payload.logger.error(error, 'Error initiating payment with Stripe')
139+
payload.logger.error({ err: error, msg: 'Error confirming order with Stripe' })
136140

137141
throw new Error(error instanceof Error ? error.message : 'Unknown error initiating payment')
138142
}

packages/plugin-ecommerce/src/payments/adapters/stripe/initiatePayment.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ export const initiatePayment: (props: Props) => NonNullable<PaymentAdapter>['ini
119119
paymentIntentID: paymentIntent.id,
120120
},
121121
},
122+
req,
122123
})
123124

124125
const returnData: InitiatePaymentReturnType = {
@@ -129,7 +130,7 @@ export const initiatePayment: (props: Props) => NonNullable<PaymentAdapter>['ini
129130

130131
return returnData
131132
} catch (error) {
132-
payload.logger.error(error, 'Error initiating payment with Stripe')
133+
payload.logger.error({ err: error, msg: 'Error initiating payment with Stripe' })
133134

134135
throw new Error(error instanceof Error ? error.message : 'Unknown error initiating payment')
135136
}

0 commit comments

Comments
 (0)