Skip to content

Commit

Permalink
Check if the order is valid to be placed
Browse files Browse the repository at this point in the history
  • Loading branch information
acasazza committed Dec 11, 2024
1 parent 4084918 commit 2179158
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import PaymentCardsTemplate from '../utils/PaymentCardsTemplate'
import { jwt } from '#utils/jwt'
import getCardDetails from '#utils/getCardDetails'
import { getPaymentAttributes } from '#utils/getPaymentAttributes'
import { canPlaceOrder } from '#utils/canPlaceOrder'

type Props = GatewayBaseType

Expand All @@ -37,7 +38,7 @@ export function AdyenGateway(props: Props): JSX.Element | null {
useContext(PaymentMethodContext)
const paymentResource: PaymentResource = 'adyen_payments'
const locale = order?.language_code as StripeElementLocale
if (!readonly && payment?.id !== currentPaymentMethodId) return null
if (!readonly && payment?.id !== currentPaymentMethodId && order != null && !canPlaceOrder(order)) return null
// @ts-expect-error no type
const clientKey = paymentSource?.public_key
const environment = accessToken && jwt(accessToken).test ? 'test' : 'live'
Expand Down
4 changes: 4 additions & 0 deletions packages/react-components/src/reducers/ShipmentReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import { type CommerceLayerConfig } from '#context/CommerceLayerContext'
import { type getOrderContext } from './OrderReducer'
import getSdk from '#utils/getSdk'
import { canPlaceOrder } from '#utils/canPlaceOrder'

export type ShipmentActionType =
| 'setErrors'
Expand Down Expand Up @@ -105,6 +106,9 @@ export async function setShippingMethod({
order
}: TSetShippingMethodParams): Promise<{ success: boolean; order?: Order }> {
try {
if (order != null && !canPlaceOrder(order)) {
return { success: false, order }
}
if (shippingMethodId) {
const sdk = getSdk(config)
await sdk.shipments.update({
Expand Down

0 comments on commit 2179158

Please sign in to comment.