-
Notifications
You must be signed in to change notification settings - Fork 212
Expand file tree
/
Copy pathone-click-payment.jsx
More file actions
685 lines (638 loc) · 30.7 KB
/
one-click-payment.jsx
File metadata and controls
685 lines (638 loc) · 30.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
/*
* Copyright (c) 2021, salesforce.com, inc.
* All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import React, {useState, useEffect, useRef, useCallback} from 'react'
import PropTypes from 'prop-types'
import {defineMessage, FormattedMessage, useIntl} from 'react-intl'
import {
Box,
Checkbox,
Heading,
Stack,
Text,
Divider
} from '@salesforce/retail-react-app/app/components/shared/ui'
import {useToast} from '@salesforce/retail-react-app/app/hooks/use-toast'
import {useShopperBasketsMutation, useCustomerType} from '@salesforce/commerce-sdk-react'
import {useCurrentBasket} from '@salesforce/retail-react-app/app/hooks/use-current-basket'
import {useCurrentCustomer} from '@salesforce/retail-react-app/app/hooks/use-current-customer'
import {useCheckout} from '@salesforce/retail-react-app/app/pages/checkout-one-click/util/checkout-context'
import {
getPaymentInstrumentCardType,
getMaskCreditCardNumber,
getCreditCardIcon
} from '@salesforce/retail-react-app/app/utils/cc-utils'
import {
ToggleCard,
ToggleCardEdit,
ToggleCardSummary
} from '@salesforce/retail-react-app/app/components/toggle-card'
import PaymentForm from '@salesforce/retail-react-app/app/pages/checkout-one-click/partials/one-click-payment-form'
import ShippingAddressSelection from '@salesforce/retail-react-app/app/pages/checkout-one-click/partials/one-click-shipping-address-selection'
import UserRegistration from '@salesforce/retail-react-app/app/pages/checkout-one-click/partials/one-click-user-registration'
import SavePaymentMethod from '@salesforce/retail-react-app/app/pages/checkout-one-click/partials/one-click-save-payment-method'
import AddressDisplay from '@salesforce/retail-react-app/app/components/address-display'
import {PromoCode, usePromoCode} from '@salesforce/retail-react-app/app/components/promo-code'
import {API_ERROR_MESSAGE} from '@salesforce/retail-react-app/app/constants'
import {FormattedNumber} from 'react-intl'
import {useCurrency} from '@salesforce/retail-react-app/app/hooks'
import {isPickupShipment} from '@salesforce/retail-react-app/app/utils/shipment-utils'
const Payment = ({
paymentMethodForm,
billingAddressForm,
enableUserRegistration,
setEnableUserRegistration,
registeredUserChoseGuest = false,
onSavePreferenceChange,
onPaymentSubmitted,
selectedPaymentMethod,
isEditing,
onSelectedPaymentMethodChange,
onIsEditingChange,
billingSameAsShipping,
setBillingSameAsShipping,
onOtpLoadingChange,
onBillingSubmit
}) => {
const {formatMessage} = useIntl()
const {data: basketForTotal} = useCurrentBasket()
const {currency} = useCurrency()
const currentBasketQuery = useCurrentBasket()
const {data: basket} = currentBasketQuery
const {data: customer, isLoading: isCustomerLoading} = useCurrentCustomer()
const {isGuest} = useCustomerType()
const selectedBillingAddress = basket?.billingAddress
const appliedPayment = basket?.paymentInstruments && basket?.paymentInstruments[0]
// Track current form values to detect new payment instruments in real-time
const [currentFormPayment, setCurrentFormPayment] = useState(null)
// Track whether user wants to save the payment method
const [shouldSavePaymentMethod, setShouldSavePaymentMethod] = useState(false)
const [isApplyingSavedPayment, setIsApplyingSavedPayment] = useState(false)
const activeBasketIdRef = useRef(null)
// Use props for parent-managed state with fallback defaults
const currentSelectedPaymentMethod =
selectedPaymentMethod ?? (appliedPayment?.customerPaymentInstrumentId || 'cc')
const currentIsEditing = isEditing ?? false
// Callback when user changes save preference
const handleSavePreferenceChange = (shouldSave) => {
setShouldSavePaymentMethod(shouldSave)
}
// Function to update current form payment data
const updateCurrentFormPayment = (formData) => {
if (formData?.number && formData?.holder && formData?.expiry) {
const [expirationMonth, expirationYear] = formData.expiry.split('/')
const paymentData = {
paymentMethodId: 'CREDIT_CARD',
paymentCard: {
holder: formData.holder,
numberLastDigits: formData.number.slice(-4),
cardType: formData.cardType,
expirationMonth: parseInt(expirationMonth),
expirationYear: parseInt(`20${expirationYear}`)
}
}
setCurrentFormPayment(paymentData)
} else {
setCurrentFormPayment(null)
}
}
// Watch form values in real-time to detect new payment instruments
useEffect(() => {
if (paymentMethodForm && !isGuest) {
const subscription = paymentMethodForm.watch((value) => {
updateCurrentFormPayment(value)
})
return () => subscription.unsubscribe()
}
}, [paymentMethodForm, isGuest])
// Notify parent when save preference changes
useEffect(() => {
if (onSavePreferenceChange) {
onSavePreferenceChange(shouldSavePaymentMethod)
}
}, [shouldSavePaymentMethod, onSavePreferenceChange])
// Handles user registration checkbox toggle (OTP handled by UserRegistration)
const onUserRegistrationToggle = async (checked) => {
setEnableUserRegistration(checked)
if (checked && isGuest) {
// Default preferences for newly registering guest
setShouldSavePaymentMethod(true)
}
}
// Determine shipment composition (pickup-only vs mixed/delivery), considering only shipments with items
const shipments = basket?.shipments || []
const items = basket?.productItems || []
const shipmentsWithItems = shipments.filter((s) =>
items.some((i) => i.shipmentId === s.shipmentId)
)
const hasPickupShipments = shipmentsWithItems.some((s) => isPickupShipment(s))
const hasDeliveryShipments = shipmentsWithItems.some((s) => !isPickupShipment(s))
const isPickupOnly = hasPickupShipments && !hasDeliveryShipments
const effectiveBillingSameAsShipping = isPickupOnly ? false : billingSameAsShipping
// For billing=shipping, align with legacy checkout. use the first delivery shipment's address
const selectedShippingAddress = React.useMemo(() => {
if (!shipmentsWithItems.length || isPickupOnly) return null
const deliveryShipment = shipmentsWithItems.find((s) => !isPickupShipment(s))
return deliveryShipment?.shippingAddress || null
}, [shipmentsWithItems, isPickupOnly])
const {mutateAsync: addPaymentInstrumentToBasket} = useShopperBasketsMutation(
'addPaymentInstrumentToBasket'
)
const {mutateAsync: updateBillingAddressForBasket} = useShopperBasketsMutation(
'updateBillingAddressForBasket'
)
const {mutateAsync: removePaymentInstrumentFromBasket} = useShopperBasketsMutation(
'removePaymentInstrumentFromBasket'
)
const showToast = useToast()
const showError = (message) => {
showToast({
title: message || formatMessage(API_ERROR_MESSAGE),
status: 'error'
})
}
const {step, STEPS, goToStep} = useCheckout()
// Using destructuring to remove properties from the object...
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const {removePromoCode, ...promoCodeProps} = usePromoCode()
// Ensure saved payment radio is selected when an applied payment exists but lacks a customerPaymentInstrumentId.
// We match by last 4 and card type to find the corresponding saved instrument and select it.
useEffect(() => {
if (step !== STEPS.PAYMENT) return
if (currentIsEditing) return
if (!appliedPayment) return
// If already selected to a saved instrument, nothing to do
if (currentSelectedPaymentMethod && currentSelectedPaymentMethod !== 'cc') return
// If the applied payment references a saved instrument id, nothing to do
if (appliedPayment.customerPaymentInstrumentId) return
const last4 = appliedPayment?.paymentCard?.numberLastDigits
const type = appliedPayment?.paymentCard?.cardType
if (!last4 || !type) return
const match = customer?.paymentInstruments?.find(
(pi) =>
pi?.paymentCard?.numberLastDigits === last4 &&
String(pi?.paymentCard?.cardType || '').toLowerCase() ===
String(type || '').toLowerCase()
)
if (match?.paymentInstrumentId) {
onSelectedPaymentMethodChange?.(match.paymentInstrumentId)
}
}, [
step,
STEPS.PAYMENT,
currentIsEditing,
appliedPayment,
currentSelectedPaymentMethod,
customer?.paymentInstruments,
onSelectedPaymentMethodChange
])
const onPaymentSubmit = async (formValue, forcedBasketId) => {
// The form gives us the expiration date as `MM/YY` - so we need to split it into
// month and year to submit them as individual fields.
const [expirationMonth, expirationYear] = formValue.expiry.split('/')
const paymentInstrument = {
amount: basket?.orderTotal || 0,
paymentMethodId: 'CREDIT_CARD',
paymentCard: {
holder: formValue.holder,
maskedNumber: getMaskCreditCardNumber(formValue.number),
cardType: getPaymentInstrumentCardType(formValue.cardType),
expirationMonth: parseInt(expirationMonth),
expirationYear: parseInt(`20${expirationYear}`)
}
}
// Notify parent component with full card details (before masking)
if (onPaymentSubmitted) {
onPaymentSubmitted(formValue)
}
return addPaymentInstrumentToBasket({
parameters: {basketId: forcedBasketId || activeBasketIdRef.current || basket?.basketId},
body: paymentInstrument
})
}
const [showRegistrationNotice, setShowRegistrationNotice] = useState(false)
const handleRegistrationSuccess = useCallback(
async (newBasketId) => {
if (newBasketId) {
activeBasketIdRef.current = newBasketId
}
setShowRegistrationNotice(true)
setShouldSavePaymentMethod(true)
showToast({
variant: 'subtle',
title: formatMessage({
defaultMessage: 'You are now signed in.',
id: 'auth_modal.description.now_signed_in_simple'
}),
status: 'success',
position: 'top-right',
isClosable: true
})
},
[showToast, formatMessage]
)
// Auto-select a saved payment instrument for registered customers (run at most once)
const autoAppliedRef = useRef(false)
useEffect(() => {
const autoSelectSavedPayment = async () => {
if (step !== STEPS.PAYMENT || isCustomerLoading) return
if (autoAppliedRef.current) return
// Don't auto-apply when in edit mode - user is manually entering/selecting payment
if (currentIsEditing) return
const isRegistered = customer?.isRegistered
const hasSaved = customer?.paymentInstruments?.length > 0
const alreadyApplied = (basket?.paymentInstruments?.length || 0) > 0
// If the shopper is currently typing a new card, skip auto-apply of saved
const entered = paymentMethodForm?.getValues?.()
const hasEnteredCard = entered?.number && entered?.holder && entered?.expiry
if (!isRegistered || !hasSaved || alreadyApplied || hasEnteredCard) return
autoAppliedRef.current = true
const preferred =
customer.paymentInstruments.find((pi) => pi.default === true) ||
customer.paymentInstruments[0]
try {
setIsApplyingSavedPayment(true)
await addPaymentInstrumentToBasket({
parameters: {basketId: activeBasketIdRef.current || basket?.basketId},
body: {
amount: basket?.orderTotal || 0,
paymentMethodId: 'CREDIT_CARD',
customerPaymentInstrumentId: preferred.paymentInstrumentId
}
})
if (isPickupOnly) {
try {
const saved = customer?.paymentInstruments?.find(
(pi) => pi.paymentInstrumentId === preferred.paymentInstrumentId
)
const addr = saved?.billingAddress
if (addr) {
const cleaned = {...addr}
delete cleaned.addressId
delete cleaned.creationDate
delete cleaned.lastModified
delete cleaned.preferred
await updateBillingAddressForBasket({
body: cleaned,
parameters: {basketId: activeBasketIdRef.current || basket.basketId}
})
}
} catch {
// ignore; user can enter billing manually
}
} else if (selectedShippingAddress) {
await onBillingSubmit()
// Ensure basket is refreshed with payment & billing
await currentBasketQuery.refetch()
// Stay on Payment; place-order button is rendered on Payment step in this flow
}
// Ensure basket is refreshed with payment & billing
await currentBasketQuery.refetch()
} catch (_e) {
// Ignore and allow manual selection
console.error(_e)
} finally {
setIsApplyingSavedPayment(false)
}
}
autoSelectSavedPayment()
}, [step, isCustomerLoading])
const onPaymentMethodChange = async (paymentInstrumentId) => {
// Only try to remove payment if there's actually an applied payment
if (appliedPayment) {
try {
await onPaymentRemoval()
} catch (_e) {
// Removal failed: inform user and do NOT proceed with payment change
showError(
formatMessage({
defaultMessage:
'Could not remove the applied payment. Please try again or use the current payment to place your order.',
id: 'checkout_payment.error.cannot_remove_applied_payment'
})
)
return
}
}
if (paymentInstrumentId === 'cc') {
onSelectedPaymentMethodChange?.('cc')
} else {
setIsApplyingSavedPayment(true)
await addPaymentInstrumentToBasket({
parameters: {basketId: activeBasketIdRef.current || basket?.basketId},
body: {
amount: basket?.orderTotal || 0,
paymentMethodId: 'CREDIT_CARD',
customerPaymentInstrumentId: paymentInstrumentId
}
})
await currentBasketQuery.refetch()
if (isPickupOnly) {
try {
const saved = customer?.paymentInstruments?.find(
(pi) => pi.paymentInstrumentId === paymentInstrumentId
)
const addr = saved?.billingAddress
if (addr) {
const cleaned = {...addr}
delete cleaned.addressId
delete cleaned.creationDate
delete cleaned.lastModified
delete cleaned.preferred
await updateBillingAddressForBasket({
body: cleaned,
parameters: {basketId: activeBasketIdRef.current || basket.basketId}
})
await currentBasketQuery.refetch()
}
} catch (_e) {
// Fail silently
}
}
setIsApplyingSavedPayment(false)
onSelectedPaymentMethodChange?.(paymentInstrumentId)
}
}
const onPaymentRemoval = async () => {
try {
await removePaymentInstrumentFromBasket({
parameters: {
basketId: activeBasketIdRef.current || basket.basketId,
paymentInstrumentId: appliedPayment.paymentInstrumentId
}
})
onSelectedPaymentMethodChange?.('cc')
} catch (e) {
showError()
throw e
}
}
const onSubmit = paymentMethodForm.handleSubmit(async (paymentFormValues) => {
try {
if (!appliedPayment) {
await onPaymentSubmit(paymentFormValues, activeBasketIdRef.current)
}
// Update billing address
await onBillingSubmit()
} catch (error) {
showError()
} finally {
onIsEditingChange?.(false)
}
})
const handleEditPayment = async () => {
// Prefer the customer's default saved instrument in edit mode. If none,
// fall back to the applied payment, then the first saved, then 'cc'.
const defaultSaved = customer?.paymentInstruments?.find((pi) => pi.default === true)
const preferredId =
defaultSaved?.paymentInstrumentId ||
appliedPayment?.customerPaymentInstrumentId ||
customer?.paymentInstruments?.[0]?.paymentInstrumentId ||
'cc'
onSelectedPaymentMethodChange?.(preferredId)
onIsEditingChange?.(true)
goToStep(STEPS.PAYMENT)
}
const billingAddressAriaLabel = defineMessage({
defaultMessage: 'Billing Address Form',
id: 'checkout_payment.label.billing_address_form'
})
try {
return (
<ToggleCard
id="step-3"
data-testid="payment-component"
title={formatMessage({
defaultMessage: 'Payment',
id: 'checkout_payment.title.payment'
})}
editing={
currentIsEditing ||
(step === STEPS.PAYMENT &&
(!appliedPayment || (isPickupOnly && !selectedBillingAddress?.address1)))
}
isLoading={
paymentMethodForm.formState.isSubmitting ||
billingAddressForm.formState.isSubmitting ||
isApplyingSavedPayment ||
(isCustomerLoading && !isGuest)
}
disabled={appliedPayment == null}
onEdit={handleEditPayment}
editLabel={formatMessage({
defaultMessage: 'Edit Payment Info',
id: 'toggle_card.action.editPaymentInfo'
})}
>
<ToggleCardEdit>
{!(customer?.isRegistered && isApplyingSavedPayment && !appliedPayment) ? (
<>
<Box mt={-2} mb={4}>
<Stack direction="row" justify="space-between" align="center">
<PromoCode {...promoCodeProps} itemProps={{border: 'none'}} />
<Text fontWeight="bold">
<FormattedNumber
value={basketForTotal?.orderTotal}
style="currency"
currency={currency}
/>
</Text>
</Stack>
</Box>
<Stack spacing={6}>
{isApplyingSavedPayment ? null : (
<PaymentForm
form={paymentMethodForm}
onSubmit={onSubmit}
savedPaymentInstruments={customer?.paymentInstruments || []}
onPaymentMethodChange={onPaymentMethodChange}
selectedPaymentMethod={currentSelectedPaymentMethod}
>
{/* Show for returning users (registered) while editing/adding a new card */}
{!isGuest && (
<SavePaymentMethod
paymentInstrument={currentFormPayment}
onSaved={handleSavePreferenceChange}
checked={shouldSavePaymentMethod}
/>
)}
</PaymentForm>
)}
<Divider borderColor="gray.100" />
<Stack spacing={2}>
<Heading as="h3" fontSize="md">
<FormattedMessage
defaultMessage="Billing Address"
id="checkout_payment.heading.billing_address"
/>
</Heading>
{!isPickupOnly && selectedShippingAddress && (
<Checkbox
name="billingSameAsShipping"
isChecked={effectiveBillingSameAsShipping}
onChange={(e) =>
setBillingSameAsShipping(e.target.checked)
}
>
<Text fontSize="sm" color="gray.700">
<FormattedMessage
defaultMessage="Same as shipping address"
id="checkout_payment.label.same_as_shipping"
/>
</Text>
</Checkbox>
)}
{effectiveBillingSameAsShipping && selectedShippingAddress && (
<Box pl={7}>
<AddressDisplay address={selectedShippingAddress} />
</Box>
)}
</Stack>
{!effectiveBillingSameAsShipping && (
<ShippingAddressSelection
form={billingAddressForm}
selectedAddress={selectedBillingAddress}
formTitleAriaLabel={billingAddressAriaLabel}
hideSubmitButton
isBillingAddress
/>
)}
{(isGuest || showRegistrationNotice) && (
<UserRegistration
enableUserRegistration={enableUserRegistration}
setEnableUserRegistration={onUserRegistrationToggle}
onLoadingChange={onOtpLoadingChange}
isGuestCheckout={registeredUserChoseGuest}
isDisabled={
!(
appliedPayment ||
paymentMethodForm.formState.isValid ||
(isPickupOnly &&
billingAddressForm.formState.isValid)
) ||
(!effectiveBillingSameAsShipping &&
!billingAddressForm.formState.isValid)
}
onSavePreferenceChange={onSavePreferenceChange}
onRegistered={handleRegistrationSuccess}
showNotice={showRegistrationNotice}
/>
)}
</Stack>
</>
) : null}
</ToggleCardEdit>
<ToggleCardSummary>
<Stack spacing={6}>
{appliedPayment && (
<Stack spacing={3}>
<Stack direction="row" justify="space-between" align="center">
<Heading as="h3" fontSize="md">
<FormattedMessage
defaultMessage="Credit Card"
id="checkout_payment.heading.credit_card"
/>
</Heading>
<Text fontWeight="bold">
<FormattedNumber
value={basketForTotal?.orderTotal}
style="currency"
currency={currency}
/>
</Text>
</Stack>
<PaymentCardSummary payment={appliedPayment} />
</Stack>
)}
<Divider borderColor="gray.100" />
{(selectedBillingAddress ||
(effectiveBillingSameAsShipping && selectedShippingAddress)) && (
<Stack spacing={2}>
<Heading as="h3" fontSize="md">
<FormattedMessage
defaultMessage="Billing Address"
id="checkout_payment.heading.billing_address"
/>
</Heading>
<AddressDisplay
address={selectedBillingAddress || selectedShippingAddress}
/>
</Stack>
)}
{(isGuest || showRegistrationNotice) && (
<UserRegistration
enableUserRegistration={enableUserRegistration}
setEnableUserRegistration={setEnableUserRegistration}
onLoadingChange={onOtpLoadingChange}
isGuestCheckout={registeredUserChoseGuest}
isDisabled={
(!appliedPayment && !paymentMethodForm.formState.isValid) ||
(!effectiveBillingSameAsShipping &&
!billingAddressForm.formState.isValid)
}
onSavePreferenceChange={onSavePreferenceChange}
onRegistered={handleRegistrationSuccess}
showNotice={showRegistrationNotice}
/>
)}
</Stack>
</ToggleCardSummary>
</ToggleCard>
)
} catch (error) {
console.error('🔍 Debug - Payment component render error:', error)
return <div>Error rendering payment component: {error.message}</div>
}
}
Payment.propTypes = {
/** Whether user registration is enabled */
enableUserRegistration: PropTypes.bool,
/** Callback to set user registration state */
setEnableUserRegistration: PropTypes.func,
/** Whether a registered user has chosen guest checkout */
registeredUserChoseGuest: PropTypes.bool,
/** Callback when save preference changes */
onSavePreferenceChange: PropTypes.func,
/** Callback when payment is submitted with full card details */
onPaymentSubmitted: PropTypes.func,
/** Selected payment method from parent */
selectedPaymentMethod: PropTypes.string,
/** Editing state from parent */
isEditing: PropTypes.bool,
/** Callback when selected payment method changes */
onSelectedPaymentMethodChange: PropTypes.func,
/** Callback when editing state changes */
onIsEditingChange: PropTypes.func,
/** Payment method form */
paymentMethodForm: PropTypes.object.isRequired,
/** Billing address form */
billingAddressForm: PropTypes.object.isRequired,
/** Whether billing address is same as shipping */
billingSameAsShipping: PropTypes.bool.isRequired,
/** Callback to set billing same as shipping state */
setBillingSameAsShipping: PropTypes.func.isRequired,
/** Callback when OTP loading state changes */
onOtpLoadingChange: PropTypes.func,
/** Callback to submit billing address */
onBillingSubmit: PropTypes.func.isRequired
}
const PaymentCardSummary = ({payment}) => {
const CardIcon = getCreditCardIcon(payment?.paymentCard?.cardType)
return (
<Stack direction="row" alignItems="center" spacing={3}>
{CardIcon && <CardIcon layerStyle="ccIcon" />}
<Stack direction="row">
<Text>{payment.paymentCard.cardType}</Text>
<Text>•••• {payment.paymentCard.numberLastDigits}</Text>
<Text>
{payment.paymentCard.expirationMonth}/{payment.paymentCard.expirationYear}
</Text>
</Stack>
</Stack>
)
}
PaymentCardSummary.propTypes = {payment: PropTypes.object}
export default Payment