Skip to content

Commit 026a5fe

Browse files
committed
W-21411273, W-21434212: Addressing comments
1 parent f13dda9 commit 026a5fe

File tree

4 files changed

+19
-20
lines changed

4 files changed

+19
-20
lines changed

packages/template-retail-react-app/app/hooks/use-current-customer.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,19 @@ import {useCustomer, useCustomerId, useCustomerType} from '@salesforce/commerce-
1010
/**
1111
* A hook that returns the current customer.
1212
* @param {Array<string>} [expand] - Optional array of fields to expand in the customer query
13+
* @param {Object} [queryOptions] - Optional React Query options
1314
*/
14-
export const useCurrentCustomer = (expand) => {
15+
export const useCurrentCustomer = (expand, queryOptions = {}) => {
1516
const customerId = useCustomerId()
1617
const {isRegistered, isGuest, customerType} = useCustomerType()
1718
const parameters = {
1819
customerId,
1920
...(expand && {expand})
2021
}
21-
const query = useCustomer({parameters}, {enabled: !!customerId && isRegistered})
22+
const query = useCustomer(
23+
{parameters},
24+
{enabled: !!customerId && isRegistered, ...queryOptions}
25+
)
2226
const value = {
2327
...query,
2428
data: {

packages/template-retail-react-app/app/pages/checkout/partials/sf-payments-sheet.events.test.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -425,9 +425,8 @@ describe('SFPaymentsSheet - SDK Event Handler Tests', () => {
425425
const updateCall = mockUpdatePaymentInstrument.mock.calls[0]
426426
const requestBody = updateCall[0].body
427427

428-
expect(
429-
requestBody.paymentReferenceRequest.gatewayProperties?.stripe?.setupFutureUsage
430-
).toBeUndefined()
428+
expect(requestBody.paymentReferenceRequest.gateway).toBeUndefined()
429+
expect(requestBody.paymentReferenceRequest.gatewayProperties).toBeUndefined()
431430
})
432431

433432
test('handlePaymentButtonApprove includes required fields for PaymentsCustomer record creation', async () => {
@@ -452,9 +451,9 @@ describe('SFPaymentsSheet - SDK Event Handler Tests', () => {
452451
expect(requestParams.orderNo).toBe('ORDER123')
453452
expect(requestParams.paymentInstrumentId).toBe('PI123')
454453
expect(requestBody.paymentReferenceRequest.gateway).toBe('stripe')
455-
expect(requestBody.paymentReferenceRequest.gatewayProperties.stripe.setupFutureUsage).toBe(
456-
'on_session'
457-
)
454+
expect(requestBody.paymentReferenceRequest.gatewayProperties.stripe).toEqual({
455+
setupFutureUsage: 'on_session'
456+
})
458457
expect(requestBody.paymentReferenceRequest.paymentMethodType).toBe('card')
459458
})
460459

packages/template-retail-react-app/app/utils/sf-payments-utils.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -250,17 +250,13 @@ export const createPaymentInstrumentBody = ({
250250
}
251251
}
252252

253-
if (!isPostRequest && gateway === PAYMENT_GATEWAYS.STRIPE) {
254-
const setupFutureUsage = storePaymentMethod
255-
? futureUsageOffSession
256-
? SETUP_FUTURE_USAGE.OFF_SESSION
257-
: SETUP_FUTURE_USAGE.ON_SESSION
258-
: null
253+
if (!isPostRequest && gateway === PAYMENT_GATEWAYS.STRIPE && storePaymentMethod) {
254+
const setupFutureUsage = futureUsageOffSession
255+
? SETUP_FUTURE_USAGE.OFF_SESSION
256+
: SETUP_FUTURE_USAGE.ON_SESSION
259257
paymentReferenceRequest.gateway = PAYMENT_GATEWAYS.STRIPE
260258
paymentReferenceRequest.gatewayProperties = {
261-
stripe: {
262-
...(setupFutureUsage && {setupFutureUsage})
263-
}
259+
stripe: {setupFutureUsage}
264260
}
265261
}
266262

packages/template-retail-react-app/app/utils/sf-payments-utils.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,7 +1300,7 @@ describe('sf-payments-utils', () => {
13001300
})
13011301
})
13021302

1303-
test('includes Stripe gateway with empty stripe props when storePaymentMethod is false (no setupFutureUsage)', () => {
1303+
test('does not include Stripe gateway or gatewayProperties when storePaymentMethod is false (no setupFutureUsage)', () => {
13041304
const paymentMethods = [{paymentMethodType: 'card', accountId: 'acct_123'}]
13051305
const paymentMethodSetAccounts = [{vendor: 'Stripe', accountId: 'acct_123'}]
13061306
const result = createPaymentInstrumentBody({
@@ -1314,8 +1314,8 @@ describe('sf-payments-utils', () => {
13141314
paymentMethodSetAccounts
13151315
})
13161316

1317-
expect(result.paymentReferenceRequest.gateway).toBe('stripe')
1318-
expect(result.paymentReferenceRequest.gatewayProperties.stripe).toEqual({})
1317+
expect(result.paymentReferenceRequest.gateway).toBeUndefined()
1318+
expect(result.paymentReferenceRequest.gatewayProperties).toBeUndefined()
13191319
})
13201320

13211321
test('does not include shippingPreference when null', () => {

0 commit comments

Comments
 (0)