Skip to content

Fix load CKO configuration #632

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 15, 2025
Merged
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
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import CheckoutComPayment from '#components/payment_source/CheckoutComPayment'
import type { GatewayBaseType } from '#components/payment_gateways/PaymentGateway'
import CustomerContext from '#context/CustomerContext'
import OrderContext from '#context/OrderContext'
import PaymentMethodChildrenContext from '#context/PaymentMethodChildrenContext'
import PaymentMethodContext from '#context/PaymentMethodContext'
import PaymentSourceContext from '#context/PaymentSourceContext'
import CheckoutComPayment from "#components/payment_source/CheckoutComPayment"
import type { GatewayBaseType } from "#components/payment_gateways/PaymentGateway"
import CustomerContext from "#context/CustomerContext"
import OrderContext from "#context/OrderContext"
import PaymentMethodChildrenContext from "#context/PaymentMethodChildrenContext"
import PaymentMethodContext from "#context/PaymentMethodContext"
import PaymentSourceContext from "#context/PaymentSourceContext"
import {
getPaymentConfig,
type PaymentResource
} from '#reducers/PaymentMethodReducer'
import type { StripeElementLocale } from '@stripe/stripe-js'
import isEmpty from 'lodash/isEmpty'
import React, { type JSX } from 'react';
import PaymentCardsTemplate from '#components/utils/PaymentCardsTemplate'
import getCardDetails from '#utils/getCardDetails'
type PaymentResource,
} from "#reducers/PaymentMethodReducer"
import type { StripeElementLocale } from "@stripe/stripe-js"
import isEmpty from "lodash/isEmpty"
import React, { type JSX } from "react"
import PaymentCardsTemplate from "#components/utils/PaymentCardsTemplate"
import getCardDetails from "#utils/getCardDetails"

type Props = GatewayBaseType

Expand All @@ -35,14 +35,14 @@ export function CheckoutComGateway(props: Props): JSX.Element | null {
const { payments, isGuest } = React.useContext(CustomerContext)
const { currentPaymentMethodId, config, paymentSource } =
React.useContext(PaymentMethodContext)
const paymentResource: PaymentResource = 'checkout_com_payments'
const paymentResource: PaymentResource = "checkout_com_payments"
const locale = order?.language_code as StripeElementLocale

if (!readonly && payment?.id !== currentPaymentMethodId) return null
// @ts-expect-error no type
const publicKey = paymentSource?.public_key
const paymentConfig = config
? getPaymentConfig<'checkout_com_payments'>(paymentResource, config)
? getPaymentConfig<"checkout_com_payments">(paymentResource, config)
: {}
const customerPayments =
!isEmpty(payments) && payments
Expand All @@ -53,9 +53,9 @@ export function CheckoutComGateway(props: Props): JSX.Element | null {
if (readonly || showCard) {
const card = getCardDetails({
customerPayment: {
payment_source: paymentSource
payment_source: paymentSource,
},
paymentType: paymentResource
paymentType: paymentResource,
})
const value = { ...card, showCard, handleEditClick, readonly }
return !card.brand ? null : (
Expand All @@ -79,7 +79,7 @@ export function CheckoutComGateway(props: Props): JSX.Element | null {
templateCustomerSaveToWallet={templateCustomerSaveToWallet}
publicKey={publicKey}
locale={locale}
{...paymentConfig}
{...paymentConfig.checkoutComPayment}
/>
</>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,7 @@ export function CheckoutComPayment({
}: Props): JSX.Element | null {
const ref = useRef<null | HTMLFormElement>(null)
const loaded = useExternalScript(scriptUrl)
const {
setPaymentRef,
setPaymentSource,
// setPaymentMethodErrors,
} = useContext(PaymentMethodContext)
const { setPaymentRef, setPaymentSource } = useContext(PaymentMethodContext)
const { accessToken } = useContext(CommerceLayerContext)
const { order } = useContext(OrderContext)
// const { setPlaceOrder } = useContext(PlaceOrderContext)
Expand Down